:root {
  color-scheme: dark;
  --bg: #070914;
  --panel: #12173a;
  --panel-2: #1b2150;
  --ink: #f4f1ff;
  --muted: #a9b0d6;
  --gold: #ffd23f;
  --red: #ff5a5f;
  --green: #5fe08a;
  --line: #070914;
  --px: 3px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font-family: "Pixelify Sans", ui-monospace, monospace; -webkit-font-smoothing: none; }
[hidden] { display: none !important; }

#screen { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; image-rendering: pixelated; }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 24px 16px 40px; z-index: 5;
  background: radial-gradient(ellipse at center, rgba(7, 9, 20, 0.55), rgba(7, 9, 20, 0.88));
}
.overlay.intro { background: linear-gradient(90deg, rgba(7, 9, 20, 0) 20%, rgba(7, 9, 20, 0.75)); align-items: center; justify-content: flex-end; }

.card {
  width: min(640px, 100%); margin: auto; background: var(--panel); padding: 22px 22px 18px;
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 var(--line), 0 var(--px) 0 0 var(--line),
    calc(-1 * var(--px)) 0 0 0 var(--line), var(--px) 0 0 0 var(--line),
    0 0 0 calc(2 * var(--px)) var(--gold), 0 12px 0 calc(2 * var(--px)) rgba(0, 0, 0, 0.35);
}

