:root {
  --gold: #c9a84c;
  --bg: #090909;
  --surface-1: #111111;
  --surface-2: #1a1a1a;
  --border: #303030;
  --text: #f2eee7;
  --muted: #8f877b;
  --muted-2: #b8afa2;
  --quiet: #6f685f;
  --danger: #b84e4e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}

body {
  font-family: "IBM Plex Mono", monospace;
}

body.help-open {
  overflow: hidden;
}

button,
textarea,
input {
  font: inherit;
}

.app-shell {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
}

.pull-refresh {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  z-index: 50;
  transform: translate(-50%, -48px);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(17, 17, 17, 0.96);
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.pull-refresh.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.pull-refresh.ready {
  border-color: var(--gold);
  color: var(--gold);
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 14px);
  background: rgba(0, 0, 0, 0.68);
}

.help-overlay[hidden] {
  display: none;
}

.paste-overlay {
  position: fixed;
  inset: 0;
  z-index: 88;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
}

.paste-overlay[hidden] {
  display: none;
}

.paste-panel {
  width: min(100%, 720px);
  max-height: calc(100dvh - max(24px, env(safe-area-inset-top, 0px)) - max(24px, env(safe-area-inset-bottom, 0px)));
  display: grid;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  padding: 14px;
  overflow: auto;
}

.paste-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.paste-title {
  margin: 4px 0 0;
  color: var(--text);
  font-family: "Bebas Neue", sans-serif;
  font-size: 32px;
  line-height: 1;
  letter-spacing: 0;
}

.paste-intro {
  margin: 0;
}

.paste-input {
  min-height: 210px;
  resize: vertical;
}

.paste-actions {
  margin-top: 0;
}

.paste-save-button {
  width: auto;
  min-width: 180px;
}

.help-panel {
  width: min(100%, 560px);
  max-height: min(78dvh, 720px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.98);
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.54);
}

.help-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.help-title {
  margin: 0;
  color: var(--text);
  font-family: "Bebas Neue", sans-serif;
  font-size: 34px;
  line-height: 0.95;
  letter-spacing: 0;
}

.help-intro {
  margin-bottom: 12px;
  color: var(--muted-2);
}

.help-list {
  display: grid;
  gap: 8px;
}

.help-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  padding: 10px;
}

.help-item h3 {
  margin: 0 0 5px;
  color: var(--text);
  font-family: "Bebas Neue", sans-serif;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 0;
}

.help-item p {
  margin: 0;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.4;
}

