:root{
  --bg0:#07060b;
  --bg1:#0c0b14;
  --stroke:rgba(255,255,255,.12);
  --text:#e9e7ff;
  --muted:rgba(233,231,255,.70);
  --accent:#7c5cff;
  --accent2:#29f2d4;
  --hot:#ff3c9b;
  --shadow:0 18px 70px rgba(0,0,0,.55);

  --board-size:min(92vw, 560px);
  --sq:calc(var(--board-size) / 8);
}

*{box-sizing:border-box}
html,body{height:auto; min-height:100%}
html,body{max-width:100%; overflow-x:hidden}
body{
  margin:0;
  font-family: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  color:var(--text);
  background:
    radial-gradient(900px 650px at 20% 0%, rgba(124,92,255,.18), transparent 60%),
    radial-gradient(700px 500px at 80% 10%, rgba(41,242,212,.14), transparent 55%),
    radial-gradient(900px 650px at 70% 110%, rgba(255,60,155,.10), transparent 58%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 45%, #07060b);
}

.chess-game{
  min-height:100svh;
  padding-bottom:max(32px, env(safe-area-inset-bottom));
}

/* ---- Theme system (3 modes) ---- */
.chess-game.theme-marble{
  --frame: rgba(230, 208, 170, .22);
  --panel: rgba(18,16,35,.92);
  --light:#f0eadf;
  --dark:#5a4f5c;
  --sq-hi: rgba(255, 223, 168, .22);
  --moveDot: rgba(41,242,212,.82);
  --capRing: rgba(255,138,61,.88);
}
.chess-game.theme-tournament{
  --frame: rgba(245, 196, 88, .24);
  --panel: rgba(18,12,10,.70);
  --light:#f3d9b6;
  --dark:#6b3b1f;
  --sq-hi: rgba(255, 210, 120, .20);
  --moveDot: rgba(255, 222, 120, .85);
  --capRing: rgba(255,60,155,.78);
}
.chess-game.theme-flat{
  --frame: rgba(255,255,255,.10);
  --panel: rgba(18,16,35,.82);
  --light:#e8e3ff;
  --dark:#5a4aa8;
  --sq-hi: rgba(124,92,255,.14);
  --moveDot: rgba(41,242,212,.86);
  --capRing: rgba(255,138,61,.90);
}

.topbar{
  position:sticky;
  top:0;
  z-index:20;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:14px 14px;
  background:
    radial-gradient(900px 520px at 20% -40%, rgba(255,210,120,.14), transparent 60%),
    radial-gradient(900px 520px at 80% -40%, rgba(124,92,255,.10), transparent 60%),
    rgba(8,8,16,.92);
  border-bottom:1px solid rgba(255,255,255,.12);
  box-shadow: 0 14px 60px rgba(0,0,0,.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.back-link{
  color:rgba(233,231,255,.92);
  text-decoration:none;
  font-weight:900;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.04);
  white-space:nowrap;
}
.back-link:hover{border-color:rgba(255,210,120,.35); background:rgba(255,210,120,.08); transform:translateY(-1px)}
.title-wrap{min-width:0; display:flex; flex-direction:column; gap:2px}
.title{margin:0; font-size:15px; letter-spacing:.55px; text-transform:uppercase; font-weight:950}
.status-line{font-size:12px; color:var(--muted); font-weight:850; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:48vw}
.top-actions{display:flex; gap:8px; align-items:center}

/* Header button polish (no content changes) */
.btn{
  border-radius:999px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.04);
  box-shadow: 0 18px 70px rgba(0,0,0,.18);
  transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover{
  transform:translateY(-1px);
  border-color:rgba(255,210,120,.26);
  background:rgba(255,210,120,.08);
  box-shadow: 0 26px 90px rgba(0,0,0,.30);
}
.btn.primary:hover{border-color:rgba(255,210,120,.40)}

.btn{
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.03);
  color:var(--text);
  padding:10px 12px;
  border-radius:999px;
  cursor:pointer;
  font-weight:900;
  font-size:13px;
  transition:transform .12s ease, border-color .15s ease, background .15s ease;
}
.btn:hover{transform:translateY(-1px); border-color:rgba(124,92,255,.45); background:rgba(124,92,255,.06)}
.btn:active{transform:translateY(0)}
.btn.primary{
  border-color:rgba(124,92,255,.55);
  background:linear-gradient(135deg, rgba(124,92,255,.95), rgba(41,242,212,.55));
  text-shadow:0 1px 10px rgba(0,0,0,.35);
}
.btn.ghost{background:rgba(255,255,255,.02)}
.btn.big{min-height:44px; padding:12px 16px; font-size:14px}
.btn[disabled]{opacity:.6; cursor:not-allowed}

.layout{
  display:grid;
  grid-template-columns: 1fr 320px;
  gap:14px;
  padding:14px 12px 22px;
  max-width:1120px;
  margin:0 auto;
  align-items:start;
}
.board-wrap{display:flex; flex-direction:column; gap:10px; align-items:center}

.board-shell{
  width:var(--board-size);
  border-radius:22px;
  border:1px solid rgba(255,255,255,.12);
  background:
    radial-gradient(120% 120% at 18% 12%, rgba(255,255,255,.10), transparent 52%),
    radial-gradient(140% 140% at 85% 115%, rgba(0,0,0,.35), transparent 55%),
    linear-gradient(180deg, rgba(10,60,34,.82), rgba(7,26,16,.82));
  box-shadow:0 30px 90px rgba(0,0,0,.55);
  padding:10px;
}

.board{
  width:calc(var(--board-size) - 20px);
  height:calc(var(--board-size) - 20px);
  display:grid;
  grid-template-columns:repeat(8, 1fr);
  grid-template-rows:repeat(8, 1fr);
  border-radius:16px;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.08);
  position:relative;
}

