:root {
  color-scheme: dark;
  --bg: #0d1017;
  --surface: rgba(21, 25, 35, .92);
  --surface-2: rgba(32, 38, 51, .9);
  --text: #f5f0e6;
  --muted: #b8b2a8;
  --gold: #d9b45b;
  --accent: #8b5cf6;
  --success: #2fbf71;
  --danger: #d95c5c;
  --light-square: #d8d0c4;
  --dark-square: #31343d;
  --piece-white: #fff5dc;
  --piece-black: #16131d;
  --shadow: 0 20px 70px rgba(0,0,0,.45);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, select { font: inherit; }
button { color: inherit; }
.is-hidden { display: none !important; }

body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .25;
  background: radial-gradient(circle at 50% -10%, var(--accent), transparent 38%),
              linear-gradient(135deg, transparent 0 49%, rgba(255,255,255,.025) 50%, transparent 51%);
}

.screen { min-height: 100vh; min-height: 100dvh; }
.home-screen { position: relative; display: grid; place-items: center; overflow: hidden; padding: 40px 20px; }
.hero-backdrop { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5,7,12,.28), rgba(5,7,12,.94)), url("assets/runic.png") center 44% / cover; transform: scale(1.02); }
.home-content { position: relative; width: min(1060px, 100%); text-align: center; }
.eyebrow { color: var(--gold); letter-spacing: .24em; font-weight: 800; font-size: .78rem; }
h1 { margin: 8px 0 2px; font-family: Georgia, serif; font-size: clamp(3rem, 10vw, 7rem); line-height: .85; text-shadow: 0 8px 28px #000; }
h1 span { display: block; color: var(--gold); }
.tagline { color: var(--muted); font-size: clamp(1rem, 2.5vw, 1.35rem); margin: 22px 0 34px; }
.match-setup { width: min(520px, 100%); margin: 0 auto 18px; padding: 12px; border: 1px solid rgba(255,255,255,.13); border-radius: 18px; background: rgba(9,11,16,.78); backdrop-filter: blur(14px); }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-button { border: 1px solid rgba(255,255,255,.13); border-radius: 12px; padding: 12px 10px; background: rgba(255,255,255,.04); color: var(--muted); cursor: pointer; font-weight: 850; letter-spacing: .04em; }
.mode-button.is-active { color: #17130b; border-color: var(--gold); background: linear-gradient(135deg, #f5d98b, var(--gold)); box-shadow: 0 8px 24px rgba(217,180,91,.22); }
.difficulty-field { display: grid; grid-template-columns: 1fr 160px; align-items: center; gap: 12px; margin-top: 10px; color: var(--muted); text-align: left; font-size: .88rem; font-weight: 700; }
.difficulty-field select { width: 100%; padding: 10px 12px; border: 1px solid rgba(255,255,255,.16); border-radius: 10px; background: var(--surface-2); color: var(--text); }
.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 0 auto 28px; max-width: 900px; }
.theme-card { position: relative; overflow: hidden; min-height: 180px; padding: 0; border: 1px solid rgba(255,255,255,.16); border-radius: var(--radius); background: #111; cursor: pointer; box-shadow: var(--shadow); transition: .25s ease; }
.theme-card:hover, .theme-card:focus-visible { transform: translateY(-5px); border-color: var(--gold); }
.theme-card.is-selected { outline: 3px solid var(--accent); outline-offset: 3px; }
.theme-card img { width: 100%; height: 180px; object-fit: cover; opacity: .85; }
.theme-card span { position: absolute; inset: auto 0 0; padding: 18px 10px; background: linear-gradient(transparent, rgba(0,0,0,.95)); font-weight: 800; }
.primary-button, .secondary-button { border: 0; border-radius: 16px; padding: 17px 28px; cursor: pointer; font-weight: 900; letter-spacing: .06em; }
.primary-button { color: #15120b; background: linear-gradient(135deg, #f5d98b, var(--gold)); box-shadow: 0 12px 35px rgba(217,180,91,.28); min-width: min(420px, 100%); }
.secondary-button { background: var(--surface-2); color: var(--text); }
.prototype-note { color: var(--muted); font-size: .82rem; }

.game-screen { padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); background: radial-gradient(circle at 50% 0, color-mix(in srgb, var(--accent) 18%, transparent), transparent 48%), #090b10; }
.game-header { max-width: 1280px; margin: auto; height: 76px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,.1); }
.game-header > div { text-align: center; }
.game-header strong { display: block; font-family: Georgia, serif; color: var(--gold); letter-spacing: .12em; }
.game-header small { color: var(--muted); }
.icon-button { width: 46px; height: 46px; border-radius: 14px; border: 1px solid rgba(217,180,91,.5); background: var(--surface); cursor: pointer; font-size: 1.35rem; }
.match-layout { max-width: 1280px; margin: 18px auto; display: grid; grid-template-columns: minmax(0, 760px) minmax(290px, 1fr); gap: 20px; align-items: start; }
.play-area { width: 100%; max-width: 760px; min-width: 0; justify-self: center; }
.player-card { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; background: var(--surface); border: 1px solid rgba(217,180,91,.35); border-radius: 18px; }
.player-card .avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #181b24); border: 2px solid var(--gold); font-weight: 900; }
.player-card small { display: block; color: var(--muted); margin-top: 2px; }
.player-card time { font-size: clamp(1.45rem, 5vw, 2.1rem); font-variant-numeric: tabular-nums; font-weight: 900; }
.board-frame { position: relative; width: 100%; min-width: 0; margin: 12px auto; padding: 13px; border-radius: 22px; background: linear-gradient(135deg, var(--gold), #3b2a12 25%, #10131a 55%, var(--accent)); box-shadow: var(--shadow); }
.chess-board { width: 100%; min-width: 0; aspect-ratio: 1 / 1; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); overflow: hidden; border-radius: 11px; contain: layout paint; }
.square { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; overflow: hidden; display: grid; place-items: center; border: 0; padding: 0; cursor: pointer; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", serif; font-size: clamp(2rem, 8vw, 4.8rem); line-height: 1; transition: filter .15s, transform .15s; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square:hover { filter: brightness(1.1); }
.square:disabled { cursor: default; }
.square:disabled:hover { filter: none; }
.square.selected { box-shadow: inset 0 0 0 5px var(--accent); z-index: 2; }
.square.legal::after { content: ""; position: absolute; width: 26%; aspect-ratio: 1; border-radius: 50%; background: color-mix(in srgb, var(--accent) 72%, transparent); box-shadow: 0 0 18px var(--accent); }
.square.capture::after { width: 72%; background: transparent; border: 5px solid color-mix(in srgb, var(--accent) 75%, transparent); }
.square .white-piece { color: var(--piece-white); text-shadow: 0 2px 1px #6e5a37, 0 5px 12px #000; z-index: 1; }
.square .black-piece { color: var(--piece-black); text-shadow: 0 1px 0 #735bd9, 0 4px 12px #000; z-index: 1; }
.square.in-check { animation: checkPulse .8s infinite alternate; }
.coord { position: absolute; font: 700 10px/1 system-ui; opacity: .65; color: currentColor; }
.coord.file { right: 4px; bottom: 3px; }.coord.rank { left: 4px; top: 3px; }
.board-message { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%,-50%); padding: 14px 20px; border-radius: 14px; background: rgba(5,7,11,.9); border: 1px solid var(--gold); font-weight: 900; opacity: 0; pointer-events: none; transition: .2s; }
.board-message.show { opacity: 1; }
.turn-strip { display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); margin: 10px; }
.turn-strip span { width: 10px; height: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px var(--success); }
.match-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.match-controls button { position: relative; border: 1px solid rgba(255,255,255,.12); background: var(--surface); border-radius: 14px; padding: 13px 10px; cursor: pointer; }
.match-controls b { position: absolute; top: -7px; right: -7px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); font-size: .7rem; }
.side-panel { min-height: 500px; background: var(--surface); border: 1px solid rgba(217,180,91,.3); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.panel-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid rgba(255,255,255,.1); }
.tab-button { padding: 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.tab-button.is-active { color: var(--gold); box-shadow: inset 0 -3px var(--gold); }
.panel-content { padding: 18px; }
.panel-content h2 { margin: 0 0 14px; font-family: Georgia, serif; }
.move-history { margin: 0; padding-left: 32px; columns: 2; color: var(--muted); }
.move-history li { padding: 5px 8px; break-inside: avoid; }
.empty-state { list-style: none; color: var(--muted); }
.chat-heading { display: flex; justify-content: space-between; align-items: center; }
.chat-heading button { border: 1px solid rgba(255,255,255,.15); border-radius: 10px; padding: 8px 12px; background: var(--surface-2); }
.messages { min-height: 180px; max-height: 300px; overflow: auto; display: flex; flex-direction: column; gap: 9px; }
.message { margin: 0; display: flex; flex-direction: column; max-width: 84%; gap: 3px; }
.message span { padding: 9px 12px; border-radius: 12px; background: var(--surface-2); }
.message.mine { align-self: end; text-align: right; }.message.mine span { background: color-mix(in srgb, var(--accent) 35%, var(--surface-2)); }
.quick-messages { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 14px; }
.quick-messages button { padding: 9px; border-radius: 10px; border: 1px solid rgba(217,180,91,.35); background: transparent; cursor: pointer; }
.chat-mode { display: grid; gap: 6px; margin-top: 14px; color: var(--muted); }
.chat-mode select { width: 100%; padding: 10px; border-radius: 10px; background: var(--surface-2); color: var(--text); border: 1px solid rgba(255,255,255,.15); }
.promotion-dialog { border: 1px solid var(--gold); border-radius: 22px; padding: 0; background: #11151e; color: var(--text); box-shadow: var(--shadow); }
.promotion-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.promotion-dialog form { padding: 24px; text-align: center; }
.promotion-choices { display: grid; grid-template-columns: repeat(4, 70px); gap: 10px; margin: 18px 0; }
.promotion-choices button { height: 70px; border-radius: 14px; border: 1px solid var(--gold); background: var(--surface-2); font-size: 2.5rem; cursor: pointer; }

.game-over-dialog { width: min(520px, calc(100% - 28px)); border: 1px solid var(--gold); border-radius: 26px; padding: 0; overflow: hidden; background: linear-gradient(145deg, #171b26, #090b10); color: var(--text); box-shadow: 0 35px 120px rgba(0,0,0,.75); }
.game-over-dialog::backdrop { background: rgba(3,5,9,.82); backdrop-filter: blur(9px); }
.game-over-card { position: relative; padding: 34px; text-align: center; overflow: hidden; }
.game-over-card::before { content:""; position:absolute; inset:-80px; z-index:-1; opacity:.35; background:radial-gradient(circle at 50% 10%, var(--accent), transparent 48%); }
.game-over-icon { width: 104px; height: 104px; margin: 10px auto 14px; display:grid; place-items:center; border-radius:50%; border:2px solid var(--gold); color:var(--gold); font: 4.5rem/1 Georgia,serif; box-shadow:0 0 42px color-mix(in srgb, var(--accent) 50%, transparent); }
.game-over-card h2 { margin:0; font: 800 clamp(2.2rem,8vw,4rem)/1 Georgia,serif; color:var(--gold); }
.game-over-card > p:not(.eyebrow) { color:var(--muted); font-size:1.05rem; }
.game-over-actions { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:24px; }
.game-over-actions .primary-button { min-width:0; }

.theme-walnut { --accent:#d89a45; --light-square:#d9b987; --dark-square:#6b3f24; --piece-white:#fff0c7; --piece-black:#301b10; }
.theme-citadel { --accent:#65a8ff; --light-square:#e4dfd3; --dark-square:#6b7079; --piece-white:#fffdf5; --piece-black:#222a33; }
.theme-runic { --accent:#8b5cf6; --light-square:#d8d0c4; --dark-square:#2d2b37; --piece-white:#fff5dc; --piece-black:#130f1d; }

@keyframes checkPulse { from { box-shadow: inset 0 0 0 4px #ff6b6b; } to { box-shadow: inset 0 0 24px 8px rgba(255,50,50,.85); } }

@media (max-width: 850px) {
  .theme-picker { grid-template-columns: 1fr; max-width: 430px; }
  .theme-card, .theme-card img { height: 118px; min-height: 118px; }
  .match-layout { grid-template-columns: 1fr; }
  .side-panel { min-height: 0; }
  .game-header { height: 64px; }
  .move-history { columns: 1; }
  .difficulty-field { grid-template-columns: 1fr 135px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

