:root {
  --bg: #14231a;
  --bg-2: #1b2e22;
  --panel: #213829;
  --line: #355240;
  --text: #f1f5ef;
  --muted: #a9bdaf;
  --red: #e53935;
  --red-deep: #b71c1c;
  --gold: #fdd835;
  --display: 'Arial Black', 'Helvetica Neue', Impact, system-ui, sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 17px;
}

body {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 40px, transparent 40px 80px),
    var(--bg);
  min-height: 100vh;
}

#app { min-height: 100vh; display: flex; }

.screen { display: none; flex: 1; align-items: flex-start; justify-content: center; padding: 24px 16px; }
.screen.active { display: flex; }

.poster {
  position: relative;
  margin: auto;
  width: 100%;
  max-width: 500px;
  padding: 40px 28px 28px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.chequer {
  position: absolute; top: 0; left: 0; right: 0; height: 14px;
  background: conic-gradient(#fff 0 25%, #111 0 50%, #fff 0 75%, #111 0) 0 0 / 14px 14px;
}

h1, h2 {
  font-family: var(--display);
  font-weight: 900;
  text-transform: uppercase;
  font-style: italic;
  line-height: 0.95;
  margin: 0;
}

h1 { font-size: clamp(52px, 14vw, 84px); color: var(--gold); text-shadow: 4px 4px 0 var(--red-deep); }
h2 { font-size: 30px; }

.tagline { color: var(--muted); margin: 12px 0 24px; line-height: 1.45; }

.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field span { font-weight: 600; font-size: 14px; color: var(--muted); }
.field[hidden] { display: none; }
.account { margin: 6px 0 0; font-size: 15px; color: var(--muted); }
.account strong { color: var(--text); }
.account a { color: var(--gold); font-weight: 600; text-underline-offset: 3px; }

input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
input:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }

.actions { display: flex; flex-direction: column; gap: 10px; margin: 20px 0; }
.actions.row { flex-direction: row; justify-content: center; margin-bottom: 0; }

.btn {
  font: 700 17px/1.2 var(--body);
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn-primary { background: var(--red-deep); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: #c62828; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn .sub { font-weight: 400; font-size: 14px; color: var(--muted); margin-left: 6px; }
.btn-primary .sub { color: #ffd4d4; }

.join { display: flex; gap: 10px; align-items: flex-end; }
.error { color: #ff8a80; min-height: 1.2em; margin: 10px 0 0; }

.howto { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.howto summary { cursor: pointer; font-weight: 700; }
.howto p { color: var(--muted); line-height: 1.5; font-size: 15px; }
.keys, .tricks { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0; font-size: 15px; }
.keys dt, .tricks dt { font-weight: 700; color: var(--gold); }
.keys dd, .tricks dd { margin: 0; color: var(--muted); }
kbd {
  font: 600 13px/1 ui-monospace, monospace;
  background: var(--bg); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 2px 5px; color: var(--text);
}

.more-games { display: inline-block; margin-top: 18px; color: var(--muted); text-underline-offset: 3px; }
.more-games:hover { color: var(--text); }
.bmc-row { margin: 16px 0 0; }

/* Buy me a coffee: the same badge on every game (see ADDING_A_GAME.md). */
.bmc {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: #ffdd00; color: #0d0c22;
  font: 600 14px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-decoration: none; white-space: nowrap;
}
.bmc:hover { background: #ffe74d; }
.bmc:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.bmc svg { width: 18px; height: 18px; flex: none; }

/* The design room */
.btn-paint { display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; background: var(--red); flex: none; }
#preview { display: block; margin: 8px auto 16px; width: 200px; height: 200px; border-radius: 50%; background: #555c63; box-shadow: inset 0 0 0 8px #e53935, inset 0 0 0 14px #fff; }
.paints { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; }
.paints button {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.25); cursor: pointer; padding: 0;
}
.paints button[aria-checked="true"] { border-color: #fff; box-shadow: 0 0 0 3px var(--gold); }
.paints button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.mix { display: flex; align-items: center; gap: 10px; margin: 14px 0; font-weight: 600; color: var(--muted); cursor: pointer; }
.mix input { width: 52px; height: 40px; padding: 2px; cursor: pointer; }
.bank { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.bank:empty { display: none; }
.bank div { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 4px; }
.bank strong { display: block; font: 900 26px/1 var(--display); color: var(--gold); }
.bank span { font-size: 13px; color: var(--muted); }

/* Waiting room */
.room-players { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 6px; }
.room-players li { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.room-players li .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; }
.room-note { color: var(--muted); }
#start { width: 100%; margin-bottom: 12px; }
.share p { color: var(--muted); margin: 16px 0 6px; }
.code { font: 900 44px/1 var(--display); letter-spacing: 0.15em; color: var(--gold); margin-bottom: 10px; }
.share-row { display: flex; gap: 8px; }
.share-row input { font-size: 14px; }
#cancel { margin-top: 14px; }

/* The race */
#race.active { padding: 0; position: fixed; inset: 0; display: block; background: #2e7d32; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.result, .notice {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 32px); overflow: auto;
  background: rgba(20, 35, 26, 0.96); border: 1px solid var(--line); border-radius: 12px;
  padding: 24px 20px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.result[hidden], .notice[hidden] { display: none; }
.result h2 { color: var(--gold); }
.note { color: var(--muted); }
.stats { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 15px; }
.stats th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; padding: 4px; }
.stats td { padding: 8px 4px; border-top: 1px solid var(--line); }
.stats td:nth-child(2) { text-align: left; }
.stats th:nth-child(2) { text-align: left; }
.stats .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.stats .pts { font-weight: 900; font-size: 18px; color: var(--gold); }

/* On-screen controls: phones and tablets */
.touch {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: none; justify-content: space-between; align-items: flex-end;
  padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.touch .pad { display: flex; gap: 12px; pointer-events: auto; }
.touch .pad.mid { flex-direction: column; gap: 8px; align-items: center; }
.touch button {
  width: 72px; height: 72px; border-radius: 50%;
  font: 700 26px/1 var(--body); color: #fff;
  background: rgba(0, 0, 0, 0.35); border: 2px solid rgba(255, 255, 255, 0.5);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.touch button.small { width: 48px; height: 48px; font-size: 18px; }
.touch button.on { background: rgba(253, 216, 53, 0.6); }
.touch button[hidden] { display: none; }
#drop { width: auto; padding: 0 14px; border-radius: 24px; background: var(--red-deep); }
@media (pointer: coarse) { .touch { display: flex; } }

.kb {
  position: absolute; left: 50%; bottom: 100px; transform: translateX(-50%);
  width: min(560px, calc(100% - 16px));
  background: rgba(0, 0, 0, 0.6); border-radius: 12px; padding: 6px;
  display: flex; flex-direction: column; gap: 6px;
}
.kb[hidden] { display: none; }
.kb-row { display: flex; gap: 4px; justify-content: center; }
.kb-row button {
  flex: 1; max-width: 48px; height: 42px; border-radius: 6px; border: none;
  font: 700 18px/1 var(--body); background: #f1f5ef; color: #14231a; touch-action: none;
}
.kb-row button.hit { background: var(--gold); }
.kb-row .kb-close { background: var(--red-deep); color: #fff; }
