/* ===== CSS VARIABLES ===== */
:root {
  --bg:          #0f0f1a;
  --bg-panel:    #1a1a2e;
  --bg-card:     #16213e;
  --border:      #2a2a4a;
  --text:        #cdd6f4;
  --text-muted:  #6c7086;
  --text-dim:    #45475a;
  --sin-color:   #f38ba8;
  --cos-color:   #89b4fa;
  --tan-color:   #cba6f7;
  --hyp-color:   #a6e3a1;
  --neutral:     #89dceb;
  --accent:      #89b4fa;
  --success:     #a6e3a1;
  --warning:     #f9e2af;
  --error:       #f38ba8;
  --state-tutor:  #f9e2af;
  --state-anim:   #89b4fa;
  --state-review: #a6e3a1;
  --state-screen: #cba6f7;
  --radius: 8px;
  --transition: 0.22s ease;
  --topbar-h: 46px;
  --col-left-w: 300px;
  --col-right-w: 280px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== TOP BAR ===== */
#top-bar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  z-index: 50;
  flex-shrink: 0;
}
#app-title { font-size: 13px; font-weight: 700; color: var(--accent); white-space: nowrap; margin-right: 6px; }
#top-bar-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#top-bar-right { display: flex; gap: 4px; flex-shrink: 0; }
.tb-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  white-space: nowrap;
}
.tb-btn:hover, .tb-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(137,180,250,0.08); }

/* ===== 3-COLUMN GRID ===== */
#app {
  display: grid;
  grid-template-columns: var(--col-left-w) 1fr auto;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#app > aside,
#app > main {
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  -webkit-overflow-scrolling: touch;
}
#col-left  {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#col-right {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#ledger-panel { display: none !important; } /* values live in #svg-ledger above triangle */

h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 6px; padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ===== SOCRATIC PANEL ===== */
#socratic-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  flex-shrink: 0;
}

#state-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  background: var(--state-screen); color: var(--bg);
  margin-bottom: 10px;
  transition: background var(--transition);
}
#state-badge.tutor  { background: var(--state-tutor); }
#state-badge.anim   { background: var(--state-anim); }
#state-badge.review { background: var(--state-review); }
#state-badge.screen { background: var(--state-screen); }

/* Phase blocks */
.phase-block { margin-bottom: 6px; }
.phase-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); margin-bottom: 6px; display: flex; align-items: center; gap: 6px;
}
#reveal-countdown {
  font-size: 11px; color: var(--warning); font-weight: 700;
  background: rgba(249,226,175,0.12); padding: 1px 6px; border-radius: 10px;
}

#tutor-text {
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  min-height: 80px;
  animation: fadeSlideIn 0.4s ease;
}

#reveal-text {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  animation: fadeSlideIn 0.35s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== SPOILER ===== */
.spoiler {
  display: inline-block;
  background: var(--border);
  color: var(--border);   /* text same as bg = invisible but selectable */
  border-radius: 3px;
  padding: 1px 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
  font-family: monospace;
  font-size: 0.95em;
  border: 1px solid rgba(137,180,250,0.2);
}
.spoiler:hover {
  background: rgba(137,180,250,0.15);
  color: var(--cos-color);
  box-shadow: 0 0 0 1px var(--cos-color);
}
.spoiler.revealed {
  background: rgba(137,180,250,0.12);
  color: var(--cos-color);
  border-color: rgba(137,180,250,0.4);
}
.spoiler.formula-spoiler:hover,
.spoiler.formula-spoiler.revealed {
  color: var(--warning);
  background: rgba(249,226,175,0.12);
  box-shadow: 0 0 0 1px var(--warning);
  border-color: rgba(249,226,175,0.4);
}
.spoiler.answer-spoiler:hover,
.spoiler.answer-spoiler.revealed {
  color: var(--success);
  background: rgba(166,227,161,0.12);
  box-shadow: 0 0 0 1px var(--success);
  border-color: rgba(166,227,161,0.4);
}

/* Screensaver auto-reveal flash */
@keyframes spoilerReveal {
  0%   { background: var(--border); color: var(--border); }
  40%  { background: rgba(249,226,175,0.25); color: var(--warning); box-shadow: 0 0 8px var(--warning); }
  100% { background: rgba(249,226,175,0.12); color: var(--warning); }
}
.spoiler.auto-revealing {
  animation: spoilerReveal 0.6s ease forwards;
  color: var(--warning) !important;
  background: rgba(249,226,175,0.12) !important;
}

#hint-area { margin-top: 8px; }
#hint-text { font-size: 13px; color: var(--warning); margin-top: 6px; font-style: italic; }

