/* ============================================================================
   Studyroom design system — foundation layer.

   Plain CSS (no @apply) so tokens + base styles are valid and painting BEFORE
   the Tailwind Play CDN finishes its first in-browser compile. This is half of
   the no-FOUC guarantee; the other half is the boot script in base.html that
   sets `html.dark` before first paint.

   Tokens are surfaced to Tailwind utilities (bg-canvas, text-secondary,
   bg-accent, …) via the inline `tailwind.config` in base.html. Every color is a
   CSS variable that swaps under `html.dark`, so token-based utilities re-theme
   with zero `dark:` variants.
   ========================================================================== */

/* ── Tokens: light ────────────────────────────────────────────────────────── */
:root {
  /* canvas / surfaces */
  --color-canvas:          #FBFBFD;
  --color-surface:         #FFFFFF;
  --color-surface-raised:  #FFFFFF;
  --color-surface-sunken:  #F5F5F7;

  /* text */
  --color-text-primary:    #1D1D1F;
  --color-text-secondary:  #6E6E73;
  --color-text-tertiary:   #8E8E93;
  --color-text-on-accent:  #FFFFFF;

  /* hairlines */
  --color-border:          rgba(0, 0, 0, 0.10);
  --color-border-subtle:   rgba(0, 0, 0, 0.06);

  /* accent — Linear-style indigo-violet */
  --color-accent:          #5E6AD2;
  --color-accent-hover:    #5059C4;
  --color-accent-muted:    rgba(94, 106, 210, 0.10);
  --color-accent-ring:     rgba(94, 106, 210, 0.32);

  /* semantic */
  --color-success:         #1A8754;
  --color-success-muted:   rgba(26, 135, 84, 0.12);
  --color-warn:            #B25E09;
  --color-warn-muted:      rgba(178, 94, 9, 0.12);
  --color-danger:          #D70015;
  --color-danger-muted:    rgba(215, 0, 21, 0.10);

  /* frosted material + elevation */
  --nav-bg:     rgba(251, 251, 253, 0.72);
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg:  0 12px 32px rgba(0, 0, 0, 0.14);

  /* radii (generous, continuous-corner feel) */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  /* motion */
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 120ms;
  --dur:      200ms;
  --dur-slow: 320ms;

  /* type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* layout */
  --header-h: 57px;

  /* syntax (light — refined GitHub-light palette on a sunken surface) */
  --code-bg:        #F5F5F7;
  --code-fg:        #1D1D1F;
  --code-comment:   #6E7781;
  --code-keyword:   #CF222E;
  --code-string:    #0A3069;
  --code-number:    #0550AE;
  --code-name:      #1D1D1F;
  --code-function:  #8250DF;
  --code-class:     #953800;
  --code-operator:  #CF222E;
  --code-deleted:   #82071E;
  --code-inserted:  #116329;

  color-scheme: light;
}

/* ── Tokens: dark ─────────────────────────────────────────────────────────── */
html.dark {
  /* Linear-style soft dark — cool blue-violet-tinted neutrals (never pure gray),
     canvas lifted to a comfortable dark, surfaces step up, code/insets sink. */
  --color-canvas:          #202127;
  --color-surface:         #2B2C32;
  --color-surface-raised:  #36373E;
  --color-surface-sunken:  #16171B;

  --color-text-primary:    #F7F8F8;
  --color-text-secondary:  #9CA0AD;
  --color-text-tertiary:   #6E7180;
  --color-text-on-accent:  #FFFFFF;

  --color-border:          rgba(255, 255, 255, 0.13);
  --color-border-subtle:   rgba(255, 255, 255, 0.07);

  --color-accent:          #6E79D6;
  --color-accent-hover:    #818BE0;
  --color-accent-muted:    rgba(110, 121, 214, 0.20);
  --color-accent-ring:     rgba(110, 121, 214, 0.45);

  --color-success:         #4CC38A;
  --color-success-muted:   rgba(76, 195, 138, 0.18);
  --color-warn:            #F2C94C;
  --color-warn-muted:      rgba(242, 201, 76, 0.16);
  --color-danger:          #F2555A;
  --color-danger-muted:    rgba(242, 85, 90, 0.18);

  --nav-bg:     rgba(32, 33, 39, 0.72);
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.40);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.50);
  --shadow-lg:  0 12px 32px rgba(0, 0, 0, 0.60);

  /* syntax (dark — One-Dark on the app's dark surface) */
  --code-bg:        #16171B;
  --code-fg:        #ABB2BF;
  --code-comment:   #7F848E;
  --code-keyword:   #C678DD;
  --code-string:    #98C379;
  --code-number:    #D19A66;
  --code-name:      #E06C75;
  --code-function:  #61AFEF;
  --code-class:     #E5C07B;
  --code-operator:  #56B6C2;
  --code-deleted:   #E06C75;
  --code-inserted:  #98C379;

  color-scheme: dark;
}

