:root {
  --bg: #12141a;
  --panel: #1c1f28;
  --ink: #e8eef4;
  --muted: #8b9aab;
  --line: rgba(232, 238, 244, 0.1);
  --gold: #d4a24c;
  --good: #6fbf8a;
  --bad: #d36b6b;
  --light: #e8d7b0;
  --dark: #678a5c;
  --frame: #252830;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(900px 420px at 0% 0%, rgba(212, 162, 76, 0.12), transparent 50%),
              linear-gradient(180deg, #161820, var(--bg));
}
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { max-width: 1120px; margin: 0 auto; padding: 1.2rem 1.2rem 3rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.brand { font-family: var(--display); font-size: 1.5rem; font-weight: 700; color: var(--ink); }
.brand span { color: var(--gold); }
.nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.nav a { color: var(--muted); }
.nav a.active, .nav a:hover { color: var(--ink); text-decoration: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.15rem;
  margin-bottom: 1rem;
}
h1 { font-family: var(--display); font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 0.4rem; }
h2 { font-family: var(--display); font-size: 1.25rem; margin: 0 0 0.8rem; }
.sub { color: var(--muted); margin: 0 0 1.1rem; }

label { display: block; color: var(--muted); font-size: 0.85rem; margin: 0.65rem 0 0.3rem; }
input, textarea, select {
  width: 100%; border-radius: 10px; border: 1px solid var(--line);
  background: #12161d; color: var(--ink); padding: 0.65rem 0.8rem; font: inherit;
}
textarea { min-height: 110px; font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }
.btn {
  display: inline-flex; align-items: center; margin-top: 0.8rem; border: 0; cursor: pointer;
  border-radius: 999px; padding: 0.65rem 1.1rem; font: inherit; font-weight: 700;
  background: var(--gold); color: #1a140c;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.bad { background: var(--bad); color: #1a0c0c; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 1rem; }
@media (min-width: 800px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.board-layout { grid-template-columns: 1.1fr 0.9fr; } }

.flash { padding: 0.7rem 0.9rem; border-radius: 10px; margin-bottom: 0.7rem; }
.flash.ok { background: rgba(111,191,138,.14); color: var(--good); }
.flash.error { background: rgba(211,107,107,.14); color: var(--bad); }
.muted { color: var(--muted); }
.badge { display: inline-block; padding: 0.12rem 0.45rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: rgba(212,162,76,.18); color: var(--gold); }
.badge.good { background: rgba(111,191,138,.18); color: var(--good); }
.badge.bad { background: rgba(211,107,107,.18); color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.55rem 0.3rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

.stat .value { font-family: var(--display); font-size: 2rem; }
.color-block { border-radius: 12px; padding: 0.9rem; border: 1px solid var(--line); }
.white-side { border-top: 3px solid var(--light); }
.black-side { border-top: 3px solid #6b4f3a; }

.tip { padding: 0.7rem 0.85rem; border-left: 3px solid var(--gold); background: rgba(0,0,0,.2); border-radius: 0 10px 10px 0; margin: 0.4rem 0; }
.pgn-box { font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; color: var(--muted); }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.2rem;
}
.top .brand { font-family: var(--display); font-size: 1.35rem; font-weight: 700; color: var(--ink); }
.top nav { display: flex; gap: 1rem; }
.top nav a { color: var(--muted); }
.top nav a:hover { color: var(--ink); text-decoration: none; }
main { max-width: 1180px; margin: 0 auto; padding: 0 1rem 2.5rem; }

.play-layout {
  display: grid;
  gap: 1.25rem;
  align-items: start;
}
@media (min-width: 900px) {
  .play-layout { grid-template-columns: minmax(0, 1fr) minmax(220px, 280px); }
}
.board-stage {
  width: min(100%, calc(100dvh - 7.5rem), 740px);
  margin: 0 auto;
  min-width: 0;
}
.file-legend {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin: 0 0 0.45rem;
  padding: 0 0.55rem;
  font-size: 0.62rem;
  font-weight: 600;
  color: rgba(196, 208, 220, 0.55);
  text-align: center;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
}
.board-frame {
  background:
    linear-gradient(180deg, #323844 0%, #1c2128 100%);
  padding: 0.55rem;
  border-radius: 12px;
  box-shadow:
    0 22px 48px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 4px;
  overflow: hidden;
  background: var(--light);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.28);
  container-type: inline-size;
}
.board button.sq {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.sq:focus { outline: none; }
.sq:focus-visible { outline: 2px solid rgba(255, 214, 90, 0.85); outline-offset: -2px; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last { box-shadow: inset 0 0 0 400px rgba(246, 214, 92, 0.42); }
.sq.sel { box-shadow: inset 0 0 0 400px rgba(255, 224, 92, 0.58); }
.sq.mark:not(.occ)::after {
  content: "";
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(20, 24, 18, 0.28);
  pointer-events: none;
  z-index: 2;
}
.sq.mark.occ::after {
  content: "";
  position: absolute;
  inset: 6%;
  border: 0.22em solid rgba(20, 24, 18, 0.28);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
}
.sq-coord {
  position: absolute;
  font-size: clamp(0.52rem, 2.2cqi, 0.74rem);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}
.sq-coord.rank { top: 0.18em; left: 0.28em; }
.sq-coord.file { right: 0.22em; bottom: 0.16em; }
.sq.light .sq-coord { color: rgba(55, 68, 40, 0.88); }
.sq.dark .sq-coord { color: rgba(255, 250, 235, 0.9); }
.piece-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 3;
}
.sq.white-piece .piece-wrap {
  filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.28));
}
.sq.black-piece .piece-wrap {
  filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.22));
}
.piece-wrap img, .piece-wrap svg {
  width: 92%;
  height: 92%;
  display: block;
  user-select: none;
}

@media (max-width: 899px) {
  .play-layout { grid-template-columns: 1fr; }
  .board-stage { width: min(100%, calc(100vw - 1.6rem), calc(100dvh - 10.5rem)); }
  .file-legend { font-size: 0.55rem; padding: 0 0.4rem; margin-bottom: 0.35rem; }
  .play-panel { order: 2; }
  .hint { min-height: 0; }
  .san { max-height: 120px; }
}
@media (max-width: 560px) {
  main { padding: 0 0.65rem 1.4rem; }
  .top { padding: 0.65rem 0.7rem; }
  .file-legend { font-size: 0.5rem; letter-spacing: 0.03em; }
  .board-frame { padding: 0.32rem; border-radius: 8px; }
  .sq-coord { font-size: 0.55rem; }
}
.look { margin: 0.9rem 0 0.8rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
.look summary { cursor: pointer; font-weight: 700; margin-bottom: 0.55rem; }
.look-label { color: var(--muted); font-size: 0.75rem; margin: 0.55rem 0 0.35rem; text-transform: uppercase; letter-spacing: 0.04em; }
.swatches, .style-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.swatch {
  width: 34px; height: 22px; border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; padding: 0; overflow: hidden; display: grid; grid-template-columns: 1fr 1fr;
}
.swatch.on, .style-btn.on { outline: 2px solid var(--gold); outline-offset: 1px; }
.swatch i { display: block; }
.style-btn {
  border: 1px solid var(--line); background: #12161d; color: var(--ink);
  border-radius: 999px; padding: 0.28rem 0.7rem; font: inherit; font-size: 0.82rem; cursor: pointer;
}
.color-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.45rem; }
.color-row label { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; margin: 0; font-size: 0.78rem; }
.color-row input[type="color"] {
  width: 42px; height: 28px; padding: 0; border: 1px solid var(--line); background: transparent; cursor: pointer;
}
.status { font-family: var(--display); font-size: 1.25rem; margin: 0 0 0.5rem; }
.hint { color: var(--muted); font-size: 0.92rem; min-height: 3.2rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.actions button, .promo button {
  border: 0; cursor: pointer; border-radius: 999px;
  padding: 0.55rem 1rem; font: inherit; font-weight: 700;
  background: var(--gold); color: #1a140c;
}
.san { padding-left: 0; list-style: none; color: var(--muted); font-size: 0.9rem; max-height: 280px; overflow: auto; }
.rules { max-width: 720px; }
.promo {
  position: fixed; inset: auto 0 18%; margin: auto;
  width: min(360px, 90vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 1rem;
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  justify-content: center;
  box-shadow: 0 18px 40px rgba(0,0,0,.4);
}
.promo.hidden { display: none; }
.promo p { width: 100%; margin: 0 0 0.3rem; text-align: center; }

.result-modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  background: rgba(8, 10, 14, 0.72);
  display: flex !important;
  align-items: center;
  justify-content: center;
  z-index: 99999 !important;
  padding: 1rem;
}
.result-modal.hidden, .result-modal[hidden] { display: none !important; }
.result-card {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.25rem 1.3rem 1.35rem;
  text-align: center;
  box-shadow: 0 22px 50px rgba(0,0,0,.45);
}
.result-title { font-family: var(--display); font-size: 1.45rem; margin: 0 0 0.4rem; }
.result-text { color: var(--muted); margin: 0 0 1rem; }
.result-card .btn, .result-card button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer; border-radius: 999px;
  padding: 0.55rem 1.15rem; font: inherit; font-weight: 700;
  background: var(--gold); color: #1a140c; text-decoration: none; margin: 0 0.2rem;
}
.result-card .btn.ghost {
  background: transparent; color: var(--ink); border: 1px solid var(--line);
}

.who { color: var(--gold); }
.auth { max-width: 420px; }
.vs { color: var(--muted); font-size: 0.9rem; }
.actions a.btn {
  display: inline-flex; align-items: center; text-decoration: none;
  border-radius: 999px; padding: 0.55rem 1rem; font-weight: 700;
}
.actions button.danger { background: #8b3a32; color: #f7efe4; }
.actions button.ghost, .actions a.btn.ghost {
  background: transparent; color: var(--ink); border: 1px solid var(--line);
}
.actions button.hidden,
.actions button[hidden] { display: none !important; }
.people { list-style: none; padding: 0; margin: 0; }
.people li {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem; flex-wrap: wrap; padding: 0.55rem 0; border-bottom: 1px solid var(--line);
}
.people button {
  border: 0; cursor: pointer; border-radius: 999px;
  padding: 0.35rem 0.75rem; font: inherit; font-weight: 700;
  background: var(--gold); color: #1a140c;
}
.people button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.people a { font-weight: 700; }
