* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: #07090d;
  color: #e8eef6;
  font-family: "Segoe UI", "Trebuchet MS", Arial, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#app {
  position: relative;
  width: 100%; height: 100%;
  background: #000;
}
#view {
  display: block;
  width: 100%;
  height: 100%;
  background: #07090d;
}
#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
#overlay.play { pointer-events: none; }
#overlay.side {
  justify-content: flex-end;
  align-items: stretch;
  background: transparent;
}
#overlay.side .panel {
  width: min(380px, 40vw);
  margin: 14px 14px 14px 0;
  max-height: calc(100vh - 28px);
  background: linear-gradient(180deg, rgba(12,16,24,0.36), rgba(6,8,12,0.42));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(232,217,160,0.22);
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}
.hint { color: #a09070; font-size: 13px; text-align: left; margin: 8px 0 4px; }
.panel {
  display: none;
  pointer-events: auto;
  width: min(520px, 92vw);
  max-height: 92vh;
  overflow: auto;
  padding: 22px 24px 18px;
  background: linear-gradient(180deg, rgba(12,16,24,0.92), rgba(6,8,12,0.94));
  border: 1px solid #3a2428;
  box-shadow: 0 0 0 1px #1a1014, 0 18px 40px rgba(0,0,0,0.55);
  text-align: center;
  border-radius: 10px;
}
.panel.show { display: block; }
.panel.slim { width: min(380px, 90vw); }
.panel.wide { width: min(720px, 94vw); }
.title-art {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 10px;
  border: 1px solid #2a1c20;
}
.logo {
  font-size: 42px;
  letter-spacing: 0.18em;
  color: #f2e6b6;
  text-shadow: 0 2px 0 #3a1010, 0 0 18px rgba(180,40,20,0.45);
  font-weight: 800;
}
.sub {
  margin: 6px 0 18px;
  color: #a09070;
  letter-spacing: 0.12em;
  font-size: 13px;
}
.menu { display: flex; flex-direction: column; gap: 8px; }
button {
  font-family: inherit;
  font-size: 18px;
  padding: 10px 14px;
  color: #e8eef6;
  background: #2a1c22;
  border: 1px solid #6a3038;
  cursor: pointer;
  border-radius: 6px;
}
button:hover, button:focus { background: #4a242c; outline: none; }
button.primary { background: #8a1c28; font-size: 20px; border-color: #d4b43a; }
button.ghost { background: transparent; margin-top: 10px; }
.panel a { color: #e8d9a0; }
.ver { margin-top: 12px; color: #5a5848; font-size: 12px; letter-spacing: 0.08em; }
.coins { margin-top: 10px; color: #e2c36d; font-size: 14px; }
h1 { font-size: 24px; margin-bottom: 12px; color: #f2e6b6; letter-spacing: 0.06em; }
h2 { font-size: 16px; color: #e2c36d; margin: 8px 0; }
p { line-height: 1.45; margin: 8px 0; color: #c8c0b0; text-align: left; }
ul { text-align: left; line-height: 1.7; color: #c8c0b0; padding-left: 8px; list-style: none; }
.cols { display: flex; gap: 18px; text-align: left; }
.cols > div { flex: 1; }
kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 5px;
  border: 1px solid #6a3038;
  background: #1a1216;
  font-family: monospace;
  font-size: 12px;
  text-align: center;
}
.chk, .rng { display: block; text-align: left; margin: 12px 0; color: #c8c0b0; font-size: 18px; }
.rng input { width: 100%; margin-top: 6px; }
.set-label { text-align: left; margin: 16px 0 8px; color: #c8c0b0; font-size: 16px; }
.lang-row, .diff-row { display: flex; gap: 8px; margin: 0 0 8px; }
.lang-row button, .diff-row button { flex: 1; font-size: 16px; padding: 8px 10px; }
button.on { background: #8a1c28; border-color: #d4b43a; }
.car-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 8px; }
.track-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 8px;
  max-height: 58vh;
  overflow: auto;
}
.track-card, .car-card { text-align: left; padding: 12px 14px; }
.track-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}
.track-card canvas.track-shape {
  width: 92px;
  height: 64px;
  flex: 0 0 92px;
  border-radius: 4px;
  background: #0a0c12;
  border: 1px solid #2a1c20;
}
.track-card .track-meta { min-width: 0; flex: 1; }
.track-card b, .car-card b { display: block; font-size: 18px; color: #f2e6b6; }
.track-card b { font-size: 16px; }
.track-card span, .car-card span {
  display: block; font-size: 13px; color: #a09070; font-weight: normal; margin-top: 4px;
}
.track-card em, .car-card em {
  display: block; font-size: 12px; color: #e2c36d; font-style: normal; margin-top: 6px;
}
#hud-cond {
  align-self: center;
  font-size: 12px;
  font-weight: 700;
  color: #e2c36d;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding: 4px 8px;
  border: 1px solid rgba(210,180,90,0.25);
  border-radius: 4px;
}
#race-brief {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translate(-50%, 0);
  font-size: 18px;
  font-weight: 700;
  color: #f2e6b6;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 0 #3a1010, 0 0 16px rgba(180,40,20,0.45);
  white-space: nowrap;
}
#score-list { text-align: left; margin: 10px 0 16px; }
#score-list li {
  display: flex; justify-content: space-between; padding: 6px 0;
  border-bottom: 1px solid #2a1c20; color: #c8c0b0;
}
.stat { display: flex; justify-content: space-between; margin: 6px 0; font-family: monospace; }
.stat.big { font-size: 20px; color: #f2e6b6; margin-top: 12px; }
.stat b { color: #e8eef6; }
.record { text-align: center; color: #e2c36d; font-weight: 700; }
#overlay.side #panel-results {
  width: min(280px, 30vw);
  align-self: center;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(14,16,22,0.82), rgba(8,10,14,0.88));
  box-shadow: 0 18px 40px rgba(0,0,0,0.5);
}
.res-mood {
  margin: 0 0 6px;
  letter-spacing: 0.22em;
  font-size: 11px;
  text-transform: uppercase;
  color: #e2c36d;
  text-align: center;
}
.res-line {
  text-align: center;
  color: #d8c8a0;
  font-size: 14px;
  margin: 0 0 12px;
}
#panel-results.joy {
  border-color: #d4b43a;
  box-shadow: 0 0 0 1px #3a2a10, 0 18px 40px rgba(0,0,0,0.5);
}
#panel-results.joy h1 {
  color: #f2e6b6;
  text-shadow: 0 0 18px rgba(226,195,109,0.55);
}
#panel-results.miss {
  border-color: #3a3430;
  background: linear-gradient(180deg, rgba(16,14,14,0.55), rgba(8,8,10,0.62));
}
#panel-results.miss h1 { color: #c4b4a4; }
#panel-results.miss .res-mood,
#panel-results.miss .res-line { color: #8a8074; }

#hud {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 8;
}
#hud-top {
  display: flex; align-items: stretch; gap: 10px;
  margin: calc(10px + env(safe-area-inset-top, 0px)) 10px 0;
  padding: 8px 10px;
  background: rgba(6,8,12,0.72);
  border: 1px solid rgba(210,180,90,0.25);
  border-radius: 8px;
}
.hud-speedbox { min-width: 180px; }
.hud-kmh { color: #f2e6b6; font-weight: 800; font-size: 22px; letter-spacing: 0.04em; }
.hud-kmh small { font-size: 11px; margin-left: 6px; color: #a09070; font-weight: 600; }
#hud-gearbox {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  min-width: 70px; text-align: center; font-weight: 800; letter-spacing: 0.12em;
}
#g-low, #g-high { color: #5a5848; font-size: 16px; }
#g-low.on { color: #3ec6e8; }
#g-high.on { color: #e0d23e; }
.g-hour {
  width: 16px; height: 22px; margin: 0 auto;
  background: linear-gradient(#e8d9a0, #8a6a32);
  clip-path: polygon(50% 0, 100% 22%, 78% 50%, 100% 78%, 50% 100%, 0 78%, 22% 50%, 0 22%);
  opacity: 0.85;
}
#hud-nums {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px;
  font-size: 12px; color: #a09070; align-content: center;
}
#hud-nums b { color: #f2e6b6; font-size: 16px; font-family: "Consolas", "Courier New", monospace; }
#minimap { border-radius: 4px; background: #05070a; margin-left: auto; }
#countdown {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-size: 92px; font-weight: 800; color: #f2e6b6;
  text-shadow: 0 4px 0 #3a1010, 0 0 24px rgba(180,40,20,0.5);
  letter-spacing: 0.08em;
}
.go-lights {
  position: absolute; left: 50%; top: 16%; transform: translateX(-50%);
  display: flex; flex-direction: row; gap: 10px;
  background: #111; padding: 10px 14px; border: 2px solid #3a3a40; border-radius: 8px;
  opacity: 0; pointer-events: none;
}
.go-lights.l1, .go-lights.l2, .go-lights.l3, .go-lights.l4 { opacity: 1; }
.go-lights i {
  display: block; width: 26px; height: 26px; border-radius: 50%; background: #2a2a2a;
}
.go-lights.l1 i:nth-child(1),
.go-lights.l2 i:nth-child(1), .go-lights.l2 i:nth-child(2),
.go-lights.l3 i:nth-child(1), .go-lights.l3 i:nth-child(2), .go-lights.l3 i:nth-child(3) { background: #c41c18; }
.go-lights.l3 i:nth-child(3) { background: #e0a020; }
.go-lights.l4 i { background: #2ecc5a; }

#rotate-hint {
  display: none; position: absolute; inset: 0; z-index: 40;
  align-items: center; justify-content: center;
  background: rgba(6,8,12,0.94); pointer-events: auto; padding: 24px; text-align: center;
}
#rotate-hint.on { display: flex; }
.rotate-card { max-width: min(320px, 86vw); }
.rotate-phone {
  width: 52px; height: 88px; margin: 0 auto 18px;
  border: 3px solid #f2e6b6; border-radius: 10px; position: relative;
  animation: rotphone 1.8s ease-in-out infinite;
}
.rotate-phone:after {
  content: ""; position: absolute; left: 50%; bottom: 7px; width: 8px; height: 8px;
  margin-left: -4px; border: 2px solid #f2e6b6; border-radius: 50%;
}
@keyframes rotphone {
  0% { transform: rotate(0deg); }
  35% { transform: rotate(90deg); }
  100% { transform: rotate(90deg); }
}
.rotate-h { font-size: 26px; color: #f2e6b6; margin: 0 0 10px; }
#rotate-hint p { text-align: center; color: #c8c0b0; }

#touch {
  display: none; position: absolute; inset: 0; z-index: 20; pointer-events: auto;
  --joy: 124px; --fire: 92px; --btn: 58px; --gap: 14px; --topbtn: 48px; --knob: 46px;
}
#touch.on { display: block; }
#touch.portrait-block { display: none !important; }
.joy {
  position: absolute;
  width: var(--joy); height: var(--joy);
  border-radius: 50%;
  border: 2px solid rgba(232,217,160,0.78);
  background: rgba(8,10,14,0.52);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.4), 0 2px 10px rgba(0,0,0,0.35);
  pointer-events: none;
  z-index: 1;
}
.joy.active { border-color: rgba(232,217,160,0.95); }
#stick { left: max(16px, env(safe-area-inset-left, 0px)); bottom: 24px; }
#gas {
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: 24px; left: auto;
  border-color: rgba(200,50,40,0.85);
  width: var(--fire); height: var(--fire);
}
.gas-joy .joy-knob { background: rgba(200,50,40,0.8); }
.joy-lab {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; letter-spacing: 0.08em; color: rgba(242,230,182,0.9);
  pointer-events: none;
}
.joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: var(--knob); height: var(--knob);
  margin: calc(var(--knob) / -2) 0 0 calc(var(--knob) / -2);
  border-radius: 50%;
  background: rgba(232,217,160,0.72);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.28);
  pointer-events: none;
}
#touch button {
  pointer-events: auto;
  position: absolute;
  width: var(--btn); height: var(--btn);
  min-width: var(--btn); min-height: var(--btn);
  margin: 0; padding: 0; border-radius: 50%;
  border: 1px solid rgba(232,217,160,0.45);
  font-size: 11px; letter-spacing: 0.02em; line-height: 1.1;
  background: rgba(42,28,34,0.82);
  -webkit-tap-highlight-color: transparent;
}
#touch #btn-gear {
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(24px + var(--fire) + 12px);
  width: calc(var(--btn) + 10px); height: calc(var(--btn) + 10px);
  font-size: 10px; font-weight: 700;
}
#touch #btn-tpause {
  top: max(10px, env(safe-area-inset-top, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  width: var(--topbtn); height: var(--topbtn);
  font-size: 12px;
}

@media (max-width: 720px) {
  .logo { font-size: 28px; letter-spacing: 0.12em; }
  .cols { flex-direction: column; gap: 8px; }
  .panel { padding: 16px 14px 12px; }
  #overlay.side .panel { width: min(300px, 48vw); }
  #hud-top { flex-wrap: wrap; }
  #countdown { font-size: 64px; }
  #race-brief { font-size: 15px; top: 26%; }
}
@media (max-width: 520px) {
  .track-list { grid-template-columns: 1fr; }
}
@media (max-height: 400px) {
  #touch { --joy: 104px; --fire: 80px; --btn: 48px; --gap: 10px; --topbtn: 42px; --knob: 38px; }
  .title-art { height: 72px; }
}
