:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --line: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --red: #e30a17;
  --red-soft: #ff4d57;
  --gold: #f2c14e;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 var(--sans);
}

a { color: var(--red-soft); }
code, pre { font-family: var(--mono); }
code { background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; font-size: .9em; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--text); color: var(--bg); padding: .5rem 1rem; z-index: 10; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem clamp(1rem, 4vw, 3rem);
  background: rgba(13, 17, 23, .9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--mono); color: var(--text); text-decoration: none; font-size: .95rem; }
.prompt { color: var(--red-soft); }
.top nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.top nav a { color: var(--muted); text-decoration: none; font-size: .9rem; }
.top nav a:hover { color: var(--text); }

main > section { padding: clamp(2.5rem, 6vw, 5rem) clamp(1rem, 4vw, 3rem); max-width: 1180px; margin: 0 auto; }

.hero { text-align: center; padding-bottom: 1.5rem !important; }
.eyebrow { font-family: var(--mono); color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.hero h1 { font-size: clamp(2rem, 5.5vw, 3.75rem); line-height: 1.15; margin: 0 0 1.25rem; letter-spacing: -.02em; }
.accent { color: var(--red-soft); }
.lead { max-width: 680px; margin: 0 auto 1.75rem; color: #c9d1d9; font-size: 1.1rem; }

.countdown {
  display: inline-flex; flex-direction: column; gap: .15rem;
  padding: .75rem 1.5rem; margin-bottom: 1.75rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2);
}
.countdown .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.countdown .time { font-family: var(--mono); font-size: clamp(1.25rem, 3.5vw, 1.75rem); font-variant-numeric: tabular-nums; }

.countdown .celebrate-again { margin-top: .6rem; font: 600 .95rem var(--sans); cursor: pointer; align-self: center; }

.fireworks { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 50; pointer-events: none; }
.celebrating .frame { animation: frame-glow 2.4s ease-in-out infinite; }
@keyframes frame-glow {
  50% { box-shadow: 0 0 40px 6px rgba(227, 10, 23, .55), 0 0 90px 10px rgba(255, 255, 255, .12); border-color: var(--red); }
}
.celebration {
  position: fixed; top: clamp(4.5rem, 10vh, 7rem); left: 0; right: 0; z-index: 60;
  display: flex; justify-content: center; padding: 0 1rem; pointer-events: none;
  opacity: 0; transition: opacity .5s ease;
}
.celebration-card { pointer-events: auto; }
.celebration-flag { width: 1.5em; height: 1em; vertical-align: -.12em; border-radius: 2px; }
.celebration.show { opacity: 1; }
.celebration.closing { opacity: 0; }
.celebration-card {
  position: relative; max-width: 560px; padding: clamp(1.5rem, 5vw, 2.5rem) clamp(1.25rem, 5vw, 3rem);
  border-radius: 16px; border: 1px solid rgba(227, 10, 23, .6); background: rgba(13, 17, 23, .88);
  text-align: center; box-shadow: 0 20px 80px rgba(227, 10, 23, .35);
  transform: scale(.85); transition: transform .6s cubic-bezier(.2, 1.4, .4, 1);
}
.celebration.show .celebration-card { transform: scale(1); }
.celebration-eyebrow { margin: 0; font-family: var(--mono); color: var(--muted); font-size: .9rem; }
.celebration-card h2 { margin: .3rem 0; font-size: clamp(2.2rem, 8vw, 3.6rem); line-height: 1.05; color: #fff; text-shadow: 0 0 24px rgba(227, 10, 23, .8); }
.celebration-sub { margin: .25rem 0 1rem; font-size: 1.15rem; }
.celebration-code { margin: 0; font-family: var(--mono); font-size: .85rem; color: #c9d1d9; word-break: break-word; }
.celebration-code span { color: var(--red-soft); }
.celebration-close {
  position: absolute; top: .5rem; right: .75rem; border: 0; background: none; color: var(--muted);
  font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.celebration-close:hover { color: #fff; }

.cta { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: .7rem 1.25rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  text-decoration: none; font-weight: 600; font-size: .95rem;
  transition: border-color .15s, transform .15s;
}
.btn:hover { border-color: var(--muted); transform: translateY(-1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #c00812; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1a1300; }
.btn.disabled { opacity: .5; pointer-events: none; }

.mosaic-section { padding-top: 1rem !important; }
.frame {
  position: relative; margin: 0 auto; max-width: 1080px;
  padding: clamp(.5rem, 1.5vw, 1rem); border: 1px solid var(--line); border-radius: 12px; background: #090c10;
}
#mosaic { display: block; margin: 0 auto; width: 100%; height: auto; image-rendering: pixelated; cursor: crosshair; touch-action: manipulation; }

.tooltip {
  position: absolute; z-index: 3; pointer-events: none; max-width: 300px;
  padding: .55rem .75rem; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(22, 27, 34, .97); box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  font-size: .85rem; line-height: 1.45;
}
.tooltip .t-msg { font-family: var(--mono); display: block; word-break: break-word; }
.tooltip .t-meta { color: var(--muted); display: block; margin-top: .2rem; }
.tooltip .t-gold { color: var(--gold); }

.final-overlay {
  position: absolute; right: clamp(1rem, 3vw, 2rem); bottom: clamp(1rem, 3vw, 2rem);
  display: flex; flex-direction: column; align-items: flex-end;
  padding: .5rem 1rem; border-radius: 10px; background: rgba(1, 4, 9, .72);
  pointer-events: none;
}
.final-count { font-family: var(--mono); font-size: clamp(2rem, 7vw, 4.5rem); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.final-label { font-size: .95rem; color: #c9d1d9; }

.finder { max-width: 1080px; margin: 1rem auto 0; text-align: center; }
.finder label { display: block; font-weight: 600; margin-bottom: .4rem; }
.finder-row { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; }
.finder input {
  flex: 1 1 260px; max-width: 360px; padding: .7rem .9rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit;
}
.finder input:focus { outline: 2px solid #58a6ff; outline-offset: 1px; }
.finder .btn { font: inherit; cursor: pointer; }
.finder-result { min-height: 1.4em; margin: .5rem 0 0; color: var(--muted); font-size: .9rem; }
.finder-result.ok { color: var(--text); }
.legend { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem 1.5rem; padding: 0; margin: 1rem 0 1.5rem; font-size: .85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .45rem; }
.sw { width: 14px; height: 14px; border-radius: 2px; display: inline-block; }
.sw.red { background: var(--red); }
.sw.gold { background: var(--gold); }
.sw.history {
  background: var(--red);
  box-shadow: inset 0 0 0 1.5px var(--red), inset 0 0 0 2.5px rgba(255, 236, 205, .75);
}
.sw.reserved { background: rgba(255, 255, 255, .25); outline: 1px dashed rgba(255, 255, 255, .7); outline-offset: 1px; }
.sw.empty { background: rgba(227, 10, 23, .2); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; max-width: 1080px; margin: 0 auto; }
.stat { padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); }
.stat .num { font-family: var(--mono); font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .of { color: var(--muted); margin-left: .35rem; font-size: .9rem; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: .6rem; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width .8s ease; }
.bar.gold i { background: var(--gold); }

h2 { font-size: clamp(1.6rem, 3.5vw, 2.25rem); margin: 0 0 .5rem; letter-spacing: -.01em; }
.section-lead { color: var(--muted); margin: 0 0 1.75rem; max-width: 720px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; max-width: 860px; }
.card { display: flex; flex-direction: column; gap: .5rem; padding: 1.5rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.card h3 { margin: 0; font-size: 1.25rem; }
.card p { margin: 0; color: #c9d1d9; }
.card .btn { margin-top: auto; align-self: flex-start; }
.card pre { margin: .25rem 0 .75rem; padding: .75rem; overflow-x: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: .8rem; line-height: 1.5; }
.card pre code { background: none; border: 0; padding: 0; }
.tag { font-family: var(--mono); font-size: .75rem; color: var(--red-soft); }

.rules { margin-top: 1.5rem; padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 10px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { margin: .75rem 0 0; color: #c9d1d9; }

.school { display: grid; grid-template-columns: 1.2fr 1fr; gap: 2.5rem; align-items: start; }
.school .cta { justify-content: flex-start; grid-column: 1 / -1; }
blockquote { margin: 1rem 0 1.25rem; padding: .75rem 1.25rem; border-left: 3px solid var(--red); font-size: 1.2rem; font-style: italic; color: #fff; }
blockquote cite { display: block; margin-top: .4rem; font-size: .85rem; font-style: normal; color: var(--muted); }
.gold-text { color: var(--gold); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 1rem; }
.steps li { counter-increment: s; position: relative; padding: 1rem 1rem 1rem 3.25rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); color: #c9d1d9; }
.steps li::before { content: counter(s); position: absolute; left: 1rem; top: 1rem; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--gold); color: #1a1300; font-weight: 700; display: grid; place-items: center; font-size: .85rem; }
.steps strong { color: var(--text); }

.terminal { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #010409; }
.terminal-bar { display: flex; align-items: center; gap: .4rem; padding: .6rem .9rem; background: var(--bg-2); border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.terminal-bar i { width: 11px; height: 11px; border-radius: 50%; background: var(--line); }
.terminal-bar span { margin-left: .5rem; }
.log { list-style: none; margin: 0; padding: 1rem 1.25rem; font-family: var(--mono); font-size: .85rem; line-height: 1.8; max-height: 560px; overflow-y: auto; }
.log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log .hash { color: var(--gold); }
.log .date { color: var(--muted); }
.log .author { color: var(--muted); }
.log .ders .msg { color: var(--gold); }
.log .history .msg { color: #79c0ff; }
.log .sep { color: var(--line); }
.more { display: block; width: 100%; padding: .75rem; border: 0; border-top: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; cursor: pointer; }
.more:hover { background: var(--line); }

.foot { border-top: 1px solid var(--line); padding: 2rem clamp(1rem, 4vw, 3rem); text-align: center; color: var(--muted); font-size: .9rem; }
.foot p { margin: .35rem 0; }
.foot .small { font-size: .8rem; }

@media (max-width: 760px) {
  .school { grid-template-columns: 1fr; }
  .top nav { gap: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn, .bar i { transition: none; }
}
