/* Quail Type — online typing races. QUAIL UNIVERSAL palette. */

:root {
  --accent: #0073ff;
  --accent-2: #3f8ef7;
  --gold: #ffc247;
  --good: #3ecf8e;
  --bad: #f03c46;
  --bg: #05070d;
  --surface: #0d1320;
  --surface-2: #121a2b;
  --border: #182238;
  --border-strong: #24324e;
  --text: #e8ecf4;
  --sub: #9aa3b8;
  --dim: #6d7488;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { border-color: var(--accent-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a84ff; }
.btn.big { padding: 14px 16px; font-size: 1.1rem; width: 100%; }
.btn.big small { font-weight: 500; font-size: .8rem; opacity: .85; }
.btn.small { padding: 6px 12px; font-size: .85rem; }

.pill {
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-size: .82rem;
  color: var(--sub);
  white-space: nowrap;
}
.pill.copy { cursor: pointer; }
.pill.copy:hover { color: var(--text); border-color: var(--accent-2); }

/* ---------- menu ---------- */

#menu { justify-content: center; align-items: center; }

.menu-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.logo {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 2.2rem;
  letter-spacing: -.02em;
  text-align: center;
}
.logo span { color: var(--accent-2); margin-left: 6px; }
.tagline { margin: -6px 0 4px; text-align: center; color: var(--sub); font-size: .92rem; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--sub); }

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 1rem;
  outline: none;
}
input:focus { border-color: var(--accent-2); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button {
  padding: 9px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--sub);
  font-weight: 600;
}
.seg button[aria-checked="true"] { background: var(--surface-2); border-color: var(--accent-2); color: var(--text); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row.join { grid-template-columns: 1fr auto; }
#code { text-transform: uppercase; letter-spacing: .2em; text-align: center; }

.error { margin: 0; color: var(--bad); font-size: .88rem; text-align: center; }
.best { margin: 0; color: var(--dim); font-size: .82rem; text-align: center; min-height: 1em; }

/* ---------- race ---------- */

.race-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.room-info { display: flex; gap: 6px; flex-wrap: wrap; }
.race-head .btn { justify-self: end; }
.status {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  text-align: center;
}
.status.go { color: var(--good); }
.status.count { color: var(--gold); font-size: 1.5rem; }

.track {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lane {
  display: grid;
  grid-template-columns: minmax(70px, 130px) 1fr 76px;
  align-items: center;
  gap: 10px;
  font-size: .88rem;
}
.lane.left { opacity: .4; }
.lane .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lane.you .who::after { content: " •"; color: var(--sub); }
.lane .road {
  position: relative;
  height: 22px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.lane .fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  opacity: .25;
  transition: width .35s linear;
}
.lane .bird {
  position: absolute;
  top: 50%;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  transform: translateY(-50%);
  transition: left .35s linear;
}
.lane .bird svg { display: block; width: 100%; height: 100%; }
.lane .stat { text-align: right; font-variant-numeric: tabular-nums; color: var(--sub); }
.lane .stat b { color: var(--text); }

.typebox {
  position: relative;
  padding: 18px 20px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  cursor: text;
}
.typebox.focused { border-color: var(--accent-2); }
.typebox.locked { opacity: .55; }

.text {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  font-size: 1.25rem;
  line-height: 1.75;
  color: var(--dim);
  word-wrap: break-word;
  white-space: pre-wrap;
}
.text .w { white-space: nowrap; }
.text .ok { color: var(--text); }
.text .bad { color: #fff; background: var(--bad); border-radius: 3px; }
.text .cur { box-shadow: inset 2px 0 0 var(--gold); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { box-shadow: none; } }

#input {
  position: absolute;
  inset: 0;
  opacity: 0;
  resize: none;
  cursor: text;
  font-size: 16px;   /* stops iOS zooming on focus */
}

.focus-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(5, 7, 13, .75);
  font-weight: 600;
  pointer-events: none;
}

.live { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.live div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.live b { font-family: "Space Grotesk", sans-serif; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.live span { color: var(--sub); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }

.results {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.results h2 { margin: 0 0 10px; font-family: "Space Grotesk", sans-serif; font-size: 1.2rem; }
.results table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.results th { text-align: left; color: var(--sub); font-weight: 500; font-size: .8rem; padding: 4px 6px; }
.results td { padding: 7px 6px; border-top: 1px solid var(--border); }
.results tr.you td { background: rgba(0, 115, 255, .08); }
.results .medal-1 { color: var(--gold); font-weight: 700; }

.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 600px) {
  .race-head { grid-template-columns: 1fr auto; }
  .status { grid-column: 1 / -1; grid-row: 2; }
  .text { font-size: 1.05rem; }
  .lane { grid-template-columns: 70px 1fr 60px; }
}

/* ---------- phones and tablets ---------- */

.kb-proxy {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  pointer-events: none;
}

.text { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* the race screen sits in the part of the page above the keyboard */
body.touch #race {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vvt, 0px);
  height: var(--vvh, 100dvh);
  max-width: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
body.touch.kb #race { padding-bottom: 8px; }
body.touch .btn { min-height: 44px; }
body.touch .seg button { min-height: 44px; }
body.touch input { min-height: 44px; }
body.touch .pill.copy { min-height: 36px; }
body.touch .btn:hover { border-color: var(--border-strong); }
body.touch .btn.primary:hover { border-color: var(--accent); background: var(--accent); }
body.touch .track { flex: none; padding: 6px 10px; gap: 5px; }
body.touch .lane .road { height: 16px; }
body.touch .lane .bird { width: 22px; height: 22px; margin-left: -11px; }
body.touch .typebox {
  flex: 1 1 auto;
  min-height: 7.4em;
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
}
body.touch .text { flex: 1 1 auto; min-height: 0; overflow: hidden; font-size: 1.12rem; line-height: 1.6; }
body.touch .live { flex: none; gap: 6px; }
body.touch .live div { flex-direction: row; align-items: baseline; justify-content: center; gap: 6px; padding: 6px 4px; }
body.touch .live b { font-size: 1.15rem; }
body.touch .live span { font-size: .68rem; }
body.touch .results, body.touch .actions { flex: none; }

@media (max-width: 600px) {
  .menu-card { padding: 22px 16px; }
  .results { padding: 10px; }
  .results table { font-size: .86rem; }
  .results th, .results td { padding-left: 4px; padding-right: 4px; }
  .results td:nth-child(2) { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lane { gap: 8px; font-size: .82rem; }
}
