:root {
  color-scheme: dark;
  --bg: #0b0e1a;
  --bg-glow: #131a3a;
  --surface: #12162a;
  --surface-2: #181d36;
  --surface-3: #1f2547;
  --line: #262c4d;
  --line-strong: #353c66;
  --text: #e7e9f4;
  --muted: #8b91b3;
  --faint: #5d6388;
  --accent: #7aa2ff;
  --accent-strong: #9bb8ff;
  --gold: #f5c542;
  --silver: #c3c9de;
  --green: #3fd68f;
  --red: #ff6b7a;
  --amber: #ffb454;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --gutter: clamp(16px, 4vw, 32px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.55 var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, #10183a55, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
code, pre, textarea, .mono, .num { font-family: var(--mono); font-variant-ligatures: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.error { color: var(--red); min-height: 1.4em; margin: 0; font-size: 0.9rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text);
  font: 600 0.9rem var(--sans); cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0e1a; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #0b0e1a; }
.btn-danger { color: var(--red); border-color: #ff6b7a55; background: transparent; }
.btn-danger:hover { background: #ff6b7a1a; color: var(--red); border-color: var(--red); }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.link:hover { color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--text);
  font: 0.95rem var(--sans);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #7aa2ff33; }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }

.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line-strong); }
.segmented button { border: 0; background: none; color: var(--muted); font: 600 0.88rem var(--sans); padding: 7px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.segmented button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: var(--gutter); }
.gate-card {
  width: min(420px, 100%); padding: 36px 32px; border-radius: 18px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line);
  box-shadow: 0 30px 80px #00000066; display: flex; flex-direction: column; gap: 16px; text-align: center;
}
.gate-card .field { text-align: left; }
.gate-card p { margin: 0; }
.gate-logo { width: 72px; height: 72px; margin: 0 auto 4px; background: url(/static/icon.svg) center/contain no-repeat; filter: drop-shadow(0 8px 24px #7aa2ff44); }

/* Shell */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: #0b0e1acc; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 12px var(--gutter); display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand:hover { color: var(--text); }
.brand em { font-style: normal; color: var(--muted); font-weight: 500; }
.brand-mark { width: 30px; height: 30px; background: url(/static/icon.svg) center/contain no-repeat; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 7px 12px; border-radius: 8px; font-weight: 500; font-size: 0.93rem; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.queue-pill { display: inline-flex; align-items: center; gap: 8px; font: 500 0.82rem var(--mono); color: var(--muted); padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); }
.queue-pill:hover { color: var(--text); }
.queue-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.queue-pill.busy .dot { background: var(--amber); box-shadow: 0 0 0 0 #ffb45488; animation: pulse 1.6s infinite; }
.queue-pill.paused .dot { background: var(--red); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #ffb45488; } 70% { box-shadow: 0 0 0 7px #ffb45400; } 100% { box-shadow: 0 0 0 0 #ffb45400; } }

.view { max-width: 1200px; margin: 0 auto; padding: 32px var(--gutter) 48px; outline: none; }
.footer { max-width: 1200px; margin: 0 auto; padding: 20px var(--gutter) calc(28px + env(safe-area-inset-bottom, 0px)); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--faint); font-size: 0.85rem; border-top: 1px solid var(--line); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.eyebrow { font: 600 0.78rem var(--mono); color: var(--accent); text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 8px; display: block; }
.crumbs { font-size: 0.88rem; color: var(--muted); margin-bottom: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 140px; }

/* Year switcher */
.year-switch { display: flex; align-items: center; gap: 6px; }
.year-switch select { width: auto; font: 700 1rem var(--mono); }

/* Calendar */
.calendar { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.day {
  position: relative; display: flex; flex-direction: column; gap: 10px; min-height: 148px;
  padding: 16px; border-radius: var(--radius); color: var(--text);
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.day:hover { color: var(--text); border-color: var(--line-strong); transform: translateY(-2px); box-shadow: 0 12px 30px #00000055; }
.day-num { font: 700 1.6rem/1 var(--mono); color: var(--text); }
.day-title { font-size: 0.86rem; color: var(--muted); line-height: 1.35; min-height: 2.7em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.day-parts { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.day-part { display: flex; align-items: center; gap: 8px; font: 0.8rem var(--mono); color: var(--muted); }
.day-part .star { color: var(--faint); }
.day-part.solved .star { color: var(--gold); }
.day-part .fast { margin-left: auto; color: var(--text); }
.day.locked { background: var(--surface); border-style: dashed; pointer-events: none; }
.day.locked .day-num { color: var(--faint); }
.day.locked .day-title { color: var(--faint); }
.day.empty .day-num { color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font: 600 0.75rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
tr.me td { background: #7aa2ff12; }
.rank { font: 700 0.95rem var(--mono); color: var(--muted); width: 1%; }
.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: #e0a272; }
.user { font-weight: 600; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state p { margin: 0 0 16px; }

/* Verdict chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font: 600 0.78rem var(--sans); border: 1px solid currentColor; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-correct { color: var(--green); background: #3fd68f14; }
.chip-incorrect { color: var(--red); background: #ff6b7a14; }
.chip-error { color: var(--red); background: #ff6b7a14; }
.chip-pending, .chip-running { color: var(--amber); background: #ffb45414; }
.chip-running::before { animation: blink 1s infinite; }
.chip-unverified { color: var(--accent); background: #7aa2ff14; }
@keyframes blink { 50% { opacity: 0.25; } }
.chip-lg { font-size: 0.95rem; padding: 6px 14px; }

/* Puzzle */
.parts-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 12px var(--mono); fill: var(--muted); }
.chart .bar { fill: var(--accent); opacity: 0.85; }
.chart .bar.first { fill: var(--gold); }
.chart .bar.me { fill: var(--green); }
.chart .grid { stroke: var(--line); }
.chart .label { fill: var(--text); font-family: var(--sans); font-weight: 500; }
.chart .label .sub { fill: var(--faint); font: 11px var(--mono); }
.chart-wrap { overflow-x: auto; }

/* Submit */
.editor { position: relative; display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); overflow: hidden; }
.editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px #7aa2ff33; }
.editor.dragging { border-color: var(--green); box-shadow: 0 0 0 3px #3fd68f33; }
.gutter { padding: 12px 10px 12px 14px; text-align: right; color: var(--faint); font: 13px/1.6 var(--mono); user-select: none; overflow: hidden; white-space: pre; background: var(--surface); border-right: 1px solid var(--line); min-width: 48px; }
.editor textarea { border: 0; border-radius: 0; box-shadow: none !important; resize: vertical; min-height: 420px; font: 13px/1.6 var(--mono); padding: 12px 14px; white-space: pre; overflow: auto; tab-size: 4; background: transparent; }
.editor-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.rules { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; font-size: 0.9rem; }
.rules li { position: relative; padding-left: 18px; }
.rules li::before { content: "›"; position: absolute; left: 2px; color: var(--accent); font-weight: 700; }
pre.snippet { margin: 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line); font-size: 12.5px; line-height: 1.6; overflow-x: auto; color: var(--silver); }

/* Submission detail */
.verdict-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 20px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); margin-bottom: 20px; }
.verdict-hero p { margin: 6px 0 0; color: var(--muted); }
.verdict-hero.correct { border-color: #3fd68f55; background: linear-gradient(90deg, #3fd68f12, var(--surface) 60%); }
.verdict-hero.incorrect, .verdict-hero.error { border-color: #ff6b7a55; background: linear-gradient(90deg, #ff6b7a12, var(--surface) 60%); }
.verdict-hero.pending, .verdict-hero.unverified { border-color: #ffb45444; background: linear-gradient(90deg, #ffb45410, var(--surface) 60%); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stat-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font: 700 1.4rem/1.3 var(--mono); margin-top: 4px; }
.stat-sub { font-size: 0.8rem; color: var(--faint); }
.code-view { margin: 0; display: grid; grid-template-columns: auto 1fr; font: 13px/1.6 var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: auto; max-height: 640px; }
.code-view .ln { padding: 12px 10px 12px 14px; color: var(--faint); text-align: right; user-select: none; background: var(--surface); border-right: 1px solid var(--line); white-space: pre; }
.code-view code { padding: 12px 14px; white-space: pre; color: var(--text); }
.sub-count { margin-left: 6px; font: 500 0.75rem var(--mono); color: var(--faint); }
.mine { margin-top: 28px; }
.mine .card-head { margin-bottom: 0; }
td.pick { width: 1%; padding-right: 0; }
.pick label { display: flex; padding: 6px; margin: -6px; cursor: pointer; }
.pick input { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--accent); cursor: pointer; }
.pick input:disabled { cursor: not-allowed; }
.chart .dot { fill: var(--accent); opacity: 0.85; }
.chart .dot.first { fill: var(--gold); }
.diff { font: 13px/1.6 var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: auto; max-height: 640px; }
.diff-body { display: inline-block; min-width: 100%; }
.diff-line { display: grid; grid-template-columns: 3.4em 3.4em 1.8em 1fr; }
.diff-line .ln { padding-right: 8px; text-align: right; color: var(--faint); background: var(--surface); user-select: none; }
.diff-line .op { text-align: center; color: var(--faint); user-select: none; }
.diff-line code { padding-right: 14px; white-space: pre; color: var(--text); }
.diff-line.add { background: #3fd68f17; }
.diff-line.del { background: #ff6b7a17; }
.diff-line.add .op, .diff-key.add { color: var(--green); }
.diff-line.del .op, .diff-key.del { color: var(--red); }
.diff-key { font: 700 0.9rem var(--mono); }
.diff-skip { padding: 3px 14px; font-size: 12px; color: var(--faint); background: var(--surface-2); border-block: 1px solid var(--line); }
pre.log { margin: 0; padding: 14px; border-radius: var(--radius-sm); background: #1a0d14; border: 1px solid #ff6b7a33; color: #ffc2c9; font-size: 12.5px; line-height: 1.55; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* Standings */
.heat { display: inline-flex; gap: 3px; }
.heat i { width: 14px; height: 14px; border-radius: 3px; background: var(--surface-3); display: inline-block; }
.heat i.r1 { background: var(--gold); }
.heat i.r2 { background: #c3c9de; }
.heat i.r3 { background: #e0a272; }
.heat i.rn { background: #7aa2ff88; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 12px; align-items: center; }
.legend .heat i { width: 12px; height: 12px; }

/* Filters */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { flex: 0 1 160px; }
.filters .field.grow { flex: 1 1 200px; }

/* Admin */
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.state { font: 600 0.8rem var(--mono); }
.state-idle { color: var(--muted); }
.state-running { color: var(--amber); }
.state-paused, .state-offline { color: var(--red); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 50; padding: 12px 18px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--line-strong); box-shadow: 0 16px 40px #00000077; font-size: 0.92rem; max-width: calc(100vw - 32px); }
.toast.bad { border-color: var(--red); }

.skeleton { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar-inner { gap: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; margin: 0 -6px; }
  .brand-text { font-size: 0.98rem; }
  .queue-pill .label { display: none; }
  .topbar-right { margin-left: auto; gap: 8px; }
  .queue-pill { padding: 5px 8px; }
  .view { padding-top: 22px; }
  .calendar { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .day { min-height: 132px; padding: 14px; }
  th, td { padding: 9px 10px; }
  .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .queue-pill { display: none; }
}
