@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;900&family=Crimson+Text:wght@400;600&family=Noto+Sans+Symbols+2&display=swap');

/* ══════════════════════════════════════
   VARIABLES
══════════════════════════════════════ */
:root {
  --bg:            #0d1117;
  --surface:       #161c28;
  --surface2:      #1e2638;
  --border:        #2d3548;
  --accent:        #c9a84c;
  --accent-dim:    rgba(201,168,76,0.12);
  --gold-light:    #e8c86a;
  --text:          #e8dcc8;
  --text-dim:      #7a7060;
  --error:         #d95454;
  --success:       #5aaa72;

  --board-light:   #f0d9b5;
  --board-dark:    #b58863;
  --last-light:    #cdd16e;
  --last-dark:     #aaa23a;

  --hint-dot:      rgba(30,190,80,0.9);
  --hint-ring:     rgba(210,50,50,0.8);
  --sel-bg:        rgba(220,50,50,0.55);

  --font-title:    'Cinzel', Georgia, serif;
  --font-body:     'Crimson Text', Georgia, serif;
  --font-piece:    'Noto Sans Symbols 2', 'Segoe UI Symbol', 'Apple Symbols', serif;

  --board-size: min(calc(100vw - 80px), calc(100dvh - 230px), 600px);
}

/* ══════════════════════════════════════
   RESET & BASE
══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 16px;
  min-height: 100%; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
input, select, button { font-family: var(--font-body); font-size: 15px; outline: none; }
button { cursor: pointer; }

/* ══════════════════════════════════════
   BUTTONS
══════════════════════════════════════ */
.btn-primary {
  background: var(--accent); color: #1a1200;
  border: none; padding: 10px 22px; border-radius: 5px;
  font-weight: 600; letter-spacing: 0.05em;
  transition: opacity .15s, transform .1s; font-family: var(--font-body);
}
.btn-primary:hover  { opacity: 0.88; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); padding: 10px 22px; border-radius: 5px;
  transition: border-color .15s, color .15s; font-family: var(--font-body);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px; font-family: var(--font-body);
  transition: border-color .15s, color .15s, background .15s;
  cursor: pointer; white-space: nowrap;
}
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); padding: 7px 14px;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 12px; font-size: 0.82rem; }

/* ══════════════════════════════════════
   FORMS
══════════════════════════════════════ */
.form-group { margin-bottom: 16px; }
.form-group label, .toggle-label {
  display: block; font-size: 0.83rem; color: var(--text-dim);
  margin-bottom: 6px; letter-spacing: 0.03em;
}
.form-input, .form-select {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 5px; transition: border-color .15s;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-dim); }
.form-select option { background: var(--surface); }

.input-row {
  display: flex; align-items: center; background: var(--bg);
  border: 1px solid var(--border); border-radius: 5px; margin-bottom: 12px;
  transition: border-color .15s;
}
.input-row:focus-within { border-color: var(--accent); }
.input-row .at-sign { padding: 9px 2px 9px 12px; color: var(--accent); font-weight: 600; pointer-events: none; }
.input-row input { flex: 1; background: transparent; border: none; color: var(--text); padding: 9px 12px 9px 4px; }
.input-row input::placeholder { color: var(--text-dim); }

.solo-input {
  display: flex; background: var(--bg); border: 1px solid var(--border);
  border-radius: 5px; margin-bottom: 12px; transition: border-color .15s;
}
.solo-input:focus-within { border-color: var(--accent); }
.solo-input input { flex: 1; background: transparent; border: none; color: var(--text); padding: 9px 12px; }
.solo-input input::placeholder { color: var(--text-dim); }

.toggle-row { display: flex; align-items: flex-start; justify-content: space-between; padding: 8px 0; gap: 12px; }
.toggle-desc { font-size: 0.82rem; color: var(--text-dim); margin-top: 2px; line-height: 1.3; }
.toggle-wrap { position: relative; width: 44px; height: 24px; flex-shrink: 0; margin-top: 2px; }
.toggle-wrap input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 24px; cursor: pointer; transition: background .2s;
}
.toggle-track::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: var(--text-dim); border-radius: 50%; transition: transform .2s, background .2s;
}
.toggle-wrap input:checked + .toggle-track { background: var(--accent); }
.toggle-wrap input:checked + .toggle-track::before { transform: translateX(20px); background: #fff; }

.err-msg { color: var(--error); font-size: 0.85rem; min-height: 18px; margin-top: 6px; }
.err-inline { font-size: 0.82rem; color: var(--error); margin-top: 6px; display: none; }
.err-inline.show { display: block; }

/* ══════════════════════════════════════
   TOAST / NOTICE
══════════════════════════════════════ */
.toast, #toast, #notice {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 24px; border-radius: 24px;
  font-size: 0.88rem; opacity: 0; transition: opacity .2s, transform .2s;
  z-index: 999; pointer-events: none; white-space: nowrap;
}
.toast.show, #toast.show, #notice.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(90,170,114,.5); color: var(--success); }
.toast.error   { border-color: rgba(217,84,84,.5);  color: var(--error); }

