* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0c1210;
  --bg2: #131c17;
  --felt1: #1f8a55;
  --felt2: #0d5432;
  --felt-edge: #3a2417;
  --gold: #e8c35a;
  --gold-dark: #b8923a;
  --ink: #f2efe6;
  --muted: #9fb0a6;
  --red: #e25555;
  --blue: #4f8fd8;
  --card-bg: #faf7ef;
  --card-red: #d5383f;
  --card-black: #23272e;
  --panel: #16201b;
  --shadow: 0 10px 30px rgba(0,0,0,.5);
  --radius: 14px;
  font-size: 16px;
}

html, body { height: 100%; }
body {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  background: radial-gradient(120% 100% at 50% 0%, #17231d 0%, var(--bg) 70%);
  color: var(--ink);
  overflow: hidden;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }
.screen { height: 100dvh; width: 100vw; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ============ HOME ============ */
#home {
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.home-card {
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, #1b2a22, #141f19);
  border: 1px solid #2c3f33;
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.logo {
  text-align: center; font-size: 1.1rem; letter-spacing: .05em;
}
.logo span {
  display: block; font-size: 2rem; font-weight: 800; color: var(--gold);
  text-shadow: 0 2px 12px rgba(232,195,90,.25);
  margin: 4px 0;
}
.tagline { text-align: center; color: var(--muted); font-size: .92rem; margin: 10px 0 22px; }

.home-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.home-tab {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid #2c3f33;
  background: transparent; color: var(--muted); font-weight: 600; font-size: .95rem;
}
.home-tab.active { background: #223429; color: var(--ink); border-color: #3a5545; }

form label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
form input {
  display: block; width: 100%; margin-top: 5px;
  background: #0e1713; color: var(--ink);
  border: 1px solid #2c3f33; border-radius: 10px;
  padding: 12px 14px; font-size: 1.05rem;
}
form input:focus { outline: 2px solid var(--gold-dark); border-color: transparent; }
.code-input { text-transform: uppercase; letter-spacing: .35em; font-weight: 700; text-align: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-block; border: none; border-radius: 12px;
  padding: 13px 20px; font-size: 1rem; font-weight: 700;
  background: #29392f; color: var(--ink);
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-gold {
  width: 100%;
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
  color: #241a05;
  box-shadow: 0 4px 16px rgba(232,195,90,.25);
}
.btn-small { padding: 8px 14px; font-size: .85rem; width: auto; }
.btn.danger { background: #552626; color: #ffb9b9; }
.error { margin-top: 14px; color: #ff9b9b; text-align: center; font-size: .9rem; }

/* ============ TOPBAR ============ */
#game { display: flex; flex-direction: column; position: relative; }
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  z-index: 30;
}
#btn-copy-code {
  background: #16241c; color: var(--muted); border: 1px solid #2c3f33;
  border-radius: 10px; padding: 7px 12px; font-size: .85rem;
}
#btn-copy-code b { color: var(--gold); letter-spacing: .15em; font-size: 1rem; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  position: relative;
  background: #16241c; border: 1px solid #2c3f33; color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; font-size: 1.05rem;
}
.dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
  background: var(--red); border-radius: 50%;
}
.chip-btn {
  background: #223429; border: 1px solid #3a5545; color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: .85rem; font-weight: 600;
}

/* ============ TAVOLO ============ */
#table-area {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 44px 10px 116px;
  min-height: 0;
}
#table {
  position: relative;
  width: min(96vw, 900px);
  height: min(100%, 560px);
  aspect-ratio: 1.55;
  max-height: 100%;
}
#felt {
  position: absolute; inset: 8% 6%;
  border-radius: 50% / 46%;
  background:
    radial-gradient(90% 85% at 50% 35%, var(--felt1) 0%, var(--felt2) 75%, #093f25 100%);
  border: clamp(8px, 1.6vw, 14px) solid var(--felt-edge);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,.45),
    0 18px 50px rgba(0,0,0,.55),
    inset 0 2px 0 rgba(255,255,255,.06);
}
#felt::after {
  content: ''; position: absolute; inset: 7%;
  border-radius: 50% / 46%;
  border: 2px solid rgba(255,255,255,.08);
  pointer-events: none;
}
#table-center {
  position: absolute; left: 50%; top: 47%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: 100%;
}
#pot {
  background: rgba(0,0,0,.35); border-radius: 999px;
  padding: 4px 14px; font-weight: 700; font-size: clamp(.8rem, 2.2vw, 1rem);
  color: var(--gold);
  border: 1px solid rgba(232,195,90,.25);
}
#phase-tag { color: rgba(255,255,255,.5); font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; }

