:root {
  --bg: #0b0e1a;
  --panel: #121733;
  --panel2: #1a2150;
  --line: #2a3270;
  --text: #e8ecff;
  --muted: #9aa4d6;
  --accent: #ffe066;
  --green: #4ade80;
  --red: #ff5c5c;
  --blue: #4f7cff;
  --mono: ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}
button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}
b {
  font-weight: 700;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.center {
  text-align: center;
  padding: 14px 4px;
}
.big {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
}
.huge {
  font-size: 64px;
  font-weight: 900;
  font-family: var(--mono);
  color: var(--accent);
  line-height: 1.1;
}
.err {
  background: #4a1b1b;
  border: 1px solid #a33;
  color: #ffd5d5;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  margin: 8px 0;
}

/* ---------- player layout ---------- */
#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
header.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 900;
  letter-spacing: 2px;
  font-family: var(--mono);
  color: var(--accent);
}
.brand span {
  color: var(--text);
}
.me {
  flex: 1;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conn {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  flex: 0 0 auto;
}
.conn.off {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}
.offline {
  background: #7a1f1f;
  color: #fff;
  text-align: center;
  font-size: 13px;
  padding: 4px;
}
section.race {
  flex: 1 1 0;
  min-height: 150px;
  position: relative;
}
section.race canvas {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
}
section.panel {
  flex: 0 0 auto;
  max-height: 66dvh;
  overflow-y: auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 2px solid var(--line);
}

/* question */
.qhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.qnum {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 15px;
  color: var(--accent);
}
.qnum .of {
  color: var(--muted);
  font-weight: 600;
}
.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 18px;
}
.timer.urgent {
  color: var(--red);
}
.ring {
  width: 30px;
  height: 30px;
  transform: rotate(-90deg);
}
.ring circle {
  fill: none;
  stroke-width: 5;
}
.ring .bg {
  stroke: var(--line);
}
.ring .fg {
  stroke: var(--accent);
  stroke-linecap: butt;
  transition: stroke-dashoffset 0.25s linear;
}
.timer.urgent .ring .fg {
  stroke: var(--red);
}
.qtext {
  font-size: clamp(15px, 4.3vw, 18px);
  line-height: 1.35;
  font-weight: 600;
  margin: 4px 0 10px;
  overflow-wrap: anywhere;
}
.opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 8px 10px;
  text-align: left;
  background: var(--panel2);
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-size: clamp(14px, 3.9vw, 17px);
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.opt:active:not([disabled]) {
  transform: scale(0.985);
  border-color: var(--blue);
}
.opt[disabled] {
  cursor: default;
  opacity: 0.75;
}
.opt.chosen {
  border-color: var(--accent);
  opacity: 1;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.opt.correct {
  border-color: var(--green);
  opacity: 1;
}
.opt.wrong {
  border-color: var(--red);
  opacity: 1;
}
.letter {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--line);
  font-family: var(--mono);
  font-weight: 800;
  font-size: 14px;
}
.opt.chosen .letter {
  background: var(--accent);
  color: #1a1a1a;
}
.opt.correct .letter {
  background: var(--green);
  color: #0b2;
  color: #06250f;
}
.opt.wrong .letter {
  background: var(--red);
  color: #2a0606;
}
.status {
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
}
.status.ok {
  color: var(--green);
}
.status.bad {
  color: var(--red);
}
.status.sending {
  color: var(--accent);
}
.loading {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
}

/* reveal */
.verdict {
  text-align: center;
  font-size: 26px;
  font-weight: 900;
  padding: 10px 0 4px;
}
.verdict.correct {
  color: var(--green);
}
.verdict.wrong {
  color: var(--red);
}
.verdict.none {
  color: var(--muted);
}
.verdict.pending {
  color: var(--muted);
  font-size: 18px;
}
.answer {
  text-align: center;
  font-size: 15px;
  margin: 4px 0 8px;
  overflow-wrap: anywhere;
}

/* finished */
.result {
  font-size: 16px;
  margin-top: 6px;
}
ol.top {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}
ol.top li {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
ol.top li.me {
  background: rgba(255, 224, 102, 0.12);
  border-radius: 6px;
}
ol.top .rk {
  font-family: var(--mono);
  font-weight: 800;
  color: var(--accent);
}
ol.top .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
ol.top .sc {
  font-family: var(--mono);
  font-weight: 700;
}
ol.top .tm {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 12px;
}

/* ---------- join overlay ---------- */
.screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.screen[hidden] {
  display: none;
}
.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 18px;
}
.card h1 {
  margin: 0 0 4px;
  font-family: var(--mono);
  letter-spacing: 3px;
  color: var(--accent);
  font-size: 28px;
}
.card h1 span {
  color: var(--text);
}
.card p {
  margin: 6px 0 14px;
}
label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0;
}
input,
textarea,
select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 16px; /* 16px stops iOS from zooming the page on focus */
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
input:focus,
textarea:focus {
  border-color: var(--blue);
}
button.primary {
  width: 100%;
  min-height: 50px;
  margin-top: 8px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
}
button.primary[disabled] {
  opacity: 0.6;
}

/* ---------- admin ---------- */
body.admin {
  overflow: auto;
}
.admin-wrap {
  max-width: 1150px;
  margin: 0 auto;
  padding: 16px;
}
.admin-wrap h1 {
  font-family: var(--mono);
  letter-spacing: 3px;
  color: var(--accent);
  margin: 0 0 12px;
}
.admin-wrap h1 span {
  color: var(--text);
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 860px) {
  .grid2 {
    grid-template-columns: 1fr;
  }
}
.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.box h2 {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--accent);
  font-family: var(--mono);
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.row label {
  margin: 0;
}
.row input {
  width: 110px;
  display: inline-block;
}
.btn {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  cursor: pointer;
  font-weight: 700;
}
.btn.go {
  background: var(--green);
  color: #06250f;
  border-color: transparent;
}
.btn.warn {
  background: #6b4a00;
  color: #ffe9b0;
}
.btn.danger {
  background: #6b1414;
  color: #ffd5d5;
}
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-family: var(--mono);
  font-size: 15px;
}
.status-bar b {
  color: var(--accent);
}
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line);
  font-size: 12px;
  font-family: var(--mono);
}
.pill.running {
  background: var(--green);
  color: #06250f;
}
.pill.finished {
  background: var(--accent);
  color: #1a1a1a;
}
.qcard {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  background: var(--bg);
}
.qcard .qtitle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-family: var(--mono);
  color: var(--accent);
}
.qcard textarea {
  resize: vertical;
  min-height: 56px;
}
.qcard .optrow {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.qcard .optrow input[type="text"] {
  margin: 0;
}
.qcard .optrow input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
}
.counter {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.counter.over {
  color: var(--red);
  font-weight: 700;
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.tbl th,
table.tbl td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
table.tbl th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
}
table.tbl td.num {
  font-family: var(--mono);
}
.scroll {
  max-height: 520px;
  overflow: auto;
}
.hint {
  font-size: 13px;
  color: var(--muted);
}
code {
  font-family: var(--mono);
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
}
