/* ===================== Base / theme ===================== */
:root {
  --felt-1: #0f5132;
  --felt-2: #0a3d26;
  --felt-edge: #062e1c;
  --gold: #e7c66b;
  --gold-dim: #b9944a;
  --card-w: 74px;
  --card-h: 104px;
  --ink: #f4f1e8;
  --muted: #a9b3ad;
  --danger: #e0463c;
  --danger-hi: #ff5a4f;
  --accent: #3aa0ff;
  --panel: #14201b;
  --panel-2: #1c2b24;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(120% 90% at 50% 0%, #14352a 0%, #0b241a 55%, #071711 100%);
  overflow: hidden;
}

#app { height: 100%; position: relative; }

/* ===================== Screens ===================== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.screen.active { display: flex; }

/* ===================== Buttons / fields ===================== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
  color: #fff;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { padding: 14px 26px; font-size: 16px; width: 100%; }
.btn.primary { background: linear-gradient(180deg, #2fa968, #1c8450); box-shadow: 0 6px 16px rgba(28, 132, 80, 0.4); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { background: linear-gradient(180deg, var(--danger-hi), var(--danger)); box-shadow: 0 6px 18px rgba(224, 70, 60, 0.45); }
.btn.ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.14); }
.btn.text { background: none; color: var(--muted); font-weight: 600; }
.btn.text:hover { color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
input, select {
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
input:focus, select:focus { border-color: var(--gold-dim); }
.code-input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 800; font-size: 22px; }

/* ===================== Landing ===================== */
.brand { text-align: center; margin-bottom: 26px; }
.brand h1 {
  font-size: 64px; margin: 6px 0 4px; letter-spacing: 8px;
  background: linear-gradient(180deg, #fbe9a8, var(--gold), var(--gold-dim));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}
.tagline { color: var(--muted); max-width: 360px; margin: 0 auto; font-size: 14px; }
.brand-cards { display: flex; justify-content: center; gap: -10px; height: 40px; }
.mini-card {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 46px; background: #fff; color: #111; border-radius: 6px;
  font-weight: 800; font-size: 15px; box-shadow: var(--shadow);
  margin: 0 -6px; transform: rotate(-8deg);
}
.mini-card:nth-child(2) { transform: rotate(0deg) translateY(-4px); z-index: 2; }
.mini-card:nth-child(3) { transform: rotate(8deg); }
.mini-card.red { color: #d23; }

.panel {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow);
}
.tabs { display: flex; gap: 6px; background: var(--panel-2); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.tab { flex: 1; background: none; border: none; color: var(--muted); padding: 9px; border-radius: 8px; font-weight: 700; cursor: pointer; }
.tab.active { background: rgba(231, 198, 107, 0.16); color: var(--gold); }
.tab-body { display: none; }
.tab-body.active { display: block; }
.settings-row { display: flex; gap: 12px; }
.settings-row .field { flex: 1; }
.footer-note { color: var(--muted); font-size: 12px; margin-top: 18px; text-align: center; max-width: 360px; }

/* ===================== Lobby ===================== */
.lobby-card {
  width: 100%; max-width: 460px; background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow); text-align: center;
}
.lobby-card h2 { margin: 0 0 18px; }
.code-share { background: var(--panel-2); border-radius: 12px; padding: 16px; margin-bottom: 18px; }
.code-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.code-value { font-size: 40px; font-weight: 900; letter-spacing: 8px; color: var(--gold); margin: 4px 0 12px; }
.lobby-players { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.lobby-player {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--panel-2); padding: 10px 14px; border-radius: 10px;
}
.lobby-player .name { font-weight: 700; }
.badge-host { font-size: 10px; background: var(--gold); color: #111; padding: 2px 7px; border-radius: 20px; font-weight: 800; text-transform: uppercase; }
.badge-you { font-size: 10px; background: var(--accent); color: #fff; padding: 2px 7px; border-radius: 20px; font-weight: 800; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

/* ===================== Game table ===================== */
#screen-game { padding: 0; }
.table-wrap {
  width: 100%; height: 100%; display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 1100px; margin: 0 auto;
}

/* Opponents */
.opponents {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 14px;
  padding: 16px 12px 4px;
}
.opponent {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 92px; padding: 10px 12px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.22); border: 1px solid rgba(255,255,255,0.06);
  transition: box-shadow 0.25s, border-color 0.25s, transform 0.25s;
}
.opponent.current { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(231,198,107,0.35), 0 0 26px rgba(231,198,107,0.25); transform: translateY(-2px); }
.opponent.finished { opacity: 0.5; }
.opponent.disconnected { opacity: 0.4; filter: grayscale(0.6); }
.opp-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: #10241a;
  background: linear-gradient(180deg, #fbe9a8, var(--gold-dim));
}
.opp-name { font-weight: 700; font-size: 14px; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp-cards { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }
.card-back-mini {
  width: 15px; height: 21px; border-radius: 3px;
  background: repeating-linear-gradient(45deg, #7a1f2b, #7a1f2b 3px, #5c1620 3px, #5c1620 6px);
  border: 1px solid rgba(255,255,255,0.25);
}
.opp-flag { font-size: 11px; color: var(--gold); font-weight: 700; height: 14px; }

/* Center */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; gap: 12px; }
.pile-area { position: relative; height: calc(var(--card-h) + 30px); display: flex; align-items: center; justify-content: center; }
.pile { position: relative; width: var(--card-w); height: var(--card-h); }
.pile .card-back { position: absolute; top: 0; left: 0; }
.pile-count {
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.5); padding: 4px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 700; color: var(--gold); white-space: nowrap;
}
.claim-banner { min-height: 26px; font-size: 15px; color: var(--ink); font-weight: 600; text-align: center; }
.claim-banner .who { color: var(--gold); }
.claim-banner .rank { color: #fff; background: rgba(255,255,255,0.12); padding: 1px 8px; border-radius: 6px; font-weight: 800; }
.reveal-area { display: flex; gap: 8px; min-height: 0; }

/* You area */
.you-area { padding: 6px 12px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.you-header { display: flex; justify-content: center; }
.turn-indicator {
  display: flex; align-items: center; gap: 10px; font-weight: 700;
  background: rgba(0,0,0,0.25); padding: 6px 16px; border-radius: 20px;
}
.turn-indicator.my-turn { background: rgba(231,198,107,0.18); color: var(--gold); }
.timer-ring {
  width: 16px; height: 16px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2); border-top-color: var(--gold);
  display: none;
}
.turn-indicator.my-turn .timer-ring, .turn-indicator.ticking .timer-ring { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Hand */
.hand { display: flex; justify-content: center; align-items: flex-end; min-height: calc(var(--card-h) + 24px); padding: 0 8px; flex-wrap: wrap; gap: 2px; }
.hand .card { margin: 0 -18px; cursor: pointer; transition: transform 0.14s ease, margin 0.14s ease; }
.hand .card:hover { transform: translateY(-14px); z-index: 5; }
.hand .card.selected { transform: translateY(-26px); box-shadow: 0 0 0 3px var(--gold), var(--shadow); z-index: 6; }

/* Controls */
.controls { min-height: 64px; display: flex; align-items: center; justify-content: center; }
.play-controls, .doubt-controls { display: none; align-items: center; gap: 14px; }
.play-controls.show, .doubt-controls.show { display: flex; }
.rank-required { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.rank-required .rr-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.rank-required .rr-value {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; padding: 0 8px;
  background: linear-gradient(180deg, #fbe9a8, var(--gold-dim));
  color: #10241a; font-weight: 900; font-size: 24px; border-radius: 10px;
  box-shadow: var(--shadow);
}
.selected-hint { color: var(--muted); font-size: 12px; }

.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 6px 18px rgba(224,70,60,0.45); } 50% { box-shadow: 0 6px 30px rgba(224,70,60,0.85); } }

/* ===================== Cards (CSS-drawn) ===================== */
.card {
  width: var(--card-w); height: var(--card-h);
  border-radius: 8px; background: #fdfdfa; color: #1a1a1a;
  position: relative; box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,0.15); user-select: none; flex: 0 0 auto;
}
.card .corner { position: absolute; font-weight: 800; line-height: 1; display: flex; flex-direction: column; align-items: center; }
.card .corner.tl { top: 5px; left: 6px; }
.card .corner.br { bottom: 5px; right: 6px; transform: rotate(180deg); }
.card .corner .r { font-size: 15px; }
.card .corner .s { font-size: 13px; }
.card .pip { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 34px; }
.card.red { color: #d5202f; }
.card-back {
  width: var(--card-w); height: var(--card-h); border-radius: 8px;
  background:
    repeating-linear-gradient(45deg, #8a2634, #8a2634 6px, #6d1c28 6px, #6d1c28 12px);
  border: 3px solid #fdfdfa; box-shadow: var(--shadow); flex: 0 0 auto;
}

/* Reveal flip animation */
.reveal-card { perspective: 600px; }
.reveal-card .card { animation: flipIn 0.5s ease; }
@keyframes flipIn { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0); opacity: 1; } }

/* deal + pickup helpers */
@keyframes dealIn { from { transform: translateY(-140px) scale(0.6); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.deal-anim { animation: dealIn 0.4s ease backwards; }

/* ===================== Overlay ===================== */
.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 40;
}
.overlay.show { display: flex; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay-card { background: var(--panel); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 400px; text-align: center; box-shadow: var(--shadow); border: 1px solid rgba(255,255,255,0.1); }
.standings { list-style: none; padding: 0; margin: 18px 0; text-align: left; }
.standings li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--panel-2); margin-bottom: 8px; font-weight: 700; }
.standings li .medal { font-size: 20px; width: 26px; text-align: center; }
.standings li.loser { background: rgba(224,70,60,0.16); color: var(--danger-hi); }

/* ===================== Toasts ===================== */
.toasts { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: 92vw; }
.toast {
  background: rgba(20, 28, 24, 0.96); border: 1px solid rgba(255,255,255,0.12);
  color: var(--ink); padding: 11px 18px; border-radius: 10px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); animation: toastIn 0.25s ease;
}
.toast.good { border-left: 3px solid #2fa968; }
.toast.bad { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.toast.out { animation: toastOut 0.3s ease forwards; }
@keyframes toastOut { to { transform: translateY(-12px); opacity: 0; } }

/* ===================== Responsive ===================== */
@media (max-width: 620px) {
  :root { --card-w: 58px; --card-h: 82px; }
  .brand h1 { font-size: 48px; }
  .hand .card { margin: 0 -24px; }
  .opponent { min-width: 76px; padding: 8px; }
  .opp-avatar { width: 34px; height: 34px; font-size: 15px; }
}
