:root {
  --bg: #120812;
  --bg2: #1f0d22;
  --gold: #c9a063;
  --gold-2: #e6c48e;
  --cream: #f6ead7;
  --muted: #b9a5b3;
  --line: rgba(201, 160, 99, 0.28);
  --panel: rgba(255, 255, 255, 0.05);
  --accent: #f7b85c;
  --spark: #f25a5a;
  --radius: 16px;
}
body[data-level="2"] { --accent: #ee8590; }
body[data-level="3"] { --accent: #b48ae0; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
  color: var(--cream);
  font: 400 16px/1.55 'Prompt', 'Kanit', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, .brand, .bigcode, .lv-badge, .timer, .btn { font-family: 'Kanit', 'Prompt', sans-serif; }
h2 { font-weight: 500; margin: .4em 0; }
h3 { font-weight: 500; color: var(--gold-2); margin: 1.4em 0 .4em; }
small, .small { font-size: .82em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.big { font-size: 1.12em; font-weight: 500; }
b { color: var(--gold-2); font-weight: 500; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* ───── buttons & inputs ───── */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #24121f; font-weight: 500; font-size: 1rem;
  padding: 12px 18px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s, filter .2s, opacity .2s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--gold-2); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.pass { background: #1a1a1d; color: #e9e9ee; box-shadow: inset 0 0 0 1.5px #55555c; }
.btn.small { padding: 6px 12px; font-size: .88rem; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn small { font-weight: 300; opacity: .8; }
.link { background: none; border: 0; color: var(--gold); text-decoration: underline; cursor: pointer; font: inherit; margin-top: 18px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.row > .btn { flex: 1 1 140px; }

input:not([type]), input[type=text], textarea, .code-in {
  width: 100%; font: inherit; color: var(--cream);
  background: rgba(255, 255, 255, .06); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 11px 14px; outline: none; margin-top: 8px;
  transition: border-color .2s, background .2s;
}
input:focus, textarea:focus { border-color: var(--gold); background: rgba(255, 255, 255, .09); }
textarea { resize: vertical; min-height: 64px; }
::placeholder { color: #8f7c8a; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--gold); flex: none; }

/* ───── home ───── */
.home { display: flex; flex-direction: column; align-items: stretch; text-align: center; padding-top: 8px; }
.cover-wrap { perspective: 900px; }
.cover {
  width: min(56vw, 230px); border-radius: 14px; margin: 6px auto 0; display: block;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55), 0 0 0 1px var(--line);
  animation: float 6s ease-in-out infinite;
}
.cover.small { width: 110px; animation: none; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-1.5deg); } }
.tag { color: var(--muted); margin: 14px 0 6px; }
.field { text-align: left; display: block; margin: 8px 0 14px; }
.field span { font-size: .9em; color: var(--muted); }
.or { color: var(--muted); font-size: .85em; margin: 14px 0 4px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.joinbox .row { flex-wrap: nowrap; margin-top: 0; }
.joinbox .row .btn { flex: 0 0 auto; margin-top: 8px; }
.code-in { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-family: 'Kanit'; font-size: 1.15rem; }
.joinbox.invited { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.invite { margin: 0 0 4px; }

/* ───── connecting ───── */
.connecting { text-align: center; padding-top: 30vh; }
.pulse { font-size: 56px; animation: pulse 1.4s ease-in-out infinite; }
.pulse.small { font-size: 32px; }
@keyframes pulse { 50% { transform: scale(1.18); opacity: .7; } }

/* ───── top bar ───── */
.bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.brand { letter-spacing: .28em; color: var(--gold); font-weight: 500; font-size: .95rem; }
.bar-r { display: flex; align-items: center; gap: 6px; }
.room { font-size: .8rem; color: var(--muted); margin-right: 4px; }
.icon {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--cream); cursor: pointer; font-size: 15px;
}
.icon.on { background: var(--gold); color: #24121f; }
.banner { background: rgba(242, 90, 90, .15); border: 1px solid rgba(242, 90, 90, .4); padding: 8px 12px; border-radius: 12px; font-size: .9em; margin-bottom: 10px; text-align: center; }

/* ───── players ───── */
.players { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.heart { color: var(--gold); }
.pchip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px;
  transition: box-shadow .3s, border-color .3s;
}
.pchip.turn { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent), 0 0 18px color-mix(in srgb, var(--accent) 30%, transparent); }
.pchip.empty { color: var(--muted); border-style: dashed; }
.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.pname small { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #666; flex: none; }
.dot.on { background: #6ee7a0; box-shadow: 0 0 8px #6ee7a0; }
.passicon { font-size: 14px; }
.passicon.used { filter: grayscale(1); opacity: .3; }

/* ───── lobby ───── */
.invitecard { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.invitecard p { margin: 0 0 4px; }
.bigcode { font-size: 2.6rem; letter-spacing: .3em; color: var(--gold-2); font-weight: 600; padding-left: .3em; }
.warn { color: #ffb36b; font-size: .85em; margin-top: 10px !important; }
.settings { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px 10px; }
.setrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.segs { display: flex; gap: 4px; }
.seg { width: 38px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--cream); font: 500 1rem 'Kanit'; cursor: pointer; }
.seg.on { background: var(--gold); color: #24121f; border-color: var(--gold); }
.seg:disabled { cursor: default; }
.tip { font-size: .86em; color: var(--muted); text-align: center; margin-top: 14px; }

/* ───── play ───── */
.levelbar {
  display: flex; justify-content: space-between; font: 500 .78rem 'Kanit'; letter-spacing: .12em;
  color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); padding-bottom: 6px;
}
.table { display: flex; justify-content: center; padding: 16px 0 12px; }
.flip, .deck { width: min(66vw, 290px, calc((100dvh - 480px) * .716)); min-width: 170px; aspect-ratio: 640 / 894; }
.flip { perspective: 1200px; }
.flip-in { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .75s cubic-bezier(.3, 1.3, .5, 1); }
.flip.flipped .flip-in { transform: rotateY(180deg); }
.flip.no-anim .flip-in { transition: none; }
.face { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: 0 14px 40px rgba(0, 0, 0, .5); }
.face.front { transform: rotateY(180deg); }

.deck { position: relative; border: 0; background: none; padding: 0; cursor: default; }
.deck img { position: absolute; inset: 0; width: 100%; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); transition: transform .3s; }
.deck img:nth-child(1) { transform: translate(8px, 8px) rotate(3deg); filter: brightness(.6); }
.deck img:nth-child(2) { transform: translate(4px, 4px) rotate(1.5deg); filter: brightness(.8); }
.deck.mine { cursor: pointer; }
.deck.mine img:nth-child(3) { animation: nudge 2.2s ease-in-out infinite; box-shadow: 0 0 0 2px var(--accent), 0 0 36px color-mix(in srgb, var(--accent) 45%, transparent); }
.deck.mine:hover img:nth-child(3) { transform: translateY(-10px) rotate(-2deg); }
@keyframes nudge { 50% { transform: translateY(-6px); } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel p { margin: 0 0 8px; }
.panel.center { text-align: center; }
.hint { font-size: .88em; color: var(--muted); }
.status { font-size: .85em; color: var(--muted); margin: 8px 0 0 !important; }
.spark-h { font: 600 .8rem 'Kanit'; letter-spacing: .12em; color: var(--spark); }
.passed { text-align: center; padding: 10px 0; }

.bubbles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bubble { background: rgba(255, 255, 255, .06); border-radius: 14px; padding: 10px 12px; animation: pop .45s cubic-bezier(.3, 1.5, .5, 1) both; min-width: 0; overflow-wrap: anywhere; }
.bubble:nth-child(2) { animation-delay: .12s; }
.bubble.me { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.bubble.solo { animation: none; }
.bubble b { display: block; font-size: .8em; margin-bottom: 2px; }
.bubble p { margin: 0; }
.bubble ol { margin: 4px 0 0; padding-left: 1.2em; }
.pick { font-size: 1.05em; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.92); } }
@media (max-width: 380px) { .bubbles { grid-template-columns: 1fr; } }

.timer { font-size: 4.5rem; text-align: center; color: var(--spark); font-weight: 600; line-height: 1.1; animation: pulse 1s ease-in-out infinite; }
.result { text-align: center; font-size: 1.15em; padding: 10px 0; }
.menu { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.mi { background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 12px; color: var(--cream); font: .72rem 'Prompt'; padding: 6px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mi span { font-size: 1.5rem; }
.mi.on { background: color-mix(in srgb, var(--spark) 25%, transparent); border-color: var(--spark); }
.polaroid { width: 100%; background: #fff; padding: 6px 6px 18px; border-radius: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); transform: rotate(-2deg); display: block; margin: 4px 0; }
.bubble:nth-child(2) .polaroid { transform: rotate(2deg); }

.reacts { display: flex; width: max-content; margin: 14px auto 0; gap: 4px; background: rgba(20, 8, 20, .85); border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px; }
.reacts button { background: none; border: 0; font-size: 22px; cursor: pointer; padding: 2px 5px; transition: transform .15s; }
.reacts button:active { transform: scale(1.4); }

/* ───── level up ───── */
.levelup { text-align: center; }
.lvcard { margin: 16px auto; padding: 26px 18px; border-radius: 20px; max-width: 320px; animation: pop .6s cubic-bezier(.3, 1.4, .5, 1) both; }
.lvcard[data-lv="2"] { background: #f8e0e6; color: #3a2128; }
.lvcard[data-lv="3"] { background: linear-gradient(135deg, #221a3a, #5e3b85 70%, #a76fc7); color: #f8f0e6; }
.lvcard .muted { color: inherit; opacity: .7; }
.lvcard h2 { font-size: 1.7rem; margin: 6px 0 2px; }
.lvcard p { margin: 0; }
.lv-badge { display: inline-block; letter-spacing: .2em; font-weight: 500; border: 1.5px solid currentColor; border-radius: 999px; padding: 4px 14px; margin-top: 8px; }
.readyrow { display: flex; justify-content: center; gap: 22px; margin: 12px 0; color: var(--muted); }
.readyrow .ok { color: #6ee7a0; }

/* ───── finale / end ───── */
.favlist { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.fav { text-align: left; background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; color: var(--cream); font: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 3px; transition: border-color .2s, background .2s; }
.fav small { color: var(--gold); letter-spacing: .12em; font-size: .7em; }
.fav .q { font-size: .88em; color: var(--muted); }
.fav .a { font-size: 1.02em; }
.fav.on { border-color: var(--gold); background: rgba(201, 160, 99, .14); }
.end .cover { display: block; margin: 0 auto 6px; }
.favcard { background: linear-gradient(135deg, rgba(201, 160, 99, .18), rgba(201, 160, 99, .04)); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 12px; }
.favcard small { color: var(--gold); }
.favcard .q { color: var(--muted); font-size: .9em; margin: 6px 0 2px; }
.favcard .a { font-size: 1.1em; margin: 0; }
.album { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.album figure { margin: 0; }
.album figcaption { font-size: .8em; color: var(--muted); text-align: center; margin-top: 6px; }
.end ol { margin-top: 0; }
.end .row { margin-top: 24px; }

/* ───── video call ───── */
#call { position: fixed; top: 128px; right: 8px; width: 100px; z-index: 20; border-radius: 14px; overflow: hidden; background: #000; box-shadow: 0 10px 30px rgba(0, 0, 0, .6), 0 0 0 1px var(--line); transition: width .3s; }
#call.big, body.eye-mode #call { width: min(92vw, 420px); right: 50%; transform: translateX(50%); }
#rv { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; background: #1b1b1b; }
#lv { position: absolute; right: 6px; top: 6px; width: 32%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .4); transform: scaleX(-1); background: #333; }
.call-ctl { display: flex; justify-content: space-around; padding: 4px; background: rgba(0, 0, 0, .7); }
.call-ctl button { background: none; border: 0; font-size: 16px; cursor: pointer; color: #fff; padding: 4px; border-radius: 8px; }
.call-ctl button.off { opacity: .35; }
.call-ctl .red { color: #ff6b6b; }
#incoming { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 30; background: #2a1528; border: 1px solid var(--gold); border-radius: 16px; padding: 12px 16px; width: min(92vw, 360px); box-shadow: 0 12px 40px rgba(0, 0, 0, .6); text-align: center; }
#incoming p { margin: 0; }
.flash { position: fixed; inset: 0; background: #fff; z-index: 50; animation: flash .5s forwards; pointer-events: none; }
@keyframes flash { to { opacity: 0; } }

/* ───── modal / toast / fx ───── */
#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden], #call[hidden], #incoming[hidden] { display: none; }
.sheet { background: var(--bg2); border: 1px solid var(--line); border-radius: 22px 22px 0 0; width: min(100%, 560px); max-height: 86dvh; overflow: auto; padding: 22px 20px calc(24px + env(safe-area-inset-bottom)); position: relative; animation: up .3s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .close { position: absolute; right: 14px; top: 12px; background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }
.rules li { margin-bottom: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #2a1528; border: 1px solid var(--line); color: var(--cream); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .3s; z-index: 60; max-width: 90vw; text-align: center; font-size: .92em; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.float { position: absolute; bottom: 60px; font-size: 34px; animation: rise 2.6s ease-out forwards; }
@keyframes rise { to { transform: translateY(-70vh) scale(1.4) rotate(15deg); opacity: 0; } }

/* ───── desktop: card beside the panel ───── */
@media (min-width: 900px) {
  #app { max-width: 940px; }
  .play { display: grid; grid-template-columns: auto 1fr; column-gap: 28px; align-items: start; }
  .play > .players, .play > .levelbar, .play > .reacts { grid-column: 1 / -1; }
  .play .table { padding-top: 22px; }
  .play .panel { margin-top: 22px; align-self: center; }
  .flip, .deck { width: min(340px, calc((100dvh - 200px) * .716)); }
  .lobby, .levelup, .finale, .end, .home { max-width: 520px; margin: 0 auto; }
}
