:root {
  --felt: #0e3b2e;
  --felt-dark: #092720;
  --cream: #f3ecd9;
  --gold: #d3a45c;
  --ink: #1c1b17;
  --board-frame: #6b665e;
  --board-frame-dark: #55514a;
  --team-a: #2f6fed; /* Azul */
  --team-b: #c0392b; /* Rojo */
  --team-c: #2e9e6b; /* Verde */
  --team-d: #9b59b6; /* Morado */
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Georgia', 'Iowan Old Style', serif;
  background: radial-gradient(ellipse at top, var(--felt) 0%, var(--felt-dark) 75%);
  color: var(--cream);
  min-height: 100vh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 60px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
}

.screen { display: none; }
.screen.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.brand { text-align: center; margin-bottom: 28px; }
.brand h1 {
  font-family: 'Baskerville', Georgia, serif;
  font-size: 2.4rem;
  letter-spacing: 0.5px;
  margin: 0 0 6px;
  color: var(--cream);
}
.brand h1 span { color: var(--gold); }
.tagline { color: #c8c0a8; margin: 0; font-style: italic; }

.card-panel {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(211,164,92,0.3);
  border-radius: var(--radius);
  padding: 24px;
}

label { display:block; font-size: 0.85rem; color: var(--gold); margin-bottom: 6px; letter-spacing: 0.5px; text-transform: uppercase; }

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(211,164,92,0.4);
  background: rgba(255,255,255,0.9);
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 16px;
  font-family: inherit;
}

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 13px;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 0.3px;
  font-family: inherit;
}
.btn-primary { background: var(--gold); color: var(--felt-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary:not(:disabled):hover { filter: brightness(1.08); }
.btn-secondary { background: transparent; border: 1.5px solid var(--gold); color: var(--gold); }
.btn-secondary:hover { background: rgba(211,164,92,0.1); }

.btn-tiny {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(211,164,92,0.4);
  color: var(--cream);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}

.link-btn {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: var(--gold);
  text-decoration: underline;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}

.divider { text-align: center; margin: 18px 0; position: relative; color: #a89b78; font-size: 0.8rem; }
.divider::before, .divider::after {
  content: ""; position: absolute; top: 50%; width: 42%; height: 1px; background: rgba(211,164,92,0.25);
}
.divider::before { left: 0; } .divider::after { right: 0; }

.error-text { color: #ff8b8b; text-align: center; min-height: 20px; }

/* LOBBY */
.lobby-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.lobby-header h2 { margin: 0; }
#lobby-code { color: var(--gold); letter-spacing: 2px; }
.hint { color: #b9ae8d; font-size: 0.85rem; }

.team-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.team-card {
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255,255,255,0.04);
  border-left: 5px solid var(--team-color, var(--gold));
}
.team-card h3 { margin: 0 0 8px; font-size: 1rem; }
.slot { padding: 6px 8px; border-radius: 6px; background: rgba(255,255,255,0.06); margin-bottom: 6px; font-size: 0.9rem; display:flex; justify-content:space-between; align-items:center;}
.slot.empty { color: #8d846a; font-style: italic; cursor: pointer; border: 1px dashed rgba(211,164,92,0.4); }
.slot.you { outline: 2px solid var(--gold); }

/* GAME */
.game-topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.team-scores { display: flex; gap: 8px; flex-wrap: wrap; }
.score-chip { padding: 4px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: bold; color: white; }
.turn-indicator { font-weight: bold; color: var(--gold); flex: 1; text-align: center; min-width: 140px; }

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 2px;
  background: var(--board-frame);
  border: 5px solid var(--board-frame-dark);
  border-radius: 6px;
  padding: 5px;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 100%;
}
.board-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  letter-spacing: 0.3px;
  padding: 0 4px;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.legend-wild { color: #4fbf8b; }
.legend-remove { color: #e07a70; }
.cell {
  position: relative;
  background: #ffffff;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: clamp(9px, 4vw, 20px);
  cursor: default;
  aspect-ratio: 1/1;
  min-width: 0;
  min-height: 0;
  font-weight: 800;
  font-family: 'Georgia', serif;
  line-height: 1;
  padding: 1px;
  white-space: nowrap;
}
.cell.black-suit-cell { color: #191714; }
.cell.red-suit-cell { color: #b32c2c; }
.cell.free {
  background: #f1ede4;
  color: var(--board-frame-dark);
  font-size: clamp(7px, 2.6vw, 11px);
  font-weight: 800;
  letter-spacing: 0.5px;
  border: 2px dashed var(--board-frame);
  border-radius: 50%;
  width: 80%;
  height: 80%;
  margin: auto;
}
.cell.playable { outline: 2px solid var(--gold); outline-offset: -2px; cursor: pointer; box-shadow: 0 0 8px rgba(211,164,92,0.9); }
.cell.removable { cursor: pointer; box-shadow: 0 0 8px rgba(192,57,43,0.9); outline: 2px solid #c0392b; outline-offset: -2px; }
.cell.card-occupied { outline: 2px dashed #ffffff; outline-offset: -2px; }
.chip {
  position: absolute;
  width: 68%;
  height: 68%;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.25);
  box-shadow: inset 0 0 4px rgba(255,255,255,0.4);
}

/* Ficha que ya forma parte de una secuencia completa (protegida) */
.cell.seq-marked { box-shadow: 0 0 0 3px var(--seq-color, #d3a45c) inset; }
.cell.seq-marked .chip::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid #d3a45c;
}

/* Puntitos en las esquinas que participaron en alguna secuencia */
.seq-corner-dots {
  position: absolute;
  bottom: 3px;
  display: flex;
  gap: 2px;
  justify-content: center;
  width: 100%;
}
.seq-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1px solid white;
}

.hand-area { margin-top: 18px; text-align: center; }
.hand-label { color: var(--gold); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.last-move { color: #cfead9; font-size: 0.8rem; font-style: italic; margin-top: 8px; min-height: 1.2em; }
.hand { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.hand-card {
  width: 62px; min-height: 78px;
  background: var(--cream);
  border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  font-weight: bold; color: var(--ink);
  cursor: pointer;
  border: 2px solid transparent;
  font-size: 0.95rem;
  padding: 4px 2px;
  transition: transform .1s ease;
}
.hand-card.red-suit { color: #c0392b; }
.hand-card.selected { border-color: var(--gold); transform: translateY(-8px); }
.hand-card:hover { transform: translateY(-4px); }
.hand-card-rank { font-size: 1.1rem; }
.hand-card-label {
  font-size: 0.55rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  line-height: 1.1;
  padding: 2px 4px;
  border-radius: 4px;
  color: white;
}
.hand-card.jack-wild { background: #fdf6e3; }
.hand-card.jack-wild .hand-card-label { background: #2e9e6b; }
.hand-card.jack-remove { background: #fdf1f0; }
.hand-card.jack-remove .hand-card-label { background: #c0392b; }

.win-banner {
  position: fixed; inset: 0; background: rgba(9,39,32,0.92);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.win-banner.hidden { display: none; }
.win-content { text-align: center; }
.win-content h2 { color: var(--gold); font-size: 1.8rem; }
.win-content .btn-secondary { margin-top: 10px; }

.reopen-win {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  z-index: 40;
  background: var(--gold);
  color: var(--felt-dark);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.reopen-win.hidden { display: none; }

.history-list { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.history-item {
  background: rgba(255,255,255,0.04);
  border-left: 4px solid var(--gold);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: flex; justify-content: space-between;
}
.history-item .date { color: #a89b78; font-size: 0.8rem; }

@media (max-width: 480px) {
  .team-slots { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.9rem; }
}
