/* PocketSync web: tokens and shared components.
   Brand rules: ~/.claude/brand-guidelines.md. Navy/gold, Inter for UI, DM Serif Display
   for the wordmark ONLY, JetBrains Mono for the Recovery Key and identifiers.
   No inline styles anywhere (CSP style-src 'self'). */

@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/shared/fonts/Inter-Regular.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/shared/fonts/Inter-Medium.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/shared/fonts/Inter-SemiBold.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("/shared/fonts/Inter-Bold.woff") format("woff"); }
@font-face { font-family: "DM Serif Display"; font-weight: 400; font-display: swap; src: url("/shared/fonts/DMSerifDisplay-Regular.woff") format("woff"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url("/shared/fonts/JetBrainsMono-Regular.woff") format("woff"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 700; font-display: swap; src: url("/shared/fonts/JetBrainsMono-Bold.woff") format("woff"); }

:root {
  color-scheme: light;
  /* Raw palette (fixed) */
  --navy: #0a1628;
  --navy-mid: #132240;
  --navy-light: #1a3058;
  --gold: #c9a84c;
  --gold-light: #e4cc7a;
  --gold-dim: #8a7234;
  --cream: #f5f0e8;
  --cream-dark: #e8e0d0;

  /* Three-tier surfaces (adaptive) */
  --bg: var(--cream);
  --surface: #ffffff;
  --surface-2: var(--cream-dark);
  --divider: var(--cream-dark);
  --divider-strong: #d3c9b3;

  /* Text */
  --text: var(--navy);
  --text-2: rgba(10, 22, 40, 0.68);
  /* PocketSync gold for TEXT on page surfaces: Gold Primary is 2.0:1 on cream. */
  --gold-text: #7a6430;
  --gold-fill: var(--gold);
  --on-gold: var(--navy);
  --danger-text: #b3261e;
  --danger-fill: #b3261e;
  --success-text: #1b6e2f;
  --warn-text: #8a4b00;
  --focus: var(--navy);
  --hover: rgba(10, 22, 40, 0.05);
  --selected: rgba(201, 168, 76, 0.18);
  --shadow-pop: 0 1px 2px rgba(10, 22, 40, 0.08), 0 12px 32px -8px rgba(10, 22, 40, 0.28);
  --shadow-card: 0 1px 0 rgba(10, 22, 40, 0.04), 0 1px 3px rgba(10, 22, 40, 0.06);
  --scrim: rgba(10, 22, 40, 0.55);

  /* Type scale: Major Third */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-brand: "DM Serif Display", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --dark: 1; }
}
:root[data-theme="dark"] { --dark: 1; }

/* Dark tokens, declared twice (media + explicit) because custom-property
   conditionals do not exist; keep both blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: var(--navy);
    --surface: var(--navy-mid);
    --surface-2: var(--navy-light);
    --divider: var(--navy-light);
    --divider-strong: #2b4573;
    --text: var(--cream);
    --text-2: rgba(245, 240, 232, 0.72);
    --gold-text: var(--gold-light);
    --gold-fill: var(--gold-light);
    --danger-text: #ff746b;
    --danger-fill: #ff746b;
    --success-text: #5fd47c;
    --warn-text: #f0b45a;
    --focus: var(--gold-light);
    --hover: rgba(245, 240, 232, 0.07);
    --selected: rgba(228, 204, 122, 0.16);
    --shadow-pop: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -8px rgba(0, 0, 0, 0.6);
    --shadow-card: 0 0 0 1px rgba(245, 240, 232, 0.04);
    --scrim: rgba(3, 8, 16, 0.7);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--navy);
  --surface: var(--navy-mid);
  --surface-2: var(--navy-light);
  --divider: var(--navy-light);
  --divider-strong: #2b4573;
  --text: var(--cream);
  --text-2: rgba(245, 240, 232, 0.72);
  --gold-text: var(--gold-light);
  --gold-fill: var(--gold-light);
  --danger-text: #ff746b;
  --danger-fill: #ff746b;
  --success-text: #5fd47c;
  --warn-text: #f0b45a;
  --focus: var(--gold-light);
  --hover: rgba(245, 240, 232, 0.07);
  --selected: rgba(228, 204, 122, 0.16);
  --shadow-pop: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -8px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 0 0 1px rgba(245, 240, 232, 0.04);
  --scrim: rgba(3, 8, 16, 0.7);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--text-base) / 1.5 var(--font-ui);
  font-feature-settings: "calt", "kern";
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.012em; line-height: 1.2; }
a { color: var(--gold-text); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-3); top: -4rem; z-index: 100;
  background: var(--navy); color: var(--cream); padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm); font-weight: 600;
}
.skip-link:focus { top: var(--space-3); outline-color: var(--gold-light); }

/* Wordmark: DM Serif Display, brand name only. Gradient-mask reset per the brand CSS gotchas. */
.wordmark {
  font-family: var(--font-brand); font-weight: 400; letter-spacing: -0.02em; line-height: 1;
  background: none; background-clip: initial; -webkit-background-clip: initial; -webkit-text-fill-color: initial;
  white-space: nowrap; text-decoration: none;
}
.wordmark .wm-pre { color: var(--text); -webkit-text-fill-color: var(--text); }
.wordmark .wm-suf { color: var(--gold-text-mark, var(--gold)); -webkit-text-fill-color: var(--gold-text-mark, var(--gold)); }
:root { --gold-text-mark: #c9a84c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --gold-text-mark: #e4cc7a; } }
:root[data-theme="dark"] { --gold-text-mark: #e4cc7a; }
.on-navy .wordmark .wm-pre { color: #fff; -webkit-text-fill-color: #fff; }
.on-navy .wordmark .wm-suf { color: #e4cc7a; -webkit-text-fill-color: #e4cc7a; }
/* Light-mode wordmark on cream: Gold Primary is a brand mark, not body text (decorative, large). */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-4); border-radius: var(--radius);
  border: 1px solid transparent; font-weight: 600; font-size: var(--text-base);
  background: transparent; text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn svg { flex: none; }
.btn-primary { background: var(--gold-fill); color: var(--on-gold); }
.btn-primary:hover { background: var(--gold-light); }
:root:not([data-theme="dark"]) .btn-primary:hover { background: #d4b658; }
.btn-primary[disabled], .btn-primary[aria-disabled="true"] { background: var(--gold-dim); color: var(--cream); opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--surface); border-color: var(--divider-strong); color: var(--text); }
.btn-secondary:hover { background: var(--hover); }
.btn-quiet { color: var(--gold-text); padding: 0 var(--space-3); }
.btn-quiet:hover { background: var(--hover); }
.btn-danger { background: var(--danger-fill); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: var(--navy); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-danger { color: var(--navy); } }
.btn-danger[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-danger-quiet { color: var(--danger-text); }
.btn-danger-quiet:hover { background: var(--hover); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius);
  border: 0; background: transparent; color: var(--text-2);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn[aria-pressed="true"] { background: var(--selected); color: var(--text); }

/* Forms */
.field { display: grid; gap: var(--space-2); }
.field label, .label { font-size: var(--text-sm); font-weight: 600; }
.hint { font-size: var(--text-sm); color: var(--text-2); }
.input {
  width: 100%; min-height: 46px; padding: 0 var(--space-3); border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--divider-strong); color: var(--text);
}
.input::placeholder { color: var(--text-2); opacity: 0.8; }
.input:hover { border-color: var(--text-2); }
.input:focus-visible { outline-offset: 0; border-color: transparent; }
.input[aria-invalid="true"] { border-color: var(--danger-text); }
.error-text { color: var(--danger-text); font-size: var(--text-sm); font-weight: 500; display: flex; gap: var(--space-2); align-items: flex-start; }
.mono { font-family: var(--font-mono); }

.check { display: inline-flex; gap: var(--space-3); align-items: flex-start; cursor: pointer; }
.check input { appearance: none; width: 22px; height: 22px; flex: none; margin: 1px 0 0; border-radius: 6px; border: 1.5px solid var(--text-2); background: var(--surface); display: grid; place-items: center; cursor: pointer; }
.check input:checked { background: var(--gold-fill); border-color: var(--gold-fill); }
.check input:checked::after { content: ""; width: 10px; height: 5px; border-left: 2px solid var(--navy); border-bottom: 2px solid var(--navy); transform: rotate(-45deg) translate(1px, -1px); }
.check input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Surfaces */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); border: 1px solid var(--divider); }
.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 10px; border-radius: 999px; font-size: var(--text-xs); font-weight: 600; background: var(--surface-2); color: var(--text); }
.badge-gold { background: var(--selected); color: var(--text); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold-fill) 55%, transparent); }
.badge-warn { background: color-mix(in srgb, var(--warn-text) 14%, transparent); color: var(--warn-text); }

