/* ==================================================================
   theme.css — design tokens, reset, primitives
   A deliberately light, paper-white surface with one cool accent and
   hairline borders. Everything that animates has a token here so motion
   stays consistent across the app.
   ================================================================== */

:root {
  /* surfaces */
  --bg: #ffffff;
  --bg-tint: #fbfbfe;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #f2f4f9;
  --overlay: rgba(255, 255, 255, 0.72);

  /* ink */
  --text: #0d1117;
  --text-2: #4a5163;
  --text-3: #8b91a3;
  --text-inverse: #ffffff;

  /* lines */
  --border: #e9ebf2;
  --border-strong: #dcdfea;
  --border-focus: #a5b4fc;

  /* accent */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-2: #0ea5e9;
  --accent-soft: #eef1ff;
  --accent-ring: rgba(79, 70, 229, 0.18);
  --gradient: linear-gradient(135deg, #4f46e5 0%, #6366f1 45%, #0ea5e9 100%);

  /* status */
  --ok: #10b981;
  --ok-soft: #ecfdf5;
  --warn: #f59e0b;
  --warn-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --info-soft: #eff6ff;

  /* shape */
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-full: 999px;

  /* elevation */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.03);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.06), 0 2px 4px rgba(16, 24, 40, 0.03);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.08), 0 4px 8px rgba(16, 24, 40, 0.03);
  --shadow-xl: 0 24px 56px rgba(16, 24, 40, 0.1), 0 8px 16px rgba(16, 24, 40, 0.04);
  --shadow-accent: 0 8px 24px rgba(79, 70, 229, 0.22);

  /* type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, Consolas,
    "Liberation Mono", monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;

  /* motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 140ms;
  --dur-base: 220ms;
  --dur-slow: 380ms;

  /* layout */
  --topbar-h: 60px;
  --composer-max: 860px;
  --transcript-max: 860px;
  --sidebar-w: 276px;
}

/* ------------------------------------------------------------------ */
/* reset                                                               */
/* ------------------------------------------------------------------ */

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

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: auto; /* the engine owns scrolling */
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  overflow: hidden;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

ul,
ol {
  list-style: none;
}

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

hr {
  border: none;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------------ */
/* focus & selection                                                   */
/* ------------------------------------------------------------------ */

:focus {
  outline: none;
}

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

::selection {
  background: rgba(99, 102, 241, 0.18);
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: 999;
  padding: 10px 18px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-inverse);
  background: var(--accent);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, -160%);
  transition: transform var(--dur-base) var(--ease-back);
}

.skip-link:focus-visible {
  transform: translate(-50%, 0);
  text-decoration: none;
}

/* ------------------------------------------------------------------ */
/* scrollbars                                                          */
/* ------------------------------------------------------------------ */

* {
  scrollbar-width: thin;
  scrollbar-color: #d5d9e4 transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #dcdfea;
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-full);
  transition: background-color var(--dur-base) var(--ease-out);
}

::-webkit-scrollbar-thumb:hover {
  background: #c3c8d8;
  background-clip: content-box;
}

/* ------------------------------------------------------------------ */
/* ambient background                                                  */
/* ------------------------------------------------------------------ */

.ambient-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* A barely-there paper grain; keeps large white areas from looking flat. */
.ambient-grain {
  position: fixed;
  inset: -50%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.4;
  background-image: radial-gradient(rgba(15, 23, 42, 0.035) 0.5px, transparent 0.5px);
  background-size: 3px 3px;
  mask-image: radial-gradient(ellipse 70% 55% at 50% 40%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 70% 55% at 50% 40%, #000 20%, transparent 78%);
}

/* ------------------------------------------------------------------ */
/* buttons                                                             */
/* ------------------------------------------------------------------ */

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  color: var(--text-2);
  border-radius: var(--r-md);
  transition:
    color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
  will-change: transform;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-3);
}

.icon-btn:active {
  background: #eaecf3;
}

.icon-btn-sm {
  width: 30px;
  height: 30px;
}

.icon-btn[disabled] {
  color: var(--text-3);
  opacity: 0.5;
}

.icon-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  transition:
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
  will-change: transform;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.ghost-btn.danger {
  color: var(--danger);
  border-color: #fecaca;
}

.ghost-btn.danger:hover {
  background: var(--danger-soft);
  border-color: #fca5a5;
}

.ghost-btn .icon {
  width: 16px;
  height: 16px;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-inverse);
  background: var(--gradient);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-accent);
  will-change: transform;
}

/* Ripple layer injected by the pressable engine. */
.press-ripple {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.28) 0%, rgba(99, 102, 241, 0) 70%);
  transform: translate(-50%, -50%) scale(0);
  will-change: transform, opacity;
}

.is-pressed {
  --press-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.06);
}

/* ------------------------------------------------------------------ */
/* custom cursor                                                       */
/* ------------------------------------------------------------------ */

body.has-custom-cursor,
body.has-custom-cursor * {
  cursor: none !important;
}

.cursor-dot,
.cursor-ring,
.cursor-label {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}

.cursor-dot {
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  background: var(--accent);
  border-radius: 50%;
  transition: width var(--dur-fast) var(--ease-out), height var(--dur-fast) var(--ease-out),
    margin var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.cursor-dot.is-hover {
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  background: var(--accent-hover);
}

.cursor-ring {
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 1.5px solid rgba(79, 70, 229, 0.42);
  border-radius: 50%;
  transition: border-color var(--dur-base) var(--ease-out);
}

.cursor-ring.is-hover {
  border-color: rgba(79, 70, 229, 0.85);
}

.cursor-label {
  padding: 3px 8px;
  margin-top: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-transform: uppercase;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

.cursor-label.is-visible {
  opacity: 0.9;
}

/* ------------------------------------------------------------------ */
/* KaTeX on a white page                                               */
/* ------------------------------------------------------------------ */

.katex {
  font-size: 1.045em;
  color: var(--text);
}

.katex-display {
  margin: 1.15em 0;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex-display > .katex {
  white-space: normal;
}

/* Formula that has not been typeset yet (KaTeX still loading, or failed). */
.md-math {
  color: var(--accent);
  transition: color var(--dur-base) var(--ease-out);
}

.md-math-inline[data-pending='true'] {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-style: italic;
  color: var(--text-2);
}

.md-math[data-render-error='true'] {
  color: var(--danger);
}

/* ------------------------------------------------------------------ */
/* reduced motion                                                      */
/* ------------------------------------------------------------------ */

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

body.reduced-motion .ambient-canvas {
  opacity: 0.6;
}
