 @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Inter:wght@300;400;500;600&display=swap');

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg:        #0f0f13;
    --surface:   #1a1a22;
    --card:      #22222e;
    --border:    #2e2e3e;
    --gold:      #c9a84c;
    --gold-dim:  #8a6f2e;
    --ivory:     #f0e8d0;
    --ivory-dim: #b0a890;
    --green:     #3a7d5c;
    --red:       #9b3a3a;
    --text:      #e8e0d0;
    --muted:     #7a7888;
    --light-sq:  #e8d5b0;
    --dark-sq:   #7a5c3a;
    --highlight: rgba(201,168,76,0.45);
    --move-dot:  rgba(201,168,76,0.35);
    --check:     rgba(155,58,58,0.65);
  }

  html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
  }

  /* ── SCREENS ── */
  .screen { display: none; flex-direction: column; align-items: center; min-height: 100vh; padding: 0 12px 24px; }
  .screen.active { display: flex; }

  /* ── START SCREEN ── */
  #start-screen {
    justify-content: center;
    gap: 0;
    background: radial-gradient(ellipse at 50% 30%, #1e1a2e 0%, var(--bg) 70%);
  }

  .logo-block { text-align: center; margin-bottom: 48px; }
  .logo-icon { font-size: 64px; line-height: 1; margin-bottom: 16px; filter: drop-shadow(0 0 24px rgba(201,168,76,0.5)); }
  .logo-title {
    font-family: 'Playfair Display', serif;
    font-size: clamp(42px, 10vw, 64px);
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.08em;
    line-height: 1;
  }
  .logo-sub {
    font-size: 11px;
    letter-spacing: 0.35em;
    color: var(--muted);
    text-transform: uppercase;
    margin-top: 8px;
  }

  .mode-label {
    font-size: 11px;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 16px;
    text-align: center;
  }

  .mode-cards { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; }

  .mode-card {
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    cursor: pointer;
    transition: border-color .2s, transform .15s, box-shadow .2s;
    position: relative;
    overflow: hidden;
  }
  .mode-card::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, transparent 60%, rgba(201,168,76,0.06));
    pointer-events: none;
  }
  .mode-card:hover, .mode-card:focus {
    border-color: var(--gold-dim);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  }
  .mode-card.selected {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px var(--gold), 0 8px 24px rgba(201,168,76,0.15);
  }
  .mode-card-head { display: flex; align-items: center; gap: 12px; }
  .mode-icon { font-size: 22px; }
  .mode-name {
    font-family: 'Playfair Display', serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
  }
  .mode-badge {
    margin-left: auto;
    font-size: 9px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 20px;
    font-weight: 600;
  }
  .badge-easy   { background: rgba(58,125,92,0.25); color: #5aad88; border: 1px solid rgba(58,125,92,0.4); }
  .badge-med    { background: rgba(201,168,76,0.2); color: var(--gold); border: 1px solid rgba(201,168,76,0.35); }
  .badge-hard   { background: rgba(155,58,58,0.25); color: #c96060; border: 1px solid rgba(155,58,58,0.4); }
  .mode-desc { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

  .color-row { display: flex; gap: 10px; width: 100%; max-width: 320px; margin-top: 20px; }
  .color-btn {
    flex: 1; padding: 12px 8px; border-radius: 10px; border: 1.5px solid var(--border);
    background: var(--card); cursor: pointer; font-size: 12px; color: var(--muted);
    transition: all .2s; font-family: 'Inter', sans-serif; text-align: center;
  }
  .color-btn:hover { border-color: var(--gold-dim); color: var(--text); }
  .color-btn.selected { border-color: var(--gold); color: var(--gold); background: rgba(201,168,76,0.08); }
  .color-btn .cb-icon { font-size: 20px; display: block; margin-bottom: 4px; }

  .start-btn {
    margin-top: 24px;
    width: 100%; max-width: 320px;
    padding: 16px;
    background: var(--gold);
    color: #1a1400;
    border: none; border-radius: 12px;
    font-family: 'Playfair Display', serif;
    font-size: 17px; font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: opacity .2s, transform .15s, box-shadow .2s;
    box-shadow: 0 4px 16px rgba(201,168,76,0.3);
  }
  .start-btn:hover { opacity: .92; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(201,168,76,0.4); }
  .start-btn:active { transform: translateY(0); }

  /* ── GAME SCREEN ── */
  #game-screen { padding: 0 0 16px; gap: 0; }

  /* Top bar */
  .topbar {
    width: 100%; display: flex; align-items: center;
    padding: 10px 14px; gap: 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .tb-back {
    background: none; border: none; color: var(--muted); cursor: pointer;
    font-size: 22px; padding: 4px; line-height: 1;
    transition: color .15s;
  }
  .tb-back:hover { color: var(--text); }
  .tb-title {
    font-family: 'Playfair Display', serif;
    font-size: 18px; color: var(--gold); flex: 1;
  }
  .tb-mode {
    font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
    padding: 4px 10px; border-radius: 20px; font-weight: 600;
  }

  /* Player panels */
  .player-panel {
    width: 100%; padding: 8px 14px;
    display: flex; align-items: center; gap: 10px;
    background: var(--surface);
  }
  .pp-color { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
  .pp-color.white { background: var(--ivory); box-shadow: 0 0 0 2px rgba(240,232,208,0.3); }
  .pp-color.black { background: #2a2a35; border: 1.5px solid var(--border); }
  .pp-name { font-size: 13px; font-weight: 500; flex: 1; }
  .pp-turn { font-size: 11px; color: var(--gold); letter-spacing: 0.1em; }
  .pp-captures { display: flex; flex-wrap: wrap; gap: 2px; }
  .pp-captures span { font-size: 13px; line-height: 1; }

  /* Board wrapper */
  .board-wrap {
    width: 100%;
    display: flex; justify-content: center; align-items: center;
    padding: 8px 6px;
    flex: 1;
  }

  .board-outer {
    position: relative;
    border: 3px solid var(--gold-dim);
    border-radius: 4px;
    box-shadow: 0 0 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(201,168,76,0.15);
  }

  #board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(96vw, calc(100vh - 280px));
    height: min(96vw, calc(100vh - 280px));
    max-width: 480px; max-height: 480px;
    min-width: 280px; min-height: 280px;
    touch-action: none;
  }

  .cell {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background-color .12s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }
  .cell.light { background: var(--light-sq); }
  .cell.dark  { background: var(--dark-sq); }
  .cell.selected    { background: var(--highlight) !important; }
  .cell.last-move   { background: rgba(201,168,76,0.22) !important; }
  .cell.in-check    { background: var(--check) !important; }

  .cell .move-dot {
    position: absolute;
    width: 32%; height: 32%;
    border-radius: 50%;
    background: var(--move-dot);
    pointer-events: none;
    z-index: 2;
  }
  .cell.can-capture .move-dot {
    width: 100%; height: 100%;
    border-radius: 0;
    background: transparent;
    border: 3px solid rgba(201,168,76,0.5);
    border-radius: 2px;
  }

  .piece {
    font-size: min(7.5vw, 38px);
    line-height: 1;
    cursor: pointer;
    position: relative;
    z-index: 3;
    pointer-events: none;
    transition: transform .1s;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6));
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  /* Coords */
  .coord-rank, .coord-file {
    position: absolute;
    font-size: 9px;
    font-weight: 600;
    opacity: 0.55;
    pointer-events: none;
    line-height: 1;
    z-index: 1;
  }
  .coord-rank { top: 2px; left: 3px; }
  .coord-file { bottom: 2px; right: 3px; }
  .cell.light .coord-rank, .cell.light .coord-file { color: var(--dark-sq); }
  .cell.dark  .coord-rank, .cell.dark  .coord-file  { color: var(--light-sq); }

  /* Status bar */
  .status-bar {
    width: 100%; text-align: center;
    padding: 8px 14px;
    font-size: 13px; color: var(--muted);
    min-height: 34px;
    letter-spacing: 0.05em;
  }
  .status-bar.check  { color: #e06060; font-weight: 600; }
  .status-bar.result { color: var(--gold); font-weight: 700; font-size: 15px; }

  /* Bottom controls */
  .controls {
    display: flex; gap: 8px;
    padding: 4px 14px 0;
    width: 100%;
  }
  .ctrl-btn {
    flex: 1; padding: 10px 4px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; color: var(--muted);
    font-size: 11px; font-family: 'Inter', sans-serif;
    cursor: pointer; transition: all .15s;
    letter-spacing: 0.05em;
  }
  .ctrl-btn:hover { border-color: var(--gold-dim); color: var(--text); }
  .ctrl-btn .ci { display: block; font-size: 18px; margin-bottom: 2px; }

  /* Promotion modal */
  .modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.75); z-index: 100;
    align-items: center; justify-content: center;
  }
  .modal-overlay.open { display: flex; }
  .modal-box {
    background: var(--card); border: 1.5px solid var(--gold);
    border-radius: 16px; padding: 24px 20px; text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.6);
    max-width: 300px; width: 90%;
  }
  .modal-title {
    font-family: 'Playfair Display', serif;
    font-size: 18px; color: var(--gold); margin-bottom: 16px;
  }
  .promo-pieces { display: flex; gap: 10px; justify-content: center; }
  .promo-btn {
    width: 60px; height: 60px;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 10px; font-size: 32px; cursor: pointer;
    transition: all .15s; display: flex; align-items: center; justify-content: center;
  }
  .promo-btn:hover { border-color: var(--gold); transform: scale(1.08); }

  /* Thinking indicator */
  .thinking {
    display: none; align-items: center; gap: 6px;
    font-size: 12px; color: var(--muted); padding: 4px 14px;
    width: 100%;
  }
  .thinking.show { display: flex; }
  .thinking-dots span {
    display: inline-block; width: 5px; height: 5px;
    border-radius: 50%; background: var(--gold);
    animation: bounce 1.1s infinite;
  }
  .thinking-dots span:nth-child(2) { animation-delay: .15s; }
  .thinking-dots span:nth-child(3) { animation-delay: .3s; }
  @keyframes bounce {
    0%,80%,100% { transform: translateY(0); opacity:.4; }
    40% { transform: translateY(-5px); opacity:1; }
  }

  @media (min-height: 700px) {
    .player-panel { padding: 10px 14px; }
  }