#board { display: flex; gap: clamp(3px, .8vw, 8px); min-height: var(--bcard-h); }
:root { --bcard-w: clamp(38px, 8.5vw, 62px); --bcard-h: calc(var(--bcard-w) * 1.42); }

.card {
  width: var(--bcard-w); height: var(--bcard-h);
  background: var(--card-bg);
  border-radius: calc(var(--bcard-w) * .12);
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  color: var(--card-black);
  flex: none;
}
.card.red { color: var(--card-red); }
.card .c-corner {
  position: absolute; top: 5%; left: 8%;
  font-size: calc(var(--bcard-w) * .30);
  font-weight: 800; line-height: 1;
  text-align: center; white-space: pre-line;
}
.card .c-pip {
  position: absolute; bottom: 4%; right: 7%;
  font-size: calc(var(--bcard-w) * .52);
  line-height: 1;
}
.card.back {
  background:
    repeating-linear-gradient(45deg, #7b2d35 0 4px, #8f3540 4px 8px);
  border: 3px solid #e9e2d0;
}
.card.deal { animation: dealIn .35s cubic-bezier(.2,.9,.3,1.2); }
@keyframes dealIn {
  from { transform: translateY(-26px) scale(.6) rotate(-8deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.card.win-glow { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(232,195,90,.8); }
.card.dim { filter: brightness(.55); }

#banner {
  position: absolute; left: 50%; top: 47%; transform: translate(-50%,-50%);
  background: rgba(10, 14, 12, .92);
  border: 1px solid var(--gold-dark);
  color: var(--ink);
  border-radius: 14px; padding: 12px 22px;
  font-size: clamp(.95rem, 2.6vw, 1.25rem); font-weight: 700; text-align: center;
  z-index: 15; max-width: 82%;
  box-shadow: 0 6px 30px rgba(0,0,0,.6);
  animation: bannerIn .4s cubic-bezier(.2,.9,.3,1.2);
}
#banner .sub { display: block; font-size: .78em; color: var(--gold); margin-top: 4px; }
@keyframes bannerIn { from { transform: translate(-50%,-30%) scale(.8); opacity: 0; } }

/* ============ SEATS ============ */
.seat {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center;
  width: clamp(74px, 16vw, 110px);
  z-index: 5;
  transition: left .4s, top .4s;
}
.seat .hole {
  display: flex; gap: 2px; margin-bottom: -10px; z-index: 1;
  --bcard-w: clamp(26px, 5.5vw, 40px);
}
.seat.you .hole { --bcard-w: clamp(40px, 9vw, 56px); margin-bottom: -8px; }
.seat .hole .card:last-child { transform: rotate(7deg) translateX(-3px); }
.seat .hole .card:first-child { transform: rotate(-5deg); }

.avatar-wrap { position: relative; z-index: 2; }
.avatar {
  width: clamp(44px, 10vw, 58px); height: clamp(44px, 10vw, 58px);
  border-radius: 50%;
  background: linear-gradient(180deg, #3b5347, #22332a);
  border: 2px solid #4a6a58;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: clamp(1rem, 2.6vw, 1.3rem);
  color: var(--gold);
  position: relative;
}
.seat.acting .avatar { border-color: var(--gold); box-shadow: 0 0 14px rgba(232,195,90,.55); }
.seat.folded { opacity: .45; }
.seat.disconnected .avatar { filter: grayscale(1); }
.seat.winner .avatar { border-color: var(--gold); animation: winPulse 1s infinite; }
@keyframes winPulse {
  0%,100% { box-shadow: 0 0 8px rgba(232,195,90,.4); }
  50% { box-shadow: 0 0 26px rgba(232,195,90,.95); }
}
.timer-ring {
  position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px);
  transform: rotate(-90deg); pointer-events: none;
}
.timer-ring circle {
  fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round;
}
.timer-ring.urgent circle { stroke: var(--red); }

.seat-badges {
  position: absolute; top: -6px; right: -10px; display: flex; gap: 2px; z-index: 3;
  font-size: .8rem;
}
.badge-btn {
  background: var(--ink); color: #1a1408;
  border-radius: 50%; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: .62rem; font-weight: 800;
  border: 1px solid rgba(0,0,0,.4);
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.badge-btn.dealer { background: var(--ink); }
.badge-btn.blind { background: #4f8fd8; color: #fff; }
.emoji-badge { font-size: .95rem; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }

.meta {
  margin-top: 4px;
  background: rgba(8,12,10,.85);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 10px;
  padding: 3px 8px; text-align: center;
  min-width: 90%;
  z-index: 2;
}
.meta .nick {
  font-size: clamp(.66rem, 1.9vw, .8rem); font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.meta .nick .doc-tag { color: #ffb3c0; font-size: .85em; }
.meta .stack { font-size: clamp(.66rem, 1.9vw, .78rem); color: var(--gold); font-weight: 600; }

.bet-bubble {
  position: absolute;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(232,195,90,.4);
  color: var(--ink);
  border-radius: 999px; padding: 2px 9px;
  font-size: clamp(.62rem, 1.8vw, .78rem); font-weight: 700;
  white-space: nowrap;
  z-index: 6;
  transition: left .35s, top .35s, opacity .3s;
}
.bet-bubble .bchip { color: var(--gold); }

.action-tag {
  position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%);
  font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  background: #223429; border-radius: 6px; padding: 1px 7px;
  border: 1px solid #3a5545;
  white-space: nowrap;
}
.action-tag.fold { background: #402024; color: #ff9b9b; border-color: #5d2c33; }
.action-tag.allin { background: #4d3413; color: var(--gold); border-color: var(--gold-dark); }

.seat .taunt-hit {
  position: absolute; inset: 0; z-index: 8; background: transparent; border: none;
}

/* ============ LOBBY BAR ============ */
#lobbybar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(5,8,7,.9) 30%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  z-index: 20; text-align: center;
}
#lobby-msg { color: var(--muted); font-size: .95rem; }
#lobby-invite { font-size: .95rem; display: flex; align-items: center; gap: 10px; }
#lobby-invite b { color: var(--gold); letter-spacing: .25em; font-size: 1.25rem; }
#btn-start { width: auto; padding: 13px 34px; }

/* ============ ACTION BAR ============ */
#actionbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(5,8,7,.95) 40%);
  z-index: 20;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
#action-buttons { display: flex; gap: 10px; width: 100%; max-width: 520px; }
#action-buttons .btn { flex: 1; padding: 14px 6px; font-size: 1.02rem; }
.act-fold { background: #5b2a2e; color: #ffc2c2; }
.act-check { background: #2c4a6b; color: #cfe4ff; }
.act-raise { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); color: #241a05; }

#raise-panel {
  width: 100%; max-width: 520px;
  background: #141f19; border: 1px solid #2c3f33; border-radius: 14px;
  padding: 12px;
}
#raise-presets { display: flex; gap: 8px; margin-bottom: 10px; }
#raise-presets .chip-btn { flex: 1; }
#raise-slider-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
#raise-slider { flex: 1; accent-color: var(--gold); height: 30px; }
#raise-amount { font-weight: 800; font-size: 1.2rem; color: var(--gold); min-width: 70px; text-align: right; }
.raise-confirm-row { display: flex; gap: 10px; }
.raise-confirm-row .btn { flex: 1; }

/* ============ CIOCIARA ============ */
#btn-taunt {
  position: absolute; left: 12px; bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 25;
  background: linear-gradient(180deg, #a3543f, #7c3a2a);
  border: 1px solid #c86a50; color: #ffe3d5;
  border-radius: 999px; padding: 9px 14px;
  font-size: .85rem; font-weight: 800;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
#btn-taunt:disabled { opacity: .5; }
#btn-taunt span { letter-spacing: .03em; }

#taunt-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#taunt-overlay-text {
  font-size: clamp(2rem, 9vw, 4.5rem); font-weight: 800;
  color: #ffce56;
  text-shadow: 0 4px 0 #7c3a2a, 0 8px 30px rgba(0,0,0,.7);
  transform: rotate(-8deg);
  animation: tauntPop 2.6s cubic-bezier(.2,.9,.3,1.2) forwards;
  text-align: center;
}
@keyframes tauntPop {
  0% { transform: scale(.2) rotate(-30deg); opacity: 0; }
  12% { transform: scale(1.15) rotate(-8deg); opacity: 1; }
  20% { transform: scale(1) rotate(-8deg); }
  80% { opacity: 1; }
  100% { transform: scale(1.05) rotate(-6deg); opacity: 0; }
}
.seat.taunted { animation: seatShake .6s; }
@keyframes seatShake {
  0%,100% { margin-left: 0; }
  20% { margin-left: -8px; } 40% { margin-left: 8px; }
  60% { margin-left: -6px; } 80% { margin-left: 6px; }
}

/* ============ PANEL ============ */
#panel {
  position: absolute; z-index: 40;
  background: var(--panel);
  border-top: 1px solid #2c3f33;
  display: flex; flex-direction: column;
  left: 0; right: 0; bottom: 0;
  height: min(70dvh, 520px);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
}
@media (min-width: 900px) {
  #panel {
    left: auto; top: 54px; bottom: 0; width: 360px;
    border-radius: 18px 0 0 0;
    border-left: 1px solid #2c3f33;
    height: auto;
  }
}
#panel-tabs {
  display: flex; gap: 6px; padding: 10px 10px 0;
  border-bottom: 1px solid #24332b;
}
.panel-tab {
  background: none; border: none; color: var(--muted);
  font-weight: 700; font-size: .92rem; padding: 8px 12px;
  border-bottom: 2px solid transparent;
}
.panel-tab.active { color: var(--ink); border-bottom-color: var(--gold); }
#btn-panel-close { margin-left: auto; border: none; background: none; width: 34px; height: 34px; }
.panel-page { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel-scroll { flex: 1; overflow-y: auto; padding: 10px 12px; overscroll-behavior: contain; }

.chat-msg { margin-bottom: 8px; font-size: .92rem; line-height: 1.35; word-wrap: break-word; }
.chat-msg .who { color: var(--gold); font-weight: 700; }
.chat-msg.sys { color: #a7c4b2; font-style: italic; font-size: .88rem; }
#chat-form {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #24332b;
}
#chat-input {
  flex: 1; background: #0e1713; color: var(--ink);
  border: 1px solid #2c3f33; border-radius: 10px; padding: 10px 12px;
}

.log-entry {
  font-size: .88rem; padding: 8px 10px; margin-bottom: 6px;
  background: #101a14; border-radius: 8px; border-left: 3px solid var(--gold-dark);
  line-height: 1.35;
}

.rank-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; border-bottom: 1px solid #22312a;
  font-size: .95rem;
}
.rank-row .pos { width: 24px; text-align: center; font-weight: 800; color: var(--muted); }
.rank-row .name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .name small { color: var(--muted); font-weight: 400; display: block; font-size: .75rem; }
.rank-row .net { font-weight: 800; }
.rank-row .net.pos-net { color: #7fdc9a; }
.rank-row .net.neg-net { color: #ff9b9b; }
#rank-footer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); color: var(--muted); font-size: .75rem; text-align: center; }

/* ============ MODALS ============ */
.modal {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(4,7,6,.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-card {
  background: #17231c; border: 1px solid #2c3f33; border-radius: 18px;
  padding: 22px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 86dvh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-card.wide { max-width: 460px; }
.modal-card h2, .modal-card h3 { text-align: center; margin-bottom: 6px; }
.row-center { display: flex; gap: 10px; justify-content: center; }

#taunt-targets { display: flex; flex-direction: column; gap: 8px; }
#taunt-targets .btn { text-align: left; }

.coccarda-big { font-size: 4rem; text-align: center; animation: coccardaDrop .8s cubic-bezier(.2,.9,.3,1.3); }
@keyframes coccardaDrop {
  0% { transform: translateY(-80px) scale(.3) rotate(-40deg); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
#ciociara-text { text-align: center; font-size: 1.05rem; line-height: 1.4; }
#ciociara-text b { color: var(--gold); }

#final-standings .rank-row { border-bottom-color: #2c3f33; }

/* ============ TOAST ============ */
#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top));
  transform: translateX(-50%);
  background: #23332a; color: var(--ink);
  border: 1px solid #3a5545;
  padding: 10px 18px; border-radius: 999px;
  z-index: 100; font-size: .9rem; font-weight: 600;
  box-shadow: var(--shadow);
  max-width: 90vw; text-align: center;
  animation: toastIn .25s;
}
#toast.err { background: #402024; border-color: #5d2c33; color: #ffc2c2; }
@keyframes toastIn { from { transform: translate(-50%, -12px); opacity: 0; } }

/* telefono in verticale: tavolo ovale in piedi */
@media (orientation: portrait) {
  #table {
    width: min(94vw, 440px);
    aspect-ratio: 0.68;
    max-height: calc(100dvh - 210px);
  }
  #felt { inset: 6% 8%; border-radius: 46% / 50%; }
  #felt::after { border-radius: 46% / 50%; }
  :root { --bcard-w: clamp(34px, 10.5vw, 52px); }
  #table-area { padding: 40px 6px 96px; }
}

/* schermi molto bassi in landscape */
@media (max-height: 480px) {
  #table-area { padding-top: 30px; padding-bottom: 8px; }
  #btn-taunt { bottom: auto; top: 60px; }
}
