/* Ink slate with a highlighter accent: the answer is the one marked thing on the page. */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-read: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-code: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --step: 1.25;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg: #121a24;
  --surface: #1a2532;
  --surface-2: #223041;
  --line: #2e3e52;
  --text: #e7ecf2;
  --muted: #9aa8b9;
  --mark: #f0c05a;
  --mark-ink: #1b1405;
  --mark-soft: rgba(240, 192, 90, 0.16);
  --code-kw: #9cc3e6;
  --ok: #7fcfa4;
  --warn: #f0c05a;
  --err: #f19a8f;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
}

[data-theme="light"] {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #e4eaf1;
  --line: #cdd6e0;
  --text: #16202b;
  --muted: #4f5d6e;
  --mark: #8a5d00;
  --mark-ink: #2a1c00;
  --mark-soft: #ffe6a3;
  --code-kw: #1f5f99;
  --ok: #1d7a4b;
  --warn: #8a5d00;
  --err: #b3362a;
  --shadow: 0 1px 2px rgba(22, 32, 43, 0.06);
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); }
body {
  margin: 0;
  font: 16px/1.5 var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; border-radius: var(--radius-sm); }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--mark); color: var(--mark-ink); padding: 8px 12px; border-radius: var(--radius-sm); z-index: 10; }
.skip:focus { left: 8px; }

/* Masthead */
.masthead {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 20px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  font: 700 22px/1 var(--font-read);
  background: var(--mark-soft); color: var(--mark);
  border-radius: 50%;
}
[data-theme="light"] .brand-mark { color: var(--mark-ink); }
.brand-name { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.brand-tag { margin: 0; font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tab {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; border-radius: 999px; color: var(--muted); font-weight: 550;
}
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
.tab:hover { color: var(--text); }

.theme-toggle {
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center;
}
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 1.7; stroke-linecap: round; }
[data-theme="dark"] .icon-moon, [data-theme="light"] .icon-sun { display: none; }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 40px); }

/* Playground layout */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; align-items: start; }
.play-main { display: grid; gap: 24px; min-width: 0; }

.composer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px 18px 12px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--mark); }
.composer-label { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
.composer textarea {
  width: 100%; resize: vertical; min-height: 64px; border: 0; background: transparent;
  font: 1.35rem/1.4 var(--font-read); padding: 4px 0;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--muted); opacity: 0.75; }
.composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; }

.primary {
  border: 0; cursor: pointer; border-radius: 999px; padding: 10px 26px; font-weight: 650;
  background: var(--mark); color: var(--mark-ink);
}
[data-theme="light"] .primary { background: var(--mark-ink); color: #fff; }
.primary:disabled { opacity: 0.55; cursor: progress; }
.hint { color: var(--muted); font-size: 0.875rem; margin: 6px 0 0; }

/* Result */
.empty { border: 1px dashed var(--line); border-radius: var(--radius-lg); padding: 28px; color: var(--muted); }
.empty-title { color: var(--text); font: 1.2rem/1.4 var(--font-read); margin: 0 0 6px; }
.empty p:last-child { margin: 0; max-width: 60ch; }

.answer-block { display: grid; gap: 6px; }
.status { font-size: 0.875rem; color: var(--muted); margin: 0; }
.status strong { font-weight: 600; }
.status .ok { color: var(--ok); }
.status .warn { color: var(--warn); }
.status .err { color: var(--err); }
.answer {
  margin: 0; font: clamp(1.5rem, 1.1rem + 1.4vw, 2.1rem)/1.3 var(--font-read);
  letter-spacing: -0.005em; max-width: 34ch;
}
.answer mark {
  background: linear-gradient(transparent 58%, var(--mark-soft) 58%);
  color: inherit; padding: 0 2px;
}
.answer.is-error { color: var(--err); font-size: 1.3rem; }
.meta { color: var(--muted); font-size: 0.875rem; margin: 2px 0 0; display: flex; gap: 16px; flex-wrap: wrap; }

.loading { display: flex; align-items: center; gap: 14px; padding: 24px 0; color: var(--muted); }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--mark); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; transform: scale(0.7); } }

