:root {
  --bg: #05070c;
  --panel: rgba(11, 16, 25, 0.78);
  --panel-strong: rgba(9, 13, 21, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --ink: #eef1f7;
  --muted: #8d97a9;
  --gold: #e8c37a;
  --gold-2: #b98f45;
  --green: #39d98a;
  --red: #ff6172;
  --cyan: #5fe0ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --sans: "Segoe UI", Inter, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "Playfair Display", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 42%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 22%, transparent 74%, rgba(0, 0, 0, 0.5));
  z-index: 1;
}

/* ------------------------------------------------------------------ lobby */

.lobby {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  gap: 14px;
  padding: 24px;
  background:
    radial-gradient(80% 60% at 50% 18%, rgba(28, 48, 62, 0.55), transparent 70%),
    radial-gradient(70% 60% at 50% 110%, rgba(71, 52, 22, 0.35), transparent 70%),
    rgba(3, 5, 9, 0.55);
  backdrop-filter: blur(7px) saturate(0.9);
  -webkit-backdrop-filter: blur(7px) saturate(0.9);
  overflow-x: hidden;
  overflow-y: auto;
}

.lobby__halo {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: min(760px, 100vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 195, 122, 0.12), transparent 62%);
  filter: blur(10px);
  pointer-events: none;
  animation: halo 9s ease-in-out infinite alternate;
}

@keyframes halo {
  from { transform: scale(0.92); opacity: 0.7; }
  to { transform: scale(1.06); opacity: 1; }
}

.lobby__card {
  position: relative;
  width: min(520px, 100%);
  padding: clamp(26px, 5vw, 44px);
  border-radius: 26px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.05), transparent 38%),
    var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: rise 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.lobby__card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(150deg, rgba(232, 195, 122, 0.55), transparent 35%, transparent 65%, rgba(95, 224, 255, 0.25));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  margin: 0 0 14px;
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--gold);
  opacity: 0.85;
}

.lobby__title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(44px, 11vw, 64px);
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: #f6efdf;
  text-shadow: 0 2px 40px rgba(232, 195, 122, 0.22);
}

.tagline {
  margin: 16px 0 28px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  max-width: 38ch;
}

.join label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.join__row {
  display: flex;
  gap: 10px;
}

