@layer base, rmx;

:root {
  --paper: #F6F2E8;
  --paper-2: #FBF8F1;
  --ink: #1A1A1A;
  --ink-2: #4A4A4A;
  --ink-3: #8A8578;
  --hair: #D9D2C0;
  --hair-2: #E7E1CF;
  --accent: #E45A2B;
  --accent-soft: #FCE3D6;
  --cool: #3F628F;
  --cool-soft: #DDE6F2;
  --good: #4A7C59;
  --good-soft: #DDE9DF;
  --warn: #C28A2C;
  --warn-soft: #F4E7C9;
  --sketch: #B8B09C;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;

  --font-sans: "Geist", "Funnel Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, monospace;

  /* Semantic tokens — primitives read from these, never from the raw palette.
     Adjust here to re-skin a shape (card, row, eyebrow, …) everywhere at once. */

  /* Page frame */
  --page-pad-x: 20px;
  --page-pad-top: 20px;

  /* Card — boxed surface (user card, modals, etc.) */
  --surface-card-bg: var(--paper-2);
  --surface-card-border-color: var(--ink);
  --surface-card-border-width: 1.5px;
  --surface-card-radius: var(--r-xl);
  --surface-card-padding-y: 18px;
  --surface-card-padding-x: 22px;

  /* Section — labelled group of flush rows on the page background */
  --section-gap: 20px;
  --section-eyebrow-gap: 4px;

  /* Row — settings-style list item (icon + label + value + chevron) */
  --row-padding-y: 14px;
  --row-gap: 14px;
  --row-label-size: 17px;
  --row-label-weight: 500;
  --row-icon-size: 22px;
  --row-icon-color: var(--ink-2);
  --row-value-color: var(--ink-3);
  --row-value-size: 14px;
  --row-chevron-color: var(--ink-3);
  --row-divider: 1px solid var(--hair);

  /* Eyebrow — small mono uppercase label above headings/sections */
  --eyebrow-tracking: 0.16em;
  --eyebrow-size: 11px;
  --eyebrow-color: var(--ink-3);

  /* Headings */
  --heading-size-xl: 40px;
  --heading-size-lg: 22px;
  --heading-weight: 700;
  --heading-tracking: -0.02em;

  /* Avatar (circular, single-initial) */
  --avatar-size-md: 46px;
  --avatar-size-sm: 36px;
  --avatar-border: 1.5px solid var(--ink);

  /* Buttons */
  --button-primary-bg: var(--ink);
  --button-primary-color: var(--paper);
  --button-primary-radius: var(--r-lg);
  --button-primary-padding: 16px 18px;

  /* Dashed action — used for opt-in surfaces like "+ Add a passkey". Shares
     radius/padding shape with primary so the two read as a button family. */
  --button-dashed-bg: transparent;
  --button-dashed-color: var(--ink);
  --button-dashed-border: 1.5px dashed var(--ink-3);
  --button-dashed-radius: var(--surface-card-radius);
  --button-dashed-padding: 16px 18px;

  --button-text-color: var(--accent);

  /* Switch (iOS-style toggle) */
  --switch-width: 46px;
  --switch-height: 26px;
  --switch-track-off: var(--hair);
  --switch-track-on: var(--ink);
  --switch-knob: var(--paper-2);
}

/* Cream-mirror dark palette. Verified AA contrast for ink/ink-2/ink-3/accent
   against paper. Applied when user explicitly chose Dark, OR when "Auto" and
   the OS prefers dark. */
html[data-theme="dark"] {
  --paper: #1A1815;
  --paper-2: #221F1A;
  --ink: #F2EDDE;
  --ink-2: #C9C2AF;
  --ink-3: #948B75;
  --hair: #34302A;
  --hair-2: #2A2722;
  --accent: #FF7A4A;
  --accent-soft: #3D241B;
  --cool: #6A92CC;
  --cool-soft: #1E2A3D;
  --good: #6FB07F;
  --good-soft: #1E2B22;
  --warn: #E0B260;
  --warn-soft: #3A2F1C;
  --sketch: #6B6450;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --paper: #1A1815;
    --paper-2: #221F1A;
    --ink: #F2EDDE;
    --ink-2: #C9C2AF;
    --ink-3: #948B75;
    --hair: #34302A;
    --hair-2: #2A2722;
    --accent: #FF7A4A;
    --accent-soft: #3D241B;
    --cool: #6A92CC;
    --cool-soft: #1E2A3D;
    --good: #6FB07F;
    --good-soft: #1E2B22;
    --warn: #E0B260;
    --warn-soft: #3A2F1C;
    --sketch: #6B6450;
  }
}

@view-transition {
  navigation: auto;
}

/* Default crossfade for any navigation that isn't given an explicit direction.
   Kept short so taps feel instant. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 140ms;
  animation-timing-function: ease-out;
}

/* Directional slide. Used by:
   - Bottom-tab navigation (Home ↔ Utilities ↔ Settings), and
   - Drill-in / drill-out between a page and one of its subpages
     (e.g. Settings → Settings/Passkeys uses `slide-forward`; back uses `slide-back`).
   The bottom nav has its own view-transition-name (app-nav) so it sits out of
   root and stays anchored during the animation. */
@keyframes check-draw {
  from { stroke-dashoffset: 30; }
  to { stroke-dashoffset: 0; }
}

/* Toast entrance/exit. Bottom variant slides up + fades in; top variant
   slides down + fades in. Exit reverses the motion. Tuned to feel quick
   without snapping — the toast is read in <1s. */
@keyframes toast-bottom-in {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
@keyframes toast-bottom-out {
  from { transform: translateY(0);     opacity: 1; }
  to   { transform: translateY(16px);  opacity: 0; }
}
@keyframes toast-top-in {
  from { transform: translateY(-16px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
@keyframes toast-top-out {
  from { transform: translateY(0);     opacity: 1; }
  to   { transform: translateY(-16px); opacity: 0; }
}

@keyframes slide-out-left {
  to { transform: translateX(-100%); }
}
@keyframes slide-in-right {
  from { transform: translateX(100%); }
}
@keyframes slide-out-right {
  to { transform: translateX(100%); }
}
@keyframes slide-in-left {
  from { transform: translateX(-100%); }
}

html:active-view-transition-type(slide-forward)::view-transition-old(root) {
  animation: 170ms cubic-bezier(0.32, 0.72, 0.32, 1) both slide-out-left;
}
html:active-view-transition-type(slide-forward)::view-transition-new(root) {
  animation: 170ms cubic-bezier(0.32, 0.72, 0.32, 1) both slide-in-right;
}
html:active-view-transition-type(slide-back)::view-transition-old(root) {
  animation: 170ms cubic-bezier(0.32, 0.72, 0.32, 1) both slide-out-right;
}
html:active-view-transition-type(slide-back)::view-transition-new(root) {
  animation: 170ms cubic-bezier(0.32, 0.72, 0.32, 1) both slide-in-left;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

@layer base {
  *, *::before, *::after {
    box-sizing: border-box;
  }

  /* Lets `block-size: auto` (and similar keywords) participate in transitions —
     required for sliding <details> open/close animation. Progressively enhances:
     browsers without support fall back to the native snap. */
  :root {
    interpolate-size: allow-keywords;
  }

  html, body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  button, input, select, textarea {
    font: inherit;
    color: inherit;
  }
}