.topbar,
.footer-bar {
  position: sticky;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.topbar {
  top: 0;
  padding: 12px 16px;
  padding-top: max(12px, calc(env(safe-area-inset-top, 0px) + 12px));
  align-items: center;
  min-height: calc(58px + env(safe-area-inset-top, 0px));
}

.topbar-title {
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.save-state {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.version-code {
  margin-top: 2px;
  color: var(--quiet);
  font-size: 9px;
  line-height: 1.2;
  text-transform: uppercase;
}

.footer-bar {
  bottom: 0;
  border-top: 1px solid var(--border);
  border-bottom: none;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.screen {
  display: none;
  min-height: calc(100dvh - 68px);
}

.screen.active {
  display: block;
}

.section {
  padding: 16px 16px 84px;
}

.section.center {
  min-height: calc(100dvh - 68px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

.label,
.eyebrow {
  color: var(--gold);
  letter-spacing: 0;
  text-transform: uppercase;
}

.label {
  font-size: 10px;
  margin: 0 0 8px;
}

.eyebrow {
  font-family: "Bebas Neue", sans-serif;
  font-size: 24px;
  margin-bottom: 3px;
  letter-spacing: 0;
}

.week-range {
  font-size: 12px;
  color: var(--quiet);
  margin: 0;
}

.headline {
  font-family: "Bebas Neue", sans-serif;
  font-size: 46px;
  line-height: 0.95;
  letter-spacing: 0;
  margin: 0 0 10px;
}

.bank-snapshot {
  margin: -2px 0 10px;
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.45;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin: 0 0 14px;
}

.intro-copy {
  color: var(--muted-2);
}

.muted.compact {
  font-size: 12px;
  line-height: 1.5;
  margin-top: 0;
  margin-bottom: 0;
}

.status-card,
.how-card,
.memory-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 0 0 14px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  margin: 0 0 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--gold);
  flex: 0 0 auto;
}

.status-title {
  color: var(--gold);
  margin: 0 0 4px;
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-copy {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted-2);
}

.week-alert {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  margin: 0 0 12px;
  background: rgba(201, 168, 76, 0.1);
  border: 1px solid rgba(201, 168, 76, 0.35);
  border-radius: 8px;
}

.week-alert[hidden] {
  display: none;
}

.week-alert-warning {
  background: rgba(201, 168, 76, 0.14);
  border-color: rgba(201, 168, 76, 0.55);
}

.week-alert-title {
  margin: 0 0 3px;
  color: var(--gold);
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.week-alert-copy {
  margin: 0;
  color: var(--text);
  font-size: 11px;
  line-height: 1.35;
}

.week-alert-button {
  min-height: 42px;
  white-space: nowrap;
}

.upload-button,
.primary-button,
.secondary-button,
.ghost-button,
.chip,
.sleep-button {
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.upload-button {
  width: 100%;
  min-height: 54px;
  padding: 14px 12px;
  background: var(--text);
  border: 1px solid var(--text);
  color: var(--bg);
  font-family: "Bebas Neue", sans-serif;
  font-size: 21px;
  letter-spacing: 0;
}

.ingest-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.8fr) minmax(0, 0.8fr);
  gap: 10px;
  margin-bottom: 10px;
}

.ingest-button {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  padding-left: 10px;
  padding-right: 10px;
  font-size: 19px;
}

.ingest-guide {
  margin-top: 2px;
  margin-bottom: 10px;
  color: var(--muted);
}

.bank-control-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 10px;
}

.review-bank-button,
.receipt-toggle-button,
.week-tool-button {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding-left: 8px;
  padding-right: 8px;
  font-size: 17px;
}

.receipt-toggle-button {
  white-space: nowrap;
}

.receipt-toggle-button[hidden] {
  display: none;
}

.utility-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.result-actions {
  margin-top: 6px;
  margin-bottom: 82px;
}

.start-week-action {
  grid-column: 1 / -1;
}

.tool-button {
  min-width: 0;
  padding: 11px 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0;
}

.handoff-copy {
  margin-top: 8px;
  color: var(--muted);
}

.primary-button,
.secondary-button {
  padding: 14px 16px;
  font-family: "Bebas Neue", sans-serif;
  font-size: 22px;
  letter-spacing: 0;
  border: none;
}

.primary-button {
  width: 100%;
  flex: 1;
  background: var(--gold);
  color: #090909;
}

.primary-button:disabled {
  background: var(--surface-2);
  color: var(--quiet);
  cursor: not-allowed;
}

.secondary-button,
.ghost-button {
  background: transparent;
  color: var(--muted-2);
  border: 1px solid var(--border);
}

.ghost-button {
  padding: 9px 12px;
}

.ghost-button.small {
  padding: 7px 10px;
  font-size: 12px;
}

.ghost-button.saved {
  border-color: var(--gold);
  color: var(--gold);
}

.icon-button {
  width: 34px;
  min-width: 34px;
  padding-left: 0;
  padding-right: 0;
  text-align: center;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.thumb-grid[hidden] {
  display: none;
}

.advanced-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 12px 0 0;
  background: var(--surface-1);
}

.advanced-panel summary {
  cursor: pointer;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.4;
  list-style-position: inside;
}

.thumb-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-1);
  display: flex;
  flex-direction: column;
}

.thumb-media {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: zoom-in;
}

.thumb-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.text-receipt-card .thumb-media {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 12px;
  background: linear-gradient(135deg, #151515, #0c0c0c);
}

.text-receipt-preview {
  overflow: hidden;
  color: var(--muted-2);
  font-size: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: 100%;
}

.thumb-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.thumb-meta-row {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.thumb-source {
  display: block;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 8px;
}

.thumb-file-name {
  font-size: 10px;
  line-height: 1.35;
  color: var(--muted-2);
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-date-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.thumb-date-input {
  width: 100%;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

.thumb-date-input:focus {
  outline: none;
  border-color: var(--gold);
}

.thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.78);
  color: var(--text);
  cursor: pointer;
}

.danger-tool-button {
  border-color: rgba(192, 64, 64, 0.44);
  color: #d78a8a;
}

.question-block {
  margin-bottom: 18px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.field-label-row .label {
  margin: 0;
}

.field-dictate-button {
  min-width: 72px;
  white-space: nowrap;
}

.field-dictate-button.active {
  border-color: var(--gold);
  color: var(--gold);
}

.voice-body {
  padding-bottom: 96px;
}

.voice-status {
  margin-bottom: 14px;
}

.voice-screen.recording .voice-status,
.recording .voice-status {
  border-color: rgba(201, 168, 76, 0.5);
}

.recording .voice-status .status-dot {
  box-shadow: 0 0 0 6px rgba(201, 168, 76, 0.14);
}

.voice-note-input {
  min-height: 260px;
}

.voice-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, 0.45fr);
  gap: 10px;
  margin-top: 10px;
}

.chip-row,
.sleep-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted-2);
}

