/* Same palette and type as the stream overlay ("midnight"). */
:root {
  --bg: #13151f;
  --bg-glow: #1d2035;
  --card: #1b1e2e;
  --card-2: #252940;
  --edge: rgba(200, 210, 255, 0.07);
  --text: #e6e8f5;
  --soft: #bcc1dc;
  --muted: #8a90b2;
  --faint: #545a7a;
  --accent: #f5b98b;
  --accent-2: #b7a6f5;
  --ok: #a6dba0;
  --bad: #f38ba8;
  --easy: #8bd5ca;
  --medium: #f0cf7a;
  --hard: #f38ba8;
  --gold: #f5d58b; --silver: #c9cfe6; --bronze: #e6a780;
  --kw: #c6a0f6; --ident: #e6e8f5; --num: #f5a97f; --str: #a6da95; --op: #91d7e3; --type: #f5d08b;
  --logo: #b7a6f5; --logo-mid: #f5b98b;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --sans: "Nunito", "Segoe UI", system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
  --pixel: "VT323", "JetBrains Mono", monospace;
  --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100vh; color: var(--text); font-family: var(--sans); font-size: 16px;
  background: radial-gradient(1100px 700px at 50% 0%, var(--bg-glow), var(--bg) 75%) no-repeat, var(--bg);
}
a { color: inherit; }
code, kbd, pre, .code { font-variant-ligatures: none; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 24px 64px; }

/* ---- header ---- */
.top { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; margin-bottom: 28px; }
.logo { font-family: var(--pixel); font-size: 48px; line-height: 1; color: var(--logo); text-decoration: none; white-space: nowrap;
  text-shadow: 0 0 18px color-mix(in srgb, var(--logo) 45%, transparent); }
