:root {
  --bg: #0f1419;
  --panel: #1a2030;
  --panel-2: #232b3d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --accent-3: #fb923c;
  --good: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;
  --code-bg: #0d1117;
  --border: #30363d;
  --phase-white: linear-gradient(135deg, #374151 0%, #6b7280 100%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

/* ── Header ── */
header {
  padding: 28px 28px 20px;
  border-bottom: 3px solid var(--accent);
  background: var(--phase-white);
}
header h1 { margin: 0 0 10px; font-size: 22px; color: #fff; }
.meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; }
.badge {
  background: rgba(0,0,0,0.35); padding: 4px 12px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2); color: #fff; font-size: 12px;
}
.badge-blue { background: #1d4ed8; border-color: #3b82f6; }
.badge-orange { background: #c2410c; border-color: var(--accent-3); }
.badge-purple { background: #5b21b6; border-color: var(--accent-2); }

/* Phase header backgrounds */
.phase-white  { background: linear-gradient(135deg, #374151 0%, #6b7280 100%); }
.phase-brown  { background: linear-gradient(135deg, #5c3a1e 0%, #a05a2c 100%); }
.phase-green  { background: linear-gradient(135deg, #14532d 0%, #22c55e 100%); }
.phase-blue   { background: linear-gradient(135deg, #1e3a5f 0%, #3b82f6 100%); }
.phase-gold   { background: linear-gradient(135deg, #92400e 0%, #f59e0b 100%); }
.phase-purple { background: linear-gradient(135deg, #3b0764 0%, #a855f7 100%); }

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ── TOC ── */
nav.toc {
  position: sticky; top: 24px;
  height: max-content;
  background: var(--panel);
  border-radius: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  font-size: 13px;
}
nav.toc h3 {
  margin: 0 0 10px; font-size: 11px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 1px;
}
nav.toc a {
  display: block; padding: 5px 10px;
  color: var(--text); text-decoration: none; border-radius: 4px;
  border-left: 2px solid transparent; transition: all 0.15s;
}
nav.toc a:hover { background: var(--panel-2); border-left-color: var(--accent); }
nav.toc a.active { border-left-color: var(--accent); color: var(--accent); background: var(--panel-2); }

/* ── Sections ── */
main { min-width: 0; }
section {
  background: var(--panel);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
}
section h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
section h2 .icon { font-size: 16px; }
section h3 { color: var(--accent-2); font-size: 15px; margin-top: 20px; margin-bottom: 8px; }
section h4 { color: var(--accent-3); font-size: 13px; margin-bottom: 4px; }

/* ── Code ── */
code {
  background: var(--code-bg); padding: 2px 6px; border-radius: 3px;
  font-family: "JetBrains Mono", "Fira Code", Menlo, monospace;
  font-size: 13px; color: #c9d1d9;
}
pre {
  background: var(--code-bg); padding: 16px; border-radius: 6px;
  overflow-x: auto; border-left: 3px solid var(--accent);
  position: relative; margin: 12px 0;
}
pre code { background: none; padding: 0; font-size: 13px; color: #e6edf3; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 10px; font-size: 11px; cursor: pointer; transition: all 0.15s;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── Go syntax highlighting (lightweight, class-based) ── */
.gokw   { color: #ff7b72; }              /* keywords: func, var, package, import, if, return... */
.gotype { color: #7ee787; }              /* types: int, string, float64, bool... */
.gostr  { color: #a5d6ff; }              /* string literals */
.gocom  { color: #8b949e; font-style: italic; } /* comments */
.gonum  { color: #79c0ff; }              /* numeric literals */
.gofn   { color: #d2a8ff; }              /* function/package identifiers e.g. fmt.Println */

/* ── Tables ── */
table {
  width: 100%; border-collapse: collapse; margin: 12px 0;
  font-size: 14px; border-radius: 6px; overflow: hidden;
}
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--panel-2); color: var(--accent-3); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(56, 189, 248, 0.04); }
td code { font-size: 12px; }

/* ── Hints (collapsible) ── */
.hint {
  background: var(--panel-2); border-radius: 6px; margin-bottom: 8px;
  border-left: 3px solid var(--warn);
}
.hint summary {
  padding: 11px 16px; cursor: pointer; font-weight: 600;
  color: var(--warn); user-select: none; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.hint summary::before { content: "▶"; font-size: 10px; transition: transform 0.2s; }
.hint[open] summary::before { transform: rotate(90deg); }
.hint[open] summary { border-bottom: 1px solid var(--border); }
.hint-body { padding: 12px 16px; }

/* ── Steps ── */
.steps { display: flex; flex-direction: column; gap: 10px; }
.step {
  background: var(--code-bg); border-left: 3px solid var(--accent-3);
  padding: 12px 16px; border-radius: 4px; display: flex; gap: 12px; align-items: flex-start;
}
.step-num {
  flex-shrink: 0;
  background: var(--accent-3); color: #000;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 13px;
}
.step-body { flex: 1; }

/* ── Viz / SVG containers ── */
.viz {
  background: var(--code-bg); border-radius: 8px;
  padding: 20px; margin: 16px 0;
  border: 1px solid var(--border); overflow-x: auto;
  display: flex; justify-content: center;
}
.viz svg text { font-family: "JetBrains Mono", monospace; }

/* ── Info boxes ── */
.info-box {
  border-radius: 6px; padding: 14px 18px; margin: 12px 0;
  display: flex; gap: 12px; align-items: flex-start;
  font-size: 14px;
}
.info-box.note  { background: rgba(56,189,248,0.08); border-left: 3px solid var(--accent); }
.info-box.warn  { background: rgba(251,191,36,0.08); border-left: 3px solid var(--warn); }
.info-box.good  { background: rgba(74,222,128,0.08); border-left: 3px solid var(--good); }
.info-box.bad   { background: rgba(248,113,113,0.08); border-left: 3px solid var(--bad); }
.info-box .icon { font-size: 18px; line-height: 1.4; flex-shrink: 0; }

/* ── Problem tabs ── */
.tab-bar { display: flex; gap: 4px; margin-bottom: 0; border-bottom: 2px solid var(--border); }
.tab-btn {
  padding: 8px 20px; background: none; color: var(--muted);
  border: none; border-bottom: 3px solid transparent; margin-bottom: -2px;
  cursor: pointer; font-size: 14px; font-weight: 600; transition: all 0.15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-pane { display: none; padding-top: 16px; }
.tab-pane.active { display: block; }

/* ── Self-eval ── */
.self-eval { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.self-eval label {
  background: var(--panel-2); padding: 9px 16px; border-radius: 20px;
  cursor: pointer; display: inline-flex; gap: 8px; align-items: center;
  font-size: 14px; border: 1px solid var(--border); transition: border-color 0.15s;
}
.self-eval label:has(input:checked) { border-color: var(--accent); color: var(--accent); }
.self-eval input { accent-color: var(--accent); }
textarea {
  width: 100%; min-height: 80px;
  background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 10px; font-family: inherit; font-size: 14px; margin-bottom: 12px;
  resize: vertical;
}
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
button.action {
  background: var(--accent); color: #000; border: none;
  padding: 8px 18px; border-radius: 5px; cursor: pointer; font-weight: 600;
}
button.action:hover { filter: brightness(1.1); }
button.action.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  nav.toc { position: static; }
}

/* ── Misc ── */
ul, ol { padding-left: 22px; }
li { margin: 4px 0; }
a { color: var(--accent); }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
strong { color: #f0f6fc; }
p { margin: 8px 0 12px; }