.chip.active,
.sleep-button.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 168, 76, 0.12);
}

.sleep-button {
  flex: 0 1 auto;
  min-width: 82px;
  padding: 12px 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted-2);
}

.text-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  color: var(--text);
  line-height: 1.7;
}

.text-input:focus {
  outline: none;
  border-color: var(--gold);
}

.suggested-card {
  margin-top: 8px;
}

.suggested-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted-2);
  display: grid;
  gap: 8px;
}

.suggested-list li {
  font-size: 13px;
  line-height: 1.6;
}

.result-subtitle-input {
  font-family: "Lora", serif;
  font-size: 18px;
  line-height: 1.5;
}

.result-body-input {
  min-height: 420px;
  font-family: "Lora", serif;
  font-size: 16px;
  line-height: 1.85;
  white-space: pre-wrap;
}

.result-toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.result-stats {
  margin: 0;
  text-align: right;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.result-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, calc(env(safe-area-inset-top, 0px) + 12px));
  min-height: calc(58px + env(safe-area-inset-top, 0px));
}

.result-body {
  padding-top: 20px;
}

.review-body {
  padding-top: 20px;
}

.review-list {
  display: grid;
  gap: 10px;
  padding-bottom: 86px;
}

.review-item {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  align-items: stretch;
  padding: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.review-media {
  min-height: 92px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
}

.review-media img {
  width: 100%;
  height: 100%;
  min-height: 92px;
  object-fit: cover;
  display: block;
}

.review-media-text {
  padding: 8px;
  color: var(--muted-2);
  font-size: 9px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.review-details {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.review-title {
  margin: 0;
  color: var(--gold);
  font-size: 10px;
  line-height: 1.2;
  text-transform: uppercase;
}

.review-meta,
.review-file {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
}

.review-meta {
  color: var(--muted-2);
}

.review-file {
  color: var(--quiet);
  overflow-wrap: anywhere;
}

.review-remove-button {
  min-height: 34px;
  padding: 8px 10px;
  justify-self: start;
  font-size: 14px;
}

.receipt-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top, 0px)) 12px max(18px, env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(10px);
}

.receipt-overlay[hidden] {
  display: none;
}

.receipt-viewer {
  width: min(100%, 920px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #050505;
  overflow: hidden;
}

.receipt-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.receipt-viewer-title {
  margin: 4px 0 0;
  color: var(--text);
  font-family: "Bebas Neue", sans-serif;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.receipt-viewer-body-wrap {
  min-height: 0;
  position: relative;
  display: grid;
}

.receipt-viewer-body {
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px;
  touch-action: pan-y;
}

.receipt-nav-button {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 42px;
  height: 58px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: var(--text);
  font-size: 34px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.receipt-nav-button[hidden] {
  display: none;
}

.receipt-prev-button {
  left: 10px;
}

.receipt-next-button {
  right: 10px;
}

.receipt-viewer-image {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
}

.receipt-viewer-text {
  width: 100%;
  margin: 0;
  white-space: pre-wrap;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  line-height: 1.65;
  letter-spacing: 0;
}

.result-title {
  font-size: 34px;
  margin-bottom: 12px;
}

.subtitle {
  color: var(--gold);
  font-family: "Lora", serif;
  font-style: italic;
  font-size: 18px;
  line-height: 1.6;
  margin: 0 0 10px;
}

.generated-copy {
  font-family: "Lora", serif;
  color: #d4cec2;
  font-size: 16px;
  line-height: 1.9;
  white-space: pre-wrap;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 420px) {
  .section {
    padding-left: 14px;
    padding-right: 14px;
  }

  .headline {
    font-size: 40px;
  }

  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .footer-bar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .upload-button,
  .ingest-button {
    min-height: 50px;
  }

  .tool-button {
    padding-left: 4px;
    padding-right: 4px;
    font-size: 10px;
  }

  .week-alert {
    grid-template-columns: 1fr;
  }

  .week-alert-button {
    width: 100%;
  }

  .bank-control-row {
    grid-template-columns: 1fr 1fr;
  }

  .week-tool-button {
    grid-column: 1 / -1;
  }

  .review-item {
    grid-template-columns: 82px 1fr;
    gap: 10px;
  }

  .review-media,
  .review-media img {
    min-height: 82px;
  }

  .result-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-stats {
    text-align: left;
  }
}

@media (max-width: 390px) {
  .ingest-actions {
    grid-template-columns: 1fr 1fr;
  }

  .upload-button {
    grid-column: 1 / -1;
  }
}
