:root {
  --bg-page: #181411;
  --bg-surface: #231d18;
  --bg-card: #2c241d;
  --border-subtle: #44372c;
  --text-main: #f5ede2;
  --text-muted: #c2b29f;
  --accent-gold: #dfb15b;
  --accent-gold-hover: #ecc271;
  --accent-crimson: #c93b2b;
  --accent-jade: #2e8b67;

  /* Shōgiban & Koma (Madera Kaya tradicional) */
  --wood-board-light: #e2b874;
  --wood-board-dark: #cfa058;
  --wood-frame: #5c3e23;
  --grid-line: #3b2816;
  --koma-top: #f7deb0;
  --koma-bottom: #dfb573;
  --koma-edge: #9b6f34;
  --koma-ink: #1e130a;
  --koma-promoted: #b82318;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-block-size: 100dvb;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: radial-gradient(circle at 50% 15%, #2b221b 0%, var(--bg-page) 80%);
  color: var(--text-main);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.75rem;
  padding-inline: 1.5rem;
  background: rgba(28, 22, 18, 0.92);
  border-block-end: 1px solid var(--border-subtle);
}

.brand {
  display: flex;
  align-items: safe center;
  gap: 0.85rem;
}

.brand-koma {
  display: grid;
  place-content: center;
  inline-size: 2.6rem;
  block-size: 2.8rem;
  background: linear-gradient(180deg, var(--koma-top), var(--koma-bottom));
  color: var(--koma-ink);
  font-weight: 800;
  font-size: 1.35rem;
  clip-path: polygon(50% 4%, 93% 22%, 86% 96%, 14% 96%, 7% 22%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.brand h1 span {
  color: var(--accent-gold);
  font-weight: 500;
  margin-inline-start: 0.35rem;
}

.subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.room-bar {
  display: flex;
  flex-wrap: wrap;
  flex-wrap: balance;
  align-items: safe center;
  gap: 0.55rem;
}

.room-pill,
.online-pill {
  display: flex;
  align-items: safe center;
  gap: 0.5rem;
  padding-block: 0.35rem;
  padding-inline: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  font-size: 0.86rem;
  white-space: nowrap;
}

.status-dot {
  inline-size: 0.6rem;
  block-size: 0.6rem;
  border-radius: 50%;
  background: #888;
}

.status-dot.online {
  background: #39d98a;
  box-shadow: 0 0 8px #39d98a;
}

.room-pill code {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-gold);
  letter-spacing: 0.08em;
}

.role-badge {
  padding-block: 0.12rem;
  padding-inline: 0.55rem;
  border-radius: 999px;
  background: rgba(223, 177, 91, 0.16);
  color: var(--accent-gold);
  font-size: 0.78rem;
  font-weight: 600;
}

/* Control de Música Zen Relajante (WCAG 1.4.2 Audio Control) */
.audio-control-pill {
  display: inline-flex;
  align-items: safe center;
  gap: 0.45rem;
  padding-block: 0.25rem;
  padding-inline: 0.45rem 0.65rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
}

.audio-control-pill.playing {
  border-color: #39d98a;
  box-shadow: 0 0 10px rgba(57, 217, 138, 0.22);
}

.btn-audio-toggle {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.2rem 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.audio-control-pill.playing .btn-audio-toggle {
  color: #6ee7b7;
}

.music-volume-slider {
  inline-size: 4.2rem;
  accent-color: var(--accent-gold);
  cursor: pointer;
}

/* ==========================================
   VISTA 1: LOBBY DE EMPAREJAMIENTO Y SALAS
   ========================================== */
.lobby-page {
  max-inline-size: 1240px;
  margin-inline: auto;
  padding-block: 1.5rem;
  padding-inline: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.lobby-hero {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

.hero-profile,
.matchmake-card,
.lobby-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 1.2rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
}

.profile-input-row {
  display: flex;
  align-items: safe center;
  gap: 0.65rem;
  margin-block-start: 0.35rem;
}

.profile-input-row .text-input {
  margin-block-end: 0;
}

.matchmake-card {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 1.25rem;
  background: linear-gradient(135deg, rgba(223, 177, 91, 0.14) 0%, var(--bg-card) 75%);
  border-color: rgba(223, 177, 91, 0.45);
}

.matchmake-card.searching {
  border-color: #39d98a;
  box-shadow: 0 0 0 2px rgba(57, 217, 138, 0.25), 0 10px 28px rgba(0, 0, 0, 0.45);
}

.matchmake-info {
  flex: 1 1 300px;
}

.matchmake-info h2 {
  margin: 0 0 0.3rem 0;
  font-size: 1.2rem;
  color: var(--accent-gold);
}

.matchmake-info p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.matchmake-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  gap: 0.85rem;
}

.queue-badge {
  padding-block: 0.3rem;
  padding-inline: 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.btn-lg {
  padding-block: 0.7rem;
  padding-inline: 1.35rem;
  font-size: 0.98rem;
}

.lobby-columns {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

.lobby-side-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel-header {
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-end: 0.9rem;
}

.panel-header h2,
.lobby-panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-block-size: 420px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.compact-list {
  max-block-size: 230px;
}

.room-row {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: border-color 0.15s ease;
}

.room-row:hover {
  border-color: var(--accent-gold);
}

.room-row-info {
  min-inline-size: 0;
  flex: 1 1 200px;
}

.room-row-title {
  display: flex;
  align-items: safe center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 0.96rem;
  margin-block-end: 0.25rem;
}

.room-row-title code {
  font-size: 0.78rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: rgba(223, 177, 91, 0.15);
  color: var(--accent-gold);
}

.room-row-players {
  font-size: 0.83rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.seat-open {
  color: #39d98a;
  font-weight: 600;
}

.empty-state {
  margin: 0;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  background: rgba(0, 0, 0, 0.16);
  border-radius: 8px;
}

.code-join-row {
  display: flex;
  gap: 0.5rem;
  margin-block-start: 0.65rem;
}

.code-join-row .text-input {
  margin-block-end: 0;
  flex: 1 1 auto;
}

.players-online-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.player-chip {
  display: inline-flex;
  align-items: safe center;
  gap: 0.4rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
}

.player-chip.searching {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* Tarjeta Academia / Partida Prearmada en el Lobby */
.tutorial-banner-card {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.35rem 1.5rem;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(46, 139, 103, 0.22) 0%, var(--bg-card) 80%);
  border: 1px solid rgba(57, 217, 138, 0.42);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
}

.tutorial-banner-info {
  flex: 1 1 520px;
}

.tutorial-tag {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(57, 217, 138, 0.16);
  color: #6ee7b7;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-block-end: 0.45rem;
}

.tutorial-banner-info h2 {
  margin: 0 0 0.4rem 0;
  font-size: 1.22rem;
  color: var(--text-main);
}

.tutorial-banner-info p {
  margin: 0 0 0.85rem 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.tutorial-chapters-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chapter-pill {
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(223, 177, 91, 0.4);
  background: rgba(24, 20, 17, 0.65);
  color: var(--accent-gold);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.chapter-pill:hover {
  background: rgba(223, 177, 91, 0.22);
  transform: translateY(-1px);
}

/* Panel del Sensei en la Partida Guiada */
.sensei-panel {
  inline-size: 100%;
  max-inline-size: 720px;
  background: linear-gradient(145deg, #243028, #1b231e);
  border: 2px solid #39d98a;
  border-radius: 12px;
  padding: 1.05rem 1.25rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}

.sensei-header {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-block-end: 0.75rem;
}

.sensei-badge {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: #39d98a;
  color: #102419;
  font-size: 0.78rem;
  font-weight: 800;
}

.sensei-header h2 {
  margin: 0;
  font-size: 1.12rem;
  color: #a7f3d0;
  flex: 1 1 auto;
}

.sensei-select {
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(57, 217, 138, 0.45);
  background: #141c17;
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.sensei-progress {
  inline-size: 100%;
  block-size: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: clip;
  margin-block-start: 0.2rem;
}

.sensei-progress-fill {
  inline-size: var(--progress, 8%);
  block-size: 100%;
  background: linear-gradient(90deg, #39d98a, var(--accent-gold));
  transition: inline-size 0.3s ease;
}

.sensei-body-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  margin-block-end: 0.8rem;
}

.sensei-lesson-text {
  margin: 0 0 0.55rem 0;
  font-size: 0.92rem;
  color: var(--text-main);
  line-height: 1.5;
}

.sensei-key-points {
  margin: 0;
  padding-inline-start: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.84rem;
  color: #d1fae5;
}

.sensei-key-points li strong {
  color: var(--accent-gold);
}

/* Brújula Visual de Movimiento (Mini-Tablero 3x3 / 5x5) */
.sensei-diagrams {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.move-diagram-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  background: rgba(15, 20, 17, 0.78);
  border: 1px solid rgba(223, 177, 91, 0.4);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
}

.move-diagram-title {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
}

.move-compass {
  display: grid;
  grid-template-columns: repeat(3, 1.85rem);
  grid-template-rows: repeat(3, 1.85rem);
  gap: 2px;
  background: #3b2816;
  border: 2px solid #6b4c2b;
  border-radius: 6px;
  padding: 2px;
}

.move-compass.compass-5x5 {
  grid-template-columns: repeat(5, 1.45rem);
  grid-template-rows: repeat(5, 1.45rem);
}

.compass-cell {
  display: grid;
  place-content: center;
  background: #dec089;
  color: #24160b;
  font-size: 0.78rem;
  font-weight: 900;
  border-radius: 2px;
}

.compass-cell.center-piece {
  background: #f59e0b;
  color: #1a1007;
  font-size: 0.88rem;
  box-shadow: inset 0 0 0 1px #78350f;
}

.compass-cell.step-one {
  background: #39d98a;
  color: #072415;
}

.compass-cell.step-ray {
  background: #38bdf8;
  color: #082f49;
}

.compass-cell.step-jump {
  background: #a855f7;
  color: #fff;
}

.compass-cell.step-forbidden {
  background: rgba(201, 59, 43, 0.25);
  color: #991b1b;
  font-size: 0.68rem;
}

.move-diagram-legend {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
}

.sensei-objective {
  margin: 0 0 0.8rem 0;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  background: rgba(223, 177, 91, 0.18);
  border-inline-start: 4px solid var(--accent-gold);
  font-size: 0.9rem;
  font-weight: 700;
  color: #fde68a;
}

.sensei-objective.completed {
  background: rgba(57, 217, 138, 0.22);
  border-inline-start-color: #39d98a;
  color: #a7f3d0;
}

.sensei-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
}

@media (max-width: 680px) {
  .sensei-body-grid {
    grid-template-columns: 1fr;
  }
}

/* Resaltados guiados en el tablero y reserva */
.board-cell.tutorial-origin,
.hand-piece-btn.tutorial-origin {
  box-shadow: inset 0 0 0 3px #f59e0b, 0 0 14px rgba(245, 158, 11, 0.75);
  animation: pulse-tut-origin 1.1s infinite alternate;
}

.board-cell.tutorial-target {
  background: rgba(57, 217, 138, 0.36);
  box-shadow: inset 0 0 0 3px #39d98a;
}

@keyframes pulse-tut-origin {
  from {
    box-shadow: inset 0 0 0 3px #f59e0b, 0 0 6px rgba(245, 158, 11, 0.45);
  }
  to {
    box-shadow: inset 0 0 0 4px #fbbf24, 0 0 16px rgba(251, 191, 36, 0.9);
  }
}

/* ==========================================
   VISTA 2: ARENA DE JUEGO (TABLERO 9x9)
   ========================================== */
.arena {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(560px, 740px) minmax(250px, 300px);
  grid-template-areas: "left board right";
  justify-content: center;
  align-items: start;
  gap: 1.35rem;
  padding-block: 1rem;
  padding-inline: 1.25rem;
  max-inline-size: 1480px;
  margin-inline: auto;
  inline-size: 100%;
}

.side-left {
  grid-area: left;
}

.board-stage {
  grid-area: board;
  display: flex;
  flex-direction: column;
  align-items: safe center;
  gap: 0.65rem;
}

.side-right {
  grid-area: right;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Tarjetas de Jugador y Komadai */
.player-card,
.match-card,
.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.player-card.active-turn {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 2px rgba(223, 177, 91, 0.3), 0 8px 24px rgba(0, 0, 0, 0.45);
}

.player-header {
  display: flex;
  align-items: safe center;
  gap: 0.75rem;
  margin-block-end: 0.85rem;
}

.player-symbol {
  font-size: 1.65rem;
  line-height: 1;
  color: var(--accent-gold);
}

.player-meta {
  min-inline-size: 0;
  flex: 1 1 auto;
}

.player-meta h2 {
  margin: 0;
  font-size: 1.02rem;
}

.player-name {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  overflow: clip;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.turn-tag {
  margin-inline-start: auto;
  padding-block: 0.2rem;
  padding-inline: 0.6rem;
  border-radius: 999px;
  background: var(--accent-gold);
  color: #1c140d;
  font-size: 0.76rem;
  font-weight: 700;
}

.komadai {
  background: linear-gradient(145deg, #4b331d, #382514);
  border: 2px solid #6b4c2b;
  border-radius: 10px;
  padding: 0.65rem;
  min-block-size: 122px;
}

.komadai-title {
  margin: 0 0 0.5rem 0;
  font-size: 0.76rem;
  color: #e4c9a0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.komadai-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-block-size: 68px;
  align-items: safe center;
}

.komadai-empty {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(245, 237, 226, 0.5);
  font-style: italic;
}

.hand-piece-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: safe center;
  justify-content: center;
  inline-size: 4.1rem;
  block-size: 4.4rem;
  padding: 0.15rem;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.hand-piece-btn:hover:not(:disabled) {
  transform: translateY(-3px);
}

.hand-piece-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.hand-piece-btn.selected .koma-tile {
  box-shadow: 0 0 0 3px var(--accent-jade), 0 6px 12px rgba(0, 0, 0, 0.5);
}

.hand-count {
  position: absolute;
  inset-block-start: -4px;
  inset-inline-end: -4px;
  background: var(--accent-crimson);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  min-inline-size: 1.25rem;
  block-size: 1.25rem;
  border-radius: 999px;
  display: grid;
  place-content: center;
  padding-inline: 0.25rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Shōgiban (Tablero 9x9) */
.shogiban-frame {
  inline-size: 100%;
  max-inline-size: 720px;
  background: linear-gradient(145deg, var(--wood-board-light), var(--wood-board-dark));
  border: 6px solid var(--wood-frame);
  border-radius: 10px;
  padding: 0.65rem 0.75rem 0.85rem 0.85rem;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.65),
    inset 0 0 24px rgba(92, 62, 35, 0.35);
}

.col-coords {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  margin-inline-end: 2.3rem;
  margin-block-end: 0.35rem;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: #3b2816;
}

.board-with-rows {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.3rem;
  align-items: stretch;
}

.row-coords {
  display: grid;
  grid-template-rows: repeat(9, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: #3b2816;
  padding-inline-start: 0.45rem;
}

.row-coords span {
  display: inline-flex;
  align-items: baseline;
  gap: 0.18rem;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  aspect-ratio: 1 / 1.04;
  border: 2px solid var(--grid-line);
  background: rgba(59, 40, 22, 0.08);
  position: relative;
}

.board-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-inline-size: 0;
  min-block-size: 0;
  border: 1px solid rgba(59, 40, 22, 0.65);
  background: transparent;
  padding: 1px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.12s ease;
}

.board-cell:hover {
  background: rgba(255, 255, 255, 0.18);
}

.board-cell:focus-visible {
  outline: 3px solid #1b5e20;
  outline-offset: -3px;
  z-index: 2;
}

.board-cell.selected {
  background: rgba(46, 139, 103, 0.36);
}

.board-cell.last-move {
  background: rgba(223, 177, 91, 0.38);
}

.board-cell.king-in-check {
  background: rgba(201, 59, 43, 0.48);
  animation: pulse-check 1.2s infinite alternate;
}

@keyframes pulse-check {
  from {
    background: rgba(201, 59, 43, 0.35);
  }
  to {
    background: rgba(201, 59, 43, 0.65);
  }
}

.board-cell.hoshi::after {
  content: "";
  position: absolute;
  inset-block-end: -4px;
  inset-inline-end: -4px;
  inline-size: 7px;
  block-size: 7px;
  border-radius: 50%;
  background: var(--grid-line);
  pointer-events: none;
  z-index: 2;
}

.board-cell.legal-target::before {
  content: "";
  position: absolute;
  inline-size: 32%;
  block-size: 32%;
  border-radius: 50%;
  background: rgba(28, 126, 86, 0.82);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45);
  pointer-events: none;
  z-index: 3;
}

.board-cell.legal-capture::before {
  inline-size: 86%;
  block-size: 86%;
  background: transparent;
  border: 3px solid rgba(201, 59, 43, 0.88);
  box-shadow: none;
}

/* Ficha Pentagonal Tradicional Grande y Legible (Koma) */
.koma-tile {
  inline-size: 95%;
  block-size: 95%;
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  align-items: safe center;
  justify-content: center;
  gap: 2px;
  background: linear-gradient(180deg, #faebd0 0%, #e4bc7a 100%);
  color: #1a1007;
  /* Pentágono ancho que apunta hacia arriba */
  clip-path: polygon(50% 2%, 97% 17%, 93% 97%, 7% 97%, 3% 17%);
  filter: drop-shadow(0 2px 3px rgba(25, 15, 5, 0.6));
  padding-block-start: 0.35rem;
  padding-block-end: 0.15rem;
  padding-inline: 0.15rem;
  position: relative;
}

.koma-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: inherit;
  border-block-end: 3px solid #8c5f26;
  pointer-events: none;
}

/* Pieza que apunta hacia abajo (Rival): giramos la silueta pentagonal pero NO el texto en español */
.koma-tile.points-down {
  background: linear-gradient(180deg, #e0b775 0%, #f5dfba 100%);
  clip-path: polygon(7% 3%, 93% 3%, 97% 83%, 50% 98%, 3% 83%);
  padding-block-start: 0.15rem;
  padding-block-end: 0.4rem;
}

.koma-tile.points-down::before {
  border-block-end: none;
  border-block-start: 3px solid #754d1b;
}

.koma-tile.promoted {
  background: linear-gradient(180deg, #fff1d0 0%, #eab965 100%);
  color: #b91c1c;
}

.koma-tile.promoted::before {
  border-color: #b91c1c;
}

.koma-top-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.22rem;
  line-height: 1;
}

.koma-kanji {
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "MS PMincho", "Noto Serif JP", serif;
  font-weight: 900;
  font-size: clamp(1rem, 1.8vw, 1.32rem);
  line-height: 1;
}

.koma-code {
  font-size: clamp(0.64rem, 1.05vw, 0.78rem);
  font-weight: 800;
  padding: 0.06rem 0.24rem;
  border-radius: 4px;
  background: rgba(26, 16, 7, 0.12);
  color: inherit;
  line-height: 1.05;
}

.koma-tile.promoted .koma-code {
  background: #b91c1c;
  color: #fff8eb;
}

.koma-sub {
  inline-size: 94%;
  font-size: clamp(0.5rem, 0.85vw, 0.64rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  text-align: center;
}

.koma-tile.promoted .koma-sub {
  color: #991b1b;
}

.board-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  max-inline-size: 54ch;
}

/* Estado de la Partida e Invitación */
.match-card h2,
.history-card h2 {
  margin: 0 0 0.65rem 0;
  font-size: 1rem;
}

.turn-banner {
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  background: rgba(223, 177, 91, 0.14);
  border: 1px solid rgba(223, 177, 91, 0.35);
  font-weight: 600;
  font-size: 0.92rem;
  margin-block-end: 0.65rem;
}

.turn-banner.winner {
  background: rgba(46, 139, 103, 0.25);
  border-color: #39d98a;
  color: #a7f3d0;
}

.check-alert {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(201, 59, 43, 0.25);
  border: 1px solid var(--accent-crimson);
  color: #fecaca;
  font-weight: 700;
  font-size: 0.88rem;
  margin-block-end: 0.65rem;
}

.invite-callout {
  background: var(--bg-surface);
  border: 1px dashed var(--accent-gold);
  border-radius: 8px;
  padding: 0.65rem;
  margin-block-end: 0.75rem;
  font-size: 0.82rem;
}

.invite-callout p {
  margin: 0 0 0.45rem 0;
  color: var(--text-muted);
}

.invite-row {
  display: flex;
  gap: 0.4rem;
}

.invite-row input {
  flex: 1 1 auto;
  min-inline-size: 0;
  padding: 0.38rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: #14100d;
  color: var(--accent-gold);
  font-size: 0.8rem;
}

.match-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Historial de Jugadas */
.history-header {
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  margin-block-end: 0.5rem;
}

.move-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.history-list {
  margin: 0;
  padding-inline-start: 1.25rem;
  max-block-size: 240px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  font-size: 0.84rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.history-list li {
  color: var(--text-main);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

/* Botones */
.btn {
  padding-block: 0.45rem;
  padding-inline: 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #352b22;
  border-color: var(--accent-gold);
}

.btn-primary {
  background: var(--accent-gold);
  color: #1b130c;
  border-color: var(--accent-gold);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-gold-hover);
}

.btn-accent {
  background: rgba(223, 177, 91, 0.18);
  color: var(--accent-gold);
  border-color: rgba(223, 177, 91, 0.5);
}

.btn-danger {
  background: rgba(201, 59, 43, 0.18);
  color: #fca5a5;
  border-color: rgba(201, 59, 43, 0.45);
}

.btn-block {
  inline-size: 100%;
  margin-block-start: 0.75rem;
  padding-block: 0.65rem;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  inline-size: 2rem;
  block-size: 2rem;
  border-radius: 6px;
  cursor: pointer;
}

/* Native <dialog> Modals */
dialog {
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background: var(--bg-card);
  color: var(--text-main);
  max-inline-size: min(560px, 94dvw);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(10, 8, 6, 0.75);
  backdrop-filter: blur(3px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-box {
  padding: 1.35rem;
}

.dialog-compact {
  max-inline-size: 420px;
  text-align: center;
}

.dialog-wide {
  max-inline-size: min(860px, 95dvw);
}

.dialog-header {
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  gap: 1rem;
  margin-block-end: 1rem;
  padding-block-end: 0.75rem;
  border-block-end: 1px solid var(--border-subtle);
}

.dialog-header h1,
.dialog-compact h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--accent-gold);
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-block-end: 0.3rem;
}

.text-input {
  inline-size: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #14100d;
  color: var(--text-main);
  font-size: 0.92rem;
  margin-block-end: 0.75rem;
}

.code-input {
  text-transform: uppercase;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1rem;
  letter-spacing: 0.14em;
  text-align: center;
}

.choice-fieldset {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.65rem;
  margin: 0 0 0.75rem 0;
}

.choice-fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding-inline: 0.35rem;
}

.radio-card {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.86rem;
}

.radio-card span {
  display: flex;
  flex-direction: column;
}

.radio-card small {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.radio-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.radio-pill {
  display: flex;
  align-items: safe center;
  gap: 0.35rem;
  font-size: 0.84rem;
  cursor: pointer;
}

.dialog-error {
  margin: 0.6rem 0 0 0;
  color: #fca5a5;
  font-size: 0.84rem;
}

.promote-preview {
  display: flex;
  align-items: safe center;
  justify-content: center;
  gap: 1.25rem;
  margin-block: 1rem;
}

.promote-preview .preview-koma {
  inline-size: 4.4rem;
  block-size: 4.8rem;
}

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

/* Glosario */
.pieces-guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
  margin-block-end: 1.1rem;
}

.guide-card {
  display: flex;
  gap: 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 0.75rem;
}

.guide-koma {
  flex: 0 0 3.3rem;
  block-size: 3.7rem;
  background: linear-gradient(180deg, var(--koma-top), var(--koma-bottom));
  color: var(--koma-ink);
  clip-path: polygon(50% 4%, 93% 21%, 86% 96%, 14% 96%, 7% 21%);
  display: flex;
  flex-direction: column;
  align-items: safe center;
  justify-content: center;
  font-weight: 800;
}

.guide-koma small {
  font-size: 0.56rem;
}

.guide-card h2 {
  margin: 0 0 0.25rem 0;
  font-size: 0.92rem;
  color: var(--accent-gold);
}

.guide-card p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rules-notes h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
  color: var(--accent-gold);
}

.rules-notes ul {
  margin: 0;
  padding-inline-start: 1.2rem;
  font-size: 0.84rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Sección Editorial / SEO en el Lobby */
.seo-editorial-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 1.4rem 1.5rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
}

.seo-editorial-section h2 {
  margin: 0 0 1rem 0;
  font-size: 1.15rem;
  color: var(--accent-gold);
}

.seo-editorial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.15rem;
}

.seo-article-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.seo-article-card h3 {
  margin: 0 0 0.45rem 0;
  font-size: 0.96rem;
  color: var(--text-main);
}

.seo-article-card p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* Footer Completo estilo Radar Black Mesa (AdSense & Indexado) */
.site-footer {
  inline-size: 100%;
  border-block-start: 1px solid var(--border-subtle);
  background: rgba(20, 16, 13, 0.95);
  margin-block-start: 2.5rem;
  padding-block: 2.25rem 2.75rem;
  padding-inline: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.site-footer-inner {
  max-inline-size: 1400px;
  margin-inline: auto;
}

.site-footer-top {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block-end: 1.5rem;
  border-block-end: 1px solid rgba(68, 55, 44, 0.65);
}

.site-footer-brand {
  max-inline-size: 480px;
}

.site-footer-logo {
  display: flex;
  align-items: safe center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 0.98rem;
  color: var(--text-main);
  margin-block-end: 0.45rem;
}

.footer-koma-icon {
  display: inline-grid;
  place-content: center;
  inline-size: 1.65rem;
  block-size: 1.75rem;
  background: linear-gradient(180deg, var(--koma-top), var(--koma-bottom));
  color: var(--koma-ink);
  font-weight: 900;
  font-size: 0.88rem;
  clip-path: polygon(50% 4%, 93% 21%, 86% 96%, 14% 96%, 7% 21%);
}

.site-footer-brand p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.site-footer-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  gap: 1.35rem;
  font-weight: 600;
  font-size: 0.84rem;
}

.site-footer-nav a,
.site-footer-bottom a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.site-footer-nav a:hover,
.site-footer-bottom a:hover,
.footer-link-btn:hover {
  color: var(--accent-gold);
  text-decoration: underline;
}

.footer-link-btn {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
}

.bug-textarea {
  resize: vertical;
  min-block-size: 96px;
  font-family: inherit;
}

.bug-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bug-external-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.bug-external-links a {
  flex: 1 1 160px;
  text-align: center;
  text-decoration: none;
}

.bug-success {
  margin: 0.75rem 0 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: rgba(57, 217, 138, 0.2);
  border: 1px solid #39d98a;
  color: #a7f3d0;
  font-size: 0.86rem;
  font-weight: 600;
}

.site-footer-bottom {
  padding-block-start: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: safe center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: rgba(194, 178, 159, 0.78);
}

.site-footer-bottom p {
  margin: 0;
}

/* Páginas Legales (/sobre-nosotros, /politica-de-privacidad, /terminos-de-servicio) */
.legal-page-container {
  max-inline-size: 900px;
  inline-size: 100%;
  margin-inline: auto;
  padding-block: 2rem;
  padding-inline: 1.5rem;
}

.legal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 2rem 2.25rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.legal-card h1 {
  margin: 0 0 0.4rem 0;
  font-size: 1.85rem;
  color: var(--accent-gold);
  padding-block-end: 0.75rem;
  border-block-end: 1px solid var(--border-subtle);
}

.legal-updated {
  margin: 0 0 1.5rem 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legal-section {
  margin-block-end: 1.6rem;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-main);
}

.legal-section h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.15rem;
  color: var(--accent-gold);
}

.legal-section p {
  margin: 0 0 0.65rem 0;
}

.legal-section ul {
  margin: 0.4rem 0 0.65rem 0;
  padding-inline-start: 1.35rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.legal-section a {
  color: var(--accent-gold);
}

.legal-highlight-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
}

.legal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-block-start: 0.75rem;
}

.legal-badges span {
  background: #16120e;
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: ui-monospace, Consolas, monospace;
}

.legal-mail-link {
  font-weight: 700;
}

@media (max-width: 1080px) {
  .lobby-hero,
  .lobby-columns {
    grid-template-columns: 1fr;
  }

  .arena {
    grid-template-columns: 1fr;
    grid-template-areas:
      "left"
      "board"
      "right";
    max-inline-size: 640px;
  }
}
