/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a5c2a;
  --bg-dark: #134420;
  --bg-panel: #0f3318;
  --text: #e8dcc8;
  --text-dim: #9a9080;
  --accent: #c9a84c;
  --accent-hover: #dbb85c;
  --danger: #c0392b;
  --success: #27ae60;
  --card-w: 72px;
  --card-h: 112px;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(ellipse at center, #1f6b33 0%, var(--bg) 60%, var(--bg-dark) 100%);
  color: var(--text);
}

.screen { display: none; height: 100%; }
.screen.active { display: flex; }

button {
  cursor: pointer; border: none; border-radius: 6px;
  font-size: 14px; font-weight: 600; padding: 8px 18px;
  transition: background .15s, transform .1s;
}
button:active { transform: scale(.96); }

/* ── Language toggle ──────────────────────────────────────── */
#lang-toggle {
  position: fixed; top: 10px; left: 10px; z-index: 250;
  background: var(--bg-panel); color: var(--accent);
  border: 1px solid var(--accent); padding: 4px 12px;
  font-size: 12px; font-weight: 700; letter-spacing: 1px;
  border-radius: 4px; cursor: pointer;
  transition: background .15s;
}
#lang-toggle:hover {
  background: var(--accent); color: var(--bg-panel);
}

/* ── Login ─────────────────────────────────────────────────── */
#screen-login { justify-content: center; align-items: center; }
.login-box {
  background: var(--bg-panel); padding: 40px 50px; border-radius: 16px;
  text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.login-box h1 { font-size: 48px; letter-spacing: 8px; color: var(--accent); margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-dim); margin-bottom: 28px; font-style: italic; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input {
  padding: 10px 14px; border-radius: 8px; border: 1px solid #3a6b40;
  background: #1a3d22; color: var(--text); font-size: 15px; outline: none;
}
#login-form input:focus { border-color: var(--accent); }
#login-form button {
  background: var(--accent); color: #1a2e10; font-size: 16px; padding: 12px;
  margin-top: 8px;
}
#login-form button:hover { background: var(--accent-hover); }
#login-error { color: var(--danger); margin-top: 10px; min-height: 20px; }

/* ── Lobby ─────────────────────────────────────────────────── */
#screen-lobby { justify-content: center; align-items: center; }
.lobby-box {
  background: var(--bg-panel); padding: 40px 50px; border-radius: 16px;
  text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.lobby-box h1 { font-size: 40px; letter-spacing: 6px; color: var(--accent); margin-bottom: 16px; }
.lobby-box p { color: var(--text-dim); margin-bottom: 20px; }
#lobby-players { display: flex; flex-direction: column; gap: 10px; }
.lobby-player {
  padding: 10px 20px; border-radius: 8px; font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
.lobby-player .dot {
  width: 12px; height: 12px; border-radius: 50%;
}
.lobby-player .dot.online { background: var(--success); }
.lobby-player .dot.offline { background: var(--danger); }
.lobby-start {
  margin-top: 20px; text-align: center;
}
.lobby-start button {
  background: var(--accent); color: var(--bg-dark);
  font-size: 18px; padding: 12px 36px;
}
.lobby-start button:hover { background: var(--accent-hover); }

/* ── Game screen layout ────────────────────────────────────── */
#screen-game {
  flex-direction: column; position: relative;
}

#info-bar {
  display: flex; gap: 24px; justify-content: center; align-items: center;
  padding: 8px 16px; background: var(--bg-panel); font-size: 14px;
  border-bottom: 1px solid #2a5a30; flex-shrink: 0;
}
#info-bar span { display: flex; align-items: center; gap: 6px; }

#game-layout {
  flex: 1; display: flex; flex-direction: column;
  padding: 16px 16px 8px; overflow: hidden;
  margin-right: 220px; /* room for scoreboard */
}