.sq{
  position:relative;
  border:0;
  padding:0;
  display:grid;
  place-items:center;
  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.sq.light{
  background: linear-gradient(180deg, color-mix(in srgb, var(--light) 86%, white 14%), var(--light));
}
.sq.dark{
  background: linear-gradient(180deg, color-mix(in srgb, var(--dark) 84%, white 16%), var(--dark));
}
.chess-game.theme-marble .board-shell{
  background:
    radial-gradient(120% 120% at 16% 12%, rgba(255,255,255,.14), transparent 56%),
    radial-gradient(120% 120% at 80% 110%, rgba(0,0,0,.40), transparent 58%),
    linear-gradient(180deg, rgba(248,236,220,.14), rgba(10,8,16,.68));
  border-color: rgba(230, 208, 170, .22);
}
.chess-game.theme-tournament .board-shell{
  background:
    radial-gradient(120% 120% at 18% 12%, rgba(255,220,140,.18), transparent 56%),
    radial-gradient(120% 120% at 80% 110%, rgba(0,0,0,.50), transparent 58%),
    linear-gradient(180deg, rgba(110,55,25,.60), rgba(14,10,12,.88));
  border-color: rgba(245, 196, 88, .24);
}
.chess-game.theme-flat .board-shell{
  background: rgba(255,255,255,.02);
  box-shadow: var(--shadow);
}

.sq.selected{outline:3px solid rgba(41,242,212,.72); outline-offset:-3px}
.sq.lastFrom,.sq.lastTo{box-shadow: inset 0 0 0 999px rgba(255,60,155,.10)}
.sq.in-check{box-shadow: inset 0 0 0 999px rgba(255,60,155,.16)}

.sq.legal::after{
  content:"";
  width:14px; height:14px;
  border-radius:999px;
  background: var(--moveDot);
  box-shadow:0 0 0 6px color-mix(in srgb, var(--moveDot) 16%, transparent);
}
.sq.capture::after{
  content:"";
  width:64%;
  height:64%;
  border-radius:999px;
  box-shadow: inset 0 0 0 3px var(--capRing);
}

.piece{
  width:92%;
  height:92%;
  display:grid;
  place-items:center;
  font-size: clamp(28px, 5.8vw, 46px);
  line-height:1;
  transition: transform .12s ease, filter .12s ease;
  position:relative;
}
.piece .sym{
  position:relative;
  z-index:2;
}
.piece .plate{
  position:absolute;
  inset:10%;
  border-radius:999px;
  z-index:1;
  opacity:0;
}

/* Flat: crisp unicode with minimal shadow */
.chess-game.theme-flat .piece{
  filter:none;
}
.chess-game.theme-flat .piece.white{color: rgba(245,245,255,.98)}
.chess-game.theme-flat .piece.black{color: rgba(18,16,40,.98)}
.chess-game.theme-flat .piece.black .sym{
  text-shadow:
    -1px -1px 0 rgba(255,255,255,.35),
    1px -1px 0 rgba(255,255,255,.35),
    -1px 1px 0 rgba(255,255,255,.35),
    1px 1px 0 rgba(255,255,255,.35);
}

/* Premium: sculpted piece disc + rim lighting */
.chess-game.theme-marble .piece,
.chess-game.theme-tournament .piece{
  filter: drop-shadow(0 12px 20px rgba(0,0,0,.46));
}
.chess-game.theme-marble .piece .plate,
.chess-game.theme-tournament .piece .plate{
  opacity:1;
  background:
    radial-gradient(70% 70% at 28% 22%, rgba(255,255,255,.55), transparent 55%),
    radial-gradient(90% 90% at 70% 86%, rgba(0,0,0,.35), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(0,0,0,.16));
  box-shadow:
    inset 0 10px 20px rgba(255,255,255,.16),
    inset 0 -14px 18px rgba(0,0,0,.26),
    0 10px 22px rgba(0,0,0,.32);
}
.chess-game.theme-marble .piece.white .plate{
  background:
    radial-gradient(70% 70% at 28% 22%, rgba(255,255,255,.70), transparent 55%),
    linear-gradient(180deg, rgba(255,255,255,.34), rgba(210,200,190,.08));
}
.chess-game.theme-marble .piece.black .plate{
  background:
    radial-gradient(70% 70% at 28% 22%, rgba(255,255,255,.24), transparent 55%),
    linear-gradient(180deg, rgba(40,40,56,.95), rgba(12,10,20,.95));
}
.chess-game.theme-tournament .piece.white .plate{
  background:
    radial-gradient(70% 70% at 28% 22%, rgba(255,255,255,.68), transparent 55%),
    linear-gradient(180deg, rgba(255,236,210,.36), rgba(120,75,40,.06));
}
.chess-game.theme-tournament .piece.black .plate{
  background:
    radial-gradient(70% 70% at 28% 22%, rgba(255,220,140,.18), transparent 55%),
    linear-gradient(180deg, rgba(42,26,18,.96), rgba(10,8,10,.96));
}

/* Strong silhouette + rim light for black pieces (visibility fix) */
.chess-game.theme-marble .piece.black .sym,
.chess-game.theme-tournament .piece.black .sym{
  color: rgba(10,10,18,.98);
  text-shadow:
    0 1px 0 rgba(255,255,255,.18),
    -1px -1px 0 rgba(255,255,255,.55),
    1px -1px 0 rgba(255,255,255,.55),
    -1px 1px 0 rgba(255,255,255,.55),
    1px 1px 0 rgba(255,255,255,.55),
    0 10px 16px rgba(0,0,0,.40);
}
.chess-game.theme-marble .piece.white .sym,
.chess-game.theme-tournament .piece.white .sym{
  color: rgba(252,252,255,.98);
  text-shadow:
    0 2px 0 rgba(0,0,0,.22),
    0 10px 18px rgba(0,0,0,.25);
}
.piece.pop{animation: pop .16s ease}
@keyframes pop{from{transform:scale(.92)} to{transform:scale(1)}}
.piece.capture{animation: cap .18s ease}
@keyframes cap{to{transform:scale(.65); opacity:0}}

.coord{
  position:absolute;
  font-size:10px;
  font-weight:950;
  color: rgba(255,255,255,.55);
  pointer-events:none;
}
.coord.file{bottom:4px; right:6px}
.coord.rank{top:4px; left:6px}
.chess-game.view-flat .coord{color: rgba(0,0,0,.38)}

.side{display:flex; flex-direction:column; gap:12px}
.panel{
  border-radius:22px;
  border:1px solid var(--stroke);
  background:linear-gradient(135deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  box-shadow:var(--shadow);
  padding:14px;
}
.panel-title{font-weight:1000; letter-spacing:.25px; font-size:14px; text-transform:uppercase; color:rgba(233,231,255,.80); margin-bottom:10px}
.row{display:flex; justify-content:space-between; align-items:center; gap:10px; padding:6px 0}
.k{color:rgba(233,231,255,.66); font-weight:950; letter-spacing:.2px; font-size:12px; text-transform:uppercase}
.v{font-weight:950; font-variant-numeric: tabular-nums}
.muted{color:rgba(233,231,255,.72)}
.btn-row{display:flex; gap:10px; flex-wrap:wrap; margin-top:10px}

.caps{display:grid; grid-template-columns:1fr 1fr; gap:10px}
.cap-h{font-size:12px; font-weight:950; color:rgba(233,231,255,.70); text-transform:uppercase; letter-spacing:.2px}
.cap-list{min-height:34px; display:flex; flex-wrap:wrap; gap:6px; margin-top:8px}
.cap{font-size:20px; line-height:1; padding:6px 8px; border-radius:12px; border:1px solid rgba(255,255,255,.10); background:rgba(255,255,255,.02)}

/* Stats box */
.stats{width:100%}
.stats-title{font-weight:1000; letter-spacing:.25px; text-transform:uppercase; font-size:13px; color:rgba(233,231,255,.86); margin:0 0 10px}
.stats-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:8px 10px;
  margin-bottom:10px;
}
.stat{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding:8px 10px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.02);
}
.stats-caps{display:grid; grid-template-columns:1fr 1fr; gap:10px}
.stats .cap-list{min-height:32px}
.stats--mobile{
  display:none;
  width:var(--board-size);
  border-radius:22px;
  border:1px solid var(--stroke);
  background:linear-gradient(135deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  box-shadow:var(--shadow);
  padding:12px;
}
.stats--desktop{display:block}

.mobile-bar{display:none; width:var(--board-size); gap:8px; flex-wrap:wrap}
.chip{
  display:inline-flex;
  align-items:center;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.02);
  color:rgba(233,231,255,.88);
  font-size:12px;
  font-weight:900;
}
.chip--warn{border-color:rgba(255,60,155,.55); background:rgba(255,60,155,.12)}