/* ══════════════════════════════════════
   MODALS
══════════════════════════════════════ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.78); backdrop-filter: blur(6px);
  z-index: 200; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.active { display: flex; }

.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.78); backdrop-filter: blur(6px);
  z-index: 200; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.open { display: flex; }

.modal-box, .modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 26px 28px; width: 100%;
  max-width: 440px; box-shadow: 0 24px 64px rgba(0,0,0,.65);
}
.modal-box.wide, .modal.wide { max-width: 580px; }

.modal-box h2, .modal-title {
  font-family: var(--font-title); font-size: 1.2rem;
  color: var(--accent); margin-bottom: 20px; letter-spacing: 0.05em;
}
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ══════════════════════════════════════
   AUTH (index.html)
══════════════════════════════════════ */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(ellipse at 50% 30%, rgba(201,168,76,.06) 0%, transparent 70%), var(--bg);
}
.auth-wrap { width: 100%; max-width: 370px; }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-chess-icon { font-size: 3.5rem; color: var(--accent); display: block; margin-bottom: 8px; text-shadow: 0 0 24px rgba(201,168,76,.4); }
.auth-logo h1 { font-family: var(--font-title); font-size: 2rem; color: var(--accent); letter-spacing: 0.1em; }
.auth-logo p  { color: var(--text-dim); font-size: 0.88rem; margin-top: 4px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 26px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.tab-btn {
  flex: 1; background: none; border: none; color: var(--text-dim);
  padding: 9px; font-family: var(--font-title); font-size: 0.88rem; letter-spacing: 0.05em;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text); }
.auth-form.hidden { display: none; }
.auth-form .btn-primary { width: 100%; padding: 11px; font-size: 0.93rem; letter-spacing: 0.08em; margin-top: 4px; }