.logo .prompt { color: var(--ok); margin-right: 8px; }
.logo .mid { color: var(--logo-mid); }
.logo .blink { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
nav { display: flex; gap: 8px; }
nav a { text-decoration: none; font-weight: 700; color: var(--soft); padding: 8px 16px; border-radius: 999px; background: var(--card); border: 1px solid var(--edge); }
nav a:hover { color: var(--text); }
nav a.on { color: #161826; background: var(--accent-2); }
.live { margin-left: auto; text-decoration: none; font-weight: 800; color: #161826; background: var(--accent); padding: 8px 18px; border-radius: 999px; display: flex; align-items: center; gap: 8px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #c0392b; box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.25); }

/* ---- building blocks ---- */
.card { background: var(--card); border: 1px solid var(--edge); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); padding: 20px 22px; min-width: 0; }
.card h2 { margin: 0 0 14px; font-family: var(--serif); font-weight: 600; font-size: 21px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card h2 .hint { font-family: var(--sans); font-size: 14px; font-weight: 600; color: var(--muted); }
h1 { font-family: var(--serif); font-weight: 600; font-size: 34px; margin: 6px 0 0; line-height: 1.15; }
h1 a { text-decoration: none; }
h1 a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.eyebrow { display: flex; gap: 10px; align-items: center; color: var(--muted); font-weight: 700; flex-wrap: wrap; }
.diff { font-weight: 700; padding: 1px 10px; border-radius: 999px; font-size: 14px; }
.diff.Easy { color: var(--easy); background: color-mix(in srgb, var(--easy) 14%, transparent); }
.diff.Medium { color: var(--medium); background: color-mix(in srgb, var(--medium) 14%, transparent); }
.diff.Hard { color: var(--hard); background: color-mix(in srgb, var(--hard) 14%, transparent); }
.empty { color: var(--muted); padding: 8px 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 22px 0; }
.tile { background: var(--card); border: 1px solid var(--edge); border-radius: 14px; padding: 12px 16px; display: flex; flex-direction: column; align-items: center; }
.tile b { font-family: var(--serif); font-size: 28px; font-weight: 600; line-height: 1.1; }
.tile span { color: var(--muted); font-size: 13px; font-weight: 700; }

.avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 800; color: #161826; }

/* ---- leaderboard ---- */
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.board li { display: grid; grid-template-columns: 36px 30px minmax(0, 1fr) auto; align-items: center; gap: 12px; background: var(--card-2);
  border-radius: 12px; padding: 8px 16px 8px 10px; position: relative; overflow: hidden; }
.board li .fill { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--rank, var(--accent-2)) 10%, transparent); }
.board li > :not(.fill) { position: relative; }
.board .rank { font-family: var(--pixel); font-size: 28px; line-height: 1; text-align: center; color: var(--rank, var(--muted)); }
.board li:nth-child(1) { --rank: var(--gold); }
.board li:nth-child(2) { --rank: var(--silver); }
.board li:nth-child(3) { --rank: var(--bronze); }
.board li:nth-child(-n+3) { box-shadow: inset 3px 0 0 var(--rank); }
.board .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board .name small { color: var(--muted); font-weight: 600; margin-left: 8px; font-size: 13px; }
.board .count { font-family: var(--pixel); font-size: 28px; line-height: 1; }
.board .count small { font-family: var(--sans); font-size: 12px; color: var(--muted); font-weight: 700; margin-left: 4px; }
.board.big li { padding: 10px 18px 10px 12px; }
.board.big .name { font-size: 18px; }

/* ---- solves list ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
a.solve { text-decoration: none; display: flex; flex-direction: column; gap: 12px; transition: transform 0.15s, border-color 0.15s; }
a.solve:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent-2) 40%, transparent); }
a.solve h3 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 20px; line-height: 1.2; }
.facts { display: flex; gap: 8px; flex-wrap: wrap; }
.facts span { background: var(--card-2); border-radius: 999px; padding: 3px 12px; font-size: 13px; font-weight: 700; color: var(--soft); }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; font-weight: 600; }
.who .stack { display: flex; }
.who .avatar { width: 28px; height: 28px; font-size: 12px; border: 2px solid var(--card); }
.who .avatar + .avatar { margin-left: -8px; }

/* ---- one solve ---- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.code { font-family: var(--mono); font-size: 15px; line-height: 1.65; overflow: auto; }
.code .ln { display: flex; white-space: pre-wrap; border-radius: 6px; }
.code .ln.cur { background: color-mix(in srgb, var(--accent-2) 10%, transparent); }
.code .gutter { flex: none; width: 3ch; margin-right: 16px; text-align: right; color: var(--faint); user-select: none; }
.code .src { padding-left: calc(var(--indent, 0) * 4ch); min-width: 0; overflow-wrap: anywhere; }
.code .caret { display: inline-block; width: 2px; height: 1.2em; vertical-align: -0.2em; background: var(--accent); margin: 0 1px; animation: blink 1s steps(1) infinite; }
.code .new { background: color-mix(in srgb, var(--accent) 22%, transparent); border-radius: 3px; }
.t-keyword { color: var(--kw); } .t-type { color: var(--type); } .t-ident { color: var(--ident); }
.t-number { color: var(--num); } .t-string, .t-char { color: var(--str); } .t-op { color: var(--op); }
.screen { height: 520px; }
.player { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.player button { font: inherit; font-weight: 800; color: var(--text); background: var(--card-2); border: 1px solid var(--edge); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.player button.on { color: #161826; background: var(--accent-2); }
.player input[type=range] { flex: 1; min-width: 140px; accent-color: var(--accent); }
.player .clock { font-family: var(--mono); color: var(--muted); font-size: 14px; min-width: 9ch; text-align: right; }
.now { min-height: 26px; margin-top: 12px; color: var(--soft); font-size: 15px; }
.now .user { font-weight: 800; margin-right: 8px; }
.now code { font-family: var(--mono); color: var(--text); }
#chat-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; height: 460px; overflow: hidden;
  mask-image: linear-gradient(to bottom, black 80%, transparent); }
#chat-feed li { font-size: 15px; line-height: 1.4; color: var(--soft); flex: none; }
#chat-feed li:first-child { animation: fadein 0.3s ease-out; }
#chat-feed .user { font-weight: 800; margin-right: 8px; }
#chat-feed .cmd { font-family: var(--mono); font-size: 14px; color: var(--text); }
#chat-feed .detail { color: var(--muted); margin-left: 8px; font-size: 14px; }
#chat-feed .bad .cmd { color: var(--bad); }
#chat-feed li.notice { background: color-mix(in srgb, var(--tint) 12%, var(--card-2)); border-left: 3px solid var(--tint); border-radius: 10px; padding: 7px 12px 8px; color: var(--text); --tint: var(--accent-2); }
#chat-feed li.notice.judge { --tint: var(--ok); }
#chat-feed li.notice.bad { --tint: var(--bad); }
#chat-feed .tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; background: var(--tint); color: #161826; border-radius: 6px; padding: 1px 6px; margin-right: 8px; }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }
.copy { margin-left: auto; font: inherit; font-size: 14px; font-weight: 800; color: var(--text); background: var(--card-2); border: 1px solid var(--edge); border-radius: 999px; padding: 4px 14px; cursor: pointer; }
.final .code { max-height: none; }
.foot { margin-top: 40px; color: var(--faint); font-size: 14px; text-align: center; }
.foot a { color: var(--muted); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .screen { height: 420px; }
  #chat-feed { height: 320px; }
}
@media (max-width: 560px) {
  .wrap { padding: 16px 16px 48px; }
  .logo { font-size: 36px; }
  .live { margin-left: 0; }
  h1 { font-size: 27px; }
  .code { font-size: 13px; }
  .grid { grid-template-columns: 1fr; }
  .board li { grid-template-columns: 28px 30px minmax(0, 1fr) auto; gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.layout.second { margin-top: 18px; }
