@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700;900&family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg0: #06060f;
  --bg1: #0c0c1e;
  --bg2: #13132a;
  --bg3: #1b1b38;
  --bg4: #242448;
  --surface: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.07);
  --purple: #7c3aed;
  --purple-l: #a78bfa;
  --red: #ef4444;
  --gold: #d9a406;
  --green: #22c55e;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #4b5563;
  --ff-head: 'Cinzel', serif;
  --ff-ui: 'Inter', sans-serif;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 4px 24px rgba(0,0,0,0.6);
  /* tablero fieltro */
  --felt: #1c7a4a;
  --felt-d: #145c37;
  --felt-line: rgba(6, 30, 16, 0.65);
  --disc-b: #16121f;
  --disc-b-hi: #3d3654;
  --disc-w: #f4efe2;
  --disc-w-sh: #b8b09a;
  --hl-last: #d9a406;
}

html, body { height: 100%; }
body {
  background: var(--bg0);
  color: var(--text);
  font-family: var(--ff-ui);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg1); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

.felt-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 85%, rgba(34,197,94,0.13) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 15%, rgba(124,58,237,0.10) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(20,92,55,0.10) 0%, transparent 70%);
}

/* ─── Top bar ─── */
.top-bar {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(6,6,15,0.75); backdrop-filter: blur(8px);
}
.top-brand { color: var(--text2); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.top-brand:hover { color: var(--text); }
.top-title { font-family: var(--ff-head); font-weight: 700; letter-spacing: 6px; font-size: 16px; color: #6ee7a0; }

#app { position: relative; z-index: 1; max-width: 1120px; margin: 0 auto; padding: 18px 14px 60px; }

.loading { text-align: center; padding: 80px 0; color: var(--text2); }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 50%;
  background: linear-gradient(90deg, var(--disc-b) 50%, var(--disc-w) 50%);
  animation: spin 1.1s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(34,197,94,0.35);
}
@keyframes spin { 100% { transform: rotateY(360deg); } }

#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 22px; border-radius: 30px; font-size: 14px; opacity: 0;
  transition: all .25s; z-index: 100; pointer-events: none; box-shadow: var(--shadow);
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--red); color: #fca5a5; }

/* ─── Botones (mismos del ajedrez) ─── */
button {
  font-family: var(--ff-ui); font-size: 14px; font-weight: 600;
  border: none; border-radius: var(--r); cursor: pointer;
  transition: all .18s; color: var(--text);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #16a34a, #15803d);
  padding: 13px 26px; width: 100%;
  box-shadow: 0 4px 18px rgba(34,197,94,0.3);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(34,197,94,0.45); }
.btn-secondary { background: var(--bg3); border: 1px solid var(--border); padding: 11px 20px; }
.btn-secondary:hover:not(:disabled) { background: var(--bg4); }
.btn-danger { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.4); color: #fca5a5; padding: 11px 20px; }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.22); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 8px 14px; font-size: 13px; }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: #16a34a; }

