:root {
  --ink: #26263a;
  --ink-soft: #5b5b78;
  --cream: #fff8ec;
  --cream-2: #f5ead6;
  --accent: #ff8a5b;
  --accent-dark: #e8653a;
  --sky: #1b2a4a;
  --good: #40c057;
  --gold: #ffc233;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.18), 0 12px 30px rgba(0, 0, 0, 0.25);
  --font: 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--ink); font-family: var(--font); }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
.hidden { display: none !important; }

#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- Lobby ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; touch-action: pan-y;
  background: radial-gradient(ellipse at 50% 120%, #7fd1ff 0%, #4a8fd6 35%, #2b4f8f 70%, #1b2a4a 100%); }
.lobby-card { position: relative; width: min(420px, 100%); background: var(--cream); border-radius: 28px; padding: 22px 22px 16px; box-shadow: var(--shadow); text-align: center; margin: auto; }
.logo h1 { margin: 0; font-size: 44px; line-height: 1; letter-spacing: -1px; color: var(--ink); }
.logo h1 span { color: var(--accent); }
.logo-island { font-size: 56px; line-height: 1; animation: bob 3s ease-in-out infinite; filter: drop-shadow(0 8px 6px rgba(0,0,0,.2)); }
.tagline { margin: 6px 0 14px; color: var(--ink-soft); font-size: 16px; line-height: 1.3; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }

.field { display: block; text-align: left; margin: 10px 0; }
.field > span { display: block; font-weight: 700; font-size: 14px; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .join-row input { width: 100%; font-size: 20px; font-weight: 700; padding: 10px 14px; border-radius: 14px; border: 3px solid var(--cream-2); background: #fff; color: var(--ink); outline: none; }
.field input:focus, .join-row input:focus { border-color: var(--accent); }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); cursor: pointer; transition: transform .1s; }
.swatch.sel { border-color: var(--ink); transform: scale(1.12); }
.preview-wrap { display: flex; justify-content: center; margin: 2px 0 6px; }
#preview { width: 96px; height: 96px; }

.btn { border: 0; border-radius: 16px; padding: 10px 18px; font-size: 18px; font-weight: 800; background: var(--cream-2); color: var(--ink); box-shadow: 0 4px 0 rgba(0,0,0,.15); transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 5px 0 var(--accent-dark); }
.btn.big { width: 100%; font-size: 24px; padding: 12px; margin-top: 4px; }
.join-row { display: flex; gap: 8px; margin-top: 12px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-size: 18px; }
.err { color: #e03131; min-height: 1.2em; margin: 8px 0 0; font-weight: 700; }
.fineprint { color: var(--ink-soft); font-size: 13px; margin: 4px 0 0; }
.joining-note { background: #e7f5ff; color: #1c7ed6; border-radius: 12px; padding: 6px 10px; font-weight: 700; margin-bottom: 4px; }

.sky-deco { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.cloud { position: absolute; width: 180px; height: 60px; background: rgba(255,255,255,.55); border-radius: 60px; filter: blur(1px); animation: drift 40s linear infinite; }
.cloud::before, .cloud::after { content: ''; position: absolute; background: inherit; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; top: -40px; left: 30px; }
.cloud::after { width: 60px; height: 60px; top: -25px; left: 95px; }
.c1 { top: 12%; animation-duration: 55s; }
.c2 { top: 45%; animation-duration: 70s; animation-delay: -30s; transform: scale(.7); }
.c3 { top: 78%; animation-duration: 45s; animation-delay: -15s; }
@keyframes drift { from { left: -220px; } to { left: 110%; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
.hud-left, .hud-right { display: flex; gap: 8px; flex: 1; }
.hud-right { justify-content: flex-end; }
.pill { border: 0; border-radius: 999px; background: rgba(255, 248, 236, .95); color: var(--ink); padding: 6px 14px; font-size: 16px; font-weight: 700; box-shadow: 0 4px 0 rgba(0,0,0,.2); white-space: nowrap; }
.pill.icon { width: 42px; height: 42px; padding: 0; font-size: 20px; }
.pill-label { color: var(--ink-soft); font-weight: 500; }
.pill-cta { margin-left: 4px; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 10px; font-size: 14px; }
.hud-center { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.hud-chip { background: rgba(20, 22, 40, .72); color: #fff; border-radius: 16px; padding: 4px 14px; font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 0 rgba(0,0,0,.25); white-space: nowrap; }
.hud-chip.warn { background: rgba(224, 49, 49, .85); animation: pulse .5s ease-in-out infinite alternate; }
.hud-chip small { font-size: 13px; font-weight: 600; opacity: .8; }
@keyframes pulse { to { transform: scale(1.07); } }

.roster { position: absolute; left: max(12px, env(safe-area-inset-left)); top: 64px; display: flex; flex-direction: column; gap: 4px; }
.chip { display: flex; align-items: center; gap: 6px; background: rgba(20,22,40,.55); color: #fff; padding: 2px 10px 2px 4px; border-radius: 999px; font-weight: 700; font-size: 14px; width: fit-content; }
.chip .dot { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.chip.off { opacity: .45; }
.chip.me { outline: 2px solid rgba(255,255,255,.7); }
.chip .ok { color: #8ce99a; }

.hub-panel { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(520px, calc(100% - 24px)); text-align: center; }
.hub-tip { background: rgba(20,22,40,.6); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 15px; display: inline-block; }
.pad-card { background: var(--cream); border-radius: 22px; padding: 12px 16px; box-shadow: var(--shadow); text-align: left; animation: pop .2s ease-out; }
.pad-card h3 { margin: 0; font-size: 24px; display: flex; align-items: center; gap: 8px; line-height: 1.1; }
.pad-card p { margin: 4px 0 6px; color: var(--ink-soft); font-size: 15px; line-height: 1.3; }
.pad-card .who { font-weight: 800; color: var(--accent-dark); }
.stars { color: var(--gold); letter-spacing: 2px; text-shadow: 0 2px 0 rgba(0,0,0,.15); }
.stars .off { color: rgba(0,0,0,.15); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

.orders { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.order { background: var(--cream); border-radius: 14px; padding: 4px 10px 6px; box-shadow: 0 4px 0 rgba(0,0,0,.25); text-align: center; min-width: 76px; animation: pop .25s ease-out; }
.order .ing { font-size: 22px; letter-spacing: 1px; line-height: 1.2; }
.order .bar { height: 6px; border-radius: 3px; background: #e9ecef; overflow: hidden; }
.order .bar i { display: block; height: 100%; background: var(--good); transition: width .3s linear; }
.order.late .bar i { background: #fa5252; }

/* ---------- Overlays ---------- */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 70px 14px 90px; background: rgba(14, 18, 36, .45); pointer-events: none; }
.card { width: min(520px, 100%); max-height: 100%; overflow: auto; background: var(--cream); border-radius: 28px; padding: 20px 22px; box-shadow: var(--shadow); text-align: center; animation: pop .3s cubic-bezier(.2,1.4,.5,1); pointer-events: auto; }
.card .gicon { font-size: 54px; line-height: 1; }
.card h2 { margin: 2px 0 4px; font-size: 34px; line-height: 1.05; }
.card .blurb { color: var(--ink-soft); font-size: 17px; margin: 0 0 10px; line-height: 1.3; }
.card ul { text-align: left; margin: 0 auto 10px; padding: 0; list-style: none; max-width: 420px; }
.card li { padding: 5px 0 5px 30px; position: relative; font-size: 16px; line-height: 1.25; }
.card li::before { content: '✦'; position: absolute; left: 6px; color: var(--accent); }
.card .goal { background: var(--cream-2); border-radius: 12px; padding: 6px; font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.card .ready-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.card .ready-row .chip { background: #e9ecef; color: var(--ink); }
.card .ready-row .chip.ready { background: #d3f9d8; }
.card .hint { font-weight: 800; color: var(--accent-dark); font-size: 17px; }
.card .timerbar { height: 6px; background: #e9ecef; border-radius: 3px; overflow: hidden; margin-top: 8px; }
.card .timerbar i { display: block; height: 100%; background: var(--accent); transition: width .12s linear; }
.card .tour-tag { display: inline-block; background: var(--ink); color: #fff; border-radius: 999px; padding: 2px 12px; font-size: 14px; font-weight: 700; margin-bottom: 6px; }

.big-stars { font-size: 64px; line-height: 1; margin: 6px 0; }
.big-stars span { display: inline-block; opacity: .18; filter: grayscale(1); transform: scale(.6); transition: all .35s cubic-bezier(.2,1.6,.5,1); }
.big-stars span.on { opacity: 1; filter: none; transform: scale(1); }
.card .headline { font-size: 22px; font-weight: 800; margin: 4px 0; line-height: 1.2; }
.card .score { color: var(--ink-soft); margin-bottom: 8px; }
.card .stat { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #fff; border-radius: 14px; padding: 6px 12px; margin: 6px 0; text-align: left; }
.card .stat b { color: var(--accent-dark); }
.badge { display: inline-block; background: var(--gold); color: var(--ink); font-weight: 800; border-radius: 999px; padding: 2px 12px; margin: 4px; animation: pulse .6s ease-in-out infinite alternate; }
.tour-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 18px; }
.tour-table td { padding: 6px 4px; border-bottom: 2px dashed var(--cream-2); text-align: left; }
.tour-table td:last-child { text-align: right; }

.bigtext { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); font-size: 120px; font-weight: 800; color: #fff; text-shadow: 0 6px 0 rgba(0,0,0,.25), 0 0 30px rgba(0,0,0,.2); pointer-events: none; opacity: 0; }
.bigtext.show { animation: bigpop .9s ease-out forwards; }
@keyframes bigpop { 0% { opacity: 0; transform: translate(-50%,-50%) scale(2); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-50%) scale(.8); } }

.toasts { position: absolute; right: max(12px, env(safe-area-inset-right)); top: 64px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.toast { background: var(--cream); padding: 6px 14px; border-radius: 14px; font-weight: 700; box-shadow: 0 4px 0 rgba(0,0,0,.2); animation: pop .2s ease-out; }
.conn { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 16px; font-weight: 800; font-size: 20px; }

/* ---------- Touch ---------- */
.touch { position: fixed; inset: 0; pointer-events: none; }
.stick { position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; background: rgba(255,255,255,.14); border: 3px solid rgba(255,255,255,.35); }
.knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.tbtn { position: absolute; pointer-events: auto; border: 0; border-radius: 50%; color: #fff; font-size: 34px; box-shadow: 0 6px 0 rgba(0,0,0,.25); touch-action: none; }
.tbtn.action { right: max(22px, env(safe-area-inset-right)); bottom: max(28px, env(safe-area-inset-bottom)); width: 96px; height: 96px; background: var(--accent); }
.tbtn.action.down { transform: translateY(4px) scale(.96); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.tbtn.emote { right: max(128px, calc(env(safe-area-inset-right) + 128px)); bottom: max(34px, env(safe-area-inset-bottom)); width: 58px; height: 58px; background: rgba(255,248,236,.9); font-size: 28px; }
.emote-menu { position: absolute; right: 110px; bottom: 104px; display: grid; grid-template-columns: repeat(3, 52px); gap: 6px; pointer-events: auto; background: rgba(20,22,40,.6); padding: 8px; border-radius: 18px; }
.emote-menu button { border: 0; background: var(--cream); border-radius: 14px; height: 52px; font-size: 28px; }

@media (max-width: 640px) {
  .hud-top { flex-wrap: wrap; row-gap: 6px; }
  .hud-center { order: 3; flex-basis: 100%; }
  .roster { top: 100px !important; }
  .toasts { top: 100px; }
  .pill-label { display: none; }
  .hud-chip { font-size: 16px; padding: 3px 10px; }
  .roster { top: 60px; }
  .chip { font-size: 12px; }
  .card h2 { font-size: 28px; }
  .card { padding: 16px; }
  .card li { font-size: 15px; }
  .big-stars { font-size: 50px; }
  .orders { top: 100px; }
  .order .ing { font-size: 18px; }
  .order { min-width: 60px; padding: 3px 6px 5px; }
  .hub-panel { bottom: 140px; }
  .bigtext { font-size: 90px; }
}
@media (hover: none) and (pointer: coarse) {
  .hub-panel { bottom: 140px; }
}