.join input {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 16px;
  border-radius: 13px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.join input::placeholder { color: #5d6675; }

.join input:focus {
  border-color: rgba(232, 195, 122, 0.65);
  box-shadow: 0 0 0 3px rgba(232, 195, 122, 0.12);
}

.join__error {
  min-height: 18px;
  margin: 9px 2px 0;
  font-size: 13px;
  color: var(--red);
}

.btn {
  position: relative;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 13px 20px;
  border-radius: 13px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.18s, background 0.18s, border-color 0.18s, opacity 0.18s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { filter: brightness(1.12); border-color: rgba(255, 255, 255, 0.3); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.995); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.btn small {
  display: block;
  font-size: 9px;
  letter-spacing: 0.16em;
  opacity: 0.55;
  font-weight: 600;
  margin-bottom: 2px;
}

.btn--primary {
  border: none;
  background: linear-gradient(180deg, #f3d9a4, #d3a95c 55%, #b4873c);
  color: #201404;
  box-shadow: 0 8px 24px rgba(214, 171, 92, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.btn--primary:hover:not(:disabled) { filter: brightness(1.05) saturate(1.05); }
.btn--ghost { background: transparent; }
.btn b { font-weight: 700; }

.online {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.online i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.lobby__hint {
  position: static;
  transform: none;
  flex: none;
  width: max-content;
  max-width: 90vw;
  text-align: center;
  font-size: 11.5px;
  color: rgba(141, 151, 169, 0.65);
  margin: 0;
}

/* ------------------------------------------------------------------- room */

.room {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(232, 195, 122, 0.28);
  background: linear-gradient(180deg, rgba(232, 195, 122, 0.09), rgba(232, 195, 122, 0.02));
}

.room__id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.room__label { font-size: 9px; letter-spacing: 0.28em; color: var(--gold); }
.room__code {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: #fff3d6;
  line-height: 1.15;
}
.room__share { height: 40px; white-space: nowrap; }

.room--empty {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  text-align: center;
  border-color: var(--line);
  background: rgba(8, 12, 19, 0.55);
}
.room__or { margin: 0; font-size: 10.5px; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; }

.room__code-form { display: flex; gap: 8px; }
.room__code-form input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  outline: none;
}
.room__code-form input:focus {
  border-color: rgba(232, 195, 122, 0.65);
  box-shadow: 0 0 0 3px rgba(232, 195, 122, 0.12);
}
.room__code-form .btn { height: 44px; padding: 0 20px; }

.room__error {
  min-height: 16px;
  margin: -8px 2px 14px;
  font-size: 12.5px;
  color: var(--red);
}

/* ------------------------------------------------------------------ share */

.share {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(2, 4, 8, 0.72);
  backdrop-filter: blur(6px);
  animation: fade 0.18s ease both;
}

.share__card {
  width: min(380px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  animation: rise 0.22s ease both;
}

.share__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.share__head .eyebrow { margin: 0 0 6px; }
.share__title {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.share__title span { color: var(--gold); letter-spacing: 0.14em; }

.share__qr {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 196px;
  margin: 16px 0 14px;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  color: var(--muted);
}
.share__svg { width: min(240px, 62vw); height: auto; border-radius: 10px; }

.share__link-row { display: flex; gap: 8px; }
.share__link-row input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.35);
  color: #cfd6e2;
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  user-select: text;
}
.share__link-row .btn { height: 44px; white-space: nowrap; }
.share__native { width: 100%; margin-top: 10px; }
.share__hint { margin: 12px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--muted); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* -------------------------------------------------------------------- HUD */

.shell { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.shell > * { pointer-events: none; }
.shell button, .shell input, .shell .log, .shell .gift-panel, .shell .winner { pointer-events: auto; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: max(14px, env(safe-area-inset-top)) clamp(16px, 3vw, 32px) 14px;
  background: linear-gradient(180deg, rgba(4, 6, 11, 0.82), transparent);
}

.meta {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.meta__sep { opacity: 0.4; }

.btn-badge {
  font-size: 8px;
  letter-spacing: 0.16em;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f3d9a4, #d3a95c);
  color: #201404;
  font-weight: 700;
}

.stack {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(95, 224, 255, 0.22);
  background: rgba(10, 18, 26, 0.55);
  margin-left: auto;
}

.stack span { font-size: 9px; letter-spacing: 0.22em; color: var(--cyan); opacity: 0.9; }
.stack b { font-size: 16px; color: #d9f6ff; font-variant-numeric: tabular-nums; }

.topbar__actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  min-width: 58px;
  height: 48px;
  padding: 4px 7px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(10, 15, 23, 0.72);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1;
  transition: background 0.18s, border-color 0.18s, transform 0.12s, box-shadow 0.18s;
}

.icon-btn__glyph { font-size: 17px; line-height: 1; }
.icon-btn__label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  white-space: nowrap;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--line-strong); }
.icon-btn:hover .icon-btn__label { color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.icon-btn:active { transform: scale(0.96); }
.icon-btn--sm { min-width: 28px; width: 28px; height: 28px; padding: 0; font-size: 12px; }
.icon-btn.is-off { opacity: 0.5; }
.icon-btn.is-off .icon-btn__label { color: var(--muted); }

.conn {
  position: absolute;
  top: 86px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 97, 114, 0.15);
  border: 1px solid rgba(255, 97, 114, 0.45);
  color: #ffd2d7;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(10px);
}

.turn-banner {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(8, 13, 21, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  animation: slideDown 0.3s ease both;
}

@keyframes slideDown {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes riseCentered {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.turn-banner__label {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.turn-banner b { font-size: 15px; color: var(--gold); }
.turn-banner__timer {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--cyan);
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.turn-banner.is-you { border-color: rgba(95, 224, 255, 0.45); box-shadow: 0 0 30px rgba(95, 224, 255, 0.14); }
.turn-banner.is-you b { color: var(--cyan); }

.status-line {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(8, 12, 19, 0.66);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- controls */

.controls {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(860px, calc(100% - 28px));
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 24, 36, 0.92), rgba(8, 12, 19, 0.94));
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(22px);
  overflow: hidden;
  animation: riseCentered 0.4s ease both;
}

.timer { height: 3px; background: rgba(255, 255, 255, 0.07); }
.timer i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), #9ef4c5);
  box-shadow: 0 0 12px rgba(95, 224, 255, 0.55);
  transition: background 0.3s;
}

.timer.is-low i { background: linear-gradient(90deg, #ffb25f, var(--red)); box-shadow: 0 0 14px rgba(255, 97, 114, 0.6); }

.actions {
  display: grid;
  grid-template-columns: 0.9fr 0.9fr 1.2fr 1.2fr 0.95fr;
  gap: 10px;
  padding: 14px;
}

.actions .btn {
  position: relative;
  height: 64px;
  padding: 10px 8px;
  font-size: 15.5px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.actions .btn small {
  font-size: 10px;
  letter-spacing: 0.14em;
  opacity: 0.6;
  margin-bottom: 1px;
}

.actions .btn kbd {
  position: absolute;
  top: 7px;
  right: 8px;
  padding: 3px 5px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.32);
  color: rgba(246, 239, 223, 0.82);
  font-family: inherit;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

.actions .btn:hover:not(:disabled) { transform: translateY(-1px); }
.actions .btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.actions .btn:disabled {
  opacity: 1;
  color: rgba(214, 222, 235, 0.5);
  background: rgba(255, 255, 255, 0.035);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  cursor: not-allowed;
}
.actions .btn:disabled small,
.actions .btn:disabled kbd { opacity: 0.45; }

.btn--fold { background: linear-gradient(180deg, rgba(255, 97, 114, 0.2), rgba(255, 97, 114, 0.08)); border-color: rgba(255, 97, 114, 0.4); }
.btn--check { background: linear-gradient(180deg, rgba(95, 224, 255, 0.18), rgba(95, 224, 255, 0.06)); border-color: rgba(95, 224, 255, 0.38); }
.btn--call { background: linear-gradient(180deg, rgba(57, 217, 138, 0.22), rgba(57, 217, 138, 0.07)); border-color: rgba(57, 217, 138, 0.42); }
.btn--raise { background: linear-gradient(180deg, rgba(232, 195, 122, 0.24), rgba(232, 195, 122, 0.07)); border-color: rgba(232, 195, 122, 0.45); }
.btn--allin { background: linear-gradient(180deg, rgba(255, 61, 87, 0.85), rgba(160, 16, 42, 0.9)); border-color: rgba(255, 120, 140, 0.55); box-shadow: 0 6px 20px rgba(255, 45, 85, 0.25); }

.actions .btn--fold:hover:not(:disabled) { border-color: rgba(255, 97, 114, 0.8); box-shadow: 0 0 0 1px rgba(255, 97, 114, 0.28), 0 8px 22px rgba(255, 97, 114, 0.14); }
.actions .btn--check:hover:not(:disabled) { border-color: rgba(95, 224, 255, 0.8); box-shadow: 0 0 0 1px rgba(95, 224, 255, 0.26), 0 8px 22px rgba(95, 224, 255, 0.12); }
.actions .btn--call:hover:not(:disabled) { border-color: rgba(57, 217, 138, 0.8); box-shadow: 0 0 0 1px rgba(57, 217, 138, 0.28), 0 8px 22px rgba(57, 217, 138, 0.14); }
.actions .btn--raise:hover:not(:disabled) { border-color: rgba(232, 195, 122, 0.8); box-shadow: 0 0 0 1px rgba(232, 195, 122, 0.28), 0 8px 22px rgba(232, 195, 122, 0.14); }
.actions .btn--allin:hover:not(:disabled) { filter: brightness(1.12); box-shadow: 0 10px 28px rgba(255, 45, 85, 0.4); }

.btn--call b, .btn--raise b { font-variant-numeric: tabular-nums; }

/* raise panel */
.raise { padding: 4px 14px 14px; animation: rise 0.2s ease both; }
.raise__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.raise__head b { font-size: 24px; color: var(--gold); font-variant-numeric: tabular-nums; }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(232, 195, 122, 0.7), rgba(232, 195, 122, 0.15));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6df, #d8ad63 55%, #8d6827);
  border: 2px solid #2a1d08;
  box-shadow: 0 0 14px rgba(232, 195, 122, 0.5);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: rgba(232, 195, 122, 0.4); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: 2px solid #2a1d08; border-radius: 50%; background: #e8c37a; }

.raise__row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.raise__row--end { justify-content: flex-end; margin-top: 12px; }

.chip {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 40px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { color: var(--ink); border-color: var(--gold); }
.chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.raise__row--end .btn { min-height: 48px; padding: 12px 22px; }

.raise input[type="number"] {
  width: 110px;
  margin-left: auto;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--gold);
  font-family: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  padding: 0 12px;
  outline: none;
  text-align: right;
}

/* ------------------------------------------------------------------- log */

.log {
  position: absolute;
  left: 18px;
  bottom: 120px;
  width: 300px;
  max-height: min(46vh, 420px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.28s ease both;
}

.log__head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 8px; }
.log__head h3 { margin: 0; font-size: 11px; letter-spacing: 0.2em; color: var(--gold); font-weight: 600; }

.log ol {
  list-style: none;
  margin: 0;
  padding: 0 14px 14px;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.45;
  color: #b7c0cf;
}

.log li { padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.045); }
.log li:last-child { border-bottom: none; }
.log li:first-child { color: var(--ink); }

/* ------------------------------------------------------------ gift panel */

.gift-panel {
  position: absolute;
  right: 18px;
  top: 92px;
  width: 268px;
  padding: 12px 14px 14px;
  border-radius: 16px;
  border: 1px solid rgba(232, 195, 122, 0.35);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  animation: giftPop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.gift-panel__head { display: flex; justify-content: space-between; align-items: center; }
.gift-panel__head h3 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--gold);
  font-weight: 600;
}
.gift-panel__hint { margin: 6px 0 10px; font-size: 11.5px; line-height: 1.45; color: var(--muted); }

.gift-panel__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(42vh, 320px);
  overflow-y: auto;
}

.gift-panel__empty { font-size: 12px; color: var(--muted); padding: 6px 2px; }

.gift-panel__pick {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.gift-panel__pick:hover:not(:disabled) {
  background: rgba(232, 195, 122, 0.14);
  border-color: rgba(232, 195, 122, 0.45);
  transform: translateX(-2px);
}
.gift-panel__pick:active:not(:disabled) { transform: scale(0.97) rotate(-1deg); }
.gift-panel__pick:disabled { opacity: 0.45; cursor: not-allowed; }

.gift-panel__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 8px currentColor;
}
.gift-panel__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gift-panel__coins { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gift-panel__pick::after { content: '💸'; font-size: 13px; }

@keyframes giftPop {
  from { opacity: 0; transform: translateY(-10px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- emotes */

.emotes {
  position: absolute;
  right: 18px;
  bottom: 120px;
  display: grid;
  grid-template-columns: repeat(2, 46px);
  gap: 6px;
  padding: 8px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.emotes button {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
}
.emotes button:hover { background: rgba(255, 255, 255, 0.1); transform: translateY(-2px) scale(1.06); }
.emotes button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.emotes button:active { transform: scale(0.92); }

/* ---------------------------------------------------------------- winner */

.winner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 10px 22px 12px;
  border-radius: 18px;
  background: radial-gradient(120% 160% at 50% 0%, rgba(232, 195, 122, 0.18), transparent 70%), rgba(7, 10, 17, 0.8);
  border: 1px solid rgba(232, 195, 122, 0.36);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), inset 0 0 50px rgba(232, 195, 122, 0.06);
  animation: winnerPop 0.55s cubic-bezier(0.16, 1, 0.3, 1) both;
  width: min(94vw, 560px);
  max-width: min(94vw, 620px);
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  z-index: 12;
}

@media (min-width: 900px) {
  .winner { left: calc(50% - 70px); }
}

@keyframes winnerPop {
  0% { opacity: 0; transform: translate(-50%, calc(-50% - 12px)) scale(0.9); }
  60% { opacity: 1; transform: translate(-50%, calc(-50% + 4px)) scale(1.02); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.winner__kicker { margin: 0; font-size: 9px; letter-spacing: 0.32em; color: var(--gold); }
.winner h2 { margin: 2px 0 0; font-family: var(--serif); font-size: clamp(22px, 4vw, 30px); font-weight: 600; color: #fff8e8; line-height: 1.1; }
.winner__amount { margin: 2px 0 0; font-size: 18px; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.winner__hand { margin: 2px 0 0; font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }

.winner__board {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.winner__rows {
  display: grid;
  gap: 3px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  max-height: min(42vh, 300px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.winner__row {
  display: grid;
  grid-template-columns: minmax(64px, 1.1fr) auto minmax(88px, 1.05fr) auto;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 12px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.winner__row.is-winner {
  background: rgba(232, 195, 122, 0.14);
  box-shadow: inset 0 0 0 1px rgba(232, 195, 122, 0.4);
}

.winner__row.is-folded { opacity: 0.55; }

.winner__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #f2f5fa; font-weight: 600; }
.winner__name[data-you='1']::after { content: ' (bạn)'; color: var(--gold); font-weight: 400; font-size: 10px; }
.winner__cards { display: flex; gap: 3px; }
.winner__best { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.winner__handname { color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.winner__detail { color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.winner__muted { color: var(--muted); font-size: 11px; }
.winner__net { justify-self: end; font-weight: 700; color: var(--muted); }
.winner__net.is-up { color: var(--green); }
.winner__net.is-down { color: var(--red); }

.winner__five {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  padding-top: 3px;
  border-top: 1px dashed rgba(255, 255, 255, 0.09);
}

.winner__five-label {
  margin-right: 2px;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.winner__five .pcard { opacity: 0.68; font-size: 10px; padding: 0 3px; }
.winner__five .pcard.is-hole { opacity: 1; box-shadow: 0 0 0 1px rgba(232, 195, 122, 0.6); }

.winner__next {
  margin: 8px 0 0;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.winner__next b { color: var(--gold); font-variant-numeric: tabular-nums; }

.pcard {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  padding: 1px 4px;
  border-radius: 4px;
  background: #f4f1ea;
  color: #12151c;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.pcard--red { color: #c2263a; }
.pcard i { font-style: normal; font-size: 10px; }

/* ---------------------------------------------------------------- toasts */

.toast-host {
  position: fixed;
  z-index: 90;
  top: 132px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: min(92vw, 460px);
}

.toast {
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(10, 15, 23, 0.92);
  border: 1px solid var(--line-strong);
  font-size: 13px;
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.25s ease both;
  text-align: center;
}

.toast.is-error { border-color: rgba(255, 97, 114, 0.5); color: #ffd2d7; }
.toast.is-emote { font-size: 15px; }
.toast.is-out { animation: toastOut 0.3s ease both; }

@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

/* --------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  .meta { display: none; }
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .stack span { font-size: 8px; letter-spacing: 0.14em; }
  .stack { padding: 5px 9px; gap: 5px; }
  .stack b { font-size: 14px; }
  .icon-btn { width: 36px; min-width: 36px; height: 40px; padding: 0; font-size: 16px; border-radius: 10px; }
  .icon-btn__label { display: none; }
  .topbar__actions { gap: 4px; }

  .turn-banner { top: 76px; padding: 8px 14px; }
  .turn-banner__label { display: none; }

  .controls { width: calc(100% - 16px); bottom: calc(48px + env(safe-area-inset-bottom)); border-radius: 16px; }
  .actions { gap: 6px; padding: 8px; grid-template-columns: 0.85fr 0.85fr 1.1fr 1.1fr; }
  .actions .btn { height: 58px; font-size: 13.5px; border-radius: 12px; }
  .actions .btn--allin { grid-column: span 4; height: 44px; flex-direction: row; gap: 6px; }
  .actions .btn--allin small { margin: 0; }
  .actions .btn kbd { top: 5px; right: 6px; font-size: 8px; padding: 2px 4px; }
  .btn small { font-size: 9px; }

  .log { left: 8px; right: 8px; width: auto; bottom: 108px; max-height: 40vh; }
  .gift-panel { left: 8px; right: 8px; width: auto; top: 112px; max-height: 46vh; }
  .emotes {
    left: 8px;
    right: 8px;
    bottom: max(4px, env(safe-area-inset-bottom));
    grid-template-columns: repeat(8, 1fr);
    padding: 4px;
    gap: 4px;
    border-radius: 12px;
  }
  .emotes button { width: 100%; height: 38px; min-width: 0; padding: 0; font-size: 18px; border-radius: 8px; }
  .status-line { bottom: calc(160px + env(safe-area-inset-bottom)); font-size: 12px; }
  .winner {
    padding: 8px 12px 10px;
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 120px);
    overflow-y: auto;
  }
  .winner__row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      'name hand net'
      'cards cards cards'
      'five five five';
    row-gap: 3px;
    gap: 5px;
    font-size: 11px;
    padding: 4px 6px;
  }
  .winner__name { grid-area: name; }
  .winner__cards { grid-area: cards; }
  .winner__best { grid-area: hand; }
  .winner__net { grid-area: net; }
  .winner__five { grid-area: five; border-top: none; padding-top: 0; align-self: center; }
  .winner__detail { white-space: normal; }
  .winner__five .pcard { font-size: 9px; }
  .winner__five-label { display: none; }
  .winner__rows { max-height: none; overflow: visible; }
  .raise__row { flex-wrap: wrap; }
  .raise input[type="number"] { margin-left: 0; flex: 1; text-align: left; }
  .toast-host { top: 168px; }
  .lobby__hint { display: none; }
}

@media (max-width: 460px) {
  .topbar { gap: 5px; padding-left: 8px; padding-right: 8px; }
  .stack span { display: none; }
  .icon-btn { width: 30px; min-width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
  .topbar__actions { gap: 3px; }
}

/* 8 nút + cụm coin không đủ một hàng dưới 343px: cho hàng nút tự xuống dòng. */
@media (max-width: 342px) {
  .topbar__actions {
    flex: 1 1 0;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 3px;
  }
  .turn-banner { top: 108px; }
  .conn { top: 108px; }
  .gift-panel { top: 140px; }
  .toast-host { top: 196px; }
}

@media (max-width: 420px) {
  .join__row { flex-direction: column; }
  .join input, .join .btn { height: 48px; }
  .lobby__title { font-size: 42px; }
  .actions .btn { height: 54px; font-size: 12.5px; }
}


@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* ------------------------------------------------------- character editor */

.character {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-top: 16px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}

.character__stage {
  position: relative;
  width: 150px;
  height: 190px;
  flex: none;
  border-radius: 14px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 30%, rgba(95, 224, 255, 0.16), rgba(8, 12, 19, 0.65) 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent);
  overflow: hidden;
}

#avatarPreview {
  display: block;
  width: 150px;
  height: 190px;
}

.character__tag {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 7px;
  text-align: center;
  font-size: 8px;
  letter-spacing: 0.26em;
  color: rgba(232, 195, 122, 0.7);
}

.character__reroll {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: rgba(8, 12, 19, 0.72);
  color: var(--gold);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.character__reroll:hover {
  transform: rotate(-12deg) scale(1.08);
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(232, 195, 122, 0.28);
}
.character__reroll:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.character__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 5px;
}

/* Tablet/desktop: xếp lựa chọn thành lưới để tận dụng chiều ngang. */
@media (min-width: 761px) {
  .lobby__card { width: min(880px, 100%); }

  .character__body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
    align-content: start;
    gap: 8px 14px;
  }

  .character__body .opt {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .character__body .opt__label {
    width: auto;
    font-size: 8.5px;
    line-height: 1.3;
  }

  .character__body .swatches { gap: 4px; }
  .character__body .swatch { width: 16px; height: 16px; border-width: 2px; }
  .character__body .swatches--sm .swatch { width: 14px; height: 14px; }
  .character__body .pill { font-size: 9px; padding: 2px 5px; }
}

/* Màn hình rộng: hai cột cho phần nhập liệu, avatar trải hết chiều ngang. */
@media (min-width: 900px) {
  .lobby__card {
    width: min(1000px, 100%);
    padding: clamp(24px, 3vw, 36px) clamp(28px, 3.4vw, 40px);
    display: grid;
    grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.14fr);
    grid-template-areas:
      "intro setup"
      "character character"
      "online online";
    align-items: start;
    column-gap: 32px;
    row-gap: 18px;
  }

  .lobby__intro { grid-area: intro; }
  .lobby__setup { grid-area: setup; }
  .character { grid-area: character; margin-top: 0; }
  .online { grid-area: online; }
  .lobby__intro .tagline { margin-bottom: 0; max-width: 46ch; }

  .character__stage { width: 168px; height: 210px; }
  #avatarPreview { width: 168px; height: 210px; }
}

.opt { display: flex; align-items: flex-start; gap: 7px; }

.opt__label {
  width: 58px;
  flex: none;
  font-size: 8.5px;
  line-height: 20px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.swatches { display: flex; flex-wrap: wrap; gap: 5px; }

.swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}

.swatch:hover { transform: scale(1.12); }
.swatch.is-active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(232, 195, 122, 0.2), 0 0 12px rgba(232, 195, 122, 0.25);
}
.swatches--sm .swatch { width: 15px; height: 15px; }

.pills { display: flex; flex-wrap: wrap; gap: 4px; }

.pill {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-family: inherit;
  font-size: 9.5px;
  line-height: 1.25;
  border-radius: 999px;
  padding: 3px 7px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover { color: var(--ink); border-color: var(--line-strong); }
.pill.is-active {
  color: #1f1503;
  border-color: transparent;
  background: linear-gradient(180deg, #f3d9a4, #d3a95c);
  font-weight: 600;
}

.icon-btn.is-active {
  border-color: rgba(95, 224, 255, 0.6);
  box-shadow: 0 0 16px rgba(95, 224, 255, 0.25);
  color: var(--cyan);
}
.icon-btn.is-active .icon-btn__label { color: var(--cyan); }

.look-hint {
  position: absolute;
  left: 18px;
  bottom: 118px;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(8, 12, 19, 0.72);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 999px;
  backdrop-filter: blur(10px);
  transition: opacity 0.4s;
}
.look-hint b { color: var(--gold); }

@media (max-width: 760px) {
  .character { flex-direction: column; gap: 10px; padding: 10px; }
  .character__stage { width: 100%; height: 168px; }
  #avatarPreview { width: 100%; height: 168px; }
  .opt { gap: 6px; }
  .opt__label { width: 54px; font-size: 8px; line-height: 19px; }
  .swatch { width: 17px; height: 17px; }
  .swatches--sm .swatch { width: 14px; height: 14px; }
  .pill { font-size: 9px; padding: 3px 6px; }
  .character__tag { display: none; }
  .look-hint {
    top: 168px;
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 10.5px;
  }
}
