:root {
  --ink: #0d1321; --ink2: #151d30; --ink3: #1e2942; --line: #2b3858;
  --paper: #efe4cc; --paper2: #e3d4b3; --paper-ink: #2b2418;
  --gold: #e8b04a; --gold2: #f5cf7a; --red: #d9534f; --green: #4cc38a; --blue: #6aa8ff;
  --text: #e8ecf4; --muted: #96a3bf;
  --serif: 'Special Elite', 'Courier New', monospace;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  font-family: Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--text); min-height: 100vh;
  background: radial-gradient(1200px 600px at 70% -10%, #23305088, transparent),
              radial-gradient(900px 500px at -10% 110%, #3a2a1466, transparent), var(--ink); }
a { color: var(--gold2); }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: #0d1321e6; backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-size: 22px; color: var(--gold); text-decoration: none; letter-spacing: .5px; }
.badge-icon { display: inline-block; transform: translateY(-1px); }
.top nav { display: flex; gap: 18px; }
.top nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.top nav a:hover { color: var(--text); }
.rank { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 14px; color: var(--muted); }
.rank b { color: var(--gold2); }
main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 60px; }

.bar { height: 8px; border-radius: 99px; background: #ffffff14; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold2)); border-radius: 99px; transition: width .5s; }

/* case board */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: center; margin-bottom: 30px; }
.hero h1 { font-family: var(--serif); font-size: 44px; margin: 0 0 8px; color: var(--paper); font-weight: 400; }
.hero p { color: var(--muted); line-height: 1.6; margin: 0 0 16px; }
.hero-art { border-radius: 16px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 16/9; background: var(--ink2); }
.hero-art img, .hero-art svg { width: 100%; height: 100%; object-fit: cover; display: block; }
.overall { display: flex; gap: 16px; align-items: center; font-size: 14px; color: var(--muted); }
.overall .bar { flex: 1; }
.board { position: relative; padding: 28px; border-radius: 18px;
  background: repeating-linear-gradient(45deg, #5a3f22 0 2px, #634626 2px 6px), #5e4224;
  box-shadow: inset 0 0 60px #00000088, 0 20px 50px #0008; }
.board svg.strings { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cases { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 26px; }
.case { position: relative; display: block; text-decoration: none; color: var(--paper-ink);
  background: var(--paper); border-radius: 4px; padding: 26px 16px 14px; min-height: 170px;
  box-shadow: 0 8px 18px #0007; transform: rotate(var(--tilt, 0deg)); transition: transform .2s, box-shadow .2s; }
.case:hover { transform: rotate(0) translateY(-4px) scale(1.02); box-shadow: 0 16px 30px #000a; }
.case::before { content: ''; position: absolute; top: -8px; left: 50%; width: 16px; height: 16px; margin-left: -8px;
  border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ff8a80, #b3261e); box-shadow: 0 3px 4px #0008; }
.case .thumb { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 2px; margin-bottom: 10px; box-shadow: inset 0 0 0 1px #0002; }
.banner { height: 200px; border-radius: 16px; overflow: hidden; margin-bottom: 20px; border: 1px solid var(--line); }
.banner img { width: 100%; height: 100%; object-fit: cover; display: block; }
.case .no { font-family: var(--serif); font-size: 13px; color: #7a6a4c; }
.case h3 { font-family: var(--serif); font-weight: 400; font-size: 20px; margin: 4px 0 6px; }
.case .topics { font-size: 12.5px; color: #5b5040; line-height: 1.4; min-height: 36px; }
.case .bar { background: #00000018; margin-top: 12px; }
.case .meta { display: flex; justify-content: space-between; font-size: 12px; margin-top: 6px; color: #5b5040; }
.case.locked { filter: grayscale(.9) brightness(.6); }
.case.locked::after { content: 'LOCKED'; position: absolute; right: 12px; bottom: 34px; font-family: var(--serif);
  color: var(--red); border: 2px solid var(--red); padding: 2px 8px; transform: rotate(-12deg); font-size: 18px; }
.case.solved::after { content: 'CLOSED'; position: absolute; right: 12px; bottom: 34px; font-family: var(--serif);
  color: #2f7d4f; border: 2px solid #2f7d4f; padding: 2px 8px; transform: rotate(-12deg); font-size: 18px; }

/* case file */
.crumbs { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.casehead { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: end; margin-bottom: 22px; }
.casehead h1 { font-family: var(--serif); font-weight: 400; font-size: 36px; margin: 0; color: var(--paper); }
.casehead p { color: var(--muted); line-height: 1.6; margin: 8px 0 0; }
.clues { display: grid; gap: 10px; }
.clue { display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center; text-decoration: none; color: var(--text);
  background: var(--ink2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; transition: border-color .15s, background .15s; }
.clue:hover { border-color: var(--gold); background: var(--ink3); }
.clue .ic { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: #ffffff0d; font-size: 20px; }
.clue small { color: var(--muted); display: block; margin-top: 2px; }
.clue.boss { border-color: #b3261e88; background: linear-gradient(90deg, #2a1418, var(--ink2)); }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 15px; }
.stars .off { color: #ffffff22; }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

/* challenge */
.play { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 20px; align-items: start; }
.brief { background: var(--paper); color: var(--paper-ink); border-radius: 6px; padding: 22px; box-shadow: 0 10px 30px #0008; position: sticky; top: 76px; }
.brief .tag { color: #7a6a4c; }
.brief h2 { font-family: var(--serif); font-weight: 400; margin: 4px 0 10px; font-size: 24px; }
.brief .story { font-style: italic; color: #5b5040; border-left: 3px solid #b3261e; padding-left: 12px; margin: 0 0 14px; line-height: 1.5; }
.brief .learn { background: #fff9; border-radius: 6px; padding: 12px 14px; line-height: 1.55; font-size: 14.5px; margin-bottom: 14px; }
.brief .task { font-weight: 600; line-height: 1.5; }
.brief code, .learn code { font-family: var(--mono); font-size: 13px; background: #2b241812; padding: 1px 5px; border-radius: 4px; }
.brief pre { font-family: var(--mono); font-size: 13px; background: #2b2418; color: var(--paper); padding: 10px 12px; border-radius: 6px; overflow-x: auto; }
.hints { margin-top: 16px; border-top: 1px dashed #7a6a4c66; padding-top: 12px; }
.hints .hint { background: #fde9a8; border-radius: 6px; padding: 10px 12px; margin-top: 8px; font-size: 14px; line-height: 1.5; }
.btn { border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 600; }
.btn.gold { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #2b1d05; }
.btn.dark { background: var(--ink3); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: #7a5b1e; border: 1px dashed #7a5b1e; padding: 6px 12px; }
.btn:disabled { opacity: .5; cursor: progress; }
.work { display: grid; gap: 14px; }
.panel { background: var(--ink2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel .ph { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.cm-editor { font-size: 14px; min-height: 220px; }
.cm-editor .cm-scroller { font-family: var(--mono); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.out { font-family: var(--mono); font-size: 13.5px; white-space: pre-wrap; padding: 14px; min-height: 60px; max-height: 360px; overflow: auto; margin: 0; }
.out .err { color: #ff8a80; }
.figs img { max-width: 100%; background: #fff; border-radius: 8px; margin: 8px 14px 14px; }
.verdict { border-radius: 12px; padding: 14px 16px; font-weight: 500; line-height: 1.5; }
.verdict.ok { background: #143a2a; border: 1px solid var(--green); color: #c9f5de; }
.verdict.no { background: #3a1418; border: 1px solid var(--red); color: #ffd6d3; }
.opts { display: grid; gap: 10px; padding: 14px; }
.opt { text-align: left; background: var(--ink3); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-family: var(--mono); font-size: 14px; }
.opt:hover { border-color: var(--gold); }
.opt.right { border-color: var(--green); background: #143a2a; }
.opt.wrong { border-color: var(--red); background: #3a1418; }
.fill { padding: 16px; line-height: 2.4; font-size: 15px; }
.fill input, .predict textarea, .term input { font-family: var(--mono); font-size: 14px; color: var(--text); background: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.fill input { width: 150px; }
.predict textarea { width: calc(100% - 28px); margin: 14px; min-height: 90px; resize: vertical; }
.term { font-family: var(--mono); font-size: 14px; padding: 14px; background: #05080f; min-height: 220px; }
.term .line { white-space: pre-wrap; color: #b9c6e4; }
.term .cmd { color: var(--green); }
.term .step { color: var(--gold2); margin: 6px 0; }
.term form { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.term input { flex: 1; background: transparent; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; }
.next { display: flex; gap: 10px; align-items: center; }

.toast { position: fixed; right: 24px; bottom: 24px; background: var(--paper); color: var(--paper-ink); border-radius: 10px; padding: 14px 18px;
  box-shadow: 0 12px 30px #000a; font-family: var(--serif); font-size: 18px; animation: pop .35s ease-out; z-index: 10; }
@keyframes pop { from { transform: translateY(20px) scale(.9); opacity: 0; } }

.book { columns: 2 380px; column-gap: 20px; }
.card { break-inside: avoid; background: var(--paper); color: var(--paper-ink); border-radius: 6px; padding: 16px 18px; margin-bottom: 18px; box-shadow: 0 6px 16px #0007; }
.card h4 { font-family: var(--serif); font-weight: 400; margin: 0 0 6px; font-size: 18px; }
.card .tag { color: #7a6a4c; }
.card p { margin: 6px 0 0; line-height: 1.55; font-size: 14.5px; }
.card code { font-family: var(--mono); font-size: 13px; background: #2b241812; padding: 1px 5px; border-radius: 4px; }
.evidence iframe { width: 100%; height: calc(100vh - 200px); border: 1px solid var(--line); border-radius: 12px; background: #0f0f1a; }
.loader { color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .hero, .casehead, .play { grid-template-columns: 1fr; }
  .brief { position: static; }
  .top { flex-wrap: wrap; gap: 10px; }
  .rank { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
