/* Ape In! — UI layer over the three.js table */

:root {
  --bg: #0b0618;
  --panel: rgba(22, 12, 46, 0.72);
  --panel-solid: #170c31;
  --panel-border: rgba(183, 125, 255, 0.22);
  --text: #f3edff;
  --muted: #a99bc9;
  --dim: #6f6390;
  --purple: #8a5cff;
  --violet: #b77dff;
  --pink: #ff4fd8;
  --cyan: #4dc9ff;
  --gold: #ffd23f;
  --green: #3ddc84;
  --red: #ff4d6d;
  --blue: #4da3ff;
  --radius: 18px;
  --display: 'Bungee', 'Arial Black', system-ui, sans-serif;
  --body: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: var(--body); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; touch-action: manipulation; user-select: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
input, select { font: inherit; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(5, 2, 12, 0.75) 100%);
}
.flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .5s ease-out; }
.flash.on { transition: none; opacity: 1; }

/* ------------------------------------------------------------ logo ---- */
.logo-word {
  font-family: var(--display); font-size: 44px; letter-spacing: 1px; line-height: 1; margin: 0;
  background: linear-gradient(180deg, #fff 0%, #ffe680 38%, #ffb21f 62%, #ff6a3d 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #3a1080) drop-shadow(0 0 24px rgba(255, 180, 60, .45));
}
.logo-word.big { font-size: clamp(64px, 16vw, 150px); }

/* --------------------------------------------------------- loading ---- */
.loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 22px;
  background: radial-gradient(circle at 50% 40%, #2a1360, var(--bg) 70%); z-index: 50; transition: opacity .5s;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading-bar { width: min(280px, 70vw); height: 8px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; }
.loading-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--gold)); border-radius: inherit; transition: width .2s; }
.loading-text { color: var(--muted); font-size: 14px; }

