* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --felt: #1e6b41;
  --felt-dark: #14512f;
  --cream: #f7f1e3;
  --ink: #2b2b2b;
  --gold: #e0b23e;
  /* presupuesto vertical: 4 alturas de carta + textos + botones <= 100vh */
  --card-h: clamp(88px, 15.5vh, 200px);
  --card-w: calc(var(--card-h) * 0.6505);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  color: var(--cream);
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---------- Login ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.start-card {
  text-align: center;
  padding: 3rem 4rem;
  border: 2px solid var(--gold);
  border-radius: 16px;
  background: var(--felt-dark);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.start-card h1 {
  font-size: 2.6rem;
  letter-spacing: 0.3em;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.subtitle {
  opacity: 0.9;
  margin-bottom: 1.6rem;
}

#google-btn {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.login-divider {
  margin: 0.9rem 0;
  font-size: 0.8rem;
  opacity: 0.5;
}

#login-form {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
}

#login-name {
  font-family: inherit;
  font-size: 1.05rem;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--cream);
  color: var(--ink);
  width: 220px;
}

#login-name:focus {
  outline: none;
  border-color: var(--gold);
}

.error-msg {
  color: #f0a89f;
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 0.8rem;
}

.credit {
  font-size: 0.7rem;
  opacity: 0.55;
  margin-top: 1.6rem;
}

.credit a {
  color: var(--gold);
}

/* ---------- La plaza ---------- */

#lobby-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.lobby-help {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  opacity: 0.75;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.4rem 1rem;
  border-radius: 10px;
}

.lobby-hint {
  position: fixed;
  bottom: 4rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gold);
  color: var(--ink);
  font-weight: 700;
  padding: 0.55rem 1.3rem;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.lobby-toast {
  position: fixed;
  top: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--gold);
  padding: 0.55rem 1.3rem;
  border-radius: 12px;
  font-weight: 600;
}

/* ---------- Modales ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 18, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.modal-card {
  text-align: center;
  background: var(--felt-dark);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 1.8rem 2.4rem;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
}

.modal-card p,
.modal-card h2 {
  margin-bottom: 1.1rem;
}

.modal-card h2 {
  color: var(--gold);
}

#rematch-status {
  margin-top: 0.9rem;
  margin-bottom: 0;
  font-size: 0.85rem;
  opacity: 0.75;
  min-height: 1.2em;
}

/* ---------- Mesa de truco ---------- */

#table {
  display: grid;
  grid-template-columns: 130px 1fr 260px;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    'score ai     log'
    'score board  log'
    'score player log'
    'score actions log';
  height: 100dvh;
  padding: 0.8rem;
  gap: 0.5rem;
}

#scoreboard {
  grid-area: score;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 1rem 0.5rem;
}

.score-label {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fosforos {
  display: block;
  margin: 0.3rem auto 0;
}

.score-mini {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
}

.score-stage {
  font-size: 0.7rem;
  font-style: italic;
  font-weight: 400;
  opacity: 0.7;
}

.score-target {
  font-size: 0.8rem;
  opacity: 0.5;
}

/* ---------- Voz (flotante, compartida entre juegos) ---------- */

#voice-panel {
  position: fixed;
  left: 0.8rem;
  bottom: 0.8rem;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  padding: 0.5rem;
  width: 130px;
}

.btn-voice {
  background: #9b8ec4;
  font-size: 0.8rem;
  padding: 0.45rem 0.8rem;
  width: 100%;
}

#voice-status {
  font-size: 0.68rem;
  opacity: 0.75;
  min-height: 1em;
  text-align: center;
}

/* ---------- Chinchón ---------- */

#table-chinchon {
  display: grid;
  grid-template-columns: 130px 1fr 260px;
  grid-template-areas: 'side main log';
  height: 100dvh;
  padding: 0.8rem;
  gap: 0.5rem;
}

#table-chinchon.hidden {
  display: none;
}

#ch-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 1rem 0.5rem;
}

.ch-score {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
}

.ch-leftover {
  font-size: 0.7rem;
  opacity: 0.7;
}

#ch-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  padding: 0.3rem 0;
}

#ch-log {
  grid-area: log;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 0.8rem;
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.45;
}

.hand-small .card {
  width: calc(var(--card-w) * 0.72);
  height: calc(var(--card-h) * 0.72);
}

#ch-center {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
}

.ch-pile-cards {
  min-height: var(--card-h);
  min-width: var(--card-w);
}

.ch-pile-label {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  opacity: 0.75;
}

