:root {
  --bg: #12141a;
  --surface: #1c1f28;
  --surface-2: #262a36;
  --border: #333847;
  --text: #e8eaf0;
  --muted: #8b91a3;
  --accent: #5fd068;      /* creeper green */
  --accent-dark: #3c9c45;
  --danger: #ff5a5a;
  --warn: #f5b942;
  --pixel: "Press Start 2P", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
kbd {
  font: 11px var(--pixel);
  padding: 2px 5px;
  border: 1px solid currentColor;
  border-radius: 3px;
  opacity: .8;
}
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- screens ---------- */
.screen { display: none; }
.screen.active { display: block; }
#screen-auth.active, #screen-start.active, #screen-summary.active {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 620px;
}
h1, .brand { font-family: var(--pixel); letter-spacing: -1px; }
h1 { font-size: 32px; margin: 0 0 8px; }
h1 span, .brand span { color: var(--accent); }
.tagline { color: var(--muted); margin: 0 0 24px; }
.rules { padding-left: 20px; margin: 0 0 24px; }
.rules li { margin-bottom: 8px; }
.error { color: var(--danger); margin: 0 0 12px; }
.link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent); font-weight: 600; text-decoration: underline dotted; }

/* ---------- auth ---------- */
.auth { max-width: 420px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; background: none; border: 0; border-radius: 6px; padding: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); }
.form { display: grid; gap: 14px; margin-bottom: 12px; }
.form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- home ---------- */
.home { display: grid; grid-template-columns: minmax(0, 620px) 280px; gap: 20px; align-items: start; width: 100%; max-width: 920px; }
@media (max-width: 900px) { .home { grid-template-columns: 1fr; } }
.userbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; font-size: 14px; color: var(--muted); }
.userbar-actions { display: flex; gap: 8px; }
a.btn { text-decoration: none; display: inline-block; color: var(--text); }
.leaderboard-card { padding: 20px; }
.leaderboard-card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.leaderboard { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.leaderboard li { padding-left: 4px; }
.leaderboard li span { display: block; }
.leaderboard li.me .link { color: var(--warn); }
.announcement {
  background: rgba(245, 185, 66, .12); border: 1px solid var(--warn); border-radius: 8px;
  padding: 10px 14px; margin: 0 0 20px; white-space: pre-line; overflow-wrap: anywhere;
}
.profile-search { position: relative; margin-bottom: 20px; }
.search-results {
  position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; right: 0;
  list-style: none; margin: 0; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.search-results button {
  width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
.search-results button:hover, .search-results button.active { background: rgba(95, 208, 104, .15); color: var(--accent); }
.search-results .muted { padding: 6px 10px; }

/* ---------- buttons ---------- */
.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: #313646; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1a0d; }
.btn.primary:hover:not(:disabled) { background: #74de7c; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #ff7676; }
.btn.big { padding: 13px 22px; font-size: 16px; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
a.btn.wide { text-align: center; }
.btn.discord { background: #5865f2; border-color: #5865f2; color: #fff; }
.btn.discord:hover:not(:disabled) { background: #6d78f5; }
.or { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ---------- game layout ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { font-size: 13px; }
.progress { flex: 1; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 2px; background: var(--surface-2); border: 1px solid var(--border); }
.dot.done { background: var(--accent-dark); border-color: var(--accent-dark); }
.dot.current { background: var(--accent); border-color: var(--accent); }
.running b { color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .topbar { padding: 12px 16px; }
}
.stage h2 { margin: 0 0 12px; font-size: 20px; }
.player-shell { position: relative; border-radius: 10px; overflow: hidden; background: #000; }
.player-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}
.player-shell:fullscreen { display: grid; place-items: center; border-radius: 0; }
.player-shell:fullscreen .player-wrap { width: 100%; max-height: 100vh; }

.overlay-buttons {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: flex; gap: 6px;
}
.overlay-buttons .btn { box-shadow: 0 2px 10px rgba(0, 0, 0, .5); padding: 7px 12px; }
.overlay-buttons .btn.icon { background: rgba(28, 31, 40, .85); }
.player-shell.flagging .overlay-buttons { display: none; }

/* The flag window sits inside the video so it stays visible in fullscreen. */
.flag-window {
  position: absolute; inset: 0; z-index: 3;
  background: rgba(10, 12, 16, .78);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 12px;
}
.fw-inner {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 18px; width: min(720px, 100%); max-height: 100%;
  display: flex; flex-direction: column;
}
.fw-body { flex: 1; min-height: 0; overflow: auto; }
.flag-window .choices.cheats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.flag-window .choice { padding: 6px 10px; }
.flag-window .dialog-actions { margin-top: 12px; }
.fw-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.fw-inner h3 { margin: 0; font-size: 16px; }
.fw-inner h4 { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
/* On phones the video is too small to hold the picker, so it takes over the screen. */
@media (max-width: 700px) {
  .flag-window { position: fixed; z-index: 50; padding: 16px; }
  .flag-window .choice small { display: none; }
  .flag-window .choices.cheats { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
.player-wrap video, .player-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-missing {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center; gap: 8px;
  color: var(--muted);
  padding: 16px;
}

.timeline {
  position: relative;
  height: 22px;
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.tl-window {
  position: absolute; top: 0; bottom: 0; min-width: 4px;
  background: rgba(245, 185, 66, .18);
  border-left: 1px dashed var(--warn); border-right: 1px dashed var(--warn);
}
.tl-answer {
  position: absolute; top: 5px; bottom: 5px; min-width: 4px;
  background: rgba(95, 208, 104, .35);
  border: 1px solid var(--accent);
  border-radius: 3px;
}
.tl-flag {
  position: absolute; top: -3px; width: 4px; height: 26px; margin-left: -2px;
  background: var(--danger); border: 0; border-radius: 2px; padding: 0; cursor: pointer;
}

/* ---------- side panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  align-self: start;
}
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.panel h3:first-child { margin-top: 0; }
.pill { background: var(--surface-2); color: var(--text); border-radius: 99px; padding: 0 8px; font-size: 12px; }

.roster { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 6px; }
.roster li { display: flex; align-items: center; gap: 8px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; display: inline-block; }
.c0 { background: #4fa3ff; } .c1 { background: #ff5a5a; } .c2 { background: #f5b942; }
.c3 { background: #b07cff; } .c4 { background: #3fd0c9; } .c5 { background: #ff8fd0; }

.flag-list, .answer-list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.flag-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border-radius: 8px; padding: 8px 10px;
}
.flag-list li span { flex: 1; min-width: 0; }
.time-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: ui-monospace, monospace; color: var(--accent); text-decoration: underline dotted;
}
.remove { background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.remove:hover { color: var(--danger); }

.answer-list li {
  background: var(--surface-2); border-radius: 8px; padding: 10px 12px;
  border-left: 4px solid var(--muted);
}
.answer-list li.hit { border-left-color: var(--accent); }
.answer-list li.partial { border-left-color: var(--warn); }
.answer-list li.miss { border-left-color: var(--danger); }
.ans-head { margin-bottom: 2px; }
.note { margin-top: 6px; color: #c9cdd8; font-style: italic; }

.clip-score { text-align: center; margin-bottom: 8px; }
.score-num { font-family: var(--pixel); font-size: 28px; color: var(--accent); }
.score-num span { font-size: .5em; color: var(--muted); margin-left: 6px; }
.score-num.huge { font-size: 44px; }

/* ---------- dialogs & flag window ---------- */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: min(640px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 0 0 8px; }
dialog h4 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#flag-time { font-family: ui-monospace, monospace; color: var(--accent); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices.cheats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.choice {
  background: var(--surface-2); border: 2px solid var(--border); border-radius: 8px;
  padding: 8px 12px; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.choice small { display: block; width: 100%; color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.choice:hover { border-color: #4a5063; }
.choice.selected { border-color: var(--accent); background: rgba(95, 208, 104, .12); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- profile ---------- */
#profile-dialog { width: min(520px, calc(100vw - 32px)); text-align: center; }
.profile-name { font-family: var(--pixel); font-size: 18px; margin: 4px 0 8px; display: flex; justify-content: center; align-items: center; gap: 8px; }
#profile-dialog .stats { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); margin-bottom: 8px; }
#profile-dialog .rank { margin: 0 0 4px; color: var(--accent); }
.recent { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; text-align: left; }
.recent li { display: grid; grid-template-columns: 1fr auto 48px; gap: 12px; background: var(--surface-2); border-radius: 6px; padding: 6px 10px; font-size: 14px; }
.recent li span:last-child { text-align: right; }

/* ---------- summary ---------- */
.summary { text-align: center; }
.rank { font-size: 18px; font-weight: 700; margin: 6px 0 24px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.stats div { background: var(--surface-2); border-radius: 8px; padding: 12px 8px; }
.stats b { display: block; font-size: 22px; }
.stats span { color: var(--muted); font-size: 12px; }
.breakdown { width: 100%; border-collapse: collapse; margin-bottom: 24px; font-size: 14px; }
.breakdown th, .breakdown td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; }
.breakdown th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.breakdown td:last-child, .breakdown th:last-child { text-align: right; }