.working { border-top: 1px solid var(--line); padding-top: 20px; display: grid; gap: 22px; }
.working h3 { margin: 0 0 10px; font-size: 1rem; }
.trail { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: 2px; }
.trail li {
  counter-increment: step; display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.trail li::before { content: counter(step); color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.trail .bad { color: var(--err); font-size: 0.875rem; }
.trail .good { color: var(--muted); font-size: 0.875rem; }

.sql-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 0.85rem; color: var(--muted); }
.ghost:hover { color: var(--text); }
pre.sql {
  margin: 0; padding: 14px 16px; overflow-x: auto; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  font: 0.9rem/1.6 var(--font-code); white-space: pre-wrap; word-break: break-word;
}
pre.sql .kw { color: var(--code-kw); font-weight: 600; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--surface); }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }
.result-table th:last-child { text-align: right; }

/* Side column */
.play-side { display: grid; gap: 28px; }
.side-title { font-size: 1rem; margin: 0 0 10px; }
.examples { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.example {
  width: 100%; text-align: left; cursor: pointer; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); padding: 9px 12px; font: 0.98rem/1.35 var(--font-read);
}
.example:hover { border-color: var(--mark); }
.field-label { display: block; font-size: 0.9rem; margin-bottom: 6px; }
select { width: 100%; padding: 9px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); }

details.table-detail { border-bottom: 1px solid var(--line); }
details.table-detail summary { cursor: pointer; padding: 9px 0; display: flex; justify-content: space-between; gap: 8px; }
details.table-detail summary span { color: var(--muted); font-size: 0.875rem; }
details.table-detail .table-wrap { margin-bottom: 12px; }

/* About */
.prose { max-width: 70ch; }
.prose h1 { font: 600 clamp(1.9rem, 1.3rem + 2vw, 2.7rem)/1.15 var(--font-read); letter-spacing: -0.015em; margin: 0 0 16px; }
.prose h2 { font-size: 1.2rem; margin: 40px 0 10px; }
.prose p, .prose li { font: 1.08rem/1.65 var(--font-read); }
.prose .lede { font-size: 1.22rem; color: var(--muted); }
.prose ul { padding-left: 1.2em; }
.prose li { margin: 4px 0; }
.prose .hint { font-family: var(--font-ui); }

.diagram { margin: 12px 0 0; }
.diagram svg { width: 100%; height: auto; font-family: var(--font-ui); }
.diagram-tall { display: none; max-width: 330px; }
.diagram figcaption { margin-top: 8px; }
.d-vert { writing-mode: vertical-rl; }
.d-box rect { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.d-core rect { stroke: var(--muted); stroke-width: 2; }
.d-answer rect { stroke: var(--mark); stroke-width: 2; }
.d-box text { fill: var(--text); font-size: 15px; text-anchor: middle; }
text.d-sub, .d-box text.d-sub { fill: var(--muted); font-size: 13px; text-anchor: middle; }
.d-line { fill: none; stroke: var(--muted); stroke-width: 1.6; }
.d-dashed { stroke-dasharray: 5 5; }
.d-arrowhead { fill: var(--muted); }

.score { display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap; margin: 8px 0 12px; }
.prose .score-big { font: 600 2.6rem/1 var(--font-read); margin: 0; }
.prose .score-big small { font-size: 1.1rem; color: var(--muted); font-weight: 400; }
.prose .score p { margin: 0; }
.result-table td.status-cell { font-family: var(--font-ui); }
.result-table .pass { color: var(--ok); }
.result-table .fail { color: var(--err); }
.result-table td:first-child { white-space: normal; min-width: 220px; }
.prose .table-wrap { margin: 12px 0; }
.prose table { font-family: var(--font-ui); font-size: 0.9rem; }

.footer { border-top: 1px solid var(--line); padding: 16px clamp(16px, 4vw, 40px); color: var(--muted); font-size: 0.85rem; }
.footer p { margin: 0; max-width: 1100px; }

/* One column on narrow screens: question, examples, answer, then settings and data. */
@media (max-width: 900px) {
  .play { display: flex; flex-direction: column; gap: 24px; }
  .play-main, .play-side { display: contents; }
  .composer { order: 1; }
  .side-examples { order: 2; }
  .result { order: 3; }
  .side-settings { order: 4; }
  .side-data { order: 5; }
}
@media (max-width: 640px) {
  .diagram-wide { display: none; }
  .diagram-tall { display: block; margin: 0 auto; }
  .masthead { grid-template-columns: 1fr auto; row-gap: 12px; }
  .tabs { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .tab { flex: 1; }
  .brand-tag { display: none; }
  .composer textarea { font-size: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; }
}