.overlay{
  position:fixed;
  inset:0;
  z-index:1000;
  display:grid;
  place-items:center;
  padding:18px;
  background: rgba(4,4,12,.55);
}
.overlay[hidden]{display:none !important}
.panel.modal{
  width:min(92vw, 560px);
  background:linear-gradient(180deg, rgba(18,16,35,.94), rgba(10,9,16,.92));
}
.modal-head{display:flex; flex-direction:column; gap:6px; margin-bottom:12px}
.modal-title{font-weight:1000; letter-spacing:.25px; font-size:18px}
.modal-sub{color:rgba(233,231,255,.74); font-weight:850; font-size:13px; line-height:1.35}
.section{margin:14px 0}
.label{font-weight:950; letter-spacing:.2px; text-transform:uppercase; font-size:12px; color:rgba(233,231,255,.68); margin-bottom:8px}
.seg{display:flex; flex-wrap:wrap; gap:10px}
.seg-btn{
  flex:1 1 auto;
  min-height:40px;
  padding:10px 12px;
  border-radius:999px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.02);
  color:var(--text);
  font-weight:950;
  cursor:pointer;
}
.seg-btn.active{
  border-color:rgba(124,92,255,.55);
  background:linear-gradient(135deg, rgba(124,92,255,.85), rgba(41,242,212,.22));
}
.actions{display:flex; justify-content:flex-end; margin-top:12px}