/* ── Opponents ─────────────────────────────────────────────── */
#opponents {
  display: flex; justify-content: space-around; padding: 0 60px;
  flex-shrink: 0;
}
.opp {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: 10px; min-width: 160px;
  background: rgba(0,0,0,.15);
}
.opp.active-turn { box-shadow: 0 0 0 2px var(--accent), 0 0 12px rgba(201,168,76,.3); }
.opp-name { font-weight: 700; font-size: 15px; }
.opp-cards { display: flex; gap: 2px; }
.card-back {
  width: 32px; height: 50px; border-radius: 4px;
  object-fit: cover;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.opp-info { font-size: 12px; color: var(--text-dim); }

/* ── Trick area ────────────────────────────────────────────── */
#trick-area {
  flex: 1; display: grid; place-items: center; position: relative;
  min-height: 180px;
}
.trick-slot {
  position: absolute; transition: all .3s ease;
}
#trick-opp-left   { top: 10px;  left: calc(50% - 120px); }
#trick-opp-center { top: 10px;  left: calc(50% - 36px); }
#trick-opp-right  { top: 10px;  left: calc(50% + 40px); }
#trick-me         { bottom: 10px; left: calc(50% - 36px); }

.trick-slot .card-img {
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.trick-slot .trick-label {
  font-size: 11px; text-align: center; margin-top: 2px; color: var(--text-dim);
}
.trick-winner-highlight {
  box-shadow: 0 0 0 3px var(--accent), 0 0 16px rgba(201,168,76,.5) !important;
}

/* ── Player area ───────────────────────────────────────────── */
#player-area {
  flex-shrink: 0; text-align: center; padding-bottom: 8px;
}
#player-area.elevated {
  position: relative;
  z-index: 101;
}
#player-info {
  margin-bottom: 8px; font-size: 14px; display: flex;
  justify-content: center; gap: 16px;
}
#player-name { font-weight: 700; }

#player-hand {
  display: flex; justify-content: center; gap: 0;
  padding: 0 40px; flex-wrap: nowrap;
}
#player-hand .card-slot {
  margin-left: -16px; transition: transform .15s, filter .15s;
  cursor: default; position: relative;
}
#player-hand .card-slot:first-child { margin-left: 0; }
#player-hand .card-slot.playable { cursor: pointer; }
#player-hand .card-slot.playable:hover { transform: translateY(-14px); z-index: 10; }
#player-hand .card-slot.dimmed { filter: brightness(.5); }
#player-hand .card-slot.selected {
  transform: translateY(-14px);
  box-shadow: 0 0 0 3px var(--accent);
  border-radius: 6px;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card-img {
  width: var(--card-w); height: var(--card-h);
  border-radius: 6px; border: 1px solid #444;
  object-fit: contain; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.card-img.small { width: 54px; height: 84px; }
.suit-icon { width: 20px; height: 20px; vertical-align: middle; object-fit: contain; }

/* ── Scoreboard ────────────────────────────────────────────── */
#scoreboard {
  position: fixed; right: 0; top: 0; bottom: 0; width: 220px;
  background: var(--bg-panel); border-left: 1px solid #2a5a30;
  padding: 12px; overflow-y: auto; font-size: 13px;
}
#scoreboard h3 {
  text-align: center; color: var(--accent); margin-bottom: 10px;
  letter-spacing: 2px;
}
#score-body table {
  width: 100%; border-collapse: collapse;
}
#score-body th, #score-body td {
  padding: 4px 6px; text-align: center; border-bottom: 1px solid #2a4a30;
}
#score-body th { color: var(--accent); font-size: 12px; }
#score-body td { font-size: 12px; }
.score-positive { color: var(--success); }
.score-negative { color: var(--danger); }
.score-zero { color: var(--text-dim); }
.score-total-row td { font-weight: 700; border-top: 2px solid var(--accent); font-size: 14px; }

/* ── Status bar ────────────────────────────────────────────── */
#status-bar {
  text-align: center; padding: 8px; font-size: 14px; font-weight: 600;
  background: var(--bg-panel); border-top: 1px solid #2a5a30;
  min-height: 38px; flex-shrink: 0; margin-right: 220px;
}

