:root {
  color-scheme: light;
  --glass: rgba(255, 252, 245, .82);
  --line: rgba(120, 100, 70, .18);
  --fg: #2a2520;
  --muted: #74695c;
  --accent: #e2574c;
  font-family: ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9d8ff; color: var(--fg); }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
button, input { font: inherit; color: inherit; }
button {
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 9px 14px; cursor: pointer;
  transition: transform .1s, background .15s, border-color .15s, box-shadow .15s;
}
button:hover:not(:disabled) { border-color: rgba(120, 100, 70, .4); }
button:active:not(:disabled) { transform: translateY(1px) scale(.98); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 800; box-shadow: 0 4px 0 #b8392f; }
button.primary:hover:not(:disabled) { background: #ec6358; }
button.primary:active:not(:disabled) { box-shadow: 0 1px 0 #b8392f; transform: translateY(3px); }
button.big { font-size: 1.1rem; padding: 12px 18px; width: 100%; }
input { background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; min-width: 0; }
input:focus { outline: 2px solid #f0a097; outline-offset: -1px; }
a { color: var(--accent); }
.badge { display: inline-block; background: var(--accent); color: #fff; border-radius: 8px; font-size: .55em; padding: .15em .45em; vertical-align: .35em; letter-spacing: .02em; }

.loading { position: fixed; inset: 0; display: grid; place-items: center; font-weight: 700; color: #2a4a66; font-size: 1.1rem; padding: 16px; text-align: center; }

/* Landing */
.landing { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; pointer-events: none; }
.landing-card {
  pointer-events: auto; width: min(480px, 100%); background: var(--glass); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, .7); border-radius: 26px; padding: 28px; box-shadow: 0 30px 80px rgba(30, 60, 90, .25);
  animation: rise .6s cubic-bezier(.2, 1.2, .4, 1);
}
@keyframes rise { from { transform: translateY(30px) scale(.96); opacity: 0; } }
.home { color: var(--muted); text-decoration: none; font-size: .9rem; }
.landing h1 { font-size: clamp(2.4rem, 9vw, 3.4rem); letter-spacing: -.03em; margin: 8px 0 6px; }
.lede { color: #4a4239; margin: 0 0 20px; }
.create { display: grid; gap: 10px; }
.create .primary { padding: 13px; font-size: 1.1rem; }
.join { display: flex; gap: 8px; margin-top: 12px; }
.hint { color: var(--muted); font-size: .85rem; margin: 14px 0 0; }

/* HUD */
.topbar {
  position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; display: flex; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 16px; padding: 6px 6px 6px 14px; box-shadow: 0 8px 30px rgba(30, 60, 90, .15); max-width: calc(100vw - 24px);
}
.brand { font-weight: 900; font-size: 1.1rem; color: var(--fg); text-decoration: none; letter-spacing: -.02em; white-space: nowrap; }
.conn { font-size: .75rem; color: #1f9d57; white-space: nowrap; }
.conn.bad { color: #d9822b; }
.cam { display: flex; gap: 4px; }
.icon { padding: 6px 9px; border-radius: 10px; font-size: 1rem; line-height: 1; background: rgba(255, 255, 255, .7); }
#cam-auto.on { background: #ffe9d6; border-color: #f0a097; }

.panel {
  position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; bottom: 12px; width: 360px;
  background: var(--glass); backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, .7); border-radius: 22px; padding: 14px; box-shadow: 0 20px 60px rgba(30, 60, 90, .2);
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto; overscroll-behavior: contain;
}
.panel-toggle { display: none; }
.players { display: grid; gap: 7px; }
.player {
  background: rgba(255, 255, 255, .75); border: 1.5px solid transparent; border-radius: 14px; padding: 8px 11px; display: grid; gap: 2px;
  font-size: .86rem; cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .2s;
}
.player.active { border-color: var(--seat); box-shadow: 0 0 0 2px var(--seat) inset, 0 6px 18px rgba(0, 0, 0, .08); transform: scale(1.01); }
.player .top { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: .95rem; }
.player .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .chip { width: 14px; height: 14px; border-radius: 5px; background: var(--seat); flex: none; box-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.player .money { margin-left: auto; font-variant-numeric: tabular-nums; }
.player .sub { color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.player .you { color: var(--muted); font-weight: 500; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #c9c0b1; flex: none; }
.dot.on { background: #2fb36d; }

.action { background: rgba(255, 255, 255, .6); border-radius: 16px; padding: 12px; display: grid; gap: 10px; }
.prompt { margin: 0; font-size: .96rem; }
.buttons:empty { display: none; }
.options { display: grid; gap: 8px; }
.options:empty { display: none; }
.opt { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 2px 10px; text-align: left; padding: 10px 12px; }
.opt .e { font-size: 24px; grid-row: span 2; text-align: center; }
.opt .l { font-weight: 800; }
.opt .c { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.opt .d { grid-column: 2 / 4; color: var(--muted); font-size: .83rem; }
.opt:not(:disabled):hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(226, 87, 76, .18); }
body.choosing .options .opt:not(:disabled) { animation: nudge 1.6s ease-in-out infinite; }
body.choosing .options .opt:nth-child(2) { animation-delay: .15s; }
body.choosing .options .opt:nth-child(3) { animation-delay: .3s; }
@keyframes nudge { 50% { transform: translateX(3px); } }

.invite { display: flex; gap: 8px; }
.invite input { font-size: .85rem; color: var(--muted); }
.you-row { display: grid; gap: 5px; }
.you-row label { font-size: .78rem; color: var(--muted); }
.results table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
.results th, .results td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.results th:first-child, .results td:first-child { text-align: left; }
.results th { color: var(--muted); font-weight: 600; font-size: .76rem; }
.results .win td { font-weight: 900; }
.results .banner { font-size: 1.35rem; font-weight: 900; margin: 0 0 8px; }
.log-wrap h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 6px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .84rem; color: #4a4239; }
.log li:first-child { color: var(--fg); font-weight: 700; }
.rules { font-size: .86rem; color: #4a4239; }
.rules summary { cursor: pointer; color: var(--fg); font-weight: 700; }
.rules p { margin: 6px 0; }

.event-card {
  position: fixed; top: calc(76px + env(safe-area-inset-top, 0px)); left: calc(50% - 186px); width: min(360px, calc(100vw - 32px));
  background: #fffdf8; border-radius: 22px; padding: 18px 22px; text-align: center; cursor: pointer;
  box-shadow: 0 20px 60px rgba(40, 30, 20, .3), 0 0 0 4px var(--who, var(--accent));
}
.event-card.in { animation: pop .45s cubic-bezier(.2, 1.5, .4, 1); }
.event-card .emoji { font-size: 46px; line-height: 1.1; animation: bounce 1.2s ease-in-out infinite; }
.event-card h3 { margin: 6px 0 6px; font-size: 1.1rem; }
.event-card p { margin: 3px 0; color: #4a4239; font-size: .92rem; }
@keyframes pop { from { transform: scale(.6) rotate(-4deg); opacity: 0; } }
@keyframes bounce { 50% { transform: translateY(-5px) rotate(4deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #2a2520; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100vw - 32px); z-index: 10;
}

@media (min-width: 861px) {
  .event-card { left: calc((100vw - 384px) / 2 - 180px); }
}
@media (max-width: 860px) {
  .panel {
    top: auto; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); width: auto;
    max-height: 44vh; max-height: 44dvh; padding: 20px 12px 12px; gap: 10px; border-radius: 20px;
    transition: max-height .3s ease;
  }
  body.panel-open .panel { max-height: 78vh; max-height: 78dvh; }
  .panel-toggle {
    display: block; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 90px; height: 20px; padding: 0;
    border: none; background: none; box-shadow: none;
  }
  .panel-toggle::after { content: ""; display: block; width: 42px; height: 5px; margin: 7px auto; border-radius: 3px; background: rgba(0, 0, 0, .22); }
  .players { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -2px; padding: 0 2px; flex: none; }
  .players::-webkit-scrollbar { display: none; }
  .player { flex: 0 0 auto; min-width: 150px; max-width: 220px; padding: 6px 9px; font-size: .78rem; }
  .player .top { font-size: .85rem; }
  .player .sub { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
  .action { padding: 10px; }
  .opt { padding: 8px 10px; }
  body:not(.panel-open) .log-wrap, body:not(.panel-open) .rules { display: none; }
  body:not(.panel-open) .you-row:not(.lobby) { display: none; }
  .topbar { left: 8px; right: 8px; padding-left: 12px; }
  .brand .badge { display: none; }
  .conn { display: none; }
  .cam { margin-left: auto; }
  .event-card { left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); padding: 12px 16px; }
  .event-card .emoji { font-size: 34px; }
  .event-card.in { animation: none; }
  .landing-card { padding: 22px; }
}

/* Lifetime Drive additions */
kbd { font: 11px ui-monospace, monospace; opacity: .75; margin-left: 6px; }
.minimap {
  position: fixed; left: 12px; bottom: 12px; width: 240px; height: 170px; border-radius: 16px; cursor: crosshair;
  background: rgba(220, 238, 205, .85); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .8); box-shadow: 0 8px 30px rgba(30, 60, 90, .18);
}
.map-toggle { display: none; }
.spinner {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(300px, 70vw); text-align: center; z-index: 5;
  background: rgba(255, 252, 245, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 28px; padding: 14px 18px 18px; box-shadow: 0 30px 80px rgba(30, 40, 60, .35), 0 0 0 4px var(--who, #e2574c);
  animation: pop .4s cubic-bezier(.2, 1.5, .4, 1);
}
.spinner p { margin: 0 0 6px; font-weight: 800; }
.spinner svg { width: 100%; display: block; }
.spin-result {
  position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%) scale(0); font-size: 88px; font-weight: 900; color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, .25), 0 0 30px var(--who, #e2574c); transition: transform .35s cubic-bezier(.2, 1.6, .4, 1); pointer-events: none;
}
.spinner.done .spin-result { transform: translate(-50%, -50%) scale(1); }
@media (min-width: 861px) {
  .spinner { left: calc((100vw - 384px) / 2); }
}
@media (max-width: 860px) {
  .minimap { display: none; left: 8px; right: auto; top: calc(66px + env(safe-area-inset-top, 0px)); bottom: auto; width: 180px; height: 130px; }
  body.map-open .minimap { display: block; }
  .map-toggle { display: inline-block; }
  .spinner { top: 32%; width: min(240px, 64vw); }
  .spin-result { font-size: 64px; }
}
