:root {
  --felt: #0f4a35;
  --felt-dark: #082a1e;
  --wood: #3a2414;
  --wood-light: #6b4426;
  --gold: #d9b450;
  --gold-soft: #f0d98a;
  --ivory: #f5eedc;
  --ink: #121212;
  --text: #f4ecd8;
  --muted: #c9bc98;
  --tile-w: 52px;
  --display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --body: 'Source Sans 3', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #050807; color: var(--text); font-family: var(--body); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* no double-tap zoom while tapping stones quickly (iPhone) */
html, button, .hand-tile, .board-wrap { touch-action: manipulation; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.about { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App frame ---------- */
.app {
  position: relative;
  height: 100vh; /* older phones */
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, rgba(40, 120, 85, .55), transparent 70%),
    radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  box-shadow: inset 0 0 0 10px var(--wood), inset 0 0 0 12px var(--wood-light), inset 0 0 60px rgba(0,0,0,.6);
}
.app::before { /* felt grain */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .18; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- HUD ---------- */
.hud {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 8px;
  padding: 10px 16px 8px 18px;
  background: linear-gradient(180deg, rgba(5, 10, 8, .85), rgba(5, 10, 8, .55));
  border-bottom: 1px solid rgba(217, 180, 80, .55);
  margin: 10px 10px 0;
  border-radius: 10px 10px 0 0;
}
.score { display: flex; align-items: center; gap: 8px; }
#score-them { justify-content: flex-end; }
.score-label { font-size: 15px; color: var(--muted); letter-spacing: .04em; }
.score-value { font-family: var(--display); font-weight: 900; font-size: 30px; color: var(--gold); line-height: 1; min-width: 1.3ch; text-align: center; }
.score-shoe .shoe { width: 40px; height: 20px; display: block; }
.status { text-align: center; }
.status-top { font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.status-turn { font-size: 16px; font-weight: 700; color: var(--text); min-height: 1.3em; }
.status-turn.is-you { color: var(--gold-soft); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(217,180,80,.4); background: rgba(0,0,0,.3); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; stroke: var(--gold-soft); stroke-width: 2; stroke-linecap: round; fill: none; }

/* ---------- Table ---------- */
.table {
  position: relative; z-index: 1; min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr;
  grid-template-areas: "left top right" "left board right";
  padding: 6px 16px 0;
  gap: 4px 6px;
}
.seat { position: relative; display: flex; align-items: center; gap: 6px; color: var(--text); }
.seat-top { grid-area: top; flex-direction: column; }
.seat-left { grid-area: left; flex-direction: column; justify-content: center; }
.seat-right { grid-area: right; flex-direction: column; justify-content: center; }
.seat-name { position: relative; font-size: 14px; font-weight: 600; padding: 2px 10px; border-radius: 999px; transition: background .25s, color .25s; white-space: nowrap; }
.seat.is-turn .seat-name { background: var(--gold); color: #1b1405; box-shadow: 0 0 16px rgba(217,180,80,.6); }
.backs { display: flex; gap: 3px; }
.seat-top .backs { flex-direction: row; min-height: 36px; } /* keeps its height when the partner has no stones left */
.seat-left .backs, .seat-right .backs { flex-direction: column; }
.seat-top .back-svg { width: 18px; height: 36px; }
.seat-left .back-svg, .seat-right .back-svg { width: 32px; height: 16px; }
.backs .stone-svg { width: 18px; height: 36px; }
.seat-left .backs .stone-svg, .seat-right .backs .stone-svg { width: 18px; height: 36px; }
/* end of game: stones lie face-up in the same direction and size as the face-down ones */
.seat-left .backs .stone-h, .seat-right .backs .stone-h { width: 32px; height: 16px; }
.backs .flip { animation: flip-v .45s cubic-bezier(.3,.7,.4,1) both; animation-delay: calc(var(--i, 0) * 70ms); }
.backs .flip-h { animation-name: flip-h; }
@keyframes flip-v { from { transform: perspective(200px) rotateY(90deg); filter: brightness(.6); } to { transform: none; filter: none; } }
@keyframes flip-h { from { transform: perspective(200px) rotateX(90deg); filter: brightness(.6); } to { transform: none; filter: none; } }
.pips {
  align-self: center; min-width: 26px; padding: 2px 8px; border-radius: 999px; text-align: center;
  background: rgba(5, 14, 10, .85); border: 1px solid rgba(217,180,80,.55); color: var(--text);
  font-size: 13px; font-weight: 700; line-height: 1.3; animation: fade .3s ease-out .4s both;
}
.pips.best { background: var(--gold); color: #1b1405; border-color: var(--gold); box-shadow: 0 0 12px rgba(217,180,80,.6); }
.hand { position: relative; min-height: calc(var(--tile-w) * 2); } /* keeps its height after your last stone */
.pips.my-pips { position: absolute; right: 100%; top: 50%; translate: -10px -50%; }
@media (prefers-reduced-motion: reduce) { .backs .flip, .pips { animation: none; } }

.board-wrap { grid-area: board; position: relative; min-height: 0; min-width: 0; }
.board { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.board-wrap { --amp: 6px; }
.board-wrap.shake { animation: shake .5s ease-out; }
@keyframes shake {
  10% { transform: translate(calc(var(--amp) * -1), calc(var(--amp) * .5)); }
  25% { transform: translate(var(--amp), calc(var(--amp) * -.7)); }
  40% { transform: translate(calc(var(--amp) * -.6), calc(var(--amp) * .35)); }
  60% { transform: translate(calc(var(--amp) * .4), calc(var(--amp) * -.3)); }
  80% { transform: translate(calc(var(--amp) * -.15), calc(var(--amp) * .1)); }
}
.impact-ring { fill: none; stroke: rgba(255, 240, 205, .85); stroke-width: .07; transform-box: fill-box; transform-origin: center; opacity: 0; animation: ring .55s ease-out forwards; }
.impact-ring.ring2 { stroke: rgba(240, 217, 138, .6); stroke-width: .05; }
@keyframes ring { from { transform: scale(.3); opacity: 1; } to { transform: scale(var(--rs, 2)); opacity: 0; } }
.dust { fill: #efe4c6; transform-box: fill-box; transform-origin: center; opacity: 0; animation: dust .6s cubic-bezier(.15,.7,.3,1) forwards; }
@keyframes dust { 0% { transform: translate(0, 0) scale(1); opacity: .95; } 100% { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
.crack { fill: none; stroke: rgba(0, 0, 0, .5); stroke-width: .045; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: crack .22s ease-out forwards, crackfade 1.6s ease-in forwards; }
@keyframes crack { to { stroke-dashoffset: 0; } }
@keyframes crackfade { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }
.placed.is-new.slammed { animation: slamdrop .3s cubic-bezier(.5,0,.75,0) both; }
@keyframes slamdrop { from { transform: scale(1.7); opacity: .4; } 85% { transform: scale(.94); opacity: 1; } to { transform: scale(1); } }

/* stones */
.stone { fill: var(--ivory); stroke: #b8ad92; stroke-width: .03; }
.stone-line { stroke: #9c917a; stroke-width: .035; }
.stone-pin { fill: #c9a74a; }
.pip { fill: var(--ink); }
.stone-back { fill: #f0e6cf; stroke: #b8ad92; stroke-width: .04; }
.stone-back-inlay { fill: none; stroke: #c8b98f; stroke-width: .05; }
.placed { filter: drop-shadow(0 .06px .08px rgba(0,0,0,.55)); }
.board .placed { filter: drop-shadow(0 0.05px 0.06px rgba(0,0,0,.6)); }
.placed.is-new { transform-box: fill-box; transform-origin: center; animation: drop .32s cubic-bezier(.2,.9,.3,1.3); }
@keyframes drop { from { transform: scale(1.35); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.connector { fill: none; stroke: rgba(240, 217, 138, .5); stroke-width: .09; stroke-linecap: round; stroke-dasharray: .05 .2; }
.end-glow { fill: none; stroke: rgba(240, 217, 138, .75); stroke-width: .06; }
.ghost { cursor: pointer; }
.ghost-rect { fill: rgba(240, 217, 138, .22); stroke: var(--gold-soft); stroke-width: .07; stroke-dasharray: .22 .14; animation: pulse 1.1s ease-in-out infinite; }
.ghost-label { fill: var(--gold-soft); font-size: .9px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; font-family: var(--body); pointer-events: none; }
@keyframes pulse { 50% { fill: rgba(240, 217, 138, .45); } }

/* bubbles */
.bubble {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--ivory); color: #1d1608; font-weight: 700; font-size: 15px;
  padding: 4px 12px; border-radius: 14px; box-shadow: 0 6px 16px rgba(0,0,0,.4);
  opacity: 0; transform: scale(.8); transition: opacity .2s, transform .2s;
  white-space: nowrap;
}
.bubble.show { opacity: 1; transform: scale(1); }
.seat-top .bubble { top: 100%; margin-top: 4px; }
.seat-left .bubble { left: 100%; margin-left: 6px; }
.seat-right .bubble { right: 100%; margin-right: 6px; }
.bubble-me { left: 50%; bottom: 100%; translate: -50% 0; }

/* changa popup */
.changa-pop {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: var(--display); font-weight: 900; font-size: clamp(48px, 13vw, 120px); letter-spacing: .04em;
  color: var(--gold); text-shadow: 0 0 30px rgba(217,180,80,.8), 0 6px 0 #6d531a, 0 10px 30px rgba(0,0,0,.6);
  opacity: 0;
}
.changa-pop.show { animation: changa 1.9s ease-out forwards; }
@keyframes changa {
  0% { opacity: 0; transform: scale(2.4) rotate(-6deg); }
  18% { opacity: 1; transform: scale(.92) rotate(2deg); }
  28% { transform: scale(1.06) rotate(-1deg); }
  40%, 80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1); }
}

/* ---------- Your hand ---------- */
.me { position: relative; z-index: 2; padding: 4px 16px calc(14px + env(safe-area-inset-bottom)); }
.message { text-align: center; min-height: 1.5em; font-size: 16px; color: var(--text); margin-bottom: 8px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.hand-row { display: flex; align-items: flex-end; justify-content: center; gap: 12px; }
.hand { display: flex; gap: clamp(4px, 1.2vw, 10px); justify-content: center; }
.hand-tile {
  width: var(--tile-w); height: calc(var(--tile-w) * 2); padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: calc(var(--tile-w) * .14);
  transition: transform .15s ease, opacity .2s, box-shadow .2s;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.5));
}
.hand-tile .stone-svg { width: 100%; height: 100%; display: block; }
.hand.is-turn .hand-tile { opacity: .45; }
.hand.is-turn .hand-tile.playable { opacity: 1; box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(217,180,80,.6); }
.hand.is-turn .hand-tile.playable:hover { transform: translateY(-6px); }
.hand-tile.selected { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--gold-soft), 0 0 22px rgba(240,217,138,.9) !important; }
.hand-tile.nope { animation: nope .3s; }
.hand-tile.charging { transition: none; z-index: 3; position: relative; touch-action: none;
  box-shadow: 0 0 0 3px var(--gold-soft), 0 0 calc(12px + 34px * var(--c, 0)) rgba(255, 196, 70, calc(.45 + .5 * var(--c, 0))) !important; }
.hint { font-size: 13px; color: var(--muted); text-align: center; margin-top: 6px; min-height: 1.2em; }
@keyframes nope { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.hand-tile:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 3px; }

.pass-btn {
  align-self: center; padding: 12px 22px; border-radius: 12px; border: 0; cursor: pointer;
  background: linear-gradient(180deg, #f0d98a, #c9a23f); color: #1d1405; font-weight: 700; font-size: 17px;
  box-shadow: 0 6px 18px rgba(0,0,0,.4); animation: pulse-btn 1.2s ease-in-out infinite;
}
@keyframes pulse-btn { 50% { box-shadow: 0 0 0 6px rgba(217,180,80,.25), 0 6px 18px rgba(0,0,0,.4); } }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 8, 6, .72); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: fade .25s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.panel {
  width: min(100%, 440px); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  padding: 26px 24px 22px; border-radius: 18px; text-align: center;
  background: linear-gradient(160deg, #163a2c, #0a1c15);
  border: 1px solid rgba(217,180,80,.6);
  box-shadow: 0 24px 80px rgba(0,0,0,.6), inset 0 1px rgba(255,255,255,.06);
  animation: rise .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.panel h2 { font-family: var(--display); color: var(--gold); margin: 0 0 14px; font-size: 26px; }

.logo-stones { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.logo-stones .stone-svg { width: 34px; height: 68px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.5)); }
.logo-stones .stone-svg:first-child { transform: rotate(-8deg); }
.logo-stones .stone-svg:last-child { transform: rotate(8deg); }
.logo-title { font-family: var(--display); font-weight: 900; color: var(--gold); font-size: clamp(36px, 10vw, 48px); margin: 4px 0 0; line-height: 1.05; text-shadow: 0 4px 18px rgba(0,0,0,.5); }
.logo-sub { margin: 4px 0 0; letter-spacing: .25em; text-transform: uppercase; font-size: 13px; color: var(--muted); }
.tagline { color: var(--text); opacity: .85; font-size: 15px; margin: 14px 0 16px; }

.langs { display: flex; justify-content: center; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.lang { padding: 6px 14px; border-radius: 999px; border: 1px solid rgba(217,180,80,.45); background: transparent; cursor: pointer; font-size: 14px; }
.lang[aria-pressed="true"] { background: var(--gold); color: #1b1405; font-weight: 700; border-color: var(--gold); }

.menu-buttons { display: grid; gap: 10px; }
.btn {
  padding: 14px 18px; border-radius: 12px; border: 1px solid rgba(217,180,80,.45); cursor: pointer;
  background: rgba(255,255,255,.04); font-size: 17px; font-weight: 600;
}
.btn small { font-weight: 400; opacity: .75; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-gold { background: linear-gradient(180deg, #f0d98a, #c9a23f); color: #1d1405; border: 0; font-weight: 700; box-shadow: 0 8px 20px rgba(0,0,0,.35); }
.btn-ghost { background: transparent; }
.btn:focus-visible, .lang:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 2px; }

.rules-list { text-align: left; padding-left: 22px; margin: 0 0 18px; line-height: 1.5; font-size: 16px; }
.rules-list li { margin-bottom: 6px; }

.result-shoe .shoe { width: 150px; height: 75px; margin: 0 auto 4px; display: block; filter: drop-shadow(0 8px 12px rgba(0,0,0,.5)); }
.result-title { font-size: 30px !important; margin-bottom: 6px !important; }
.result-sub { margin: 0 0 6px; font-size: 16px; }
.result-points { margin: 0 0 6px; font-weight: 700; color: var(--gold-soft); font-size: 18px; }
.result-extra { margin: 0 0 10px; font-family: var(--display); font-weight: 900; color: var(--gold); font-size: 22px; }
.result-extra:empty, .result-points:empty, .result-sub:empty { display: none; }
.result-scores { display: flex; justify-content: center; gap: 28px; margin: 6px 0 12px; font-size: 15px; color: var(--muted); }
.result-scores b { display: block; font-family: var(--display); font-size: 34px; color: var(--gold); }

/* ---------- Sizes ---------- */
@media (max-width: 520px) {
  .hud { padding: 8px 10px 6px 12px; margin: 8px 8px 0; grid-template-columns: 1fr auto 1fr auto; }
  .score-value { font-size: 26px; }
  .score-label { font-size: 13px; }
  .status-turn { font-size: 14px; }
  .table { padding: 4px 12px 0; }
  .seat-left .back-svg, .seat-right .back-svg { width: 24px; height: 12px; }
  .seat-top .back-svg { width: 14px; height: 28px; }
  .seat-name { font-size: 12px; padding: 2px 8px; }
  .me { padding: 2px 12px calc(14px + env(safe-area-inset-bottom)); }
  .message { font-size: 14px; }
  .pass-btn { position: absolute; right: 14px; bottom: calc(100% + 4px); padding: 10px 18px; }
  .hand-row { position: relative; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .seat-left .back-svg, .seat-right .back-svg { width: 22px; height: 11px; }
  .seat-top .back-svg { width: 11px; height: 22px; }
  .message { margin-bottom: 4px; }
}

/* ---------- Online: HUD buttons ---------- */
.hud { grid-template-columns: 1fr auto 1fr auto; }
.hud-buttons { display: flex; gap: 6px; }
.icon-btn { position: relative; }
.icon-btn .mic-slash { display: none; stroke: #ff8a7a; }
#btn-mic.is-off svg { opacity: .55; }
#btn-mic.is-muted .mic-slash { display: inline; }
#btn-mic.is-on { border-color: #6fd38f; background: rgba(60, 160, 90, .25); }
#btn-mic.is-on.talking { box-shadow: 0 0 0 3px rgba(111, 211, 143, .6); }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #e5484d; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* talking + emoji reactions on seats */
.seat.talking .seat-name { box-shadow: 0 0 0 2px #6fd38f, 0 0 14px rgba(111, 211, 143, .8); }
.react { position: absolute; z-index: 6; pointer-events: none; font-size: 40px; line-height: 1; opacity: 0; transform: translateY(10px) scale(.5); }
.react.show { animation: react 2.2s ease-out forwards; }
@keyframes react { 0% { opacity: 0; transform: translateY(10px) scale(.4); } 12% { opacity: 1; transform: translateY(-6px) scale(1.25); } 22% { transform: translateY(0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-28px) scale(1); } }
.seat-top .react { top: 100%; }
.seat-left .react { left: 100%; top: 0; }
.seat-right .react { right: 100%; top: 0; }
.react-me { left: 50%; bottom: 100%; margin-left: -20px; margin-bottom: 30px; }
.bubble.chatty { white-space: normal; max-width: 220px; font-weight: 600; font-size: 14px; }

/* forms */
.field { display: grid; gap: 6px; text-align: left; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.field input, .join-row input, .chat-form input {
  font: inherit; font-size: 17px; color: var(--text); background: rgba(0,0,0,.35);
  border: 1px solid rgba(217,180,80,.45); border-radius: 10px; padding: 12px 14px; min-width: 0;
}
.field input:focus, .join-row input:focus, .chat-form input:focus { outline: 2px solid var(--gold-soft); outline-offset: 1px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; font-weight: 700; }
.join-field { margin: 4px 0 0; }
.lobby-kicker { margin: 0; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
#lobby-title { margin-top: 2px; }
.note { margin: 0; min-height: 1.2em; font-size: 14px; color: var(--gold-soft); }

/* lobby */
.lobby-panel { width: min(100%, 480px); }
.invite-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.btn-whatsapp { background: #1f8f4e; border-color: #1f8f4e; color: #fff; font-weight: 700; }
.lobby-sub { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.seat-picker {
  display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto auto; gap: 8px; margin-bottom: 10px;
  grid-template-areas: ". s2 ." "s3 mid s1" ". s0 .";
}
.seat-picker .mid { grid-area: mid; border-radius: 12px; background: radial-gradient(circle, #1d6a4c, #0d3a2a); display: grid; place-items: center; font-size: 12px; color: var(--muted); min-height: 64px; }
.pick { border-radius: 12px; padding: 8px 6px; min-height: 64px; border: 1px dashed rgba(217,180,80,.5); background: rgba(0,0,0,.25); cursor: pointer; display: grid; align-content: center; gap: 2px; font-size: 14px; }
.pick b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick:not(.taken) b { color: var(--muted); font-weight: 600; }
.pick small { color: var(--muted); font-size: 12px; }
.pick.taken { border-style: solid; background: rgba(217,180,80,.12); cursor: default; }
.pick.mine { border: 2px solid var(--gold); background: rgba(217,180,80,.25); }
.pick.team-0 small.team { color: #8fd3ff; }
.pick.team-1 small.team { color: #ffb38f; }
.pick:disabled { opacity: 1; }
.watchers { font-size: 13px; color: var(--muted); margin: 0 0 10px; min-height: 1em; }
.lobby-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* chat */
.chat {
  position: fixed; z-index: 40; right: 12px; bottom: 12px; top: auto; width: min(380px, calc(100vw - 24px)); height: min(560px, calc(100vh - 24px)); height: min(560px, calc(100dvh - 24px));
  display: grid; grid-template-rows: auto 1fr auto auto auto; border-radius: 16px; overflow: hidden;
  background: linear-gradient(170deg, #143528, #0a1b14); border: 1px solid rgba(217,180,80,.55); box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: rise .25s ease-out;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 8px 16px; border-bottom: 1px solid rgba(217,180,80,.25); }
.chat-head .icon-btn { width: 34px; height: 34px; }
.chat-log { overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; user-select: text; -webkit-user-select: text; }
.msg { max-width: 85%; padding: 7px 11px; border-radius: 14px; background: rgba(255,255,255,.08); font-size: 15px; line-height: 1.35; word-wrap: break-word; }
.msg b { display: block; font-size: 12px; color: var(--gold-soft); margin-bottom: 1px; }
.msg.mine { align-self: flex-end; background: rgba(217,180,80,.22); }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 0; }
.chat-quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 0; scrollbar-width: none; }
.chat-quick button { flex: none; padding: 6px 11px; border-radius: 999px; border: 1px solid rgba(217,180,80,.45); background: rgba(0,0,0,.25); font-size: 13px; cursor: pointer; white-space: nowrap; }
.chat-emoji button { font-size: 20px; padding: 2px 8px; border: 0; background: none; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; }
.chat-form input { flex: 1; font-size: 16px; padding: 10px 12px; }
.chat-form .btn { padding: 10px 14px; font-size: 15px; }
@media (max-width: 520px) {
  .chat { right: 0; left: 0; bottom: 0; width: 100%; height: 62vh; height: 62dvh; border-radius: 16px 16px 0 0; }
  .hud-buttons { gap: 4px; }
  .icon-btn { width: 36px; height: 36px; }
  .hud { gap: 4px; }
}
.toast { position: fixed; z-index: 50; left: 50%; top: 70px; translate: -50% 0; padding: 8px 14px; border-radius: 999px; background: rgba(10,20,15,.92); border: 1px solid rgba(217,180,80,.5); font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none; }
.toast.show { opacity: 1; }

/* Keep stones and buttons away from the very bottom edge on phones,
   where the browser's own bar and swipe gestures catch taps. */
@media (max-width: 520px), (pointer: coarse) {
  .me { padding-bottom: calc(26px + env(safe-area-inset-bottom)); }
  .chat-form { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}

.win-mark { color: var(--gold); font-size: 20px; line-height: 1; text-shadow: 0 0 10px rgba(217,180,80,.7); }

/* Thought balloon over the player whose turn it is.
   It floats above the table (position: absolute), so it never takes space
   from the board and the stones keep their size. */
.think {
  position: absolute; z-index: 6; pointer-events: none;
  display: flex; align-items: center; gap: 4px; padding: 8px 12px;
  background: var(--ivory); border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
  opacity: 0; transform: scale(.4); transition: opacity .25s ease, transform .35s cubic-bezier(.3, 1.6, .6, 1);
}
.think::before, .think::after { content: ''; position: absolute; border-radius: 50%; background: var(--ivory); box-shadow: 0 3px 8px rgba(0,0,0,.35); }
.think::before { width: 9px; height: 9px; }
.think::after { width: 5px; height: 5px; }
.think span { width: 7px; height: 7px; border-radius: 50%; background: #1d1608; opacity: .3; }
.seat.thinking .think { opacity: 1; transform: scale(1); animation: think-float 2.6s ease-in-out .35s infinite; }
.seat.thinking .think span { animation: think-dot 1.2s ease-in-out infinite; }
.seat.thinking .think span:nth-child(2) { animation-delay: .18s; }
.seat.thinking .think span:nth-child(3) { animation-delay: .36s; }
@keyframes think-dot { 0%, 60%, 100% { opacity: .3; translate: 0 0; } 30% { opacity: 1; translate: 0 -3px; } }
@keyframes think-float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -3px; } }
/* left player: balloon above, trail of little circles down toward the name */
.seat-left .think { bottom: 100%; left: 50%; margin-bottom: 14px; transform-origin: bottom left; }
.seat-left .think::before { left: 2px; bottom: -10px; }
.seat-left .think::after { left: -5px; bottom: -18px; }
/* right player: mirrored */
.seat-right .think { bottom: 100%; right: 50%; margin-bottom: 14px; transform-origin: bottom right; }
.seat-right .think::before { right: 2px; bottom: -10px; }
.seat-right .think::after { right: -5px; bottom: -18px; }
/* partner at the top: balloon beside the name, trail toward it */
.seat-top .think { left: 100%; top: 50%; margin-top: -13px; margin-left: 22px; transform-origin: left center; }
.seat-top .think::before { left: -12px; bottom: 3px; }
.seat-top .think::after { left: -20px; bottom: 1px; }
@media (prefers-reduced-motion: reduce) {
  .seat.thinking .think, .seat.thinking .think span { animation: none; }
  .seat.thinking .think span { opacity: .7; }
}
/* keep the table-name row inside the panel on narrow phones */
.menu-buttons { grid-template-columns: minmax(0, 1fr); }
.join-field, .join-row { min-width: 0; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 100%; min-width: 0; }
.join-row .btn { flex: none; }
.join-row input::placeholder { font-weight: 400; }

/* fair-play check on the result screen */
.result-check:empty { display: none; }
.result-check { margin: 4px 0 12px; padding: 8px 12px; border-radius: 10px; font-size: 14px; text-align: left; }
.result-check.ok { color: #9be3b0; background: rgba(60, 160, 90, .15); text-align: center; }
.result-check.skip { color: var(--muted); text-align: center; }
.result-check.bad { color: #ffd2cc; background: rgba(200, 50, 40, .25); border: 1px solid rgba(255, 120, 100, .6); }
.result-check.bad b { display: block; margin-bottom: 4px; color: #ffb4a8; }
.result-check.bad ul { margin: 0; padding-left: 18px; }

/* away from the game screen */
.seat.away .seat-name::before { content: '👀 '; }
.seat.away .backs { opacity: .45; }
.result-away { margin: -4px 0 10px; font-size: 14px; color: #ffcf8a; }
.result-away:empty { display: none; }

/* pop-ups sit below the partner's seat so they never hide it */
.toast { top: calc(170px + env(safe-area-inset-top)); max-width: calc(100vw - 32px); text-align: center; }

/* data warning before voice chat */
.overlay-top { z-index: 60; }
.datawarn-panel { width: min(100%, 420px); text-align: center; }
.datawarn-text { margin: 0 0 14px; line-height: 1.45; color: var(--text); font-size: 16px; }
.datawarn-skip { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 14px; font-size: 14px; color: var(--muted); cursor: pointer; }
.datawarn-skip input { width: 18px; height: 18px; accent-color: #d9b450; }
.datawarn-buttons { display: grid; gap: 8px; }

/* speaker button to mute one player (only on my side). Floats next to the name,
   so it never takes space from the board. */
.vol {
  position: absolute; top: 50%; translate: 0 -50%; z-index: 7;
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  border: 1px solid rgba(217,180,80,.55); background: rgba(5, 14, 10, .85); color: var(--text);
  font-size: 15px; line-height: 1; display: grid; place-items: center; cursor: pointer;
}
.vol[hidden] { display: none; }
.vol.off { border-color: #ff8a7a; background: rgba(120, 30, 20, .85); }
.seat-left .vol { left: 100%; margin-left: 6px; }
.seat-right .vol, .seat-top .vol { right: 100%; margin-right: 6px; }


/* connection note (host slow / my connection weak) */
.netnote {
  position: fixed; z-index: 45; left: 50%; translate: -50% 0; top: calc(74px + env(safe-area-inset-top));
  max-width: calc(100vw - 32px); padding: 6px 14px; border-radius: 999px; text-align: center;
  background: rgba(60, 25, 10, .92); border: 1px solid #ffb38f; color: #ffe1cf; font-size: 14px; font-weight: 600;
  pointer-events: none; animation: fade .25s ease-out;
}
.netnote[hidden] { display: none; }

/* game over: "tap to continue" */
.message.tap-hint { color: var(--gold-soft, #f0d98a); font-weight: 700; animation: tap-pulse 1.6s ease-in-out infinite; }
@keyframes tap-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .message.tap-hint { animation: none; } }

/* vote to remove a player */
.kick-warn { color: #ffb38f; font-weight: 600; }
.votebox {
  position: fixed; z-index: 55; left: 50%; translate: -50% 0; top: calc(70px + env(safe-area-inset-top));
  width: min(calc(100vw - 24px), 420px); padding: 12px 14px; border-radius: 14px; text-align: center;
  background: rgba(10, 30, 20, .97); border: 1px solid var(--gold); box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: fade .25s ease-out;
}
.votebox[hidden] { display: none; }
.votebox p { margin: 0 0 10px; font-size: 15px; line-height: 1.4; }
.votebox-buttons { display: flex; gap: 8px; justify-content: center; }
.votebox-buttons[hidden] { display: none; }
.votebox-buttons .btn { flex: 1; }
.seat-name.can-vote { cursor: pointer; }

/* ---------- After the game: moving stones on the table ---------- */
.board .tappable { cursor: pointer; }
.pg-stone { cursor: pointer; }
.pg-picked { filter: drop-shadow(0 0 4px var(--gold)); }
#btn-review { margin-bottom: 8px; width: 100%; }
