:root {
  --canvas: var(--tg-theme-bg-color, #10182d);
  --canvas-deep: #0b1020;
  --surface: #f1e4c2;
  --surface-soft: #f7edcf;
  --ink: #422f18;
  --muted: #776b57;
  --night-ink: #f3e5c2;
  --blue: #7cc0ee;
  --teal: #2e7f83;
  --brass: #d9a44f;
  --rust: #a94d42;
  --line: color-mix(in srgb, var(--ink) 22%, transparent);
  --night-line: #f6dfae38;
  --serif: Iowan Old Style, "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas-deep); }
body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  color: var(--night-ink);
  background:
    radial-gradient(ellipse 75% 45% at 50% 0%, #273456 0%, transparent 72%),
    radial-gradient(ellipse 80% 50% at 50% 100%, #432719 0%, transparent 78%),
    var(--canvas-deep);
  font-family: var(--sans);
}
body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: .6;
  background-image: radial-gradient(circle at 18% 20%, #fff8 0 1px, transparent 1.5px), radial-gradient(circle at 82% 13%, #f6dfae99 0 1px, transparent 1.5px), radial-gradient(circle at 67% 36%, #fff6 0 1px, transparent 1.5px), radial-gradient(circle at 8% 63%, #f6dfae77 0 1px, transparent 1.5px), radial-gradient(circle at 91% 76%, #fff5 0 1px, transparent 1.5px);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { width: 100%; max-width: 920px; margin: 0 auto; }
.auth-view { max-width: 470px; min-height: calc(100dvh - 56px); display: flex; flex-direction: column; justify-content: center; margin: 0 auto; }
.auth-view, .work-card { color: var(--ink); }
.auth-view { padding: 30px 28px; border: 1px solid var(--night-line); border-radius: 12px; background: linear-gradient(145deg, #f7edcf 0%, #ead6a7 100%); box-shadow: 0 24px 70px #0008, inset 0 0 40px #fff2; }
.auth-view h1 { color: var(--ink); text-shadow: none; }
.auth-view .intro { color: var(--muted); }
.page-header { padding: 14px 4px 30px; }
.page-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.eyebrow, .section-label {
  margin: 0 0 8px;
  color: var(--brass);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .14em;
  line-height: 1.2;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: var(--serif); }
h1 { margin-bottom: 10px; font-size: clamp(32px, 5vw, 46px); line-height: 1.06; font-style: italic; font-weight: 400; letter-spacing: .01em; color: var(--night-ink); text-shadow: 0 2px 18px #7cc0ee2e; }
h2 { margin-bottom: 6px; font-size: 19px; line-height: 1.25; }
.intro { max-width: 42rem; margin-bottom: 0; color: #d9c39a; font-size: 16px; line-height: 1.65; }
.vault-state { margin: 18px 0 0; color: #d9a44f; font-size: 12px; letter-spacing: .04em; }
.vault-state span { margin-right: 5px; color: #bde4ff; }

.auth-form, .work-form { display: grid; gap: 9px; }
.auth-form { margin-top: 25px; }
label { color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.field-help { margin: -2px 0 1px; color: var(--muted); font-size: 13px; line-height: 1.5; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface-soft) 86%, white);
}
input { min-height: 48px; padding: 12px; font-family: var(--mono); font-size: 14px; }
textarea { min-height: 150px; resize: vertical; padding: 13px; font-size: 15px; line-height: 1.55; }
input:focus-visible, textarea:focus-visible { border-color: var(--teal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 25%, transparent); }

.button {
  min-height: 52px;
  border: 0;
  border-radius: 7px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
}
.button:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal) 58%, white); outline-offset: 2px; }
.button:disabled { cursor: wait; opacity: .58; }
.button-primary, .button-teal { color: #fff; background: #286e76; box-shadow: 0 5px 14px #153c4a38; }
.button-brass { color: #241a08; background: var(--brass); }
.button-lock { flex: 0 0 auto; min-height: 48px; padding: 10px 13px; color: #f6dfae; background: #ffffff0b; box-shadow: inset 0 0 0 1px var(--night-line); font-size: 13px; }
.button-lock:hover { color: #fff; background: #ffffff16; }
.security-note { margin: 16px 0 0; color: var(--muted); font-family: var(--mono); font-size: 11px; line-height: 1.5; }
.companion-note { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.status { min-height: 21px; margin: 12px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.status.error, .result.error { color: var(--rust); }

.work-grid { display: grid; gap: 18px; }
.find-card { margin-top: 18px; }
.find-card::before { background: var(--teal); }
.inbox-card { margin-top: 18px; }
.inbox-card::before { background: var(--teal); }
.tasks-card { margin-top: 18px; }
.tasks-card::before { background: var(--brass); }
.work-card {
  position: relative;
  overflow: hidden;
  padding: 24px 22px 22px 28px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 14px 32px #0004, inset 0 0 30px #fff2;
}
.work-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  content: "";
  background: var(--teal);
}
.capture-card::before { background: var(--brass); }
.find-form { display: grid; gap: 9px; }
.find-form input { min-height: 52px; font-family: var(--sans); font-size: 15px; }
.find-status { margin-top: 14px; }
.find-results { display: grid; gap: 8px; margin-top: 16px; }
.find-results[hidden] { display: none; }
.find-result {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface-soft) 72%, white);
  text-align: left;
}
.find-result:hover { border-color: var(--teal); }
.find-result:focus-visible, .reader-back:focus-visible, .retry-button:focus-visible, .citation-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal) 58%, white); outline-offset: 2px; }
.find-result-title { display: block; font-family: var(--serif); font-size: 16px; font-weight: 700; line-height: 1.3; }
.find-result-summary { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.find-result-meta { display: block; margin-top: 6px; color: var(--muted); font-family: var(--mono); font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }
.button-quiet { color: var(--muted); background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.retry-button { min-height: 44px; margin-top: 10px; }
.reader { margin-top: 2px; }
.reader-back { width: 100%; min-height: 44px; margin-bottom: 22px; text-align: left; }
.reader h2 { margin-bottom: 7px; font-size: clamp(22px, 5vw, 30px); }
.reader-id { margin: 0 0 16px; color: var(--muted); font-family: var(--mono); font-size: 11px; overflow-wrap: anywhere; }
.reader-meta { display: grid; gap: 5px; margin-bottom: 4px; }
.reader-meta-row { display: flex; gap: 9px; font-size: 13px; line-height: 1.5; }
.reader-meta-label { flex: 0 0 70px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.reader-meta-value { overflow-wrap: anywhere; }
.reader-body { width: 100%; max-height: 60dvh; min-height: 150px; margin: 16px 0 0; overflow: auto; padding: 16px; border: 1px solid #d9a44f66; border-radius: 6px; color: var(--ink); background: linear-gradient(170deg, #f8ecc9, var(--surface) 78%); box-shadow: 0 12px 28px #00000038, inset 0 0 30px #c9a46835; font-family: var(--mono); font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; }
.reader-empty { margin: 16px 0 0; padding: 18px; color: var(--muted); background: color-mix(in srgb, var(--surface-soft) 72%, white); font-size: 15px; line-height: 1.5; }
.reader-actions, .reader-edit-form { margin-top: 16px; }
.reader-actions, .reader-delete-confirm { display: grid; gap: 8px; }
.reader-actions .button, .reader-edit-actions .button, .reader-delete-confirm .button { width: 100%; }
.reader-edit-form { display: grid; gap: 9px; }
.reader-edit-form textarea { min-height: 220px; }
.reader-edit-actions { display: grid; gap: 8px; margin-top: 2px; }
.reader-ai-form, .reader-ai-preview { margin-top: 16px; }
.reader-ai-form { display: grid; gap: 9px; }
.reader-ai-form textarea { min-height: 110px; }
.reader-ai-help { margin: -2px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.reader-ai-actions, .reader-ai-preview-actions { display: grid; gap: 8px; margin-top: 2px; }
.reader-ai-preview { display: grid; gap: 9px; padding-top: 16px; border-top: 1px dashed var(--line); }
.reader-ai-heading { margin: 0; color: var(--teal); font-family: var(--serif); font-size: 18px; }
.reader-ai-copy { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.reader-ai-diff { margin: 0; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface-soft); font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-ai-add { color: #216448; background: #d9efd9; }
.reader-ai-remove { color: var(--rust); background: #f4d9d2; text-decoration: line-through; }
.reader-convert-preview { display: grid; gap: 9px; margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.reader-convert-heading { margin: 0; color: var(--teal); font-family: var(--serif); font-size: 18px; }
.reader-convert-copy { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.reader-convert-actions { display: grid; gap: 8px; margin-top: 2px; }
.reader-delete-confirm { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.reader-delete-heading { margin: 0; color: var(--rust); font-family: var(--serif); font-size: 18px; }
.reader-delete-copy { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.reader-body[hidden], .reader-empty[hidden], .reader[hidden], .retry-button[hidden] { display: none; }
.citation-button { display: block; width: 100%; min-height: 44px; padding: 8px 2px; border: 0; color: var(--teal); background: transparent; font: inherit; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.citation-button:hover { color: #205b62; }
.inbox-status { margin-top: 0; }
.inbox-item-title { margin: 0 0 5px; color: var(--ink); font-family: var(--serif); font-size: 22px; line-height: 1.25; }
.inbox-item-id { margin: 0 0 16px; color: var(--muted); font-family: var(--mono); font-size: 11px; overflow-wrap: anywhere; }
.inbox-label { margin: 17px 0 7px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.inbox-body { max-height: 42dvh; min-height: 120px; margin: 0; overflow: auto; padding: 14px; border: 1px solid #d9a44f66; border-radius: 6px; color: var(--ink); background: linear-gradient(170deg, #f8ecc9, var(--surface) 78%); box-shadow: inset 0 0 24px #c9a46835; font-family: var(--mono); font-size: 14px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.proposed-panel, .source-panel { margin-top: 16px; padding: 13px; border-radius: 6px; background: color-mix(in srgb, var(--surface-soft) 72%, white); }
.proposed-panel { border: 1px solid color-mix(in srgb, var(--brass) 65%, transparent); }
.source-panel { border: 1px solid var(--line); }
.proposed-panel .inbox-label, .source-panel .inbox-label { margin-top: 0; }
.proposed-note { margin: -2px 0 10px; color: var(--muted); font-size: 12px; }
.inbox-meta { display: grid; gap: 5px; }
.inbox-meta-row { display: flex; gap: 9px; font-size: 13px; line-height: 1.45; }
.inbox-meta-label { flex: 0 0 72px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.inbox-meta-value { overflow-wrap: anywhere; }
.inbox-actions { display: grid; gap: 8px; margin-top: 18px; }
.inbox-preview { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line); }
.inbox-preview-heading { margin: 0 0 7px; color: var(--teal); font-family: var(--serif); font-size: 18px; }
.inbox-preview-warning { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.inbox-preview-body { max-height: 35dvh; margin: 12px 0 0; overflow: auto; padding: 13px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface-soft); font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.inbox-preview-actions { display: grid; gap: 8px; margin-top: 14px; }
.inbox-unknown { margin-top: 16px; padding: 13px; border: 1px solid color-mix(in srgb, var(--rust) 60%, transparent); border-radius: 6px; color: var(--rust); font-size: 13px; line-height: 1.5; }
.inbox-refresh { width: 100%; min-height: 44px; margin-top: 16px; }
.inbox-zero { padding: 20px 4px 6px; text-align: center; }
.inbox-zero h3 { margin: 0 0 6px; color: var(--ink); font-family: var(--serif); font-size: 20px; }
.inbox-zero p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.inbox-card [hidden] { display: none; }
.section-heading { margin-bottom: 20px; }
.section-heading p:last-child { margin-bottom: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.capture-card .section-label { color: color-mix(in srgb, var(--brass) 78%, var(--ink)); }

.task-create-form, .task-edit-form { display: grid; gap: 9px; }
.task-create-form input, .task-edit-form input, .task-search-form input { font-family: var(--sans); font-size: 15px; }
.task-more-fields { margin: 2px 0 4px; border-top: 1px dashed var(--line); padding-top: 11px; }
.task-more-fields summary { width: fit-content; margin-bottom: 13px; color: var(--teal); cursor: pointer; font-size: 13px; font-weight: 700; }
.task-more-fields textarea { min-height: 90px; }
.optional { color: var(--muted); font-size: 10px; font-weight: 400; letter-spacing: .04em; text-transform: none; }
.task-toolbar { display: grid; gap: 12px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.task-segments { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 8px; background: color-mix(in srgb, var(--ink) 9%, transparent); }
.segment-button { min-height: 43px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; font-size: 14px; font-weight: 750; }
.segment-button.is-selected { color: var(--ink); background: var(--surface-soft); box-shadow: 0 2px 8px #0002; }
.task-search-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.task-search-form input { min-height: 46px; }
.task-search-form .button { min-height: 46px; padding-inline: 14px; }
.task-status { margin-top: 14px; }
.task-list { display: grid; gap: 8px; margin-top: 10px; }
.task-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: stretch; padding: 9px; border: 1px solid var(--line); border-radius: 7px; background: color-mix(in srgb, var(--surface-soft) 72%, white); }
.task-row-open { min-width: 0; padding: 4px; border: 0; color: var(--ink); background: transparent; text-align: left; }
.task-row-open:hover .task-row-title { color: var(--teal); }
.task-row-open:focus-visible, .segment-button:focus-visible, .task-complete:focus-visible, .task-back:focus-visible, .task-retry:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal) 58%, white); outline-offset: 2px; }
.task-row-title, .task-row-summary, .task-row-id { display: block; overflow-wrap: anywhere; }
.task-row-title { font-family: var(--serif); font-size: 17px; font-weight: 700; line-height: 1.3; }
.task-row-summary { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.task-row-id, .task-detail-id { margin-top: 6px; color: var(--muted); font-family: var(--mono); font-size: 10px; }
.task-complete { align-self: center; min-height: 40px; padding: 8px 11px; font-size: 12px; }
.task-done-mark { align-self: center; padding: 0 5px; color: var(--teal); font-size: 12px; font-weight: 750; }
.task-empty { margin: 9px 0 2px; padding: 20px 8px; color: var(--muted); text-align: center; font-size: 14px; }
.task-retry { width: 100%; margin-top: 10px; }
.task-detail { margin-top: 20px; padding-top: 18px; border-top: 1px dashed var(--line); }
.task-back { width: 100%; min-height: 44px; margin-bottom: 22px; text-align: left; }
.task-detail h3 { margin: 0 0 4px; color: var(--ink); font-family: var(--serif); font-size: 25px; line-height: 1.2; overflow-wrap: anywhere; }
.task-detail-id { margin: 0 0 20px; }
.task-edit-form { margin-top: 8px; }
.task-edit-form textarea { min-height: 130px; }
.task-detail-actions { display: grid; gap: 8px; margin-top: 7px; }
.task-convert-preview { margin-top: 18px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.result { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); font-size: 15px; line-height: 1.65; }
.result-heading { margin-bottom: 7px; color: var(--teal); font-family: var(--serif); font-size: 17px; font-weight: 700; }
.capture-card .result-heading { color: color-mix(in srgb, var(--brass) 78%, var(--ink)); }
.result-copy { margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.result-meta { margin: 0; color: var(--muted); font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.result-meta + .result-meta { margin-top: 3px; }
.source-label { margin: 17px 0 7px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.sources { display: grid; gap: 5px; margin: 0; padding-left: 18px; }
.sources li { padding-left: 2px; overflow-wrap: anywhere; }
.result-action { width: 100%; margin-top: 15px; }
.warning { margin: 13px 0 0; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

/* iOS WebViews zoom editable controls below 16px on focus. Keep the desktop
   type scale intact while giving every mobile field the platform-safe minimum. */
@media (max-width: 759px) {
  input,
  textarea,
  .find-form input,
  .task-create-form input,
  .task-edit-form input,
  .task-search-form input {
    font-size: 16px;
  }
}

@media (min-width: 760px) {
  body { padding-top: max(42px, env(safe-area-inset-top)); }
  .page-header { padding-top: 10px; padding-bottom: 28px; }
  .work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .work-card { min-width: 0; }
  .result { grid-column: auto; }
  .task-toolbar { grid-template-columns: 190px minmax(0, 1fr); align-items: end; }
  .task-detail-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
  body { padding-left: 12px; padding-right: 12px; }
  .auth-view { padding: 24px 20px; }
  .page-header-row { display: block; }
  .page-header { padding-left: 2px; padding-right: 2px; }
  .button-lock { margin-top: 18px; width: 100%; }
  .work-card { padding: 21px 17px 18px 22px; }
  .find-card { margin-top: 14px; }
  .inbox-card { margin-top: 14px; }
  textarea { min-height: 132px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
