:root {
  --yellow: #f5c518;
  --ink: #1d1430;
  --card: rgba(29, 20, 48, 0.88);
  --line: rgba(255, 255, 255, 0.14);
  --text: #fff8e7;
  --muted: #d6c9b8;
  --good: #3ecf8e;
  --bad: #ff5d5d;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); }
body { -webkit-tap-highlight-color: transparent; user-select: none; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.screen { position: fixed; inset: 0; }
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(20, 12, 34, 0.45); z-index: 20; }

/* Cards and buttons */
.menu-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}
.menu-card.small { max-width: 300px; display: grid; gap: 10px; text-align: center; }
.menu-card h2 { margin: 0 0 8px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px 18px; margin-top: 10px;
  font: inherit; font-weight: 800; font-size: 16px; cursor: pointer; transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--yellow); color: #1b1b1b; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.18); }
.btn.startng { background: #fff; color: #111; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row .btn { margin-top: 10px; }

/* Menu */
#menu { display: grid; place-items: center end; padding: 24px clamp(16px, 6vw, 80px); }
.eyebrow { margin: 0; letter-spacing: .2em; text-transform: uppercase; font-size: 12px; color: var(--yellow); font-weight: 700; }
.logo {
  margin: 4px 0 0; font-size: clamp(56px, 12vw, 84px); line-height: 1; font-weight: 900; letter-spacing: .04em;
  color: var(--yellow); text-shadow: 4px 4px 0 #111, 0 0 30px rgba(245, 197, 24, .35);
}
.tagline { margin: 10px 0 18px; color: var(--muted); }
.welcome { font-size: 20px; font-weight: 800; margin: 0 0 4px; }
.status, .note { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.best { color: var(--muted); font-size: 14px; margin: 4px 0 6px; }
.link { background: none; border: 0; color: var(--yellow); font: inherit; font-size: 14px; cursor: pointer; padding: 10px 0 0; text-decoration: underline; }

/* Creator */
#creator { display: grid; grid-template-columns: 1fr minmax(340px, 440px); }
#preview { position: relative; cursor: grab; touch-action: none; }
#preview:active { cursor: grabbing; }
.drag-hint { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); font-size: 13px; color: var(--muted); background: rgba(0,0,0,.3); padding: 6px 12px; border-radius: 99px; }
#creator-panel { overflow-y: auto; padding: 24px; background: var(--card); border-left: 1px solid var(--line); user-select: text; }
#creator-panel h2 { margin: 0 0 6px; font-size: 26px; }
#creator-panel h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--yellow); }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.field input {
  font: inherit; font-size: 16px; color: var(--text); background: rgba(255,255,255,.08);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.field input:focus { outline: 2px solid var(--yellow); outline-offset: 1px; }
.row { display: grid; gap: 6px; margin: 10px 0; }
.row > span { font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 14px; color: var(--text); background: rgba(255,255,255,.08); border: 1px solid var(--line);
  border-radius: 99px; padding: 7px 12px; cursor: pointer;
}
.chip.on { background: var(--yellow); color: #1b1b1b; border-color: var(--yellow); font-weight: 700; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); cursor: pointer; padding: 0; position: relative; overflow: hidden; }
.swatch.on { outline: 3px solid var(--yellow); outline-offset: 2px; }
.swatch.picker { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); display: inline-block; }
.swatch.picker input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.from-startng { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.from-startng em, .from-note { font-style: normal; font-weight: 700; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #1b1b1b; background: var(--yellow); padding: 3px 8px; border-radius: 99px; }
.from-note { justify-self: start; }
.swatch-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); display: inline-block; }
.field input:disabled { opacity: .7; }
.personalities { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.persona {
  text-align: left; font: inherit; color: var(--text); background: rgba(255,255,255,.06); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px; cursor: pointer; display: grid; gap: 4px;
}
.persona span { font-size: 12px; color: var(--muted); line-height: 1.35; }
.persona.on { border-color: var(--yellow); background: rgba(245,197,24,.14); }
.actions { position: sticky; bottom: -24px; margin: 24px -24px -24px; padding: 12px 24px 20px; background: linear-gradient(transparent, #1d1430 30%); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn { margin: 0; }
.actions .btn.primary { grid-column: 1 / -1; }

/* HUD */
#hud { pointer-events: none; }
#hud button, #hud .overlay { pointer-events: auto; }
.hud-top { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 10px; align-items: flex-start; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px; }
#portrait { width: 52px; height: 52px; flex: none; border: 3px solid var(--yellow); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.money { font-size: 22px; font-weight: 900; color: var(--yellow); position: relative; min-width: 110px; display: grid; line-height: 1.1; }
#me-name { font-size: 12px; font-weight: 700; color: var(--text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#money-pop { position: absolute; left: 14px; top: 100%; font-size: 16px; opacity: 0; }
#money-pop.show { animation: pop 1.1s ease-out; }
#money-pop.plus { color: var(--good); }
#money-pop.minus { color: var(--bad); }
@keyframes pop { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(18px); } }
.route { flex: 1; max-width: 380px; margin: 0 auto; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; }
#stop-count { font-weight: 800; }
#next-stop { color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { grid-column: 1 / -1; height: 6px; background: rgba(255,255,255,.12); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.progress i { display: block; height: 100%; width: 0; background: var(--yellow); transition: width .3s; }
.hud-buttons { display: flex; gap: 6px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 18px; cursor: pointer; }
#warning {
  position: absolute; top: 84px; left: 50%; transform: translateX(-50%); background: var(--yellow); color: #1b1b1b;
  font-weight: 900; padding: 10px 18px; border-radius: 12px; white-space: nowrap; animation: blink 1s infinite; font-size: 15px;
  max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
@keyframes blink { 50% { opacity: .75; } }
#seats { position: absolute; top: 140px; left: 12px; display: grid; gap: 6px; width: 200px; }
.seat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 10px; font-size: 13px; }
.seat .who { display: flex; justify-content: space-between; gap: 6px; }
.seat b { white-space: nowrap; }
.seat small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mood { height: 6px; border-radius: 99px; background: rgba(255,255,255,.12); margin-top: 5px; overflow: hidden; }
.mood i { display: block; height: 100%; border-radius: 99px; transition: width .2s, background .2s; }
#feed { position: absolute; left: 50%; top: 132px; transform: translateX(-50%); width: min(520px, calc(100% - 460px)); display: grid; gap: 6px; justify-items: center; }
.bubble {
  background: #fffaf0; color: #1b1b1b; border-radius: 16px; padding: 8px 14px; font-size: 15px; line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: in .25s ease-out; max-width: 100%;
}
.bubble b { margin-right: 6px; }
.bubble.out { opacity: 0; transition: opacity .5s; }
.bubble.star { background: #fff2b8; border: 2px solid var(--yellow); }
@keyframes in { from { opacity: 0; transform: translateY(10px) scale(.96); } }
.speedo { position: absolute; left: 12px; bottom: max(16px, env(safe-area-inset-bottom)); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 12px; color: var(--muted); width: 160px; }
.speedo .bar { height: 8px; background: rgba(255,255,255,.12); border-radius: 99px; margin-top: 5px; overflow: hidden; }
.speedo i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--good), var(--yellow), var(--bad)); }
#toast { position: absolute; top: 140px; right: 12px; background: var(--yellow); color: #1b1b1b; font-weight: 800; padding: 10px 14px; border-radius: 12px; animation: in .3s ease-out; }
.keys-hint { position: absolute; right: 12px; bottom: max(16px, env(safe-area-inset-bottom)); margin: 0; font-size: 12px; color: #fff; background: rgba(0,0,0,.35); padding: 6px 10px; border-radius: 8px; }
#touch { display: none; }

/* Results and modals */
.results { max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; }
.big-money { font-size: 46px; font-weight: 900; color: var(--yellow); margin: 0; }
.new-best { display: inline-block; background: var(--good); color: #0b2b1d; font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 99px; margin-left: 8px; vertical-align: middle; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.stat { background: rgba(255,255,255,.07); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.rep { background: rgba(245,197,24,.14); border: 1px solid var(--yellow); border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.rep strong { color: var(--yellow); font-size: 18px; }
.rep p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.quote { font-style: italic; border-left: 4px solid var(--yellow); padding: 4px 0 4px 12px; margin: 12px 0; }
.quote cite { display: block; font-style: normal; font-size: 13px; color: var(--muted); margin-top: 4px; }
.secrets { color: var(--good); font-weight: 700; font-size: 14px; }
.modal-card { position: relative; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; }
.close { position: absolute; top: 12px; right: 12px; background: rgba(255,255,255,.1); border: 0; color: var(--text); width: 36px; height: 36px; border-radius: 50%; font-size: 16px; cursor: pointer; }
.book-entry { display: grid; grid-template-columns: 14px 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.book-entry .dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 4px; }
.book-entry h4 { margin: 0; }
.book-entry p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.book-entry .secret { color: var(--text); }
.book-entry .locked { font-style: italic; }
.board { width: 100%; border-collapse: collapse; margin-top: 8px; }
.board td { padding: 10px 6px; border-top: 1px solid var(--line); }
.board td:last-child { text-align: right; font-weight: 800; color: var(--yellow); }
.board small { color: var(--muted); font-size: 12px; }
.dot-sm { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.board tr.me td { background: rgba(245,197,24,.1); }

/* Phones */
@media (max-width: 760px) {
  #menu { place-items: end center; padding: 16px; }
  .menu-card { padding: 22px; }
  #creator { grid-template-columns: 1fr; grid-template-rows: 38vh 1fr; }
  #creator-panel { border-left: 0; border-top: 1px solid var(--line); padding: 18px 16px; }
  .actions { margin: 24px -16px -18px; padding: 12px 16px 16px; bottom: -18px; }
  .personalities { grid-template-columns: 1fr; }
  #seats { top: auto; bottom: 200px; width: auto; right: 12px; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .seat { padding: 5px 8px; font-size: 12px; }
  .seat small { display: none; }
  #feed { top: 112px; width: calc(100% - 24px); }
  .bubble { font-size: 14px; }
  .money { font-size: 18px; min-width: 0; padding: 6px 10px; }
  #portrait { width: 46px; height: 46px; }
  #me-name { max-width: 80px; }
  .hud-top { gap: 6px; }
  .route { font-size: 12px; }
  #warning { top: 70px; font-size: 13px; }
  .speedo { display: none; }
  .keys-hint { display: none; }
}
@media (pointer: coarse) {
  #touch {
    display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; position: absolute; left: 12px; right: 12px;
    bottom: max(14px, env(safe-area-inset-bottom));
  }
  #touch button {
    height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); color: var(--text);
    font: inherit; font-weight: 900; font-size: 18px; touch-action: none;
  }
  #touch #t-brake { background: #b83434; }
  #touch #t-horn { background: #3a3a6b; }
  #touch button.down { filter: brightness(1.4); }
  .keys-hint, .speedo { display: none; }
  #seats { bottom: auto; top: 120px; }
}
@media (pointer: coarse) and (max-width: 760px) {
  #seats { top: auto; bottom: 90px; left: 12px; right: 12px; }
}