#ch-actions {
  min-height: 44px;
  margin-top: 0.3rem;
}

#ch-hint {
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--gold);
  font-weight: 600;
}

.card.selected {
  transform: translateY(-14px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.5), 0 0 0 3px #7fb3d5;
}

@media (max-width: 900px) {
  #table-chinchon {
    grid-template-columns: 100px 1fr;
    grid-template-areas: 'side main';
  }

  #ch-log {
    display: none;
  }
}

/* ---------- Jugadores ---------- */

#ai-area {
  grid-area: ai;
  text-align: center;
  position: relative;
  padding-top: 0.3rem;
}

#player-area {
  grid-area: player;
  text-align: center;
  position: relative;
}

.player-tag {
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  opacity: 0.8;
  margin: 0.4rem 0;
}

.mano-chip {
  background: var(--gold);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.1rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  margin-left: 0.4rem;
}

.hand {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  min-height: calc(var(--card-h) + 4px);
}

/* ---------- Cartas ---------- */

.card {
  width: var(--card-w);
  height: var(--card-h);
  background: var(--cream);
  border-radius: calc(var(--card-h) * 0.055);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card.playable {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card.playable:hover {
  transform: translateY(-12px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.5), 0 0 0 3px var(--gold);
}

/* ---------- Mesa central ---------- */

#board {
  grid-area: board;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2rem;
}

.trick {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.4rem;
  border-radius: 12px;
  border: 2px dashed transparent;
  transition: border-color 0.3s;
}

.trick-current {
  border-color: rgba(247, 241, 227, 0.35);
}

.trick-won {
  background: rgba(224, 178, 62, 0.14);
}

.trick-lost {
  background: rgba(0, 0, 0, 0.18);
}

.slot {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-h) * 0.055);
  background: rgba(0, 0, 0, 0.12);
}

/* ---------- Globos ---------- */

.bubble {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: -0.2rem;
  background: var(--cream);
  color: var(--ink);
  font-weight: 800;
  padding: 0.5rem 1.1rem;
  border-radius: 18px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
  white-space: nowrap;
}

#ai-area .bubble {
  top: auto;
  bottom: -1.2rem;
}

#player-area .bubble {
  top: -2.4rem;
}

.bubble.pop {
  animation: pop 0.25s ease;
}

@keyframes pop {
  0% {
    transform: translateX(-50%) scale(0.5);
  }
  70% {
    transform: translateX(-50%) scale(1.12);
  }
  100% {
    transform: translateX(-50%) scale(1);
  }
}

/* ---------- Acciones ---------- */

#actions {
  grid-area: actions;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.1s, filter 0.1s;
}

.btn:hover {
  filter: brightness(1.05);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn-big {
  font-size: 1.05rem;
  padding: 0.7rem 1.6rem;
  background: var(--gold);
}

.btn-envido {
  background: #7fb3d5;
}

.btn-truco {
  background: var(--gold);
}

.btn-mazo {
  background: #b0a08c;
}

.btn-si {
  background: #82c98c;
}

.btn-no {
  background: #d98a80;
}

#response-panel {
  text-align: center;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 0.7rem 1.2rem;
}

#response-question {
  font-weight: 700;
  margin-bottom: 0.6rem;
  color: var(--gold);
}

/* ---------- Registro ---------- */

#log {
  grid-area: log;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 0.8rem;
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.45;
}

.log-entry {
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  opacity: 0.9;
}

.log-entry:first-child {
  color: var(--gold);
}

/* ---------- Pantallas bajas (notebooks) ---------- */

@media (max-height: 820px) {
  #table {
    padding: 0.4rem;
    gap: 0.25rem;
  }

  .player-tag {
    margin: 0.15rem 0;
    font-size: 0.7rem;
  }

  .trick {
    gap: 0.35rem;
    padding: 0.3rem;
  }

  #actions {
    min-height: 52px;
  }

  .btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.9rem;
  }

  #response-panel {
    padding: 0.45rem 0.9rem;
  }

  #response-question {
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
  }

  #scoreboard {
    gap: 0.5rem;
    padding: 0.6rem 0.4rem;
  }

  .hand {
    gap: 0.45rem;
  }
}

/* ---------- Pantallas chicas ---------- */

@media (max-width: 900px) {
  #table {
    grid-template-columns: 100px 1fr;
    grid-template-areas:
      'score ai'
      'score board'
      'score player'
      'score actions';
  }

  #log {
    display: none;
  }
}
