:root { --blue: #1d5fa8; --blue2: #164c88; --yel: #ffd23f; --ink: #1f2a44; --cream: #fffaf0; --green: #2f9d5a; --red: #e8434b;
  font-size: clamp(11px, min(2.1vh, 1.5vw) + 4px, 18px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #6cc06a; font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; color: var(--ink);
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
canvas#cv { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; }
button:focus { outline: none; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* HUD */
#hud { position: fixed; left: 8px; top: 8px; right: 140px; pointer-events: none; z-index: 5; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { background: var(--blue); color: #fff; border: 2px solid #fff; border-radius: 9px; padding: 3px 10px 4px; box-shadow: 0 2px 0 rgba(0,0,0,.25);
  display: flex; flex-direction: column; align-items: flex-start; min-width: 4.4rem; line-height: 1.05; }
.pill .lab { font-size: .68rem; opacity: .85; text-transform: uppercase; letter-spacing: .04em; }
.pill b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
#btns { position: fixed; right: 8px; top: 8px; display: flex; gap: 6px; z-index: 30; }
.ib { width: 2.6rem; height: 2.6rem; min-width: 34px; min-height: 34px; border-radius: 10px; background: var(--blue); color: #fff; border: 2px solid #fff;
  box-shadow: 0 2px 0 rgba(0,0,0,.25); display: grid; place-items: center; padding: 0; }
.ib svg { width: 62%; height: 62%; }
.ib.off { background: #6b7690; }
#tip { position: fixed; left: 50%; transform: translateX(-50%); bottom: 10px; background: rgba(31,42,68,.82); color: #fff; padding: 5px 12px; border-radius: 99px;
  font-size: .85rem; white-space: nowrap; pointer-events: none; z-index: 6; max-width: 96vw; overflow: hidden; text-overflow: ellipsis; }
body.touch #tip { bottom: auto; top: calc(8px + 3.6rem); }
#banner { position: fixed; left: 50%; top: 34%; transform: translate(-50%, -50%); font-size: 3.2rem; font-weight: 900; color: #fff; z-index: 7; pointer-events: none;
  text-shadow: 0 3px 0 var(--ink), 0 0 10px rgba(0,0,0,.35); -webkit-text-stroke: 2px var(--ink); white-space: nowrap; }
#banner.pop { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(.4); } 60% { transform: translate(-50%, -50%) scale(1.15); } 100% { transform: translate(-50%, -50%) scale(1); } }

/* touch controls */
#touch { position: fixed; inset: auto 0 0 0; height: 0; z-index: 8; }
.tg { position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.tg.left { left: 10px; } .tg.right { right: 10px; }
.tb { width: min(19vmin, 96px); height: min(19vmin, 96px); min-width: 60px; min-height: 60px; border-radius: 18px; background: rgba(29,95,168,.78); color: #fff;
  border: 3px solid rgba(255,255,255,.9); display: grid; place-items: center; font-weight: 900; font-size: .85rem; touch-action: none; }
.tb svg { width: 55%; height: 55%; }
.tb.gas { background: rgba(47,157,90,.85); } .tb.brake { background: rgba(232,67,75,.8); }
.tb.on { transform: scale(.93); filter: brightness(1.25); }
body.kids .tb { width: min(24vmin, 120px); height: min(24vmin, 120px); }

/* overlay panels */
#ov { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#ov.dim { background: rgba(14,30,60,.35); }
.panel { pointer-events: auto; position: absolute; left: 50%; top: 50%; width: 780px; height: 432px; transform-origin: 50% 50%;
  background: var(--blue); color: #fff; border: 5px solid #fff; outline: 3px solid var(--blue2); border-radius: 22px; padding: 14px 18px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  display: flex; flex-direction: column; gap: 8px; font-size: 16px; }
.panel.small { width: 520px; height: 360px; }
body.portrait .panel { width: 360px; height: 690px; }
body.portrait .panel.small { width: 340px; height: 440px; }
.mhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.logo h1 { margin: 0; font-size: 40px; line-height: 1; letter-spacing: .01em; color: #fff; text-shadow: 0 3px 0 var(--blue2); }
.logo .sub { font-size: 15px; color: var(--yel); font-weight: 700; margin-top: 2px; }
h2 { margin: 0; font-size: 30px; }
.starbox { background: var(--yel); color: var(--ink); border-radius: 12px; padding: 4px 12px; font-size: 22px; display: flex; gap: 6px; align-items: center; border: 3px solid #fff; }
.starbox .st { color: #e88a00; }
.intro { margin: 0; font-size: 14px; line-height: 1.3; opacity: .95; }
.gsub { margin: 0; font-size: 14px; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; flex: 1; min-height: 0; }
body.portrait .modes { grid-template-columns: 1fr 1fr; }
.mode { background: var(--cream); color: var(--ink); border-radius: 14px; border: 3px solid #fff; padding: 8px; display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 3px; cursor: pointer; position: relative; box-shadow: 0 3px 0 var(--blue2); min-height: 0; overflow: hidden; }
.mode.sel { outline: 4px solid var(--yel); }
.mode:active { transform: translateY(2px); }
.mode canvas { width: 100%; flex: 1; min-height: 40px; border-radius: 9px; background: #8fd18a; }
.mode b { font-size: 18px; }
.mode .d { font-size: 12px; line-height: 1.15; opacity: .8; }
.mode .rec { font-size: 12px; font-weight: 700; color: var(--blue); }
.chip { background: var(--blue); color: #fff; border-radius: 99px; padding: 3px 10px; font-size: 12.5px; font-weight: 700; border: 0; white-space: nowrap; }
.chip:active { filter: brightness(1.2); }
.mfoot { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.big { background: var(--yel); color: var(--ink); font-weight: 900; font-size: 24px; padding: 10px 34px; border-radius: 14px; border: 3px solid #fff; box-shadow: 0 4px 0 #b88f00; }
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 #b88f00; }
.sec { background: #fff; color: var(--blue); font-weight: 800; font-size: 17px; padding: 9px 16px; border-radius: 12px; box-shadow: 0 3px 0 var(--blue2); display: inline-flex; align-items: center; gap: 7px; }
.tog .dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--blue); background: #fff; }
.tog[aria-pressed="true"] { background: var(--green); color: #fff; }
.tog[aria-pressed="true"] .dot { background: var(--yel); border-color: #fff; }
.gIcon { width: 18px; height: 14px; border: 3px solid currentColor; border-top-width: 6px; border-radius: 3px 3px 0 0; }
.keys { display: flex; gap: 14px; justify-content: center; font-size: 13px; opacity: .92; flex-wrap: wrap; }
kbd { display: inline-block; background: #fff; color: var(--ink); border-radius: 5px; padding: 0 5px; margin-right: 2px; font: 700 12px/18px sans-serif; box-shadow: 0 2px 0 var(--blue2); }
body.portrait .keys span:not(.touchhint) { display: none; }
body:not(.portrait) .touchhint { display: none; }
body.portrait .logo h1 { font-size: 34px; }
body.portrait .mfoot .big { width: 100%; }
body.portrait .mode canvas { min-height: 70px; }

.cars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; flex: 1; min-height: 0; }
body.portrait .cars { grid-template-columns: 1fr 1fr; }
.car { background: var(--cream); color: var(--ink); border-radius: 12px; border: 3px solid #fff; padding: 5px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; min-height: 0; }
.car canvas { width: 100%; flex: 1; min-height: 30px; }
.car b { font-size: 15px; } .car .k { font-size: 11px; opacity: .75; }
.car.sel { outline: 4px solid var(--yel); }
.car.locked { opacity: .62; }
.car .lock { font-size: 12px; font-weight: 800; color: var(--red); }
.car .bars { width: 90%; display: grid; grid-template-columns: auto 1fr; gap: 1px 4px; font-size: 10px; align-items: center; }
.car .bars i { display: block; height: 5px; background: #d7dce6; border-radius: 3px; overflow: hidden; }
.car .bars i span { display: block; height: 100%; background: var(--green); }

#result h2 { text-align: center; font-size: 34px; color: var(--yel); text-shadow: 0 3px 0 var(--blue2); }
#rLines { flex: 1; display: flex; flex-direction: column; gap: 5px; justify-content: center; font-size: 18px; min-height: 0; overflow: auto; }
#rLines .ln { display: flex; justify-content: space-between; background: rgba(255,255,255,.12); border-radius: 9px; padding: 5px 12px; }
#rLines .ln b { color: var(--yel); }
#rLines .new { color: var(--yel); text-align: center; font-weight: 900; }
.rstars { text-align: center; font-size: 22px; font-weight: 800; }
.rstars .st { color: var(--yel); }
body.portrait #result .mfoot .big { width: 100%; }

.hr { display: flex; align-items: center; gap: 8px; }
.slot #btns { position: static; }
.slot .ib { width: 44px; height: 44px; }
#result .mhead { justify-content: space-between; }
#result h2 { text-align: left; font-size: 30px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.portrait #result .mhead { flex-direction: column-reverse; align-items: stretch; gap: 2px; }
body.portrait #result .mhead .hr { align-self: flex-end; }
body.portrait #result .slot .ib { width: 38px; height: 38px; }
body.portrait #result h2 { text-align: center; font-size: 26px; }