/* ─── Landing ─── */
.landing-hero { text-align: center; padding: 40px 0 26px; }
.landing-hero h1 {
  font-family: var(--ff-head); font-size: clamp(34px, 7vw, 54px); font-weight: 900;
  background: linear-gradient(120deg, #f4efe2 30%, #6ee7a0 70%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: 4px;
}
.landing-hero .tagline { color: var(--text2); font-size: 16px; margin-top: 4px; }
.hero-discs { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; }
.hero-discs .hd {
  width: 54px; height: 54px; border-radius: 50%;
  animation: hero-flip 3.2s ease-in-out infinite;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5);
}
.hero-discs .hd.w { background: radial-gradient(circle at 35% 30%, #fff, var(--disc-w) 55%, var(--disc-w-sh)); }
.hero-discs .hd.b { background: radial-gradient(circle at 35% 30%, #4a4266, var(--disc-b) 60%); }
.hero-discs .hd:nth-child(2) { animation-delay: .4s; }
.hero-discs .hd:nth-child(3) { animation-delay: .8s; }
@keyframes hero-flip { 0%,100% { transform: rotateY(0); } 50% { transform: rotateY(180deg) translateY(-6px); } }

.action-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; max-width: 860px; margin: 0 auto; }
.action-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 24px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color .2s, transform .2s;
}
.action-card:hover { border-color: #16a34a; transform: translateY(-2px); }
.action-card h3 { font-family: var(--ff-head); font-size: 17px; letter-spacing: 1px; }
.action-card p { color: var(--text2); font-size: 13.5px; flex: 1; }
.action-card input {
  background: var(--bg1); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text); padding: 11px 14px; font-size: 16px; letter-spacing: 4px;
  text-align: center; text-transform: uppercase; font-weight: 700; width: 100%;
}
.action-card input:focus { outline: none; border-color: #16a34a; }
.action-card .btn-primary { padding: 12px 18px; }

/* ─── Lobby ─── */
.lobby { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
@media (max-width: 860px) { .lobby { grid-template-columns: 1fr; } }
.panel {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; margin-bottom: 14px;
}
.panel h4 { font-family: var(--ff-head); letter-spacing: 2px; font-size: 13px; color: var(--text2); margin-bottom: 12px; }
.lobby-code {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg2); border: 1px dashed rgba(34,163,74,0.55); border-radius: var(--r-lg);
  padding: 16px 20px; margin-bottom: 16px;
}
.lobby-code-label { color: var(--text2); font-size: 13px; }
.lobby-code-value { font-family: var(--ff-head); font-size: 26px; font-weight: 700; letter-spacing: 6px; color: var(--gold); }
.copy-btn { background: var(--bg3); border: 1px solid var(--border); padding: 8px 14px; font-size: 13px; border-radius: 8px; }

.seat-row { display: flex; flex-direction: column; gap: 10px; }
.seat {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 14px;
}
.seat.empty { border-style: dashed; color: var(--text3); justify-content: center; min-height: 62px; }
.seat.is-me { border-color: rgba(34,163,74,0.7); }
.seat .player-avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  background: var(--bg4); display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.seat .p-name { font-weight: 600; }
.seat .p-meta { font-size: 12px; color: var(--text2); }
.seat .host-tag, .seat .bot-tag { margin-left: auto; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.seat .host-tag { color: var(--gold); background: rgba(217,164,6,0.12); }
.seat .bot-tag { color: #6ee7a0; background: rgba(34,163,74,0.15); }

.opt-group { margin-bottom: 14px; }
.opt-group .opt-label { font-size: 12.5px; color: var(--text2); margin-bottom: 7px; font-weight: 600; }
.opt-pills { display: flex; flex-wrap: wrap; gap: 7px; }
.opt-pill {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 20px;
  padding: 7px 13px; font-size: 13px; color: var(--text2);
}
.opt-pill.sel { background: rgba(34,163,74,0.28); border-color: #16a34a; color: #fff; }

/* ─── Layout de partida ─── */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 920px) { .game { grid-template-columns: 1fr; } }
.board-col { min-width: 0; max-width: 640px; margin: 0 auto; width: 100%; }

.player-bar { display: flex; align-items: center; gap: 10px; padding: 8px 4px; }
.player-bar .player-avatar {
  width: 34px; height: 34px; border-radius: 9px; object-fit: cover; flex-shrink: 0;
  background: var(--bg4); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.player-bar .pb-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar .pb-sub { font-size: 11.5px; color: var(--text2); }
.player-bar .pb-score {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
}
.score-chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 4px 12px; font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums;
  transition: border-color .3s, box-shadow .3s;
}
.score-chip .mini-disc { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.score-chip .mini-disc.b { background: radial-gradient(circle at 35% 30%, #4a4266, var(--disc-b) 60%); }
.score-chip .mini-disc.w { background: radial-gradient(circle at 35% 30%, #fff, var(--disc-w) 55%, var(--disc-w-sh)); }
.score-chip.turn { border-color: #16a34a; box-shadow: 0 0 12px rgba(34,197,94,0.35); }

.clock {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 19px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 4px 12px; letter-spacing: 1px; color: var(--text2);
}
.clock.active { color: #fff; border-color: #16a34a; box-shadow: 0 0 14px rgba(34,197,94,0.3); }
.clock.low { color: #fecaca; border-color: var(--red); animation: clock-pulse 1s infinite; }
@keyframes clock-pulse { 50% { box-shadow: 0 0 16px rgba(239,68,68,0.6); } }

/* ─── Tablero ─── */
.board-wrap {
  position: relative; width: 100%; aspect-ratio: 1;
  border-radius: 12px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, var(--felt) 0%, var(--felt-d) 85%);
  box-shadow: 0 0 0 3px #0d3b23, 0 0 50px rgba(34,197,94,0.18), var(--shadow);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.board-grid {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
}
.cell { position: relative; border: 1px solid var(--felt-line); }
.cell .coord {
  position: absolute; left: 3px; top: 1px; font-size: clamp(7px, 1.4vw, 10px);
  font-weight: 700; color: rgba(220, 245, 230, 0.4); pointer-events: none;
}
/* puntos guía clásicos del tablero */
.cell.star::before {
  content: ''; position: absolute; width: 14%; height: 14%;
  left: -8%; top: -8%; border-radius: 50%; background: var(--felt-line); z-index: 1;
}

.cell .hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 34%; height: 34%; border-radius: 50%;
  background: rgba(8, 40, 22, 0.35); border: 2px dashed rgba(230, 250, 238, 0.5);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(9px, 1.8vw, 12px); font-weight: 800; color: rgba(240, 252, 245, 0.85);
  cursor: pointer; transition: transform .15s, background .15s;
}
.cell .hint:hover { transform: translate(-50%,-50%) scale(1.18); background: rgba(8, 40, 22, 0.55); }

/* fichas: dos caras con flip 3D */
.disc {
  position: absolute; inset: 9%;
  perspective: 300px; pointer-events: none;
}
.disc .inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.3, .9, .4, 1.05);
}
.disc.is-w .inner { transform: rotateY(180deg); }
.disc .face {
  position: absolute; inset: 0; border-radius: 50%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 3px 6px rgba(0,0,0,0.45);
}
.disc .face.fb { background: radial-gradient(circle at 35% 30%, var(--disc-b-hi), var(--disc-b) 62%); }
.disc .face.fw { background: radial-gradient(circle at 35% 30%, #ffffff, var(--disc-w) 55%, var(--disc-w-sh)); transform: rotateY(180deg); }
.disc.spawn .inner { animation: disc-spawn .3s ease-out; }
@keyframes disc-spawn { from { transform: scale(0.2); opacity: 0; } }
.disc.is-w.spawn .inner { animation: disc-spawn-w .3s ease-out; }
@keyframes disc-spawn-w { from { transform: rotateY(180deg) scale(0.2); opacity: 0; } to { transform: rotateY(180deg) scale(1); } }

.cell.hl-last::after {
  content: ''; position: absolute; inset: 4%;
  border-radius: 50%; border: 3px solid var(--hl-last); pointer-events: none;
  box-shadow: 0 0 10px rgba(217,164,6,0.5);
}

/* aviso de pase */
.pass-banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: rgba(6,6,15,0.85); border: 1px solid var(--gold); color: var(--gold);
  font-family: var(--ff-head); letter-spacing: 3px; font-weight: 700; font-size: 18px;
  padding: 14px 30px; border-radius: var(--r-lg); z-index: 15;
  animation: pass-pop 1.8s ease forwards; pointer-events: none;
}
@keyframes pass-pop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.7); }
  15%, 75% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.05); }
}

.review-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: rgba(217,164,6,0.12); border: 1px solid rgba(217,164,6,0.4);
  color: var(--gold); border-radius: var(--r); padding: 8px 12px; margin-top: 10px; font-size: 13px;
}

/* ─── Sidebar ─── */
.side-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.moves-panel { max-height: 280px; display: flex; flex-direction: column; }
.moves-list { overflow-y: auto; font-size: 13.5px; flex: 1; font-variant-numeric: tabular-nums; }
.moves-list .mv-row { display: grid; grid-template-columns: 34px 1fr 1fr; padding: 2px 4px; border-radius: 6px; }
.moves-list .mv-row:nth-child(odd) { background: rgba(255,255,255,0.025); }
.moves-list .mv-no { color: var(--text3); }
.moves-list .mv { cursor: pointer; padding: 1px 8px; border-radius: 6px; font-weight: 500; }
.moves-list .mv:hover { background: var(--bg3); }
.moves-list .mv.current { background: rgba(34,163,74,0.3); color: #fff; }
.moves-list .mv.pass { color: var(--text3); font-style: italic; }
.moves-nav { display: flex; gap: 6px; margin-top: 10px; }
.moves-nav button { flex: 1; padding: 7px 0; font-size: 15px; }

.game-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.game-actions button { flex: 1 1 45%; }

.draw-offer-box {
  background: rgba(217,164,6,0.1); border: 1px solid rgba(217,164,6,0.45);
  border-radius: var(--r); padding: 12px; text-align: center; font-size: 13.5px;
}
.draw-offer-box .row { display: flex; gap: 8px; margin-top: 10px; }
.draw-offer-box .row button { flex: 1; }

.chat-panel { display: flex; flex-direction: column; max-height: 260px; }
.chat-messages { flex: 1; overflow-y: auto; font-size: 13.5px; margin-bottom: 10px; min-height: 60px; }
.chat-msg { padding: 2px 0; word-wrap: break-word; }
.chat-msg .from { font-weight: 700; color: #6ee7a0; }
.chat-input { display: flex; gap: 8px; }
.chat-input input {
  flex: 1; background: var(--bg1); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text); padding: 9px 12px; font-size: 13.5px; min-width: 0;
}
.chat-input input:focus { outline: none; border-color: #16a34a; }
.chat-input button { padding: 9px 14px; background: var(--bg3); border: 1px solid var(--border); font-size: 13px; }

.pref-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; font-size: 13.5px; color: var(--text2); }
.toggle { position: relative; width: 40px; height: 22px; background: var(--bg4); border-radius: 20px; cursor: pointer; transition: background .2s; flex-shrink: 0; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text2); transition: all .2s; }
.toggle.on { background: #16a34a; }
.toggle.on::after { left: 21px; background: #fff; }

/* ─── Fin de partida ─── */
.end-overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,6,15,0.68); backdrop-filter: blur(2px);
  animation: fade-in .4s;
}
@keyframes fade-in { from { opacity: 0; } }
.end-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 26px 34px; text-align: center; box-shadow: var(--shadow); max-width: 92%;
  animation: pop-in .35s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes pop-in { from { transform: scale(0.7); opacity: 0; } }
.end-card.win { border-color: rgba(34,197,94,0.55); box-shadow: 0 0 50px rgba(34,197,94,0.18), var(--shadow); }
.end-card.loss { border-color: rgba(239,68,68,0.45); }
.end-card.draw { border-color: rgba(217,164,6,0.5); }
.end-card h2 { font-family: var(--ff-head); font-size: 24px; letter-spacing: 2px; margin-bottom: 4px; }
.end-card .end-score { font-size: 30px; font-weight: 800; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.end-card .end-reason { color: var(--text2); font-size: 14px; margin-bottom: 16px; }
.end-card .end-actions { display: flex; flex-direction: column; gap: 9px; }

@media (max-width: 560px) {
  #app { padding: 12px 8px 40px; }
  .clock, .score-chip { font-size: 16px; padding: 3px 9px; }
  .top-title { letter-spacing: 3px; font-size: 14px; }
}