/* ── Overlay ───────────────────────────────────────────────── */
#overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.6); display: flex;
  justify-content: center; align-items: center;
}
#overlay.hidden { display: none; }
#overlay.overlay-upper {
  align-items: flex-start;
  padding-top: 50px;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,.7) 0%,
    rgba(0,0,0,.5) 50%,
    rgba(0,0,0,.15) 80%,
    transparent 100%
  );
}
#overlay-inner {
  background: var(--bg-panel); border-radius: 16px;
  padding: 32px 40px; max-width: 700px; width: 90%;
  box-shadow: 0 12px 48px rgba(0,0,0,.5); text-align: center;
  max-height: 85vh; overflow-y: auto;
}
#overlay-inner h2 {
  color: var(--accent); margin-bottom: 16px; letter-spacing: 2px;
}
#overlay-inner p { margin-bottom: 12px; }

/* Overlay buttons */
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.btn-call {
  background: var(--bg); color: var(--text); border: 2px solid #3a6b40;
  padding: 10px 20px; font-size: 16px; min-width: 60px;
}
.btn-call:hover { border-color: var(--accent); color: var(--accent); }
.btn-call.btn-mexico {
  background: var(--accent); color: #1a2e10; border-color: var(--accent);
}
.btn-call.btn-mexico:hover { background: var(--accent-hover); }
.btn-pass {
  background: transparent; color: var(--text-dim); border: 1px solid #555;
  padding: 10px 20px; font-size: 14px;
}
.btn-pass:hover { border-color: var(--danger); color: var(--danger); }

.btn-suit {
  background: var(--bg); color: var(--text); border: 2px solid #3a6b40;
  padding: 12px 24px; font-size: 18px;
}
.btn-suit:hover { border-color: var(--accent); color: var(--accent); }

.btn-primary {
  background: var(--accent); color: #1a2e10; padding: 12px 28px; font-size: 16px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* Talon exchange */
.talon-section { margin: 16px 0; }
.talon-section h3 { color: var(--accent); margin-bottom: 10px; font-size: 16px; }
.talon-cards, .exchange-hand {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
}
.exchange-hand .card-slot {
  cursor: pointer; transition: transform .15s; position: relative;
}
.exchange-hand .card-slot:hover { transform: translateY(-8px); }
.exchange-hand .card-slot.discard-selected {
  transform: translateY(-8px);
}
.exchange-hand .card-slot.discard-selected .card-img {
  box-shadow: 0 0 0 3px var(--danger);
  filter: brightness(.7);
}
.discard-badge {
  position: absolute; top: -8px; right: -8px;
  background: var(--danger); color: white; border-radius: 50%;
  width: 20px; height: 20px; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* Round summary */
.summary-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.summary-table th, .summary-table td {
  padding: 8px 12px; text-align: center; border-bottom: 1px solid #2a4a30;
}
.summary-table th { color: var(--accent); }

/* Game over */
.winner-name { font-size: 28px; color: var(--accent); font-weight: 700; margin: 12px 0; }
.final-scores { margin: 16px 0; }

/* ── Animation layer ──────────────────────────────────────── */
#anim-layer {
  position: fixed; inset: 0; z-index: 150;
  pointer-events: none;
}
#anim-layer.hidden { display: none; }

/* Deck pile shown during dealing */
.deal-deck {
  position: fixed; z-index: 149;
}
.deal-deck .card-back {
  position: absolute; top: 0; left: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}

/* Flying card (play animation) */
.flying-card {
  position: fixed; z-index: 200; pointer-events: none;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.5));
}

/* ── Scoreboard toggle (mobile only) ─────────────────────── */
#scoreboard-toggle {
  display: none;
  position: fixed; top: 10px; right: 10px; z-index: 250;
  background: var(--bg-panel); color: var(--accent);
  border: 1px solid var(--accent); padding: 4px 10px;
  font-size: 12px; font-weight: 700; letter-spacing: 1px;
  border-radius: 4px; cursor: pointer;
  transition: background .15s;
}
#scoreboard-toggle:hover {
  background: var(--accent); color: var(--bg-panel);
}

