:root {
  color-scheme: dark;
  --bg: #120f17;
  --panel: rgba(255, 255, 255, 0.075);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --text: #fff8ec;
  --muted: #c9bdad;
  --accent: #ffbd59;
  --accent-2: #f97316;
  --danger: #ff6b6b;
  --ok: #7ee787;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(249, 115, 22, .22), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(255, 189, 89, .16), transparent 26rem),
    var(--bg);
  color: var(--text);
  transition: background .4s ease, filter .25s ease;
}
body.my-turn {
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 236, 133, .36), transparent 18rem),
    radial-gradient(circle at top left, rgba(249, 115, 22, .34), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(255, 48, 99, .2), transparent 26rem),
    #1c1117;
}
body.turn-flash { animation: screenFlash 1.45s ease both; }

button, input { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  padding: .9rem 1.1rem;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
button:not(:disabled):active { transform: scale(.96); }
button:not(:disabled):hover { filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1d1208; box-shadow: none; }
button.ghost { background: transparent; }
input {
  width: 100%;
  margin-top: .45rem;
  padding: .9rem 1rem;
  border-radius: 1rem;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(0,0,0,.2);
  color: var(--text);
  outline: none;
}
a { color: var(--accent); }
label { display: block; text-align: left; color: var(--muted); font-size: .9rem; margin: 1rem 0; }

.app { width: min(1060px, 100%); margin: 0 auto; padding: 1rem; }
.panel {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 1.5rem;
  padding: 1rem;
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 60px rgba(0,0,0,.22);
}
.hero { max-width: 460px; margin: 8vh auto; text-align: center; padding: 1.5rem; }
h1 { font-size: clamp(2.8rem, 13vw, 5.5rem); line-height: .9; margin: .2rem 0 1rem; letter-spacing: -.08em; }
h2, h3 { margin: .1rem 0 .6rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--accent); text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 900; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; }
.hidden { display: none !important; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1.2rem 0 .6rem; }
.divider::before, .divider::after { content: ''; height: 1px; background: rgba(255,255,255,.12); flex: 1; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.avatar-setup { display: grid; grid-template-columns: auto 1fr; gap: .8rem; align-items: center; text-align: left; margin: 1rem 0; }
.avatar { width: 3rem; height: 3rem; border-radius: 999px; object-fit: cover; display: inline-grid; place-items: center; background: linear-gradient(135deg, rgba(255,189,89,.34), rgba(249,115,22,.22)); border: 2px solid rgba(255,255,255,.22); color: var(--text); font-weight: 1000; overflow: hidden; flex: 0 0 auto; }
.avatar img, .avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-preview { width: 5rem; height: 5rem; font-size: 2rem; }
.avatar.small { width: 2.25rem; height: 2.25rem; font-size: .95rem; }
.ranking-row .avatar { grid-area: avatar; }
.camera-panel { max-width: 460px; margin: 1rem auto; text-align: center; }
.camera-preview { width: 100%; max-height: 340px; border-radius: 1rem; object-fit: cover; background: rgba(0,0,0,.35); margin: .5rem 0 .75rem; }
.lobby { text-align: center; margin-bottom: 1rem; }
.qr { width: min(72vw, 260px); background: #fff; border-radius: 1rem; padding: .75rem; margin: .5rem auto; display: block; }
.game-grid { display: grid; grid-template-columns: 1.5fr .9fr; gap: 1rem; margin-bottom: 1rem; }
.table-card { text-align: center; }
.big-card {
  width: min(58vw, 220px);
  aspect-ratio: 2.5/3.5;
  border-radius: 1.2rem;
  margin: .5rem auto;
  background: linear-gradient(155deg, #fffaf0, #ffd089);
  color: #2b1605;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 20vw, 7rem);
  font-weight: 1000;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
  animation: cardDeal .36s cubic-bezier(.2, 1.25, .5, 1) both;
}
.my-turn .big-card { animation: cardDeal .36s cubic-bezier(.2, 1.25, .5, 1) both, cardWiggle 1.8s ease-in-out infinite; }
.pot { color: var(--accent); font-size: 1.1rem; font-weight: 900; }
.turn { font-weight: 900; font-size: 1.1rem; min-height: 2.6em; }
.turn-banner {
  border-radius: 999px;
  padding: .6rem .85rem;
  margin: .25rem auto .65rem;
  background: linear-gradient(135deg, #fff36d, #ff7a18);
  color: #201006;
  font-size: .82rem;
  font-weight: 1000;
  letter-spacing: .04em;
  text-transform: uppercase;
  box-shadow: 0 0 28px rgba(255, 189, 89, .35);
  animation: bannerPulse .8s ease-in-out infinite alternate;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.my-turn .actions button:not(:disabled) { animation: buttonNudge 1.4s ease-in-out infinite; }
.my-turn .actions button.primary:not(:disabled) { box-shadow: 0 0 0 4px rgba(255,189,89,.2), 0 18px 42px rgba(249,115,22,.38); }
.rules ul { margin: .5rem 0 0; padding-left: 1.1rem; color: var(--muted); line-height: 1.55; }
.players-panel, .log-panel, #result { margin-bottom: 1rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.pill { border-radius: 999px; padding: .35rem .65rem; background: rgba(255,255,255,.1); color: var(--muted); font-size: .8rem; font-weight: 800; }
.players { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .75rem; }
.player {
  border-radius: 1rem;
  background: rgba(0,0,0,.18);
  padding: .85rem;
  border: 1px solid rgba(255,255,255,.08);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.player.draggable { cursor: grab; }
.player.dragging { opacity: .55; transform: scale(.98); }
.player.drag-over { border-color: var(--accent); background: rgba(255,189,89,.12); }
.player.current { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(255,189,89,.35); }
.player.spotlight { animation: playerPulse 1.25s ease-in-out infinite; }
.player.me { background: rgba(255,189,89,.08); }
.player-top { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.seat-number { width: 1.65rem; height: 1.65rem; border-radius: 50%; display: inline-grid; place-items: center; flex: 0 0 auto; background: rgba(255,255,255,.1); color: var(--accent); font-weight: 1000; }
.player-name { font-weight: 1000; flex: 1; }
.score { color: var(--accent); font-weight: 1000; }
.reorder-controls { display: flex; justify-content: flex-end; gap: .4rem; margin-top: .7rem; }
.mini-action { padding: .35rem .55rem; min-width: 2.2rem; border-radius: .7rem; font-size: .9rem; }
.cards { display: flex; flex-wrap: wrap; gap: .32rem; margin-top: .65rem; }
.mini-card { min-width: 2rem; padding: .25rem .35rem; border-radius: .42rem; font-weight: 950; text-align: center; }
.meta { color: var(--muted); font-size: .83rem; margin-top: .45rem; }
.log { display: grid; gap: .45rem; color: var(--muted); font-size: .88rem; max-height: 190px; overflow: auto; }
.ranking { display: grid; gap: .65rem; padding: 0; margin: .75rem 0 0; list-style: none; line-height: 1.2; }
.ranking-row { display: grid; grid-template-columns: 3rem 2.25rem 1fr auto; grid-template-areas: "medal avatar name score" "medal avatar detail detail"; gap: .15rem .7rem; align-items: center; padding: .75rem; border-radius: 1rem; background: rgba(0,0,0,.18); border: 1px solid rgba(255,255,255,.08); }
.ranking-row.winner { background: linear-gradient(135deg, rgba(255,189,89,.24), rgba(249,115,22,.14)); border-color: rgba(255,189,89,.55); box-shadow: 0 14px 40px rgba(249,115,22,.18); }
.ranking-medal { grid-area: medal; font-size: 2rem; width: 3rem; height: 3rem; border-radius: 1rem; display: grid; place-items: center; background: rgba(255,255,255,.09); }
.ranking-name { grid-area: name; font-weight: 1000; }
.ranking-score { grid-area: score; color: var(--accent); font-weight: 1000; }
.ranking-detail { grid-area: detail; color: var(--muted); font-size: .85rem; }
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: .65rem; margin: 1rem 0; min-height: 330px; }
.podium-player { position: relative; text-align: center; display: grid; justify-items: center; gap: .35rem; align-self: end; }
.podium-player.place-1 { transform: translateY(-34px); }
.podium-player.place-2 { transform: translateY(8px); }
.podium-player.place-3 { transform: translateY(30px); }
.podium-medal { font-size: 2rem; filter: drop-shadow(0 8px 18px rgba(0,0,0,.35)); }
.podium-avatar { width: 6.5rem; height: 6.5rem; font-size: 2.4rem; border-width: 4px; box-shadow: 0 18px 45px rgba(0,0,0,.32); }
.podium-name { font-weight: 1000; }
.podium-score { color: var(--accent); font-weight: 900; }
.podium-step { width: 100%; border-radius: 1rem 1rem .55rem .55rem; padding: 1rem .5rem; color: #1d1208; font-weight: 1000; font-size: 1.8rem; background: linear-gradient(135deg, #ffbd59, #f97316); }
.podium-player.place-2 .podium-step { padding-top: .75rem; background: linear-gradient(135deg, #eef2f6, #aeb8c5); }
.podium-player.place-3 .podium-step { padding-top: .6rem; background: linear-gradient(135deg, #e0a05f, #9b5c2d); color: #fff8ec; }
.toast { position: fixed; left: 1rem; right: 1rem; bottom: 1rem; background: #2a1420; color: #fff; border: 1px solid rgba(255,255,255,.18); padding: .9rem 1rem; border-radius: 1rem; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.turn-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255, 235, 120, .28), rgba(255, 102, 0, .08), transparent 68%);
}
.turn-overlay-card {
  width: min(86vw, 420px);
  padding: 1.25rem;
  border-radius: 1.5rem;
  background: rgba(20, 12, 18, .88);
  border: 2px solid rgba(255, 235, 120, .58);
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,.48), 0 0 50px rgba(255,189,89,.28);
  transform: scale(.78) rotate(-2deg);
  animation: overlayPop 1.25s cubic-bezier(.2, 1.35, .4, 1) both;
}
.turn-overlay-card strong { display: block; font-size: clamp(2.1rem, 11vw, 4rem); line-height: .9; letter-spacing: -.06em; color: #fff36d; }
.turn-overlay-card span { display: block; margin-top: .65rem; color: var(--text); font-weight: 850; }
.turn-overlay-emoji { font-size: 3rem; animation: emojiSpin 1s ease-in-out both; }
.fx-layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.fx-bit { position: absolute; bottom: 10%; font-size: 1.75rem; animation: fxFly 1.05s ease-out forwards; filter: drop-shadow(0 8px 16px rgba(0,0,0,.38)); }

@keyframes screenFlash {
  0%, 100% { filter: none; }
  10% { filter: brightness(1.6) saturate(1.35); }
  24% { filter: brightness(.9) saturate(1.2); }
  38% { filter: brightness(1.45) saturate(1.45); }
}
@keyframes cardDeal { from { transform: translateY(-16px) rotate(-4deg) scale(.96); opacity: .2; } to { transform: none; opacity: 1; } }
@keyframes cardWiggle { 0%, 100% { transform: rotate(0deg) translateY(0); } 35% { transform: rotate(-1.4deg) translateY(-3px); } 70% { transform: rotate(1.2deg) translateY(2px); } }
@keyframes bannerPulse { from { transform: scale(.98); box-shadow: 0 0 18px rgba(255,189,89,.25); } to { transform: scale(1.02); box-shadow: 0 0 34px rgba(255,189,89,.5); } }
@keyframes buttonNudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes playerPulse { 0%, 100% { transform: translateY(0); box-shadow: 0 0 0 1px rgba(255,189,89,.35), 0 0 0 0 rgba(255,189,89,.26); } 50% { transform: translateY(-4px); box-shadow: 0 0 0 1px rgba(255,189,89,.7), 0 0 0 9px rgba(255,189,89,.08); } }
@keyframes overlayPop { 0% { opacity: 0; transform: scale(.55) rotate(-7deg); } 18% { opacity: 1; } 72% { opacity: 1; transform: scale(1.02) rotate(1deg); } 100% { opacity: 0; transform: scale(1.1) rotate(2deg); } }
@keyframes emojiSpin { from { transform: rotate(-18deg) scale(.8); } to { transform: rotate(8deg) scale(1.08); } }
@keyframes fxFly { 0% { transform: translate(0, 0) scale(.7) rotate(0deg); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.35) rotate(28deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

@media (max-width: 760px) {
  .app { padding: .75rem; }
  .topbar { align-items: flex-start; }
  .game-grid { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr; position: sticky; bottom: .7rem; z-index: 5; }
  .rules { display: none; }
  .panel { border-radius: 1.15rem; }
  .podium { gap: .35rem; min-height: 300px; }
  .podium-avatar { width: 5rem; height: 5rem; }
  .podium-name { font-size: .85rem; }
  .ranking-row { grid-template-columns: 2.6rem 2.1rem 1fr; grid-template-areas: "medal avatar name" "medal avatar score" "medal avatar detail"; }
}

@media (max-width: 760px) and (orientation: portrait) {
  html, body { height: 100%; }
  body.phase-game { overflow: hidden; width: 100%; }
  body.phase-game .app {
    width: 100%;
    height: 100svh;
    padding: max(1rem, calc(env(safe-area-inset-top) + .75rem)) .45rem max(.28rem, env(safe-area-inset-bottom));
    overflow: hidden;
  }
  body.phase-game #room {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: .32rem;
  }
  body.phase-game .topbar {
    margin: 0;
    padding: .42rem .55rem;
    border-radius: .9rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .35rem;
    align-items: center;
  }
  body.phase-game .topbar .eyebrow { margin: 0; font-size: .58rem; letter-spacing: .08em; }
  body.phase-game .topbar h2 { margin: 0; font-size: clamp(.82rem, 3.5vw, 1rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58vw; }
  body.phase-game .topbar button { padding: .45rem .55rem; font-size: .72rem; }
  body.phase-game .topbar #alertBtn { max-width: 5.6rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.phase-game .topbar #copyBtn,
  body.phase-game .topbar #roomPhotoBtn { display: none; }
  body.phase-game .game-grid {
    min-height: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }
  body.phase-game .table-card {
    min-height: 0;
    padding: .48rem;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    align-items: center;
    gap: .22rem;
  }
  body.phase-game .table-card .eyebrow { display: none; }
  body.phase-game .turn-banner { margin: 0 auto .15rem; padding: .38rem .58rem; font-size: .64rem; max-width: 100%; }
  body.phase-game .big-card {
    width: min(31vw, 118px);
    border-radius: .8rem;
    font-size: clamp(3rem, 14vw, 4.3rem);
    margin: .1rem auto;
    box-shadow: 0 10px 26px rgba(0,0,0,.32);
  }
  body.phase-game .pot { font-size: .88rem; }
  body.phase-game .turn { margin: .05rem 0; min-height: 2.15em; font-size: .82rem; line-height: 1.08; }
  body.phase-game .actions {
    position: static;
    grid-template-columns: 1fr 1fr;
    gap: .4rem;
  }
  body.phase-game .actions button { min-width: 0; padding: .62rem .4rem; font-size: .76rem; line-height: 1.05; overflow: hidden; text-overflow: ellipsis; white-space: normal; }
  body.phase-game #actionHint { margin: .05rem 0 0; min-height: 1em; font-size: .68rem; }
  body.phase-game .players-panel {
    min-height: 0;
    margin: 0;
    padding: .42rem;
    border-radius: .9rem;
  }
  body.phase-game .section-head { margin-bottom: .28rem; }
  body.phase-game .section-head h3 { margin: 0; font-size: .88rem; }
  body.phase-game #cardsRemaining { font-size: .64rem; padding: .22rem .42rem; }
  body.phase-game .lobby-order-hint,
  body.phase-game .log-panel { display: none; }
  body.phase-game .players {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
    gap: .32rem;
    min-width: 0;
  }
  body.phase-game .player {
    min-width: 0;
    padding: .34rem;
    border-radius: .7rem;
  }
  body.phase-game .player-top {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: .22rem;
    align-items: center;
  }
  body.phase-game .seat-number { display: none; }
  body.phase-game .avatar.small { width: 1.55rem; height: 1.55rem; font-size: .68rem; border-width: 1px; }
  body.phase-game .player-name {
    min-width: 0;
    font-size: .68rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.phase-game .score { min-width: 0; font-size: .64rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.phase-game .meta { margin-top: .2rem; font-size: .58rem; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.phase-game .cards { gap: .18rem; margin-top: .25rem; max-height: 2.25rem; overflow: hidden; }
  body.phase-game .player:not(.me) .cards {
    display: flex;
    flex-wrap: nowrap;
    max-height: 1.25rem;
    overflow: hidden;
  }
  body.phase-game .mini-card { min-width: 1.35rem; padding: .12rem .18rem; border-radius: .28rem; font-size: .62rem; }
}

@media (max-width: 380px) and (orientation: portrait) {
  body.phase-game .topbar #roomPhotoBtn { display: none; }
  body.phase-game .big-card { width: min(28vw, 104px); }
  body.phase-game .turn { font-size: .76rem; }
  body.phase-game .actions button { padding: .52rem .35rem; font-size: .72rem; }
  body.phase-game .players { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: .24rem; }
  body.phase-game .player { padding: .26rem; }
  body.phase-game .avatar.small { width: 1.35rem; height: 1.35rem; }
}