/* ---------------------------------------------------------- screens --- */
.screen { position: fixed; inset: 0; z-index: 10; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.splash { display: grid; place-items: center; cursor: pointer; background: radial-gradient(ellipse at 50% 50%, rgba(11,6,24,.2), rgba(11,6,24,.75)); }
.splash-inner { text-align: center; padding: 24px 16px 120px; animation: rise .8s ease-out both; }
.tagline { font-family: var(--display); font-weight: 400; font-size: clamp(18px, 4.4vw, 34px); color: #fff; margin: 16px 0 0; letter-spacing: .5px; text-shadow: 0 0 22px rgba(255,79,216,.45), 0 3px 0 rgba(0,0,0,.55); }
.rekt { color: #ff4d6d; text-shadow: 0 0 18px rgba(255,77,109,.7), 0 3px 0 rgba(0,0,0,.55); display: inline-block; animation: rektShake 3.2s 1.4s ease-in-out infinite; }
@keyframes rektShake { 0%, 88%, 100% { transform: none; } 90% { transform: translateX(-3px) rotate(-2deg); } 93% { transform: translateX(3px) rotate(2deg); } 96% { transform: translateX(-2px); } }
.descriptor { display: block; margin-top: 10px; font-size: clamp(12px, 2.6vw, 15px); font-weight: 700; letter-spacing: 2.5px; text-transform: uppercase; color: var(--muted); text-shadow: 0 2px 8px #000; }
.feature-row { list-style: none; padding: 0; margin: 0 auto 34px; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 640px; }
.feature-row li {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 16px; min-width: 120px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; font-weight: 700; backdrop-filter: blur(8px);
}
.feature-row li span { font-size: 26px; }
.feature-row small { color: var(--muted); font-weight: 500; font-size: 11px; }
.crh { position: absolute; bottom: calc(16px + var(--safe-b)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; pointer-events: none; }
.crh img { width: min(240px, 60vw); opacity: .9; }

@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

/* ----------------------------------------------------------- intro ---- */
.intro { position: fixed; inset: 0; z-index: 12; overflow: hidden; touch-action: none; cursor: ns-resize; transition: opacity .6s; }
.intro.leaving { opacity: 0; pointer-events: none; }
.intro::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(11,6,24,.0) 55%, rgba(11,6,24,.85) 100%); }
.intro-hero { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-58%); text-align: center; padding: 0 16px; pointer-events: none; transition: opacity .6s, transform .8s cubic-bezier(.2,.8,.2,1); }
.intro-hero.gone { opacity: 0; transform: translateY(-140%) scale(.8); }
.intro-hero .logo-word.big { animation: heroIn 1.1s cubic-bezier(.2,1.3,.4,1) both; }
.intro-hero .tagline { animation: rise .8s .5s ease-out both; }
.intro-hero .descriptor { animation: rise .8s .8s ease-out both; }
@keyframes heroIn { from { opacity: 0; transform: scale(.4) rotate(-6deg); } }

.intro-chapter {
  position: absolute; left: 0; right: 0; bottom: calc(96px + var(--safe-b)); text-align: center; padding: 0 20px; pointer-events: none;
  opacity: 0; transform: translateY(30px); transition: opacity .45s, transform .55s cubic-bezier(.2,.9,.3,1.2);
}
.intro-chapter.show { opacity: 1; transform: none; }
.ic-num { font-family: var(--display); font-size: 12px; letter-spacing: 3px; color: var(--pink); margin-bottom: 6px; }
.ic-title { font-family: var(--display); font-weight: 400; margin: 0; font-size: clamp(34px, 8vw, 72px); line-height: 1; color: #fff; text-shadow: 0 0 30px rgba(255,79,216,.55), 0 5px 0 rgba(0,0,0,.5); }
.ic-text { margin: 10px auto 0; max-width: 560px; font-size: clamp(15px, 3.6vw, 20px); font-weight: 600; color: #e6dbff; text-shadow: 0 2px 10px #000; }
.ic-text b { color: var(--gold); }
.ic-text b.r { color: #ff6b81; }

.intro-counter { position: absolute; top: calc(16px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; pointer-events: none; animation: rise .4s both; }
.intro-counter > div { display: flex; flex-direction: column; align-items: center; padding: 8px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(8px); min-width: 96px; }
.intro-counter span { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.intro-counter b { font-family: var(--display); font-weight: 400; font-size: 26px; color: var(--gold); }
.intro-counter .bank b { color: var(--green); }

.intro-rail { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); width: 4px; height: min(46vh, 320px); border-radius: 99px; background: rgba(255,255,255,.1); pointer-events: none; }
.intro-rail .fill { position: absolute; left: 0; right: 0; top: 0; height: 0; border-radius: inherit; background: linear-gradient(180deg, var(--pink), var(--gold)); box-shadow: 0 0 12px var(--pink); }
.intro-rail .dot { position: absolute; left: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: #2a1854; border: 2px solid rgba(255,255,255,.25); transition: background .3s, border-color .3s, transform .3s; }
.intro-rail .dot.on { background: var(--gold); border-color: #fff; transform: scale(1.2); }

.scroll-hint { position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; color: #d9cdf5; font-weight: 700; font-size: 13px; letter-spacing: .5px; pointer-events: none; transition: opacity .4s; }
.scroll-hint .mouse { width: 22px; height: 34px; border: 2px solid currentColor; border-radius: 12px; position: relative; }
.scroll-hint .mouse i { position: absolute; left: 50%; top: 6px; width: 4px; height: 7px; margin-left: -2px; border-radius: 2px; background: var(--gold); animation: wheel 1.4s ease-in-out infinite; }
.touch .scroll-hint .mouse { border-radius: 50%; width: 30px; height: 30px; }
.touch .scroll-hint .mouse i { top: auto; bottom: 4px; height: 10px; animation: swipe 1.4s ease-in-out infinite; }
@keyframes wheel { 0% { opacity: 0; transform: translateY(0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(12px); } }
@keyframes swipe { 0% { opacity: 0; transform: translateY(0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
.scroll-hint.nudge { animation: nudge 1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(-50%) translateY(-8px); color: var(--gold); } }

.intro-top { position: absolute; top: calc(10px + var(--safe-t)); right: 12px; display: flex; gap: 6px; }
.intro-top .btn { padding: 8px 12px; font-size: 13px; background: rgba(22,12,46,.55); border: 1px solid var(--panel-border); backdrop-filter: blur(8px); }
.intro .crh { transition: opacity .4s; bottom: calc(92px + var(--safe-b)); }
.intro .crh img { width: min(200px, 50vw); }
.intro .crh.gone { opacity: 0; }

@media (max-width: 640px) {
  .intro-rail { right: 8px; height: 34vh; }
  .intro-chapter { bottom: calc(84px + var(--safe-b)); }
  .intro-counter { top: calc(58px + var(--safe-t)); }
  .intro-counter > div { padding: 6px 12px; min-width: 84px; }
  .intro-counter b { font-size: 22px; }
}

/* ---------------------------------------------------------- buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  padding: 12px 20px; border-radius: 14px; font-weight: 800; letter-spacing: .3px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); transition: transform .12s, filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .act:focus-visible, .icon-btn:focus-visible, .mode-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn-primary { background: linear-gradient(180deg, #ffd84a, #ff9b1f); color: #2a0f00; border: 0; box-shadow: 0 6px 0 #a34a00, 0 10px 30px rgba(255, 160, 40, .35); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #a34a00; }
.btn-danger { background: linear-gradient(180deg, #ff6b81, #e0234a); border: 0; }
.btn-ghost { background: transparent; }
.btn-xl { font-family: var(--display); font-size: clamp(18px, 4vw, 26px); padding: 18px 34px; border-radius: 18px; font-weight: 400; }
.btn-block { width: 100%; }
.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); filter: brightness(1.12); } }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--panel-border); background: var(--panel);
  display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(8px); flex: none;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .snd-off { display: none; }
.muted .icon-btn .snd-on { display: none; }
.muted .icon-btn .snd-off { display: block; }

/* ------------------------------------------------------------- menu --- */
.menu { background: linear-gradient(180deg, rgba(11,6,24,.55), rgba(11,6,24,.9) 60%); }
.menu-wrap { max-width: 1100px; margin: 0 auto; padding: calc(18px + var(--safe-t)) 16px calc(40px + var(--safe-b)); animation: rise .5s ease-out both; }
.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.menu-head .logo-word { font-size: clamp(34px, 7vw, 56px); }
.menu-head .tools { display: flex; gap: 8px; }
.menu-sub { margin: 0 0 22px; }
.menu-sub .tagline-inline { font-family: var(--display); font-size: clamp(15px, 3.4vw, 20px); color: #fff; letter-spacing: .4px; }
.menu-sub .descriptor { margin-top: 4px; font-size: 11.5px; }
@media (prefers-reduced-motion: reduce) { .rekt { animation: none; } }
.section-title { font-family: var(--display); font-size: 15px; letter-spacing: 1px; color: #d9caff; margin: 26px 0 12px; font-weight: 400; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--panel-border), transparent); }

.continue {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 6px;
  background: linear-gradient(90deg, rgba(61,220,132,.18), rgba(61,220,132,.04)); border: 1px solid rgba(61,220,132,.45);
}
.continue .c-txt { flex: 1; min-width: 0; }
.continue .c-txt b { display: block; }
.continue .c-txt span { color: var(--muted); font-size: 14px; }

.name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.name-row label { color: var(--muted); font-size: 14px; font-weight: 600; }
.input {
  background: rgba(255,255,255,.06); border: 1px solid var(--panel-border); color: var(--text); border-radius: 12px;
  padding: 10px 12px; min-width: 0; outline: none; user-select: text;
}
.input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(183,125,255,.25); }
select.input { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select.input option { background: var(--panel-solid); }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.mode-card {
  --c: var(--violet); position: relative; text-align: left; cursor: pointer; padding: 14px; border-radius: var(--radius);
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 22%, transparent), rgba(22,12,46,.85) 55%);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); backdrop-filter: blur(8px);
  display: flex; flex-direction: column; gap: 8px; transition: transform .15s, box-shadow .15s; overflow: hidden;
}
.mode-card:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 10px 30px color-mix(in srgb, var(--c) 30%, transparent); }
.mode-card:disabled { cursor: default; opacity: .55; }
.mode-card .avatar { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; border: 2px solid var(--c); box-shadow: 0 0 18px color-mix(in srgb, var(--c) 50%, transparent); }
.mode-card .tier { position: absolute; top: 12px; right: 12px; font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; padding: 4px 8px; border-radius: 99px; background: color-mix(in srgb, var(--c) 25%, transparent); color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 50%, transparent); }
.mode-card h3 { margin: 4px 0 0; font-family: var(--display); font-weight: 400; font-size: 20px; letter-spacing: .5px; }
.mode-card .persona { font-size: 12.5px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--c); margin-top: -4px; }
.mode-card p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.35; flex: 1; }
.mode-card .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: rgba(255,255,255,.07); color: #ddd0ff; white-space: nowrap; }
.mode-card .play { font-weight: 800; color: var(--c); font-size: 14px; }
.record { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ------------------------------------------------------------- HUD ---- */
.hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; display: flex; flex-direction: column; }
.hud > * { pointer-events: auto; }
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 6px; }
.topbar-title { flex: 1; text-align: center; min-width: 0; }
.mode-name { font-family: var(--display); font-size: 15px; letter-spacing: .5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round { color: var(--muted); font-size: 12.5px; font-weight: 600; }

/* Seats: one connected turn-order track */
.seats {
  --n: 2; position: relative; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 8px;
  margin: 2px auto 0; padding: 0 12px; width: min(100%, calc(var(--n) * 210px + 24px));
}
.seats::before {
  content: ''; position: absolute; left: 30px; right: 30px; top: 50%; height: 2px; z-index: -1;
  background: linear-gradient(90deg, transparent, rgba(183,125,255,.35) 10%, rgba(183,125,255,.35) 90%, transparent);
}
.seat {
  --c: var(--violet); position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 16px; min-width: 0;
  background: var(--panel); border: 1px solid rgba(255,255,255,.08); backdrop-filter: blur(10px);
  transition: transform .25s, border-color .25s, box-shadow .25s, opacity .25s;
}
.seat.active { border-color: var(--c); box-shadow: 0 0 0 1px var(--c), 0 0 28px color-mix(in srgb, var(--c) 45%, transparent); transform: translateY(2px) scale(1.03); }
.seat.active::after {
  content: '▶ TURN'; position: absolute; top: -9px; left: 50%; transform: translateX(-50%); font-size: 9.5px; font-weight: 800; letter-spacing: 1px;
  padding: 2px 8px; border-radius: 99px; background: var(--c); color: #12062a; white-space: nowrap;
}
.seat.out { opacity: .38; filter: grayscale(1); }
.seat .av { width: 42px; height: 42px; flex: none; border-radius: 12px; border: 2px solid var(--c); display: grid; place-items: center; font-weight: 800; font-size: 17px; background: color-mix(in srgb, var(--c) 25%, #140a2c); overflow: hidden; }
.seat .av img { width: 100%; height: 100%; object-fit: cover; }
.seat .info { flex: 1; min-width: 0; }
.seat .nm { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: color-mix(in srgb, var(--c) 60%, #fff); }
.seat .tot { font-family: var(--display); font-size: 22px; line-height: 1.05; }
.seat .tot small { font-family: var(--body); font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 3px; }
.seat .bar { height: 5px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; margin-top: 3px; }
.seat .bar span { display: block; height: 100%; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 70%, #000), var(--c)); border-radius: inherit; transition: width .6s cubic-bezier(.2,.9,.3,1.2); }
.seat .pending { position: absolute; right: 8px; top: 6px; font-size: 11px; font-weight: 800; color: var(--gold); }
.seat .bears { font-size: 10.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .bears b { color: #ff9aa9; font-weight: 700; }
.seat .bears s { opacity: .45; }
.seat.pop .tot { animation: pop .6s ease-out; }
.seat.hurt { animation: hurt .5s; }
@keyframes pop { 30% { transform: scale(1.35); color: var(--gold); } }
@keyframes hurt { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.seat .bubble {
  position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 3; width: max-content; max-width: 220px;
  padding: 7px 11px; border-radius: 12px; font-size: 12.5px; font-weight: 600; background: #f3edff; color: #1d0f45; box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: rise .25s ease-out both;
}
.seat .bubble::before { content: ''; position: absolute; top: -6px; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top: 0; border-bottom-color: #f3edff; }

/* Compact seats for 4–6 players */
.seats.compact .seat { flex-direction: column; text-align: center; gap: 3px; padding: 7px 4px 6px; }
.seats.compact .seat .av { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; }
.seats.compact .seat .tot { font-size: 18px; }
.seats.compact .seat .tot small { display: none; }
.seats.compact .seat .info { width: 100%; }
.seats.compact .seat .nm { font-size: 11.5px; }
.seats.compact .seat .bears { display: none; }
.seats.compact .seat .pending { top: 3px; right: 4px; font-size: 10px; }

.center-stack { flex: 1; position: relative; pointer-events: none; }
.banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.6); opacity: 0; pointer-events: none;
  text-align: center; white-space: nowrap; transition: opacity .2s, transform .35s cubic-bezier(.2,1.4,.4,1);
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner .big { font-family: var(--display); font-size: clamp(40px, 11vw, 96px); line-height: 1; color: var(--bc, #fff); text-shadow: 0 0 30px var(--bc, #fff), 0 5px 0 rgba(0,0,0,.6); }
.banner .small { margin-top: 8px; font-weight: 700; font-size: clamp(14px, 3.4vw, 20px); text-shadow: 0 2px 10px #000; }
.banner .ban-av { width: 64px; height: 64px; border-radius: 18px; border: 3px solid var(--bc); margin: 0 auto 10px; display: grid; place-items: center; font-weight: 800; font-size: 26px; overflow: hidden; background: #1d0f45; box-shadow: 0 0 30px var(--bc); }
.banner .ban-av img { width: 100%; height: 100%; object-fit: cover; }

.bottom { padding: 0 12px calc(12px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.turnbox { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-radius: 16px; background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(10px); }
.turn-label { font-size: 12px; color: var(--muted); font-weight: 700; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-score { display: flex; align-items: baseline; gap: 6px; }
.turn-score span { font-family: var(--display); font-size: 30px; color: var(--gold); text-shadow: 0 0 18px rgba(255,210,63,.5); min-width: 1.2em; text-align: right; }
.turn-score small { color: var(--muted); font-weight: 600; font-size: 12px; }
.turn-score.bump span { animation: pop .5s ease-out; }
.apein-badge { font-family: var(--display); font-size: 13px; padding: 5px 10px; border-radius: 10px; background: linear-gradient(180deg, #5cf0a0, #1fae5f); color: #062814; box-shadow: 0 0 20px rgba(61,220,132,.6); animation: pulse 1s infinite; }
.hint { font-size: 13.5px; color: #d9cdf5; text-align: center; min-height: 1.3em; max-width: 560px; text-shadow: 0 1px 6px #000; }
.hint b { color: var(--gold); }
.hint .risk { color: #ff9aa9; }
.hint .safe { color: var(--green); }

.actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(100%, 520px); }
.act {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 12px 6px 10px; min-height: 74px;
  border-radius: 18px; border: 0; cursor: pointer; color: #fff; font-family: var(--display); font-size: 17px; letter-spacing: .5px;
  transition: transform .12s, filter .2s, opacity .2s, box-shadow .2s;
}
.act-ico { font-size: 24px; line-height: 1; font-family: var(--body); }
.act kbd { position: absolute; top: 6px; right: 8px; font-family: var(--body); font-size: 10px; font-weight: 800; opacity: .55; }
.act-draw { background: linear-gradient(180deg, #7b5cff, #4a2bd6); box-shadow: 0 5px 0 #2a1585; }
.act-roll { background: linear-gradient(180deg, #ff5fb0, #d42a7a); box-shadow: 0 5px 0 #7d1046; }
.act-stack { background: linear-gradient(180deg, #ffd84a, #ff9b1f); box-shadow: 0 5px 0 #a34a00; color: #2a0f00; }
.act:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.act:disabled { opacity: .28; filter: grayscale(.7); cursor: not-allowed; }
.act.primary:not(:disabled) { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { filter: brightness(1.2); transform: translateY(-2px); } }
.act .sub { font-family: var(--body); font-size: 11px; font-weight: 700; opacity: .85; }

.thinking { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--panel-border); font-weight: 600; min-height: 74px; width: min(100%, 520px); justify-content: center; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--violet); animation: dot 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 50% { transform: translateY(-5px); opacity: .5; } }

/* -------------------------------------------------------- floaters --- */
.floaters { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.floater { position: absolute; transform: translate(-50%, -50%); font-family: var(--display); font-size: 40px; color: var(--fc, var(--gold)); text-shadow: 0 0 20px var(--fc, var(--gold)), 0 4px 0 rgba(0,0,0,.6); animation: floatUp 1.3s ease-out forwards; white-space: nowrap; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.5); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1); } }

/* ----------------------------------------------------------- modals --- */
.modal-root { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(6, 2, 16, .66); backdrop-filter: blur(6px); animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 22px 20px; border-radius: 22px;
  background: linear-gradient(180deg, #221146, #150a2e); border: 1px solid var(--panel-border); box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: rise .3s ease-out both; user-select: text;
}
.modal.wide { width: min(760px, 100%); }
.modal h2 { font-family: var(--display); font-weight: 400; font-size: 24px; margin: 0 0 6px; letter-spacing: .5px; }
.modal .lead { color: var(--muted); margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.modal-actions .btn { flex: 1; min-width: 140px; }
.stack-list { display: flex; flex-direction: column; gap: 10px; }

.rules h3 { font-family: var(--display); font-weight: 400; font-size: 15px; letter-spacing: .5px; margin: 18px 0 8px; color: #e0d2ff; }
.rules ol, .rules ul { padding-left: 20px; margin: 0; line-height: 1.55; color: #ddd2f7; }
.rules li { margin-bottom: 4px; }
.card-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.card-gallery figure { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.card-gallery img { width: 100%; border-radius: 8px; box-shadow: 0 6px 16px rgba(0,0,0,.4); display: block; margin-bottom: 4px; }
.card-gallery b { color: var(--text); display: block; font-size: 13px; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.setting .lbl b { display: block; }
.setting .lbl span { color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: rgba(255,255,255,.15); cursor: pointer; transition: .2s; }
.switch span::after { content: ''; position: absolute; left: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }
.seg { display: inline-flex; background: rgba(255,255,255,.06); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--violet); color: #12062a; }
input[type=range] { accent-color: var(--violet); width: 130px; }

/* table setup */
.seat-rows { display: flex; flex-direction: column; gap: 8px; }
.seat-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) 128px 36px; gap: 8px; align-items: center; }
.seat-row .dot { width: 12px; height: 12px; border-radius: 50%; }
.seat-row .rm { width: 36px; height: 40px; padding: 0; }
.setup-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; margin-top: 12px; }

/* game over */
.result-hero { text-align: center; margin-bottom: 8px; }
.result-hero .trophy { font-size: 56px; line-height: 1; filter: drop-shadow(0 0 20px rgba(255,210,63,.7)); }
.result-hero h2 { font-size: clamp(26px, 6vw, 38px); margin-top: 6px; }
.scoreboard { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
.scoreboard th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 6px; border-bottom: 1px solid rgba(255,255,255,.08); }
.scoreboard td { padding: 8px 6px; border-bottom: 1px solid rgba(255,255,255,.05); }
.scoreboard td.num, .scoreboard th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scoreboard .who { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.scoreboard .who i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.scoreboard tr.win td { background: rgba(255,210,63,.08); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.stat { padding: 12px; border-radius: 14px; background: rgba(255,255,255,.05); }
.stat b { display: block; font-family: var(--display); font-size: 24px; font-weight: 400; }
.stat span { color: var(--muted); font-size: 12px; font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 40; padding: 10px 16px; border-radius: 12px; background: #f3edff; color: #1d0f45; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: rise .25s both; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; }

/* --------------------------------------------------------- responsive - */
@media (max-width: 640px) {
  .seats { gap: 6px; padding: 0 8px; }
  .seat { padding: 7px 8px; gap: 7px; }
  .seat .av { width: 36px; height: 36px; }
  .seat .tot { font-size: 19px; }
  .act { min-height: 64px; font-size: 15px; padding: 10px 4px 8px; }
  .act-ico { font-size: 21px; }
  .act kbd { display: none; }
  .turn-score span { font-size: 26px; }
  .hint { font-size: 12.5px; }
  .seat-row { grid-template-columns: 10px minmax(0, 1fr) 128px 36px; gap: 6px; }
  .seat-row select.input { font-size: 14px; padding-left: 8px; padding-right: 24px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .act { min-height: 52px; flex-direction: row; gap: 8px; }
  .turnbox { padding: 4px 12px; }
  .turn-score span { font-size: 22px; }
  .topbar { padding-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse, .act.primary:not(:disabled), .apein-badge { animation: none; }
}

/* ------------------------------------------------------------ moods --- */
/* Character portraits react to the game. Badges sit on the avatar's corner. */
.av, .ban-av { position: relative; }
.seat .av, .think-av { overflow: visible !important; }
.seat .av img, .think-av img { border-radius: 10px; }
.av::after, .think-av::after {
  content: attr(data-badge); position: absolute; right: -8px; top: -8px; font-size: 16px; line-height: 1;
  opacity: 0; transform: scale(.3); transition: opacity .2s, transform .3s cubic-bezier(.2,1.6,.4,1); pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.av[data-badge]:not([data-badge=""])::after, .think-av[data-badge]:not([data-badge=""])::after { opacity: 1; transform: scale(1); }
.mood-idle.breathe { animation: breathe 3s ease-in-out infinite; }
.mood-happy { animation: moodHappy .55s ease-out 3; box-shadow: 0 0 18px rgba(255,210,63,.75); }
.mood-sad { animation: moodSad .6s ease-out forwards; }
.mood-sad img { filter: grayscale(.65) brightness(.75) hue-rotate(190deg) saturate(.6); }
.mood-anxious { animation: moodAnxious calc(.32s - var(--tension, 0) * .2s) linear infinite; box-shadow: 0 0 calc(6px + var(--tension, 0) * 18px) rgba(255,77,109,.8); }
.mood-smug { animation: moodSmug .5s ease-out forwards; }
.mood-shocked { animation: moodShocked .45s cubic-bezier(.2,1.6,.4,1) forwards; box-shadow: 0 0 20px rgba(77,201,255,.8); }
@keyframes breathe { 50% { transform: scale(1.04); } }
@keyframes moodHappy { 40% { transform: translateY(-7px) scale(1.08); } }
@keyframes moodSad { to { transform: translateY(3px) rotate(-7deg) scale(.95); } }
@keyframes moodAnxious { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-1.5px, 1px) rotate(-1.5deg); } 50% { transform: translate(1.5px, -1px); } 75% { transform: translate(-1px, -1px) rotate(1.5deg); } }
@keyframes moodSmug { to { transform: rotate(9deg) scale(1.05); } }
@keyframes moodShocked { 0% { transform: scale(1); } 60% { transform: scale(1.22); } 100% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .mood-happy, .mood-sad, .mood-anxious, .mood-smug, .mood-shocked, .mood-idle.breathe { animation: none; } }

/* Character portrait in the bottom bar while they play */
.thinking { gap: 14px; }
.think-av { width: 54px; height: 54px; flex: none; border-radius: 14px; border: 2px solid var(--c, var(--violet)); position: relative; background: #1d0f45; }
.think-av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.think-copy { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.think-copy small { font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--c, var(--violet)); }
#thinking-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tension: the turn box pulses with the heartbeat */
.turnbox.tense { animation: tense var(--beat, 0.8s) ease-in-out infinite; border-color: rgba(255,77,109,.6); }
@keyframes tense { 0%, 100% { box-shadow: 0 0 0 rgba(255,77,109,0); } 15% { box-shadow: 0 0 26px rgba(255,77,109,.55); } }

/* Menu: quotes and ticker */
.mode-card .quote { font-size: 13px; font-style: italic; color: #f1e9ff; padding-left: 10px; border-left: 2px solid var(--c); line-height: 1.35; }
.ticker { position: relative; overflow: hidden; margin: 0 -16px 14px; padding: 7px 0; background: rgba(0,0,0,.35); border-block: 1px solid rgba(255,210,63,.25); mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
.ticker-track { display: inline-flex; gap: 34px; white-space: nowrap; padding-left: 34px; animation: tick var(--dur, 40s) linear infinite; font-weight: 800; font-size: 13px; letter-spacing: .6px; font-variant-numeric: tabular-nums; }
.ticker-track span { color: var(--muted); }
.ticker-track b { color: #fff; margin-left: 6px; }
.ticker-track .up { color: var(--green); }
.ticker-track .down { color: var(--red); }
@keyframes tick { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .ticker-track { animation: none; } }
