:root {
  color-scheme: dark;
  --bg: #0f2a2e;
  --bg2: #17393f;
  --card: #1b434a;
  --line: #2f5c63;
  --text: #f6efe0;
  --muted: #a9c3c1;
  --gold: #f2b53a;
  --ink: #1d1503;
  --tabbar: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(circle at 30% 0%, #1b4a50, var(--bg) 60%) fixed var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button, input, select { font: inherit; }
button {
  background: var(--gold); color: var(--ink); border: 0; border-radius: 14px;
  padding: 10px 18px; font-weight: 700; cursor: pointer; min-height: 44px; touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.link { background: none; color: var(--muted); padding: 4px 6px; min-height: 36px; font-weight: 600; font-size: 14px; }
.small-btn { min-height: 38px; padding: 6px 14px; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px 4px; max-width: 1180px; margin: 0 auto; }
.top h1 { margin: 0; font-size: clamp(22px, 5vw, 30px); color: var(--gold); white-space: nowrap; }
.chips-top { display: flex; gap: 8px; min-width: 0; }
.chip {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; min-height: 38px; font-weight: 600; font-size: 14px; max-width: 46vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#chip-round { color: var(--gold); }

/* ---- layout */
main { display: grid; gap: 12px; max-width: 1180px; margin: 0 auto; padding: 0 16px 8px; grid-template-columns: minmax(0, 1fr); }
.stage { text-align: center; }
.modes { display: inline-flex; gap: 4px; background: #0a1f22; padding: 4px; border-radius: 16px; }
.modes button { background: transparent; color: var(--muted); min-height: 40px; padding: 6px 14px; }
.modes button[aria-pressed="true"] { background: var(--gold); color: var(--ink); }
#turn { min-height: 1.4em; margin: 10px 0 6px; font-size: clamp(20px, 5vw, 28px); font-weight: 800; letter-spacing: -.01em; }
.wheel-wrap { position: relative; margin: 6px auto; aspect-ratio: 1; width: min(100%, 620px, calc(100dvh - 330px)); min-width: 240px; }
#wheel { width: 100%; height: 100%; display: block; will-change: transform; filter: drop-shadow(0 12px 28px #0009); }
.pointer {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%); z-index: 2;
  border-left: 18px solid transparent; border-right: 18px solid transparent; border-top: 38px solid #fff;
  filter: drop-shadow(0 3px 3px #000a);
}
#spin {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 24%; aspect-ratio: 1; border-radius: 50%; border: 5px solid #fff;
  font-size: clamp(16px, 4vw, 26px); padding: 0; font-weight: 900; letter-spacing: .02em; box-shadow: 0 6px 18px #0008;
}
#spin:not(:disabled):active { transform: translate(-50%, -50%) scale(.95); }
#spin:disabled { opacity: 1; filter: grayscale(.6); }
#hint { color: var(--muted); min-height: 1.5em; margin: 8px 0 4px; }

/* ---- tabs and panels: a slide-up sheet on phones */
.tabs {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: #0a1f22ee; backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; background: transparent; color: var(--muted); border-radius: 0; font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; padding: 4px;
}
.tabs button .ico { font-size: 22px; line-height: 1; }
.tabs button[aria-selected="true"] { color: var(--gold); }
.tabs b {
  position: absolute; top: 4px; left: calc(50% + 6px); background: var(--gold); color: var(--ink);
  border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; line-height: 18px;
}
.panel-body {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); z-index: 25;
  max-height: min(70dvh, 560px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg2); border-top: 2px solid var(--line); border-radius: 22px 22px 0 0;
  padding: 18px 16px 24px; transform: translateY(110%); visibility: hidden;
  transition: transform .22s ease, visibility 0s .22s; box-shadow: 0 -10px 40px #0009;
}
body.sheet-open .panel-body { transform: none; visibility: visible; transition: transform .22s ease; }
#scrim { position: fixed; inset: 0; z-index: 20; background: #0007; }
.panel h2 { margin: 0 0 10px; font-size: 20px; display: flex; justify-content: space-between; gap: 8px; }
.panel h2.gap { margin-top: 26px; }
footer { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 20px); }

@media (min-width: 900px) {
  :root { --tabbar: 0px; }
  main { grid-template-columns: minmax(0, 1.2fr) minmax(360px, 1fr); align-items: start; gap: 28px; }
  .stage { position: sticky; top: 8px; }
  .wheel-wrap { width: min(100%, 600px, calc(100dvh - 300px)); }
  #panels { background: var(--bg2); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; }
  .tabs { position: static; height: auto; padding: 0; background: #0a1f22; border: 0; border-bottom: 1px solid var(--line); backdrop-filter: none; }
  .tabs button { flex-direction: row; gap: 6px; font-size: 14px; min-height: 50px; }
  .tabs button .ico { font-size: 16px; }
  .tabs b { position: static; }
  .panel-body {
    position: static; transform: none; visibility: visible; max-height: none; overflow: visible; box-shadow: none;
    border: 0; border-radius: 0; padding: 18px 20px 24px; background: transparent; min-height: 320px;
  }
  #scrim { display: none !important; }
  footer { padding-bottom: 30px; }
}

/* ---- panel content */
form { display: flex; gap: 8px; flex-wrap: wrap; }
input:not([type=range]):not([type=checkbox]), select {
  background: #0a1f22; color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; flex: 1 1 120px; min-width: 0; min-height: 46px; font-size: 16px;
}
#pub-search, #table, #room-name { width: 100%; }
#table { margin-top: 8px; }
#item-price { flex: 0 1 90px; }
ul { list-style: none; margin: 8px 0 0; padding: 0; }
li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
li .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
li.current .grow { color: var(--gold); font-weight: 700; }
li button { padding: 4px 12px; min-height: 40px; }
li button[aria-pressed="false"] { background: transparent; color: var(--muted); border: 1px solid var(--line); }
li small { color: var(--muted); font-weight: 400; }
li .score { display: block; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  font-weight: 600; min-height: 40px; padding: 6px 14px; text-align: left;
}
.chips button[aria-pressed="true"] { background: #4a3a20; color: #f7d774; border-color: #a77b2a; }
.prompt {
  display: flex; flex-direction: column; gap: 2px; width: min(100%, 460px); margin: 4px auto 10px; padding: 12px 16px;
  background: var(--gold); color: var(--ink); text-align: center; border-radius: 16px;
}
.prompt b { font-size: 18px; }
.prompt span { font-weight: 600; font-size: 14px; }
.presets { margin-bottom: 10px; }
.presets button { min-height: 44px; font-size: 15px; }
.chips h3.group { flex-basis: 100%; margin: 8px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.chips h3.group:first-child { margin-top: 0; }
.quick { max-width: 420px; margin: 8px auto 4px; }
.quick .chips { justify-content: center; }
.quick .chips button { min-width: 48px; text-align: center; }
.quick form { justify-content: center; margin-top: 10px; }
.cat-head, .cat-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0 8px; }
.cat-foot { margin: 8px 0 0; }
.row { display: flex; justify-content: space-between; margin-top: 14px; }
input[type=range] { width: 100%; accent-color: var(--gold); min-height: 36px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--gold); }
summary { cursor: pointer; min-height: 40px; padding-top: 8px; }
.small { color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
#join-form { margin-top: 12px; }
#join-code { text-transform: uppercase; letter-spacing: 3px; }
.code { text-align: center; margin: 0; font-size: 18px; }
.code b { color: var(--gold); font-size: 30px; letter-spacing: 5px; }
.room-only { display: none; }
.in-room .room-only { display: block; }
.in-room .local-only { display: none; }
.reactions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.reactions button { font-size: 22px; padding: 4px 10px; }
footer { max-width: 760px; margin: 14px auto 0; padding-left: 16px; padding-right: 16px; text-align: center; color: var(--muted); font-size: 13px; }
footer a { color: var(--gold); }

/* ---- dialogs */
dialog {
  background: var(--card); color: var(--text); border: 2px solid var(--gold); border-radius: 26px;
  padding: 24px 22px; width: min(92vw, 420px); text-align: center; overflow-x: hidden;
}
dialog::backdrop { background: #000b; }
dialog h2 { margin: 4px 0; font-size: 28px; line-height: 1.15; }
dialog p { margin: 4px 0; }
.big { font-size: 64px; line-height: 1.2; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.stack button { min-height: 50px; font-size: 17px; }
#result-price { font-size: 22px; color: var(--gold); margin: 4px 0; }
#result-price s { color: var(--muted); font-size: 16px; margin-right: 6px; }
.offer { color: #f7d774; font-weight: 700; }
#result-tweaks { margin: 10px 0 4px; }
#result-tweaks .chips { justify-content: center; }
.mixer { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 10px; }
.mixer select { flex: 0 1 220px; }
.bubble {
  position: fixed; bottom: 18%; z-index: 40; background: var(--gold); color: var(--ink); font-weight: 700;
  padding: 6px 14px; border-radius: 999px; pointer-events: none; animation: rise 2.6s ease-out forwards;
}
dialog .bubble { position: absolute; bottom: 10%; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } 15% { opacity: 1; } to { transform: translateY(-40vh); opacity: 0; } }
.confetti { position: absolute; top: 0; width: 8px; height: 14px; pointer-events: none; opacity: 0; animation: fall 1.6s ease-in forwards; }
@keyframes fall { 0% { opacity: 1; transform: translateY(0) rotate(0); } 100% { opacity: 0; transform: translateY(320px) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) {
  .panel-body, body.sheet-open .panel-body { transition: none; }
  .bubble { animation-duration: 1s; }
}