/* Prototype banner: present on every page while the app runs on demo data. */
.proto-banner {
  display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); align-items: center; justify-content: center;
  padding: 7px var(--space-4); background: var(--navy); color: var(--cream);
  font-size: var(--text-sm); text-align: center; border-bottom: 2px solid var(--gold);
}
.proto-banner strong { color: var(--gold-light); font-weight: 700; letter-spacing: 0.01em; }
.proto-banner a { color: var(--gold-light); font-weight: 600; }
.proto-banner :focus-visible { outline-color: var(--gold-light); }

/* Dialogs: centered modals only (brand rule). */
dialog.modal {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(30rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); overflow: auto;
  margin: auto;
}
dialog.modal::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: pop var(--dur) var(--ease); }
.modal-body { padding: var(--space-5) var(--space-5) var(--space-4); display: grid; gap: var(--space-3); }
.modal-body h2 { font-size: var(--text-xl); }
.modal-body p { color: var(--text-2); }
.modal-body .field p { color: var(--text-2); }
.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; padding: 0 var(--space-5) var(--space-5); flex-wrap: wrap; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }

/* Toast */
.toast-region { position: fixed; left: 0; right: 0; bottom: var(--space-5); display: grid; justify-items: center; gap: var(--space-2); pointer-events: none; z-index: 60; padding: 0 var(--space-4); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-3);
  background: var(--navy); color: var(--cream); padding: 10px 10px 10px var(--space-4);
  border-radius: var(--radius); box-shadow: var(--shadow-pop); font-size: var(--text-sm); border: 1px solid var(--navy-light);
  animation: pop var(--dur) var(--ease);
}
.toast button { background: none; border: 0; color: var(--gold-light); font-weight: 600; min-height: 36px; padding: 0 var(--space-3); border-radius: var(--radius-sm); }
.toast button:hover { background: rgba(255, 255, 255, 0.08); }
.toast button:focus-visible { outline-color: var(--gold-light); }

/* Menu */
.menu {
  position: absolute; z-index: 40; min-width: 13rem; padding: var(--space-1);
  background: var(--surface); border: 1px solid var(--divider-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); animation: pop var(--dur) var(--ease);
}
:root[data-theme="dark"] .menu { background: var(--surface-2); border-color: #2b4573; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .menu { background: var(--surface-2); border-color: #2b4573; } }
.menu [role="menuitem"] {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 40px; padding: 0 var(--space-3);
  background: none; border: 0; border-radius: var(--radius-sm); text-align: left; font-size: var(--text-sm); font-weight: 500;
}
.menu [role="menuitem"]:hover, .menu [role="menuitem"]:focus-visible { background: var(--hover); outline-offset: -2px; }
.menu [role="menuitem"].danger { color: var(--danger-text); }
.menu hr { border: 0; border-top: 1px solid var(--divider); margin: var(--space-1) 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