.promo-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}
.promo-btn{
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.03);
  border-radius:18px;
  min-height:54px;
  padding:10px;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  color:var(--text);
  cursor:pointer;
  font-weight:1000;
}
.promo-btn:hover{border-color:rgba(41,242,212,.45)}
.promo-sym{font-size:34px; line-height:1}

.drawer-panel{
  position:fixed;
  left:50%;
  top:max(12px, env(safe-area-inset-top));
  bottom:max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width:min(94vw, 760px);
  overflow:hidden;
  display:flex;
  flex-direction:column;
  z-index:1100;
  border-radius:22px;
  background: rgba(8, 45, 28, 0.98);
  border:1px solid rgba(255,255,255,0.18);
  box-shadow:0 24px 80px rgba(0,0,0,0.55);
}
.drawer-panel[hidden]{display:none !important}
.drawer-header{
  flex:0 0 auto;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding:14px 16px 10px;
  border-bottom:1px solid rgba(255,255,255,0.14);
}
.drawer-header h2{margin:0; font-size:16px; font-weight:1000; letter-spacing:.2px}
.drawer-body{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding:10px 16px 18px;
}
.drawer-footer{
  flex:0 0 auto;
  padding:10px 16px max(14px, env(safe-area-inset-bottom));
  border-top:1px solid rgba(255,255,255,0.14);
  background: rgba(8, 45, 28, 0.98);
}
.lead{color:rgba(233,231,255,.86); font-weight:850; line-height:1.35}

