:root {
  --bg: #101418;
  --panel: #1a2027;
  --line: #2c343d;
  --text: #e8ebee;
  --muted: #8a949e;
  --accent: #e0442e;
  --win: #4cbb5c;
  --boost: #3fa0ff;
  --gas: #1d2a1f;
  --brake: #2d1d1d;
  --boostzone: #1b2533;
  --coast: #181c21;
  --roof: #23272c;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 ui-monospace, Menlo, Consolas, monospace;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }

#app {
  position: relative;
  height: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen[hidden] { display: none; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  cursor: pointer;
}
button:active { background: var(--line); }

h1 { font-size: 1.3rem; margin: 0; letter-spacing: 0.05em; }
h2 { font-size: 1rem; margin: 0.3rem 0 0; color: var(--muted); font-weight: normal; }

/* League */
#league, #season { padding: calc(env(safe-area-inset-top) + 1rem) 1rem calc(env(safe-area-inset-bottom) + 1rem); overflow-y: auto; gap: 0.6rem; }
#league h2 { margin-top: 0.6rem; font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; }
.standings { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.standings th { color: var(--muted); font-weight: normal; font-size: 0.8rem; text-align: right; padding: 0.2rem 0.3rem; }
.standings th:nth-child(-n+2) { text-align: left; }
.standings td { padding: 0.45rem 0.3rem; border-bottom: 1px solid var(--line); text-align: right; }
.standings td:nth-child(-n+2) { text-align: left; }
.standings tr.you td { color: var(--accent); font-weight: bold; }
#fixtures { list-style: none; margin: 0.4rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
#fixtures li { display: grid; grid-template-columns: 1fr auto; gap: 0 0.6rem; padding: 0.4rem 0.6rem; background: var(--panel); border-radius: 6px; font-size: 0.9rem; }
#fixtures li.next { outline: 1px solid var(--accent); }
#fixtures .track { color: var(--muted); font-size: 0.8rem; }
#fixtures .outcome { grid-row: span 2; align-self: center; text-align: right; }
#fixtures .outcome.won { color: var(--win); }
#fixtures .outcome.lost { color: var(--accent); }
#holes { margin: 0; color: var(--muted); }
#holes:empty { display: none; }
#divisions { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.8rem; font-size: 0.85rem; }
#divisions dt { color: var(--muted); }
#divisions dd { margin: 0; }
#copy-link { align-self: flex-start; margin-top: 0.6rem; padding: 0.4rem 0.8rem; font-size: 0.85rem; }
#moves { margin: 0.6rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: 0.9rem; }
#league .actions, #season .actions, #result .actions {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 0.8rem 0 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Race */
#race { touch-action: none; }
#view-wrap { position: relative; flex: 1; min-height: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map {
  position: absolute;
  right: 8px;
  top: calc(env(safe-area-inset-top) + 56px);
  width: 92px;
  height: 92px;
  pointer-events: none;
}
#hud {
  position: absolute;
  left: 0; right: 0; top: 0;
  padding: calc(env(safe-area-inset-top) + 4px) 8px 16px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--roof);
  border-bottom: 3px solid #050607;
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  text-shadow: 0 1px 2px #000;
}
#hud-time { flex: 1; text-align: center; }
#hud-gap { min-width: 5.5rem; text-align: right; }
#crack {
  position: absolute;
  left: 0; bottom: 0;
  width: 100%;
  height: 14px;
  pointer-events: none;
}
#menu-button { padding: 0.2rem 0.7rem; font-size: 1.2rem; background: rgba(0,0,0,0.35); }
#paused {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 0.3rem 0.8rem;
  background: rgba(0,0,0,0.55);
  border-radius: 4px;
  letter-spacing: 0.2em;
  font-weight: bold;
}
#paused[hidden] { display: none; }
#hit {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 70px 26px rgba(235, 40, 20, 0.9);
  opacity: 0;
  transition: opacity 1.4s ease-out;
}
#speedbar { height: 10px; background: var(--bg); }
#speedbar b { display: block; height: 100%; width: 0; }

#meters {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 6px 10px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
#speed { min-width: 5.5rem; font-weight: bold; }
.bar { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.bar label { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.1em; }
.bar i { display: block; height: 7px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.bar b { display: block; height: 100%; width: 0; }
#boost { background: var(--boost); }

#pad {
  position: relative;
  height: 36%;
  max-height: 320px;
  margin: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}
.zone {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  pointer-events: none;
}
.zone.active { outline: 2px solid rgba(255,255,255,0.8); outline-offset: -2px; z-index: 1; }
.z-boost { top: 0; height: 18%; background: var(--boostzone); }
.z-gas { top: 18%; height: 27%; background: var(--gas); }
.z-coast { top: 45%; height: 20%; background: var(--coast); }
.z-brake { top: 65%; height: 35%; background: var(--brake); }
#pad-centre {
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  border-left: 1px dashed var(--line);
  pointer-events: none;
}
#knob {
  position: absolute;
  width: 44px; height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  border: 2px solid var(--text);
  background: rgba(255,255,255,0.12);
  transition: background 60ms linear, box-shadow 60ms linear;
  pointer-events: none;
  z-index: 2;
}
#knob[hidden] { display: none; }

#race-menu {
  position: absolute;
  inset: 0;
  background: rgba(10,12,15,0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.8rem;
  padding: 2rem;
}
#race-menu[hidden] { display: none; }

/* Result */
#result { padding: calc(env(safe-area-inset-top) + 1.5rem) 1rem calc(env(safe-area-inset-bottom) + 1rem); gap: 0.6rem; overflow-y: auto; }
#result-title.won { color: var(--win); }
#result-title.lost { color: var(--accent); }
#result-table { width: 100%; border-collapse: collapse; margin-top: 0.8rem; font-variant-numeric: tabular-nums; }
#result-table td { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
#result-table td:last-child { text-align: right; }

#rotate {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  z-index: 10;
}
@media (orientation: landscape) and (pointer: coarse) {
  #rotate { display: flex; }
}