/* ===== COLLAPSIBLE PANELS ===== */
.side-panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; flex-shrink: 0;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; user-select: none;
  transition: color var(--transition);
}
.panel-header:hover { color: var(--text); }
.panel-header .chevron { font-size: 14px; transition: transform var(--transition); }
.side-panel.collapsed .panel-header .chevron { transform: rotate(-90deg); }
.panel-body {
  padding: 10px 12px 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.side-panel.collapsed .panel-body { display: none; }

/* Tools */
.tool-section { display: flex; flex-direction: column; gap: 4px; }
.tool-section label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tool-section select, .tool-section input[type="range"] {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); padding: 5px 8px;
  font-size: 13px; outline: none; cursor: pointer;
}
.tool-section select:focus { border-color: var(--accent); }
#speed-label { font-size: 11px; color: var(--text-muted); text-align: right; }

/* Calculator */
#calc-display {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; text-align: right; margin-bottom: 6px;
}
#calc-expr   { font-size: 11px; color: var(--text-muted); min-height: 16px; font-family: monospace; }
#calc-result { font-size: 20px; font-family: monospace; color: var(--text); }
#calc-grid   { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.calc-btn {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); padding: 7px 4px; font-size: 12px; cursor: pointer;
  transition: background var(--transition), border-color var(--transition); text-align: center;
}
.calc-btn:hover { border-color: var(--accent); background: rgba(137,180,250,0.1); }
.calc-btn.fn    { color: var(--tan-color); font-size: 11px; }
.calc-btn.op    { color: var(--cos-color); }
.calc-btn.clear { color: var(--error); border-color: rgba(243,139,168,0.3); }
.calc-btn.equals { background: rgba(137,180,250,0.15); border-color: var(--accent); color: var(--accent); font-weight: 700; }
#calc-mode { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); padding-top: 4px; }
#calc-mode label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#calc-mode input { accent-color: var(--accent); }

/* Scratchpad */
#scratchpad {
  width: 100%; min-height: 140px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: monospace; font-size: 13px;
  padding: 8px 10px; resize: vertical; outline: none; line-height: 1.6;
}
#scratchpad:focus { border-color: var(--accent); }

/* ===== MIDDLE COLUMN ===== */
#col-mid {
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; gap: 8px; background: var(--bg); padding: 12px 16px;
}

/* SVG Ledger bar */
#svg-ledger {
  width: 100%; max-width: min(96vw, 980px);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.svg-ledger-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 13px; font-family: monospace;
}
.slr-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); width: 48px; flex-shrink: 0; }
.slr-val {
  padding: 2px 8px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text-muted); font-size: 13px;
  transition: color 0.4s ease, border-color 0.4s ease, background 0.4s ease;
}
.slr-val.known  { color: var(--cos-color); border-color: var(--cos-color); }
.slr-val.solved { color: var(--success);   border-color: var(--success); background: rgba(166,227,161,0.08); }
.slr-val.active { color: var(--warning);   border-color: var(--warning); background: rgba(249,226,175,0.1); }

.slr-input {
  min-width: 0;
  max-width: 120px;
  font: inherit;
  font-family: monospace;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
}
.slr-input:read-only {
  cursor: default;
  background: var(--bg-card);
}
.slr-input.guess-active:not(:read-only) {
  border-color: var(--warning);
  background: rgba(249, 226, 175, 0.08);
}
.slr-input.correct:not(:read-only) {
  border-color: var(--success);
  box-shadow: 0 0 0 1px rgba(166, 227, 161, 0.35);
}
.slr-input.wrong:not(:read-only) {
  border-color: var(--error);
  box-shadow: 0 0 0 1px rgba(243, 139, 168, 0.35);
}

#ledger-feedback-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}
#ledger-feedback-wrap #feedback-area {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  min-height: 20px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ledger-feedback-wrap #feedback-area.correct { color: var(--success); }
#ledger-feedback-wrap #feedback-area.wrong { color: var(--error); }
#ledger-feedback-wrap #btn-check-answer {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 12px;
}

/* Pop-in animation for newly solved values */
@keyframes popIn {
  0%   { transform: scale(0.7); opacity: 0; }
  70%  { transform: scale(1.1); }
  100% { transform: scale(1);   opacity: 1; }
}
.slr-val.pop { animation: popIn 0.45s cubic-bezier(0.34,1.56,0.64,1); }