#scoreboard-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 199;
  background: rgba(0,0,0,.3);
}
#scoreboard-backdrop.open { display: block; }

/* ── Chat ─────────────────────────────────────────────────── */
#chat-toggle {
  position: fixed; top: 10px; left: 50px; z-index: 250;
  background: var(--bg-panel); color: var(--accent);
  border: 1px solid var(--accent); padding: 4px 10px;
  font-size: 12px; font-weight: 700; letter-spacing: 1px;
  border-radius: 4px; cursor: pointer;
  transition: background .15s;
}
#chat-toggle:hover { background: var(--accent); color: var(--bg-panel); }
#chat-badge {
  position: absolute; top: -4px; right: -4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
}
#chat-badge.hidden { display: none; }

#chat-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 255;
  background: rgba(0,0,0,.3);
}
#chat-backdrop.open { display: block; }

#chat-panel {
  position: fixed; left: 0; top: 0; bottom: 0; width: 260px;
  background: var(--bg-panel); border-right: 1px solid #2a5a30;
  display: none; flex-direction: column; z-index: 260;
  box-shadow: 4px 0 24px rgba(0,0,0,.5);
  border-radius: 0 16px 16px 0;
}
#chat-panel.open { display: flex; }

#chat-messages {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.chat-msg {
  font-size: 13px; line-height: 1.3;
  word-wrap: break-word; overflow-wrap: break-word;
}
.chat-msg .chat-name {
  font-weight: 700; color: var(--accent); margin-right: 6px;
}
.chat-msg.chat-system {
  color: var(--text-dim); font-style: italic; font-size: 12px;
}
.chat-msg.chat-system .suit-icon {
  width: 14px; height: 14px;
}

#chat-form {
  display: flex; gap: 6px; padding: 8px 12px;
  border-top: 1px solid #2a5a30;
}
#chat-input {
  flex: 1; padding: 6px 10px; border-radius: 6px;
  border: 1px solid #3a6b40; background: #1a3d22;
  color: var(--text); font-size: 13px; outline: none;
  min-width: 0;
}
#chat-input:focus { border-color: var(--accent); }
#chat-form button {
  background: var(--accent); color: var(--bg-dark);
  padding: 6px 12px; font-size: 14px; font-weight: 700;
}
#mic-btn {
  background: transparent; color: var(--text); border: 1px solid #3a6b40;
  padding: 6px 8px; font-size: 16px; line-height: 1;
}
#mic-btn::before { content: '\1F3A4'; }
#mic-btn.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: mic-pulse .8s infinite; }
#mic-btn.recording::before { content: none; }
@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* Voice messages */
.chat-voice { display: flex; align-items: center; gap: 6px; }
.voice-play-btn {
  width: 28px; height: 28px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: var(--bg-dark); font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0;
}
.voice-play-btn:hover { background: var(--accent-hover); }
.voice-duration { font-size: 12px; color: var(--text-dim); }