/* ── Base / reset niceties ───────────────────────────────────────────────── */
html { scroll-behavior: smooth; }

body {
  background-color: var(--color-canvas);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

code, pre, kbd, samp { font-family: var(--font-mono); }

*:focus-visible {
  outline: 2px solid var(--color-accent-ring);
  outline-offset: 2px;
}

::selection {
  background-color: var(--color-accent-muted);
  color: var(--color-text-primary);
}

@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;
  }
}

/* ── Frosted nav material (the highest-impact "Apple chrome" move) ────────── */
.nav-frost {
  background-color: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--color-border-subtle);
}

/* ── Refined form controls ───────────────────────────────────────────────── */
.field {
  width: 100%;
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  transition: border-color var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease-out);
}
.field::placeholder { color: var(--color-text-tertiary); }
.field:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-ring);
}

/* ── Prose tuning (typography plugin → tokens, light + dark) ──────────────── */
/* `html .prose` (0,1,1) beats the plugin's `.prose` (0,1,0) regardless of the
   CDN's runtime style-injection order; `html.dark .prose` (0,2,1) wins in dark.
   Templates drop `prose-gray` + per-screen color modifiers and rely on these. */
html .prose {
  --tw-prose-body:          var(--color-text-secondary);
  --tw-prose-headings:      var(--color-text-primary);
  --tw-prose-lead:          var(--color-text-secondary);
  --tw-prose-links:         var(--color-accent);
  --tw-prose-bold:          var(--color-text-primary);
  --tw-prose-counters:      var(--color-text-tertiary);
  --tw-prose-bullets:       var(--color-border);
  --tw-prose-hr:            var(--color-border-subtle);
  --tw-prose-quotes:        var(--color-text-primary);
  --tw-prose-quote-borders: var(--color-border-subtle);
  --tw-prose-captions:      var(--color-text-tertiary);
  --tw-prose-code:          var(--color-text-primary);
  --tw-prose-pre-code:      var(--code-fg);
  --tw-prose-pre-bg:        var(--code-bg);
  --tw-prose-th-borders:    var(--color-border);
  --tw-prose-td-borders:    var(--color-border-subtle);
}

/* Inline code chips (not inside <pre>); strip the plugin's backtick pseudo-els */
.section-prose :not(pre) > code,
.quiz-prose :not(pre) > code {
  background-color: var(--color-surface-sunken);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.375rem;
  font-size: 0.875em;
  font-weight: 500;
  font-family: var(--font-mono);
}
.section-prose :not(pre) > code::before,
.section-prose :not(pre) > code::after,
.quiz-prose :not(pre) > code::before,
.quiz-prose :not(pre) > code::after { content: none; }

/* Pygments codehilite blocks bring their own container — strip prose <pre>
   defaults inside the reader so they don't double up. */
.section-prose pre {
  background: transparent;
  color: inherit;
  padding: 0;
  margin: 1rem 0;
}
.section-prose pre code { background: none; padding: 0; }

/* ── Sortable.js drag states for ordering quiz items (retokenized) ────────── */
.quiz-ordering-ghost {
  opacity: 0.4;
  background: var(--color-accent-muted);
  border-color: var(--color-accent);
}
.quiz-ordering-chosen { background: var(--color-accent-muted); }
.quiz-ordering-drag {
  box-shadow: var(--shadow-lg);
  border-color: var(--color-accent);
}