/* style pills */
.style-pills{display:inline-flex; gap:6px; flex-wrap:wrap; justify-content:flex-end}
.pill{
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.02);
  color:rgba(233,231,255,.92);
  padding:8px 10px;
  border-radius:999px;
  font-weight:950;
  cursor:pointer;
}
.pill.active{border-color:rgba(41,242,212,.55); background:rgba(41,242,212,.10)}

/* Guide styling */
.guide{scroll-behavior:smooth}
.toc{
  margin-top:12px;
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(255,255,255,0.04);
  border-radius:18px;
  padding:12px;
  position:sticky;
  top:0;
  z-index:3;
  backdrop-filter:none;
}
.toc-title{font-weight:1000; letter-spacing:.2px; margin-bottom:8px}
.toc-grid{display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:6px}
.toc a{
  color:rgba(233,231,255,.90);
  text-decoration:none;
  font-weight:850;
  font-size:13px;
  padding:8px 10px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(0,0,0,.18);
}
.toc a:hover{border-color:rgba(124,92,255,.35)}
.gsec{padding-top:10px; margin-top:8px}
.gsec h3{margin:12px 0 8px; font-size:16px}
.cards{display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:10px}
.card{
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(255,255,255,0.04);
  border-radius:16px;
  padding:10px;
}
.card .h{font-weight:1000}
.card .b{color:rgba(233,231,255,.78); font-weight:850; margin-top:4px; font-size:13px; line-height:1.25}
.callout{
  margin-top:10px;
  border-radius:18px;
  padding:10px 12px;
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(0,0,0,.20);
}
.callout .t{font-weight:1000; letter-spacing:.2px}
.callout.tip{border-color:rgba(41,242,212,.28); background:rgba(41,242,212,.08)}
.callout.warn{border-color:rgba(255,138,61,.28); background:rgba(255,138,61,.08)}
.toplink{
  display:inline-block;
  margin-top:10px;
  color:rgba(233,231,255,.82);
  font-weight:900;
  text-decoration:none;
  border:1px solid rgba(255,255,255,0.12);
  background:rgba(255,255,255,0.03);
  padding:8px 10px;
  border-radius:999px;
}
.piece-cards{display:grid; grid-template-columns:1fr; gap:10px}
.pc{
  display:flex;
  gap:12px;
  align-items:flex-start;
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(255,255,255,0.04);
  border-radius:16px;
  padding:10px;
}
.pc .sym{font-size:34px; line-height:1}
.pc .h{font-weight:1000}
.pc .b{color:rgba(233,231,255,.78); font-weight:850; margin-top:4px; font-size:13px; line-height:1.25}
.ref{
  display:grid;
  gap:8px;
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(255,255,255,0.04);
  border-radius:16px;
  padding:12px;
  font-weight:850;
  color:rgba(233,231,255,.82);
}

@media (max-width: 720px){
  .toc-grid{grid-template-columns:1fr}
  .cards{grid-template-columns:1fr}
}

body.modal-open{overflow:hidden}

@media (max-width: 980px){
  .layout{grid-template-columns:1fr; justify-items:center}
  .side{width:min(92vw, 560px)}
  .status-line{max-width:55vw}
  .mobile-bar{display:flex}
  .stats--mobile{display:block}
  .stats--desktop{display:none}
}

@media (max-width: 520px){
  :root{ --board-size: min(94vw, 420px); }
  .top-actions .btn{padding:9px 10px}
}

@media (max-height: 620px){
  .drawer-panel{
    top:max(6px, env(safe-area-inset-top));
    bottom:max(6px, env(safe-area-inset-bottom));
    border-radius:16px;
  }
  .drawer-header{padding:10px 12px 8px}
  .drawer-body{padding:8px 12px 12px}
  .drawer-footer{padding:8px 12px max(10px, env(safe-area-inset-bottom))}
  .drawer-header h2{font-size:15px}
}
