html, body { --bg: #e8e6e1; --bar: #d6d3cc; --fg: #333; --accent: #b36b00; --splash1: #fff; --splash2: #cfcbc2; --title: #222; --shadow: #bbb; --input: #fff; --border: #999; color-scheme: light; }
@media (prefers-color-scheme: dark) {
  html, body { --bg: #1b1f23; --bar: #111; --fg: #ccc; --accent: #f9a825; --splash1: #2b3138; --splash2: #111; --title: #eee; --shadow: #000; --input: #1b1f24; --border: #555; color-scheme: dark; }
}
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; font-family: sans-serif; }
body { display: flex; flex-direction: column; }
canvas { flex: 1; width: 100%; min-height: 0; display: block; }
footer { color: var(--fg); padding: 8px 16px; font-size: 14px; background: var(--bar); text-align: center; }
footer b { color: var(--accent); }

#splash { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: radial-gradient(circle at 50% 40%, var(--splash1), var(--splash2) 75%); color: var(--fg); z-index: 10; transition: opacity .4s; text-align: center; }
#splash.hide { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .4s, visibility 0s .4s; }
#splash.hide * { animation: none; }
#splash h1 { margin: 0; font-size: clamp(40px, 9vw, 96px); font-style: italic; letter-spacing: 2px; text-transform: uppercase; color: var(--title); text-shadow: 0 4px 0 var(--shadow); }
#splash h1 span { color: #f9a825; }
#splash p { margin: 0; font-size: 18px; }
#splash .credits { font-size: 14px; opacity: .7; max-width: 640px; } #splash .credits a { color: inherit; }
#splash .press { color: #f9a825; font-weight: bold; animation: blink 1.2s infinite; }
#splash .opt { font-size: 16px; cursor: pointer; } #splash .opt input { width: auto; vertical-align: middle; }
#splash .tip { max-width: 520px; font-size: 15px; } #splash .tip b { color: var(--accent); }
#splash form { display: flex; gap: 8px; align-items: center; font-size: 16px; }
#splash input { width: 160px; padding: 6px 8px; font: inherit; color: var(--title); background: var(--input); border: 1px solid var(--border); border-radius: 4px; }
#splash input:focus { outline: 2px solid #f9a825; }
#splash button { padding: 6px 14px; font: inherit; font-weight: bold; color: #111; background: #f9a825; border: 0; border-radius: 4px; cursor: pointer; }
#splash button svg { display: block; }
@keyframes blink { 50% { opacity: .25; } }
#splashAnim { width: 440px; height: 190px; flex: none; }

#record { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); color: var(--fg); z-index: 20; }
#record.hide { display: none; }
#record form { background: var(--splash1); padding: 20px 28px; border-radius: 8px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
#record h2 { margin: 0; color: var(--accent); }
#record p { margin: 0; }
#record input { width: 160px; padding: 6px 8px; font: inherit; color: var(--title); background: var(--input); border: 1px solid var(--border); border-radius: 4px; }
#record button { padding: 6px 14px; font: inherit; font-weight: bold; color: #111; background: #f9a825; border: 0; border-radius: 4px; cursor: pointer; }

#tutorial { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); max-width: 520px; padding: 12px 20px; border-radius: 8px; text-align: center;
  background: var(--splash1); color: var(--fg); border: 2px solid #f9a825; box-shadow: 0 4px 16px rgba(0,0,0,.5); z-index: 5; pointer-events: none; }
#tutorial.hide { display: none; }
#tutorial small { display: block; color: var(--accent); font-weight: bold; margin-bottom: 4px; }
#tutorial b { color: var(--accent); }

#menu { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); color: var(--fg); z-index: 15; }
#menu.hide { display: none; }
#menu .panel { background: var(--splash1); padding: 20px 28px; border-radius: 8px; display: flex; flex-direction: column; gap: 12px; min-width: 260px; }
#menu h2 { margin: 0; color: var(--accent); text-align: center; }
#menu label { cursor: pointer; } #menu label input { vertical-align: middle; }
#menu #menuGoto { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
#menu #menuLevel { width: 4.5em; font: inherit; }
#menu #menuShare { display: flex; flex-direction: column; gap: 6px; }
#menu #stateText { font: 12px monospace; resize: vertical; width: 100%; box-sizing: border-box; }
#menu #menuShare div { display: flex; gap: 8px; }
#menu #stateMsg { min-height: 1em; opacity: .8; }
#menu button { padding: 8px 14px; font: inherit; font-weight: bold; color: #111; background: #f9a825; border: 0; border-radius: 4px; cursor: pointer; }

#touch { display: none; }
@media (pointer: coarse) {
  footer, #splash .tip:not(.scoring) { display: none; }
  canvas { touch-action: none; }
  #touch { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 5; user-select: none; -webkit-user-select: none; touch-action: none; }
  #touch .pad { position: absolute; display: flex; gap: 12px; }
  #touch .left { left: 16px; bottom: 16px; }
  #touch .right { right: 16px; bottom: 16px; display: grid; grid-template-columns: repeat(2, 84px); }
  #touch .top { top: 8px; right: 8px; }
  #touch button { -webkit-touch-callout: none; pointer-events: auto; touch-action: none; font: bold 20px sans-serif; color: #fff; background: rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.5); border-radius: 14px; width: 84px; height: 84px; opacity: .8; -webkit-tap-highlight-color: transparent; user-select: none; }
  #touch .left button { height: 180px; }
  #touch button.sm { width: auto; height: 40px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
  #touch button.on { background: rgba(249,168,37,.8); color: #111; }
  #splash, #menu, #record { touch-action: manipulation; }
}
/* Landscape touch: steering bottom left, drive/forks bottom right, minimap (drawn in render.js) between; the field extends down between them. */
@media (pointer: coarse) and (orientation: landscape) {
  #touch .left { left: 28px; bottom: 8px; gap: 8px; }
  #touch .right { right: 44px; bottom: 8px; gap: 8px; grid-template-columns: repeat(2, 64px); }
  #touch button { width: 64px; height: 64px; font-size: 15px; border-radius: 12px; }
  #touch .left button { width: 84px; height: 136px; }
  #touch button.sm { width: auto; height: 36px; }
  #touch .top { right: 96px; }
  #tutorial { bottom: 8px; width: calc(100vw - 2 * 220px); max-width: none; max-height: 80px; box-sizing: border-box; overflow: hidden; padding: 6px 10px; font-size: 13px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  #splash { justify-content: safe center; overflow-y: auto; gap: 8px; padding: 8px 0; box-sizing: border-box; }
  #splash h1 { font-size: 36px; }
  #splashAnim { width: 264px; height: 114px; }
  #menu { align-items: safe center; overflow-y: auto; }
  #menu .panel { margin: 8px; padding: 12px 20px; gap: 8px; display: grid; grid-template-columns: 1fr 1fr; align-items: center; column-gap: 24px; box-sizing: border-box; max-width: calc(100vw - 16px); }
  #menu h2, #menu #menuShare { grid-column: 1 / -1; }
  #record form { padding: 12px 20px; gap: 6px; }
}
@media (pointer: coarse) {
  #menu, #record, #splash { z-index: 30; }
}