/* ── Mobile: tablets & landscape phones (≤768px) ─────────── */
@media (max-width: 768px) {
  :root {
    --card-w: 56px;
    --card-h: 88px;
  }

  /* Scoreboard: hidden by default, overlay when toggled open */
  #scoreboard-toggle { display: block; }
  #scoreboard {
    display: none;
    z-index: 200;
    width: 260px;
    border-radius: 16px 0 0 16px;
    box-shadow: -4px 0 24px rgba(0,0,0,.5);
  }
  #scoreboard.open { display: block; }

  /* Remove scoreboard margin from layout */
  #game-layout { margin-right: 0; }
  #status-bar { margin-right: 0; }

  /* Info bar compact */
  #info-bar {
    flex-wrap: wrap; gap: 8px 16px;
    font-size: 12px; padding: 6px 12px;
  }

  /* Opponents compact */
  #opponents { padding: 0 16px; }
  .opp { padding: 6px 12px; min-width: 120px; }
  .opp-name { font-size: 13px; }
  .opp-info { font-size: 11px; }
  .card-back { width: 24px; height: 38px; }

  /* Trick area */
  #trick-area { min-height: 140px; }
  #trick-opp-left   { left: calc(50% - 90px); }
  #trick-opp-center { left: calc(50% - 28px); }
  #trick-opp-right  { left: calc(50% + 20px); }

  /* Player hand */
  #player-hand .card-slot { margin-left: -18px; }
  #player-hand { padding: 0 20px; }
  #player-info { font-size: 12px; }

  /* Overlays compact */
  #overlay-inner {
    padding: 20px 24px; max-width: 95%; font-size: 14px;
  }
  #overlay-inner h2 { font-size: 20px; margin-bottom: 10px; }
  .btn-row { gap: 6px; }
  .btn-call { padding: 8px 14px; font-size: 14px; min-width: 48px; }
  .btn-suit { padding: 8px 16px; font-size: 16px; }

  /* Talon exchange cards */
  .exchange-hand .card-img,
  .talon-cards .card-img { width: 52px; height: 82px; }

  /* Login/lobby responsive */
  .login-box, .lobby-box { padding: 28px 24px; }
  .login-box h1 { font-size: 36px; letter-spacing: 6px; }
}

/* ── Mobile: small phones portrait (≤480px) ───────────────── */
@media (max-width: 480px) {
  :root {
    --card-w: 46px;
    --card-h: 72px;
  }

  .card-back { width: 20px; height: 32px; }

  #opponents { padding: 0 8px; }
  .opp { padding: 4px 8px; min-width: auto; gap: 4px; border-radius: 6px; }
  .opp-name { font-size: 11px; }
  .opp-info { font-size: 10px; }

  #trick-area { min-height: 100px; }
  #trick-opp-left   { left: calc(50% - 70px); }
  #trick-opp-center { left: calc(50% - 23px); }
  #trick-opp-right  { left: calc(50% + 10px); }

  #player-hand .card-slot { margin-left: -22px; }
  #player-hand { padding: 0 8px; }

  #overlay.overlay-upper { padding-top: 30px; }
  #overlay-inner { padding: 16px 16px; }
  #overlay-inner h2 { font-size: 18px; }
  .btn-call { padding: 6px 10px; font-size: 13px; min-width: 40px; }
  .btn-suit { padding: 6px 12px; font-size: 14px; }
  .btn-primary { padding: 10px 20px; font-size: 14px; }

  .exchange-hand .card-img,
  .talon-cards .card-img { width: 44px; height: 68px; }

  .login-box h1 { font-size: 28px; letter-spacing: 4px; }
  .login-box, .lobby-box { padding: 20px 16px; width: 90%; }
}

/* ── Landscape phones (short viewport) ────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --card-w: 50px;
    --card-h: 78px;
  }

  #info-bar { padding: 3px 12px; font-size: 11px; gap: 8px 14px; }
  #game-layout { padding: 6px 12px 2px; }
  #opponents { padding: 0 12px; }
  .opp { padding: 3px 8px; }
  .card-back { width: 20px; height: 32px; }

  #trick-area { min-height: 90px; }
  #trick-opp-left   { left: calc(50% - 80px); }
  #trick-opp-center { left: calc(50% - 25px); }
  #trick-opp-right  { left: calc(50% + 15px); }

  #player-area { padding-bottom: 2px; }
  #player-info { margin-bottom: 4px; font-size: 11px; }
  #player-hand .card-slot { margin-left: -20px; }

  #status-bar { padding: 3px; font-size: 12px; min-height: 24px; }

  #overlay.overlay-upper { padding-top: 10px; }
  #overlay-inner {
    padding: 12px 18px; max-height: 75vh; font-size: 13px;
  }
  #overlay-inner h2 { font-size: 16px; margin-bottom: 6px; }
  .btn-call { padding: 6px 10px; font-size: 13px; }
  .btn-suit { padding: 6px 12px; font-size: 14px; }
}