.logo { font-family: "Press Start 2P", monospace; font-size: clamp(22px, 6vw, 34px); margin: 4px 0 8px; letter-spacing: 1px; color: #fff; text-shadow: 3px 3px 0 #e53935; }
.logo span { color: var(--gold); margin-left: 10px; text-shadow: 3px 3px 0 #1e63d6; }
.tag { color: var(--muted); margin: 0 0 16px; font-size: 16px; }

.field { display: block; margin: 14px 0 6px; font-weight: 700; font-size: 17px; color: var(--gold); }
.field small, legend small { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 14px; }
input, textarea, select {
  width: 100%; margin-top: 6px; font: inherit; font-size: 17px; color: var(--ink); background: #0a0d24;
  border: 0; padding: 10px 12px; outline: 3px solid #2d3570; border-radius: 0;
}
input:focus, textarea:focus, select:focus { outline-color: var(--gold); }
textarea { resize: vertical; min-height: 150px; line-height: 1.35; }
select { appearance: none; cursor: pointer; }
select option:disabled { color: #555; }

.row-info { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 15px; margin-top: 6px; }
.row-info .bad { color: var(--red); }
#f-count.bad { color: var(--red); }

fieldset.winners { border: 0; margin: 18px 0 0; padding: 12px; background: var(--panel-2); display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
fieldset.winners legend { font-weight: 700; color: var(--gold); font-size: 17px; padding: 0; float: left; width: 100%; margin-bottom: 8px; grid-column: 1 / -1; }
.place { display: flex; flex-direction: column; font-weight: 700; font-size: 15px; color: #cfd6f5; }
.place select { margin-top: 4px; padding: 8px 6px; font-size: 15px; }
.place.p1 span { color: #ffd23f; }
.place.p2 span { color: #dfe6f0; }
.place.p3 span { color: #e59a5c; }
#f-random { grid-column: 1 / -1; justify-self: start; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.seg button { font: inherit; font-weight: 700; font-size: 16px; color: var(--ink); background: #0a0d24; border: 0; padding: 10px 6px; cursor: pointer; outline: 3px solid #2d3570; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.seg button small { font-weight: 400; color: var(--muted); font-size: 13px; }
.seg button.on { background: var(--gold); color: #10101a; outline-color: #fff; }
.seg button.on small { color: #3a3000; }

button { font-family: inherit; }
.big {
  font-family: "Press Start 2P", monospace; font-size: clamp(11px, 2.4vw, 14px); line-height: 1.5; padding: 14px 16px; cursor: pointer; border: 0;
  background: var(--gold); color: #10101a; box-shadow: 0 5px 0 #a8820f, 0 0 0 3px var(--line); transition: transform 0.05s;
}
.big:hover { filter: brightness(1.08); }
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #a8820f, 0 0 0 3px var(--line); }
.big.alt { background: #7ec8ff; box-shadow: 0 5px 0 #3a7fb3, 0 0 0 3px var(--line); }
.big.alt:active { box-shadow: 0 1px 0 #3a7fb3, 0 0 0 3px var(--line); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 22px; }
.link { background: none; border: 0; color: #9fd4ff; font: inherit; font-size: 15px; cursor: pointer; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
.error { color: var(--red); min-height: 1.2em; font-weight: 700; margin: 12px 0 0; }

#share-box { margin-top: 12px; padding: 12px; background: var(--panel-2); }
.share-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.share-row input { margin: 0; font-size: 14px; }
.share-row button:not(.link) { font: inherit; font-weight: 700; background: var(--green); color: #10101a; border: 0; padding: 10px 14px; cursor: pointer; }
.share-row a { color: #9fd4ff; }
.note { color: var(--muted); font-size: 14px; margin: 4px 0 0; line-height: 1.35; }

/* viewer landing */
.intro-card { text-align: center; background: rgba(18, 23, 58, 0.94); width: min(560px, 100%); margin: auto max(3vw, 12px) auto auto; }
@media (max-width: 900px) { .intro-card { margin: auto; } .overlay.intro { justify-content: center; } }
.intro-card .sub { font-family: "Press Start 2P", monospace; font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.intro-card h1 { font-family: "Press Start 2P", monospace; font-size: clamp(18px, 4.5vw, 28px); margin: 12px 0 6px; color: var(--gold); text-shadow: 3px 3px 0 #e53935; line-height: 1.35; overflow-wrap: anywhere; }
.hype { color: #fff; margin: 0 0 14px; font-size: 17px; }
.runner-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; text-align: left; max-height: 36vh; overflow-y: auto; margin-bottom: 16px; padding: 2px; }
.runner-card { display: flex; gap: 8px; align-items: center; background: #0a0d24; padding: 6px 8px; }
.runner-card .lane { flex: none; width: 26px; height: 26px; display: grid; place-items: center; font-weight: 700; outline: 2px solid var(--line); }
.runner-card .rname { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.runner-card .bio { color: var(--muted); font-size: 13px; line-height: 1.2; }
.intro-foot { display: flex; justify-content: center; gap: 18px; margin-top: 12px; }

#hud-buttons { position: fixed; right: 10px; bottom: 10px; z-index: 6; display: flex; gap: 8px; }
#hud-buttons button { font-size: 18px; width: 40px; height: 40px; border: 0; background: rgba(8, 10, 26, 0.8); color: #fff; cursor: pointer; outline: 2px solid #2d3570; }

#results-bar { position: fixed; left: 0; right: 0; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 6; display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 0 12px; }
#results-bar button { font-family: "Press Start 2P", monospace; font-size: clamp(10px, 1.6vw, 12px); padding: 12px 14px; border: 0; cursor: pointer; background: var(--gold); color: #10101a; box-shadow: 0 4px 0 #a8820f, 0 0 0 3px var(--line); }
#results-bar button.admin-only { background: #7ec8ff; box-shadow: 0 4px 0 #3a7fb3, 0 0 0 3px var(--line); }

.table-card h2 { font-family: "Press Start 2P", monospace; font-size: 16px; color: var(--gold); margin: 4px 0 14px; text-align: center; }
#table-list { list-style: none; margin: 0 0 16px; padding: 0; max-height: 60vh; overflow-y: auto; }
#table-list li { display: grid; grid-template-columns: 52px 18px 1fr auto; gap: 10px; align-items: center; padding: 7px 10px; background: #0a0d24; margin-bottom: 4px; font-size: 17px; }
#table-list li.top { background: #1e2658; }
#table-list li.top .pl { color: var(--gold); }
#table-list .pl { font-weight: 700; color: var(--muted); }
#table-list .chip { width: 16px; height: 16px; outline: 2px solid var(--line); }
#table-list .nm { font-weight: 700; overflow-wrap: anywhere; }
#table-list .tm { color: var(--green); font-variant-numeric: tabular-nums; white-space: pre; }
.table-card .big { display: block; margin: 0 auto; }

#rotate-hint { display: none; position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 7; background: var(--gold); color: #10101a; font-weight: 700; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
body.portrait #rotate-hint { display: block; }

@media (max-width: 560px) {
  .card { padding: 16px 14px 14px; }
  fieldset.winners { grid-template-columns: 1fr 1fr; }
  .actions { grid-template-columns: 1fr; }
  .seg button { font-size: 14px; }
}