#svg-container {
  width: 100%;
  max-width: min(96vw, 720px);
  min-height: 0;
  max-height: min(48vh, 440px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
#triangle-svg {
  width: 100%;
  height: auto;
  max-height: min(48vh, 440px);
  display: block;
  vertical-align: middle;
}

/* SVG elements */
.tri-side {
  stroke: var(--neutral);
  transition: stroke 0.5s ease, stroke-width 0.3s ease, filter 0.5s ease;
}
.tri-side.sin-active { stroke: var(--sin-color); filter: url(#glow); }
.tri-side.cos-active { stroke: var(--cos-color); filter: url(#glow); }
.tri-side.tan-active { stroke: var(--tan-color); filter: url(#glow); }
.tri-side.hyp-active { stroke: var(--hyp-color); filter: url(#glow); }
.tri-side.solved     { stroke: var(--success); }

/* Draw-in animation for sides */
@keyframes drawIn {
  from { stroke-dashoffset: 1000; opacity: 0.3; }
  to   { stroke-dashoffset: 0;    opacity: 1; }
}
.tri-side.draw-in {
  stroke-dasharray: 1000;
  animation: drawIn 0.7s ease forwards;
}

.tri-arc { stroke: var(--text-muted); transition: stroke 0.4s ease; fill: none; }
.tri-arc.active { stroke: var(--warning); }
.tri-arc.solved { stroke: var(--success); }

/* Arc draw-in */
@keyframes arcIn {
  from { stroke-dashoffset: 200; opacity: 0; }
  to   { stroke-dashoffset: 0;   opacity: 1; }
}
.tri-arc.draw-in {
  stroke-dasharray: 200;
  animation: arcIn 0.5s ease 0.3s forwards;
  opacity: 0;
}

.tri-label {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
  transition: fill 0.4s ease;
  pointer-events: none;
}
.vertex-label {
  font-size: 22px; fill: var(--warning);
  paint-order: stroke fill;
  stroke: #0f0f1a; stroke-width: 5px; stroke-linejoin: round;
}
.angle-val-label {
  font-size: 13px; fill: var(--warning);
  paint-order: stroke fill;
  stroke: #0f0f1a; stroke-width: 4px; stroke-linejoin: round;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.angle-val-label.visible { opacity: 1; }

.side-label {
  font-size: 16px; fill: var(--text-muted);
  paint-order: stroke fill;
  stroke: #0f0f1a; stroke-width: 6px; stroke-linejoin: round;
}
.side-label.known  { fill: var(--cos-color); }
.side-label.solved { fill: var(--success); }

/* Side label pop-in */
@keyframes labelPop {
  0%   { opacity: 0; }
  60%  { opacity: 1; }
  100% { opacity: 1; }
}
.side-label.pop-in { animation: labelPop 0.5s ease forwards; }

#highlight-dot { fill: var(--warning); opacity: 0.85; transition: opacity 0.3s ease; }

@keyframes pulse-solve {
  0%   { opacity: 1; stroke-width: 3; }
  40%  { opacity: 0.3; stroke-width: 8; filter: url(#glow-strong); }
  100% { opacity: 1; stroke-width: 3; }
}
.tri-side.pulse { animation: pulse-solve 0.8s ease 2; }

/* Triangle appear animation */
/* Opacity only — JS sets SVG transform for centering; avoid fighting CSS transform */
@keyframes triAppear {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#svg-triangle-group.appear { animation: triAppear 0.5s cubic-bezier(0.34,1.2,0.64,1); }

/* Progress bar */
#progress-bar-wrap {
  width: 100%; max-width: min(96vw, 980px); height: 5px;
  background: var(--border); border-radius: 3px; overflow: hidden;
}
#progress-bar {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.3s linear, background var(--transition);
}

#nav-controls { display: flex; gap: 8px; align-items: center; }

/* ===== RIGHT COLUMN ===== */
#ledger-panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; flex-shrink: 0;
}
#known-values { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 8px; }
.ledger-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 8px; background: var(--bg-card); border-radius: 4px;
  border: 1px solid transparent;
  transition: border-color 0.4s ease, background 0.4s ease;
}
.ledger-row.known  { border-color: var(--cos-color); }
.ledger-row.solved { border-color: var(--success); background: rgba(166,227,161,0.08); }
.ledger-row.active { border-color: var(--warning); background: rgba(249,226,175,0.1); }
.ledger-key { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.ledger-val { font-size: 13px; font-weight: 600; color: var(--text); font-family: monospace; transition: color 0.4s ease; }
.ledger-val.known  { color: var(--cos-color); }
.ledger-val.solved { color: var(--success); }

@keyframes ledgerPop {
  0%   { transform: scale(0.8); opacity: 0.3; }
  70%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
.ledger-val.pop { animation: ledgerPop 0.4s cubic-bezier(0.34,1.56,0.64,1); }

#case-badge { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
#ssa-alert { margin-top: 8px; padding: 8px; background: rgba(243,139,168,0.1); border: 1px solid var(--sin-color); border-radius: var(--radius); font-size: 12px; }
#ssa-solutions { margin-top: 4px; color: var(--text-muted); }

#vault-filters { display: flex; flex-wrap: wrap; gap: 6px; }
#vault-filters label { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; cursor: pointer; }
#vault-filters input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
#vault-list { display: flex; flex-direction: column; gap: 4px; }
.vault-item {
  padding: 6px 10px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; font-size: 12px;
  transition: border-color var(--transition), background var(--transition);
  display: flex; justify-content: space-between; align-items: center;
}
.vault-item:hover { border-color: var(--accent); background: rgba(137,180,250,0.08); }
.vault-item .vault-name { font-weight: 600; color: var(--text); }
.vault-item .vault-tag  { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.vault-item.quiz-active { border-color: var(--warning); background: rgba(249,226,175,0.08); }

#mistake-list { display: flex; flex-direction: column; gap: 4px; }
.mistake-item { font-size: 11px; padding: 4px 8px; background: rgba(243,139,168,0.08); border: 1px solid rgba(243,139,168,0.3); border-radius: 4px; color: var(--text-muted); }
.empty-msg { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* ===== BUTTONS ===== */
button {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 6px 12px; font-size: 12px; cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  white-space: nowrap;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:active { background: rgba(137,180,250,0.15); }
#btn-generate  { border-color: var(--success); color: var(--success); }
#btn-generate:hover { background: rgba(166,227,161,0.1); }
#btn-screensaver { border-color: var(--state-screen); color: var(--state-screen); }
#btn-screensaver:hover { background: rgba(203,166,247,0.1); }
#btn-submit { border-color: var(--accent); color: var(--accent); padding: 7px 14px; }
#btn-hint   { font-size: 11px; padding: 4px 10px; }
#btn-save   { border-color: var(--success); color: var(--success); }
#btn-clear-mistakes, #btn-clear-scratch { font-size: 11px; padding: 3px 8px; border-color: var(--error); color: var(--error); }
#btn-prev, #btn-next { padding: 6px 16px; }
#btn-pause { padding: 6px 16px; border-color: var(--warning); color: var(--warning); }

/* ===== CHEATSHEET ===== */
.floating-panel {
  position: fixed; top: 60px; right: 20px; width: 320px;
  max-height: calc(100vh - 80px); background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  z-index: 200; display: flex; flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5); overflow: hidden;
}
.floating-panel.docked-left  { right:auto; left:0; top:var(--topbar-h); border-radius:0 var(--radius) var(--radius) 0; height:calc(100vh - var(--topbar-h)); max-height:none; }
.floating-panel.docked-right { left:auto; right:0; top:var(--topbar-h); border-radius:var(--radius) 0 0 var(--radius); height:calc(100vh - var(--topbar-h)); max-height:none; }
#cheatsheet-titlebar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--bg-card); border-bottom: 1px solid var(--border);
  cursor: grab; user-select: none; font-size: 13px; font-weight: 600; color: var(--text); flex-shrink: 0;
}
#cheatsheet-titlebar:active { cursor: grabbing; }
.docked-left #cheatsheet-titlebar, .docked-right #cheatsheet-titlebar { cursor: default; }
#cheatsheet-controls { display: flex; gap: 4px; }
.dock-btn, #cheatsheet-close { background: transparent; border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted); padding: 2px 7px; font-size: 12px; cursor: pointer; }
.dock-btn:hover, #cheatsheet-close:hover { border-color: var(--accent); color: var(--accent); }
#cheatsheet-body { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.cs-section h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 6px; padding-bottom: 3px; border-bottom: 1px solid var(--border); }
.cs-row { font-size: 13px; font-family: monospace; padding: 3px 6px; border-radius: 3px; margin-bottom: 2px; }
.cs-row.sin     { color: var(--sin-color); background: rgba(243,139,168,0.07); }
.cs-row.cos     { color: var(--cos-color); background: rgba(137,180,250,0.07); }
.cs-row.tan     { color: var(--tan-color); background: rgba(203,166,247,0.07); }
.cs-row.neutral { color: var(--text); background: var(--bg-card); }
.cs-table { display: grid; grid-template-columns: repeat(4,1fr); gap: 2px; font-size: 12px; font-family: monospace; }
.cs-table > div { padding: 3px 4px; background: var(--bg-card); border-radius: 2px; text-align: center; }
.cs-th { font-weight: 700; color: var(--text-muted); background: transparent !important; }
.cs-th.sin { color: var(--sin-color); } .cs-th.cos { color: var(--cos-color); } .cs-th.tan { color: var(--tan-color); }

/* ===== MODAL ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 300; backdrop-filter: blur(4px); }
.modal-content { background: var(--bg-panel); border: 1px solid var(--sin-color); border-radius: var(--radius); padding: 24px; max-width: 420px; width: 90%; }
.modal-content h2 { font-size: 16px; margin-bottom: 10px; color: var(--warning); }
.modal-content p  { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.6; }
#ssa-modal-choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.ssa-choice-btn { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 10px 14px; text-align: left; cursor: pointer; font-size: 13px; transition: border-color var(--transition); }
.ssa-choice-btn:hover { border-color: var(--accent); }
.modal-close { font-size: 11px; }

/* ===== TOAST ===== */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg-panel); border: 1px solid var(--accent); border-radius: 20px; padding: 8px 20px; font-size: 13px; color: var(--text); z-index: 400; transition: opacity 0.3s ease; }
#toast.error   { border-color: var(--error);   color: var(--error); }
#toast.success { border-color: var(--success); color: var(--success); }

/* ===== UTILITY ===== */
.hidden { display: none !important; }
body.screensaver-active #col-left  { opacity: 0.5; pointer-events: none; }
body.screensaver-active #col-right { opacity: 0.7; pointer-events: none; }
/* Keep socratic text + spoilers interactive during screensaver */
body.screensaver-active #socratic-panel { pointer-events: auto; }
body.screensaver-active #reveal-text .spoiler { pointer-events: auto; cursor: pointer; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

@media (max-width: 1000px) {
  body { overflow: auto; }
  #app { grid-template-columns: 1fr; grid-template-rows: auto; overflow: visible; }
  #col-left, #col-right { border: none; border-bottom: 1px solid var(--border); }
  #col-mid { min-height: 420px; }
  .side-panel { overflow: hidden; }
  .floating-panel { width: 95vw; right: 2.5vw; }
  .floating-panel.docked-left, .floating-panel.docked-right { width: 100vw; left: 0; right: 0; border-radius: 0; }
}

/* ===== QUIZ MODE ===== */
.quiz-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 4px;
}

#quiz-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

#btn-start-quiz { border-color: var(--success); color: var(--success); width: 100%; }
#btn-start-quiz:hover { background: rgba(166,227,161,0.1); }
#btn-quiz-reveal { border-color: var(--warning); color: var(--warning); flex: 1; }
#btn-quiz-next   { border-color: var(--accent);  color: var(--accent);  flex: 1; }
#btn-quiz-skip   { font-size: 11px; color: var(--text-muted); }
#btn-quiz-exit   { font-size: 11px; color: var(--error); border-color: rgba(243,139,168,0.3); }

#quiz-progress-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  text-align: center;
}

.quiz-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin: 4px 0 8px;
  line-height: 1.45;
}
#quiz-custom-case {
  width: 100%;
  margin-bottom: 4px;
}
.quiz-custom-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 6px 0;
}
.quiz-custom-grid label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
}
.quiz-custom-grid input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 5px 6px;
  font-size: 13px;
  outline: none;
}
.quiz-custom-grid input:focus { border-color: var(--accent); }
.quiz-guess.guess-right { border-color: var(--success) !important; box-shadow: 0 0 0 1px rgba(166, 227, 161, 0.25); }
.quiz-guess.guess-wrong  { border-color: var(--error) !important; box-shadow: 0 0 0 1px rgba(243, 139, 168, 0.25); }

#btn-quiz-load-custom,
#btn-quiz-check-guesses {
  width: 100%;
  margin-top: 6px;
}

#btn-add-mistake-current {
  width: 100%;
  margin-bottom: 10px;
  border-color: var(--warning);
  color: var(--warning);
}
#btn-add-mistake-current:hover {
  background: rgba(249, 226, 175, 0.08);
}

/* ===== CHEATSHEET HIGHLIGHT ===== */
.cs-section {
  transition: background 0.3s ease, box-shadow 0.3s ease;
  border-radius: 4px;
  padding: 2px;
}
.cs-section.highlighted {
  background: rgba(249,226,175,0.12);
  box-shadow: 0 0 0 2px var(--warning);
}
.cs-section a { color: var(--accent); }
.cs-section a:hover { text-decoration: underline; }