/* ══════════════════════════════════════
   MAIN MENU (main.html)
══════════════════════════════════════ */
#main-layout {
  min-height: 100dvh; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% -10%, rgba(201,168,76,.08) 0%, transparent 55%), var(--bg);
}
.main-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: rgba(22,28,40,.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar-brand { font-family: var(--font-title); font-size: 1rem; color: var(--accent); letter-spacing: .1em; }
.topbar-user  { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-dim); border: 1px solid rgba(201,168,76,.35);
  font-family: var(--font-title); font-size: 0.88rem; color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-name { font-family: var(--font-title); font-size: 0.82rem; letter-spacing: .05em; color: var(--text); }
.btn-icon {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  padding: 5px 10px; border-radius: 4px; font-size: 0.8rem; transition: border-color .15s, color .15s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.danger:hover { border-color: var(--error); color: var(--error); }
.main-hero {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 40px 24px; gap: 44px;
}
.hero-logo { text-align: center; }
.hero-icon {
  font-size: clamp(3.5rem, 10vw, 5.5rem); color: var(--accent);
  display: block; text-shadow: 0 0 40px rgba(201,168,76,.35);
}
.hero-title {
  font-family: var(--font-title); font-size: clamp(1.8rem, 6vw, 3.2rem);
  color: var(--accent); letter-spacing: .12em; font-weight: 900;
}
.hero-sub { color: var(--text-dim); font-size: .95rem; margin-top: 5px; letter-spacing: .06em; }
.main-nav { display: flex; flex-direction: column; gap: 11px; width: 100%; max-width: 270px; }
.btn-menu {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 13px 24px; border-radius: 6px; font-family: var(--font-title); font-size: 0.88rem;
  letter-spacing: 0.08em; transition: border-color .15s, background .15s, color .15s;
  text-align: center; width: 100%;
}
.btn-menu:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.btn-menu.highlight { border-color: var(--accent); color: var(--accent); }
.btn-menu.highlight:hover { background: var(--accent); color: #1a1200; }
.btn-menu.muted { border-color: var(--border); color: var(--text-dim); }
.btn-menu.muted:hover { border-color: var(--error); color: var(--error); background: rgba(217,84,84,.07); }

/* Modifier cards */
.modifier-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.modifier-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px; cursor: pointer; transition: border-color .15s, background .15s;
}
.modifier-card:hover { border-color: #3d4a66; }
.modifier-card.selected { border-color: var(--accent); background: var(--accent-dim); }
.mod-name { font-family: var(--font-title); font-size: 0.82rem; letter-spacing: .05em; color: var(--text); }
.mod-desc { font-size: 0.74rem; color: var(--text-dim); margin-top: 2px; }

/* Room list */
.rooms-search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.rooms-search-bar input { flex: 1; text-transform: uppercase; letter-spacing: .12em; }
.refresh-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.refresh-bar-label { font-size: .78rem; color: var(--text-dim); }
#refresh-countdown { font-size: .78rem; color: var(--text-dim); }

.room-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.room-list::-webkit-scrollbar { width: 4px; }
.room-list::-webkit-scrollbar-track { background: var(--bg); }
.room-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.room-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 9px 12px; gap: 10px; transition: border-color .15s;
}
.room-item:hover { border-color: #3d4a66; }
.room-item-info { flex: 1; min-width: 0; }
.room-item-name { font-size: 0.93rem; color: var(--text); }
.room-item-meta { display: flex; gap: 6px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.room-badge {
  font-size: 0.72rem; padding: 1px 7px; border-radius: 3px;
  border: 1px solid; letter-spacing: 0.04em;
}
.badge-classic { color: #a0b8a0; border-color: rgba(160,184,160,.3); background: rgba(160,184,160,.07); }
.badge-blitz5  { color: #e0a860; border-color: rgba(224,168,96,.3);  background: rgba(224,168,96,.07); }
.badge-bullet1 { color: #e06060; border-color: rgba(224,96,96,.3);   background: rgba(224,96,96,.07); }
.badge-slow30  { color: #80b0e0; border-color: rgba(128,176,224,.3); background: rgba(128,176,224,.07); }
.badge-locked  { background: none; border: none; padding: 0; }
.room-empty { text-align: center; color: var(--text-dim); padding: 28px 16px; font-size: 0.9rem; line-height: 1.6; }
.room-empty-icon { display: block; font-size: 2rem; margin-bottom: 6px; }
#room-password-group { display: none; margin-top: 8px; }

/* ══════════════════════════════════════
   LOADING SCREEN
══════════════════════════════════════ */
.loading-full {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; z-index: 1000;
}
.spinner {
  width: 38px; height: 38px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-full-text { font-family: var(--font-title); font-size: .82rem; letter-spacing: .12em; color: var(--text-dim); }

/* ══════════════════════════════════════
   GAME LAYOUT (game.html)
══════════════════════════════════════ */
.game-layout {
  display: flex; flex-direction: column;
  height: 100dvh; max-height: 100dvh;
  overflow: hidden; background: var(--bg);
}

/* Topbar */
.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; height: 46px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(18,22,34,.96); backdrop-filter: blur(8px);
  gap: 10px;
}
.game-topbar-brand {
  font-family: var(--font-title); font-size: 0.88rem;
  color: var(--accent); letter-spacing: .1em; white-space: nowrap;
}
.game-room-code {
  font-family: var(--font-title); font-size: 0.72rem;
  color: var(--text-dim); letter-spacing: .06em; flex: 1; text-align: center;
}
.game-room-code span { color: var(--accent); letter-spacing: .22em; }

/* Player panels */
.player-panel {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; height: 52px; flex-shrink: 0;
  background: var(--surface); gap: 10px;
}
#panel-opponent { border-bottom: 1px solid var(--border); }
#panel-me       { border-top:    1px solid var(--border); }

.player-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }

.player-color-dot {
  width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.1);
}
.player-color-dot.white { background: #f0e8d0; border-color: rgba(120,100,60,.6); }
.player-color-dot.black { background: #1c1208; border-color: rgba(200,160,50,.4); }
.player-color-dot.blue  { background: #4a80c0; border-color: rgba(60,100,180,.6); }

.player-name-badge {
  font-family: var(--font-title); font-size: 0.82rem; letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-name-badge.white-side { color: #f0e8d0; }
.player-name-badge.black-side { color: var(--accent); }
.player-name-badge.blue-side  { color: #80b0e0; }
.player-name-badge.unknown    { color: var(--text-dim); font-style: italic; }

.captured-row {
  font-family: var(--font-piece); font-size: 0.72rem; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; max-width: 130px; text-overflow: ellipsis;
  letter-spacing: 0.02em;
}

.player-timer {
  font-family: var(--font-title); font-size: 1rem; font-weight: 600;
  letter-spacing: 0.05em; color: var(--text-dim);
  min-width: 54px; text-align: right; flex-shrink: 0;
}
.player-timer.hidden   { display: none; }
.player-timer.ticking  { color: var(--accent); }
.player-timer.low      { color: var(--error); animation: timerPulse 1s ease-in-out infinite; }
@keyframes timerPulse  { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* Status bar */
.game-status {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 34px; flex-shrink: 0;
  font-family: var(--font-title); font-size: 0.73rem; letter-spacing: .07em;
  border-bottom: 1px solid var(--border);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.game-status.status-waiting    { background: rgba(40,60,120,.2); color: var(--text-dim); }
.game-status.status-waiting    .status-dot { background: #4060a0; }
.game-status.status-your-turn  { background: rgba(201,168,76,.1); color: var(--accent); }
.game-status.status-your-turn  .status-dot { background: var(--accent); animation: pulseDot 1.2s ease-in-out infinite; }
.game-status.status-their-turn { background: rgba(22,28,40,.6); color: var(--text-dim); }
.game-status.status-their-turn .status-dot { background: var(--border); }
.game-status.status-check      { background: rgba(217,84,84,.13); color: #e88888; }
.game-status.status-check      .status-dot { background: var(--error); animation: pulseDot .6s ease-in-out infinite; }
.game-status.status-checkmate  { background: rgba(217,84,84,.18); color: #e88888; }
.game-status.status-checkmate  .status-dot { background: var(--error); }
.game-status.status-stalemate  { background: rgba(100,100,100,.12); color: #a0a0a0; }
.game-status.status-stalemate  .status-dot { background: #888; }
@keyframes pulseDot { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.65); } }


/* ══════════════════════════════════════
   BOARD FRAME — aligns coords with board
   Works correctly on desktop + mobile
══════════════════════════════════════ */
.board-frame {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
}
.board-frame-colrow {
  display: flex;
  align-items: center;
}
.board-frame-corner {
  width: 16px;
  flex-shrink: 0;
}
.board-frame-midrow {
  display: flex;
  align-items: stretch;
  gap: 3px;
}
.board-cell-wrap {
  position: relative;
  line-height: 0;
  flex-shrink: 0;
}
/* Board wrap */
.board-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 4px 6px; min-height: 0;
}

.coord-col-labels {
  display: grid; grid-template-columns: repeat(8, 1fr);
  width: var(--board-size); padding: 0 1px;
}
.coord-label {
  text-align: center;
  font-family: var(--font-title); font-size: clamp(8px, 1.3vw, 11px);
  color: var(--text-dim); letter-spacing: .05em; line-height: 1.7;
}
.coord-row-labels {
  display: flex; flex-direction: column;
  height: var(--board-size); width: 14px;
}
.coord-row-label {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-size: clamp(8px, 1.3vw, 11px);
  color: var(--text-dim); line-height: 1;
}

/* Chess board */
.chess-board {
  display: grid; grid-template-columns: repeat(8, 1fr);
  width: var(--board-size); height: var(--board-size);
  border: 3px solid #4a3520;
  box-shadow:
    0 0 0 1px #2a1a08,
    0 12px 50px rgba(0,0,0,.72),
    inset 0 0 0 1px rgba(255,255,255,.03);
  border-radius: 2px; overflow: hidden;
  touch-action: manipulation;
}

.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: filter .06s; aspect-ratio: 1;
}
.cell.light { background: var(--board-light); }
.cell.dark  { background: var(--board-dark); }
.cell.last-move.light { background: var(--last-light); }
.cell.last-move.dark  { background: var(--last-dark); }
.cell.selected  { background: var(--sel-bg) !important; }
.cell.in-check  { background: rgba(210,50,50,.72) !important; }

.cell.hint-move::after {
  content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: var(--hint-dot); pointer-events: none; z-index: 5;
  box-shadow: 0 0 6px rgba(30,190,80,.5);
}
.cell.hint-capture::before {
  content: ''; position: absolute; inset: 2px; border-radius: 50%;
  border: 4px solid var(--hint-ring); pointer-events: none; z-index: 5;
}


/* ══════════════════════════════════════
   PIECE ANIMATION
══════════════════════════════════════ */
/* Flying piece during move */
.piece-flying {
  -webkit-text-stroke: 1.8px #2a1800;
  paint-order: stroke fill;
  filter:
    drop-shadow(0 6px 12px rgba(0,0,0,0.7))
    drop-shadow(0 2px 0 rgba(0,0,0,0.5));
  transform: scale(1.12);
}
.piece-flying.black-piece {
  -webkit-text-stroke: 1.5px #b8902a;
}

/* Landing flash on destination cell */
@keyframes cellLand {
  0%   { background: rgba(201,168,76,0.45); }
  100% { background: transparent; }
}
.cell.landing {
  animation: cellLand 0.25s ease-out forwards;
}

/* Opponent piece arrival */
@keyframes pieceArrive {
  0%   { transform: scale(1.25); opacity: 0.6; }
  60%  { transform: scale(0.95); }
  100% { transform: scale(1);    opacity: 1; }
}
.piece.arriving {
  animation: pieceArrive 0.2s cubic-bezier(0.34,1.56,0.64,1) forwards;
}
/* ══════════════════════════════════════
   CHESS PIECES — detailed
══════════════════════════════════════ */
.piece {
  font-family: var(--font-piece);
  font-size: clamp(22px, 4.8vw, 50px);
  line-height: 1; user-select: none;
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  width: 92%; height: 92%;
  transition: transform .08s, filter .08s;
}

/* White: ivory with dark outline + elevated shadow */
.white-piece {
  color: #f7eed8;
  -webkit-text-stroke: 1.8px #2a1800;
  paint-order: stroke fill;
  filter:
    drop-shadow(0 3px 5px rgba(0,0,0,.65))
    drop-shadow(0 1px 0 rgba(0,0,0,.4));
}

/* Black: near-black with warm gold outline + depth */
.black-piece {
  color: #1c1006;
  -webkit-text-stroke: 1.5px #b8902a;
  paint-order: stroke fill;
  filter:
    drop-shadow(0 3px 5px rgba(0,0,0,.8))
    drop-shadow(0 1px 0 rgba(201,168,76,.2));
}

/* Blue waiting pieces */
.blue-piece {
  color: #3868b8;
  -webkit-text-stroke: 1.5px #1a3870;
  paint-order: stroke fill;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.55));
}

.cell:hover .piece    { transform: scale(1.1) translateY(-1px); }
.cell.selected .piece { transform: scale(1.08) translateY(-1px); }

/* coord labels inside cells */
.rank-label, .file-label {
  position: absolute; font-size: clamp(7px, 1.2vw, 10px);
  font-weight: 600; line-height: 1; z-index: 3; pointer-events: none; opacity: 0.65;
  font-family: var(--font-title);
}
.rank-label { top: 2px; left: 2px; }
.file-label { bottom: 2px; right: 2px; }
.cell.light .rank-label, .cell.light .file-label { color: var(--board-dark); }
.cell.dark  .rank-label, .cell.dark  .file-label { color: var(--board-light); }

/* ══════════════════════════════════════
   BOARD OVERLAY (waiting / start)
══════════════════════════════════════ */
.board-overlay {
  position: absolute; inset: 0;
  background: rgba(6,10,20,.72); backdrop-filter: blur(2px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; z-index: 20;
  padding: 20px; box-sizing: border-box; overflow: hidden; text-align: center;
}
.board-overlay.hidden { display: none; }

.overlay-room-id {
  text-align: center; font-family: var(--font-title);
  font-size: 0.72rem; color: var(--text-dim); letter-spacing: .1em; line-height: 1.8;
}
.overlay-room-id strong {
  display: block; font-size: 1.7rem; letter-spacing: .4em;
  color: var(--accent); text-shadow: 0 0 20px rgba(201,168,76,.5);
}

.overlay-waiting-text {
  font-family: var(--font-title); font-weight: 900;
  font-size: clamp(1rem, 5vw, 2.2rem); color: var(--accent);
  letter-spacing: .2em; text-shadow: 0 0 28px rgba(201,168,76,.55);
  animation: breathe 2s ease-in-out infinite;
  white-space: nowrap; max-width: 100%;
}
@keyframes breathe { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.overlay-start-btn {
  font-family: var(--font-title); font-weight: 700;
  font-size: clamp(0.9rem, 3.5vw, 1.3rem); color: #1a1200;
  background: var(--accent); border: none;
  padding: 14px 38px; letter-spacing: .15em; border-radius: 4px; cursor: pointer;
  box-shadow: 0 4px 20px rgba(201,168,76,.45);
  transition: transform .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.overlay-start-btn:hover  { transform: scale(1.05); box-shadow: 0 6px 28px rgba(201,168,76,.6); }
.overlay-start-btn:active { transform: scale(0.97); }

/* ══════════════════════════════════════
   GAME RESULT OVERLAY
══════════════════════════════════════ */
.result-overlay {
  position: fixed; inset: 0;
  background: rgba(6,10,20,.88); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px; animation: fadeIn .3s ease;
}
.result-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.result-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px 32px;
  text-align: center; max-width: 320px; width: 100%;
  box-shadow: 0 32px 80px rgba(0,0,0,.7);
  animation: slideUp .35s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.result-icon {
  display: block; font-size: 3.5rem; font-family: var(--font-piece);
  margin-bottom: 12px; filter: drop-shadow(0 4px 12px rgba(0,0,0,.5));
}
.result-title {
  font-family: var(--font-title); font-size: 1.8rem;
  letter-spacing: .08em; margin-bottom: 8px; color: var(--gold-light);
}
.result-subtitle { color: var(--text-dim); font-size: .9rem; margin-bottom: 28px; line-height: 1.5; }
.result-btns { display: flex; gap: 10px; justify-content: center; }

/* ══════════════════════════════════════
   PAWN PROMOTION
══════════════════════════════════════ */
.promo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 8px 0; }
.promo-piece {
  background: var(--bg); border: 2px solid var(--border);
  border-radius: 8px; padding: 10px 4px;
  font-family: var(--font-piece); font-size: 2.2rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color .15s, background .15s, transform .1s;
  aspect-ratio: 1;
}
.promo-piece:hover { border-color: var(--accent); background: var(--accent-dim); transform: scale(1.08); }

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
/* ── Small phones ── */
@media (max-width: 480px) {
  :root { --board-size: min(calc(100vw - 8px), calc(100dvh - 200px)); }
  .game-topbar { padding: 0 10px; }
  .game-topbar-brand { font-size: 0.76rem; letter-spacing: .07em; }
  .player-panel { padding: 6px 10px; }
  .game-status { padding: 0 10px; font-size: 0.67rem; }
  .modal, .modal-box { padding: 18px 14px; }
  .promo-piece { font-size: 1.8rem; }
  .result-card { padding: 28px 18px; }
  .result-title { font-size: 1.5rem; }
}

/* ── Short screens ── */
@media (max-height: 680px) {
  :root { --board-size: min(calc(100vw - 8px), calc(100dvh - 180px)); }
  .player-panel { height: 44px; }
  .game-status  { height: 28px; font-size: 0.67rem; }
  .game-topbar  { height: 40px; }
}

/* ── Desktop: wide layout ── */
@media (min-width: 700px) {
  :root { --board-size: min(calc(100dvh - 230px), 600px); }

  body.game-page {
    background: #060a10;
  }

  .game-layout {
    /* Full height, centered board section */
    max-width: 720px;
    margin: 0 auto;
  }

  .game-topbar {
    padding: 0 28px;
    height: 52px;
  }

  .player-panel {
    padding: 10px 28px;
    height: 58px;
  }

  .game-status {
    padding: 0 28px;
    height: 38px;
    font-size: 0.8rem;
  }

  .board-wrap {
    padding: 8px 24px;
  }

  .coord-label,
  .coord-row-label {
    font-size: 12px;
  }

  .piece {
    font-size: clamp(28px, 3.5vw, 54px);
  }
}

/* ── Landscape phones ── */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --board-size: calc(100dvh - 84px); }
  .game-topbar { height: 34px; }
  .player-panel { height: 38px; padding: 4px 10px; }
  .game-status  { height: 24px; font-size: 0.65rem; }
}
