/* ==========================================================================
   CHESS · kandabatata.com
   Day-first board room: warm paper, berry + amber accents, ink pieces.
   Night mode flips the same tokens to a deep slate board.
   ========================================================================== */

:root {
  --paper: #f6f1e8;
  --paper-2: #efe7da;
  --paper-3: #e6dbc9;
  --panel: #fffdfa;
  --panel-soft: rgba(255, 253, 250, .72);
  --line: rgba(58, 42, 26, .14);
  --line-strong: rgba(58, 42, 26, .28);
  --text: #241c15;
  --muted: #6b5b49;
  --muted-2: #8b7a67;

  --berry: #b8305a;
  --berry-deep: #95254a;
  --berry-dark: #7a1d3c;
  --amber: #a06a12;
  --amber-soft: #f0c988;
  --good: #1a7f5a;
  --bad: #b23a2c;

  --sq-light: #f4e9d7;
  --sq-dark: #bb8b5f;
  --sq-light-edge: rgba(120, 84, 48, .12);
  --piece-w-fill: #fffdf8;
  --piece-w-line: #2b2118;
  --piece-b-fill: #2b2118;
  --piece-b-line: #f8f0e3;
  --hl-last: rgba(232, 182, 78, .38);
  --hl-sel: rgba(184, 48, 90, .48);
  --hl-move: rgba(184, 48, 90, .9);
  --hl-capture: rgba(178, 58, 44, .85);
  --hl-check: rgba(214, 60, 44, .55);

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 26px 60px -34px rgba(58, 40, 22, .45);
  --shadow-soft: 0 14px 34px -26px rgba(58, 40, 22, .5);

  --font-display: 'Fraunces', 'Outfit', Georgia, serif;
  --font-ui: 'Outfit', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html[data-theme="night"] {
  --paper: #101a26;
  --paper-2: #0c141d;
  --paper-3: #182534;
  --panel: #16212e;
  --panel-soft: rgba(22, 33, 46, .74);
  --line: rgba(196, 218, 240, .16);
  --line-strong: rgba(196, 218, 240, .3);
  --text: #eaf1f8;
  --muted: #a7b7c8;
  --muted-2: #7f90a3;

  --berry: #f0668f;
  --berry-deep: #d8507a;
  --berry-dark: #a62f56;
  --amber: #f0b450;
  --amber-soft: #f8d79a;
  --good: #4fd6a0;
  --bad: #f0685a;

  --sq-light: #7f95ad;
  --sq-dark: #445b73;
  --sq-light-edge: rgba(255, 255, 255, .12);
  --piece-w-fill: #f6fafd;
  --piece-w-line: #16212c;
  --piece-b-fill: #16212c;
  --piece-b-line: #d6e4f0;
  --hl-last: rgba(240, 180, 80, .3);
  --hl-sel: rgba(240, 102, 143, .5);
  --hl-move: rgba(240, 102, 143, .95);
  --hl-capture: rgba(240, 104, 90, .9);
  --hl-check: rgba(240, 90, 74, .6);

  --shadow: 0 26px 60px -34px rgba(0, 0, 0, .85);
  --shadow-soft: 0 14px 34px -26px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background .35s ease, color .35s ease;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; }
button { font-family: inherit; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }
.wrap { width: min(1180px, calc(100% - 2.5rem)); margin-inline: auto; }
.link { color: var(--berry); text-decoration: none; border-bottom: 1px solid rgba(184, 48, 90, .4); }
.link:hover { color: var(--berry-deep); }
.kbd {
  font-family: var(--font-ui);
  font-size: .78em;
  padding: .12em .45em;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--paper-2);
  color: var(--text);
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ================================ PIECES ================================ */
.piece { width: 100%; height: 100%; display: block; }
.piece--w .piece-body,
.piece--w .piece-base { fill: var(--piece-w-fill); stroke: var(--piece-w-line); stroke-width: 1.7; stroke-linejoin: round; }
.piece--b .piece-body,
.piece--b .piece-base { fill: var(--piece-b-fill); stroke: var(--piece-b-line); stroke-width: 1.7; stroke-linejoin: round; }
.piece-detail { fill: none; stroke-width: 1.7; stroke-linecap: round; }
.piece--w .piece-detail { stroke: var(--piece-w-line); }
.piece--b .piece-detail { stroke: var(--piece-b-line); }
.piece-detail-fill { stroke: none; }
.piece--w .piece-detail-fill { fill: var(--piece-w-line); }
.piece--b .piece-detail-fill { fill: var(--piece-b-line); }

/* ============================== BACKGROUND ============================== */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; background:
  radial-gradient(120% 90% at 50% -10%, var(--paper) 0%, var(--paper-2) 60%, var(--paper-3) 100%); }

.bg-glow { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .55; }
.bg-glow--berry {
  width: 46vw; height: 46vw; min-width: 300px; min-height: 300px;
  top: -16vw; left: -12vw;
  background: radial-gradient(circle, rgba(184, 48, 90, .3), transparent 70%);
  animation: glowDrift 28s ease-in-out infinite alternate;
}
.bg-glow--amber {
  width: 40vw; height: 40vw; min-width: 260px; min-height: 260px;
  right: -12vw; bottom: -14vw;
  background: radial-gradient(circle, rgba(196, 138, 54, .3), transparent 72%);
  animation: glowDrift 34s ease-in-out infinite alternate-reverse;
}
html[data-theme="night"] .bg-glow--berry { background: radial-gradient(circle, rgba(240, 102, 143, .3), transparent 70%); }
html[data-theme="night"] .bg-glow--amber { background: radial-gradient(circle, rgba(240, 180, 80, .22), transparent 72%); }

.bg-board {
  position: absolute; top: 50%; left: 50%;
  width: 132vh; height: 132vh; min-width: 900px; min-height: 900px;
  transform: translate(-50%, -50%) rotate(-8deg);
  opacity: .5;
  animation: boardDrift 60s ease-in-out infinite alternate;
}
.bg-check-a { fill: var(--text); opacity: .035; }
html[data-theme="night"] .bg-check-a { opacity: .06; }

.bg-silhouettes { position: absolute; inset: 0; }
.bg-piece { position: absolute; opacity: .055; }
.bg-piece .piece { width: 100%; height: 100%; }
.bg-piece--1 { width: 190px; height: 190px; top: 8%; right: 6%; animation: floatPiece 26s ease-in-out infinite; }
.bg-piece--2 { width: 130px; height: 130px; bottom: 14%; left: 5%; animation: floatPiece 32s ease-in-out infinite reverse; }
.bg-piece--3 { width: 96px; height: 96px; top: 62%; right: 16%; animation: floatPiece 38s ease-in-out infinite; }
.bg-piece--4 { width: 78px; height: 78px; top: 22%; left: 14%; animation: floatPiece 30s ease-in-out infinite reverse; }
html[data-theme="night"] .bg-piece { opacity: .1; }

.bg-scan {
  position: absolute; inset: -30% 0 auto;
  height: 60%;
  background: linear-gradient(to bottom, transparent, rgba(184, 48, 90, .05), transparent);
  animation: scanDown 18s linear infinite;
}
.bg-vignette {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 80% at 50% 40%, transparent 45%, rgba(120, 92, 60, .16) 100%),
    linear-gradient(to bottom, rgba(255, 255, 255, .35), transparent 20%, transparent 82%, rgba(120, 92, 60, .12));
}
html[data-theme="night"] .bg-vignette {
  background:
    radial-gradient(120% 80% at 50% 40%, transparent 45%, rgba(4, 9, 15, .7) 100%),
    linear-gradient(to bottom, rgba(6, 12, 19, .5), transparent 20%, transparent 82%, rgba(4, 9, 15, .6));
}

@keyframes glowDrift { 0% { transform: translate3d(0, 0, 0) scale(1); } 100% { transform: translate3d(3vw, 3vh, 0) scale(1.1); } }
@keyframes boardDrift {
  0% { transform: translate(-50%, -50%) rotate(-8deg) scale(1); }
  100% { transform: translate(-49%, -51%) rotate(-5deg) scale(1.04); }
}
@keyframes floatPiece { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(14px, -18px); } }
@keyframes scanDown { 0% { transform: translateY(-20%); } 100% { transform: translateY(160%); } }

/* ================================ TOPBAR ================================ */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  width: min(1180px, calc(100% - 2.5rem)); margin-inline: auto;
  padding: 1.4rem 0 .7rem;
}
.brand { display: inline-flex; align-items: center; gap: .7rem; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px;
  color: #fff;
  background: linear-gradient(150deg, #d4486f, var(--berry-dark));
  box-shadow: 0 12px 26px -14px rgba(184, 48, 90, .9), inset 0 1px 0 rgba(255, 255, 255, .3);
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-text { display: grid; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.14rem; letter-spacing: .01em; }
.brand-sub { font-size: .72rem; color: var(--muted-2); letter-spacing: .09em; text-transform: uppercase; }
.topnav { display: flex; align-items: center; gap: .85rem; }
.topnav-link { color: var(--muted); text-decoration: none; font-size: .88rem; }
.topnav-link:hover { color: var(--berry); }
.topnav-sep { width: 1px; height: 18px; background: var(--line); }

.theme-toggle {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .38rem .7rem; border-radius: 999px; cursor: pointer;
  font-family: inherit; font-size: .78rem; letter-spacing: .04em;
  border: 1px solid var(--line); background: var(--panel-soft);
  color: var(--muted);
  transition: color .2s, border-color .2s, background .2s, transform .2s;
}
.theme-toggle:hover { color: var(--berry); border-color: rgba(184, 48, 90, .4); transform: translateY(-1px); }
.theme-toggle:focus-visible { outline: 2px solid var(--berry); outline-offset: 2px; }
.theme-icon { width: 15px; height: 15px; }
html[data-theme="day"] .theme-icon--sun { display: none; }
html[data-theme="night"] .theme-icon--moon { display: none; }

.kanda {
  display: inline-flex; align-items: center; gap: .45rem;
  text-decoration: none; font-size: .78rem; letter-spacing: .04em;
  color: var(--muted-2);
  padding: .38rem .7rem; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  transition: color .2s, border-color .2s, transform .2s;
}
.kanda:hover { color: var(--berry); border-color: rgba(184, 48, 90, .4); transform: translateY(-1px); }
.kanda-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--berry); box-shadow: 0 0 10px rgba(184, 48, 90, .8); }

/* ================================ SHARED ================================ */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
.card--flat { background: var(--panel-soft); }

.btn {
  --btn-bg: linear-gradient(150deg, #cd4170, var(--berry) 55%, var(--berry-dark));
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .68rem 1.15rem;
  font-family: var(--font-ui); font-weight: 600; font-size: .94rem; letter-spacing: .01em;
  color: #fff; text-decoration: none; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 12px;
  background: var(--btn-bg);
  box-shadow: 0 14px 30px -18px rgba(184, 48, 90, .9), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform .16s ease, box-shadow .2s ease, filter .2s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1.5px); filter: brightness(1.05); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.2); box-shadow: none; }
.btn--lg { padding: .92rem 1.6rem; font-size: 1.02rem; border-radius: 14px; }
.btn--sm { padding: .48rem .85rem; font-size: .84rem; border-radius: 10px; }
.btn--ghost {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  color: var(--text);
  box-shadow: none;
}
.btn--ghost:hover:not(:disabled) { background: var(--paper-2); border-color: var(--berry); color: var(--berry); }

.tag {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--font-ui);
  font-size: .72rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--amber); font-weight: 600;
}
.eyebrow {
  display: inline-flex; align-items: center; gap: .55rem;
  padding: .42rem .85rem; border-radius: 999px;
  border: 1px solid rgba(160, 106, 18, .3);
  background: rgba(240, 201, 136, .28);
  color: #7d4e0c; font-size: .78rem; letter-spacing: .05em;
}
html[data-theme="night"] .eyebrow {
  border-color: rgba(240, 180, 80, .3);
  background: rgba(240, 180, 80, .14);
  color: var(--amber-soft);
}
.eyebrow-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--berry);
  box-shadow: 0 0 0 0 rgba(184, 48, 90, .5);
  animation: blip 2.6s ease-out infinite;
}
@keyframes blip {
  0% { box-shadow: 0 0 0 0 rgba(184, 48, 90, .5); }
  70% { box-shadow: 0 0 0 9px rgba(184, 48, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(184, 48, 90, 0); }
}

.field-label {
  display: block; font-family: var(--font-ui);
  font-size: .72rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted-2); margin-bottom: .45rem;
}
.field-help { color: var(--muted-2); font-size: .8rem; line-height: 1.55; }
.field-label--gap { margin-top: 1.2rem; }
.name-row { margin-top: 1.8rem; max-width: 360px; }
.text-input,
.code-input,
.rename-input {
  width: 100%; padding: .72rem .95rem;
  font-family: var(--font-ui); font-size: 1rem; font-weight: 600;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: 12px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.text-input::placeholder,
.rename-input::placeholder { color: var(--muted-2); opacity: .7; font-weight: 500; }
.text-input:focus,
.code-input:focus,
.rename-input:focus {
  border-color: var(--berry);
  box-shadow: 0 0 0 4px rgba(184, 48, 90, .14);
}
.alert {
  border: 1px solid rgba(178, 58, 44, .4);
  background: rgba(178, 58, 44, .08);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem; margin-top: 1rem;
  color: #8a2016; font-size: .86rem;
}
.alert strong { display: block; margin-bottom: .35rem; color: #75160f; }
.alert ul { margin: .2rem 0 0; padding-left: 1.1rem; }
html[data-theme="night"] .alert { color: #ffd0c9; }
html[data-theme="night"] .alert strong { color: #fff; }

/* ================================ LANDING ================================ */
.home { padding-bottom: 3rem; flex: 1 0 auto; }
.game-shell { flex: 1 0 auto; padding-bottom: 3rem; }
.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 400px);
  gap: 3rem;
  align-items: center;
}
.hero { padding: 3rem 0 2rem; max-width: 800px; }

/* --- decorative board on the landing page --- */
.hero-board-wrap { position: relative; padding-top: .5rem; }
.hero-board-card {
  padding: .85rem .85rem .7rem;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: rotate(-1.2deg);
  transition: transform .5s cubic-bezier(.2, .7, .3, 1);
}
.hero-board-card:hover { transform: rotate(0deg) translateY(-3px); }
.hero-board-top, .hero-board-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .25rem .5rem;
}
.hero-board-foot { padding: .6rem .25rem 0; }
.hero-board-name { font-family: var(--font-ui); font-size: .78rem; font-weight: 700; color: var(--ink); letter-spacing: .01em; }
.hero-board-tag {
  font-family: var(--font-ui); font-size: .62rem; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted-2);
}
.hero-board-turn {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--font-ui); font-size: .7rem; font-weight: 600; color: var(--berry);
}
.hero-board-turn .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--berry);
  box-shadow: 0 0 0 3px rgba(184, 48, 90, .16);
  animation: livePulse 2.4s ease infinite;
}
.hero-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line);
}
.hero-board .sq { position: relative; }
.hero-board .piece-holder svg { width: 86%; height: 86%; }
.hero-board-note {
  margin-top: 1rem;
  padding: .7rem .9rem;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 14px 30px -22px rgba(58, 40, 22, .8);
  font-size: .8rem; line-height: 1.5; color: var(--muted);
}
.hero-board-note strong { color: var(--berry); font-family: var(--font-ui); }
.hero-title {
  margin-top: 1.1rem;
  font-size: clamp(2.4rem, 5.8vw, 4.2rem);
  font-weight: 700; line-height: 1.02;
  letter-spacing: -.02em;
}
.hero-title-accent {
  background-image: linear-gradient(96deg, var(--berry) 0%, #d4486f 45%, var(--amber) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-title--sm { font-size: clamp(1.9rem, 4vw, 2.9rem); }
.hero-sub { margin-top: 1.15rem; color: var(--muted); font-size: 1.02rem; line-height: 1.7; max-width: 62ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 1.7rem; align-items: center; }
.hero-actions--tight { margin-top: 1.3rem; justify-content: center; }
.hero-hint { margin-top: 1.15rem; color: var(--muted-2); font-size: .84rem; line-height: 1.6; }
.hero--compact { padding-top: 2.4rem; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.4rem; }
.step { padding: 1.4rem 1.35rem 1.5rem; position: relative; overflow: hidden; }
.step::after {
  content: ''; position: absolute; inset: auto -30% -60% auto; width: 60%; height: 120%;
  background: radial-gradient(circle, rgba(184, 48, 90, .12), transparent 65%);
  pointer-events: none;
}
.step-num { font-family: var(--font-ui); font-size: .8rem; font-weight: 700; letter-spacing: .18em; color: var(--berry); }
.step-title { margin-top: .5rem; font-size: 1.24rem; }
.step-text { margin-top: .5rem; color: var(--muted); font-size: .89rem; line-height: 1.65; }

.rules-strip { margin-top: 1rem; padding: 1.4rem 1.45rem 1.5rem; }
.rules-title { font-size: 1.12rem; }
.rules-list { list-style: none; margin: .95rem 0 0; padding: 0; display: grid; gap: .6rem; }
.rules-list li {
  display: flex; flex-wrap: wrap; gap: .35rem 1rem; align-items: baseline;
  padding-bottom: .6rem; border-bottom: 1px dashed var(--line);
  color: var(--muted); font-size: .89rem;
}
.rules-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.rule-k {
  flex: 0 0 auto; min-width: 108px; color: var(--berry); font-family: var(--font-ui);
  font-weight: 700; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
}

/* ================================= JOIN ================================= */
.code-form { max-width: 520px; padding: 1.6rem 1.5rem 1.7rem; margin-top: 1.6rem; }
.code-input {
  font-family: var(--font-display); font-size: clamp(1.15rem, 3.4vw, 1.55rem);
  letter-spacing: .16em;
}
.code-input::placeholder { color: var(--muted-2); opacity: .55; letter-spacing: .12em; }

/* ============================== STATUS BAR ============================== */
.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  flex-wrap: wrap; padding: .5rem 0 1rem;
}
.statusbar-left, .statusbar-right { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.codepill {
  display: inline-flex; align-items: center; gap: .55rem;
  padding: .5rem .8rem .5rem .9rem; cursor: pointer;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
  transition: border-color .2s, transform .2s;
}
.codepill:hover { border-color: var(--berry); transform: translateY(-1px); }
.codepill-label { font-family: var(--font-ui); font-size: .66rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-2); }
.codepill-code { font-family: var(--font-display); font-weight: 700; letter-spacing: .14em; font-size: .98rem; }
.codepill .icon { color: var(--muted-2); width: 15px; height: 15px; }

.role-chip {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .45rem .8rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: .84rem; font-weight: 600;
}
.role-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--berry); box-shadow: 0 0 9px rgba(184, 48, 90, .6); }
.role-dot--w { background: #f7f1e6; box-shadow: 0 0 0 1px var(--line-strong); }
.role-dot--b { background: #2b2118; box-shadow: 0 0 0 1px rgba(255, 255, 255, .35); }
html[data-theme="night"] .role-dot--w { background: #f2f7fb; }
html[data-theme="night"] .role-dot--b { background: #101a26; box-shadow: 0 0 0 1px rgba(214, 228, 240, .6); }
.role-sub { color: var(--muted-2); font-weight: 400; font-size: .74rem; }
.role-name { max-width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-chip[hidden] { display: none !important; }
.role-edit {
  display: inline-grid; place-items: center; padding: .1rem; margin-left: .1rem;
  background: none; border: 0; border-radius: 6px; cursor: pointer; color: var(--muted-2);
  transition: color .18s, background .18s;
}
.role-edit:hover { color: var(--berry); background: rgba(184, 48, 90, .1); }
.role-edit .icon { width: 14px; height: 14px; }
.rename-form { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.rename-form[hidden] { display: none; }
.rename-input { width: 160px; max-width: 46vw; padding: .42rem .65rem; font-size: .88rem; border-radius: 10px; }

.live { display: inline-flex; align-items: center; gap: .4rem; font-family: var(--font-ui); font-size: .76rem; color: var(--good); letter-spacing: .04em; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: livePulse 1.9s ease-in-out infinite; }
.live.is-off { color: var(--amber); }
@keyframes livePulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }

.phase-chip {
  font-family: var(--font-ui);
  padding: .42rem .8rem; border-radius: 999px; font-size: .72rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  border: 1px solid rgba(160, 106, 18, .35); color: #7d4e0c;
  background: rgba(240, 201, 136, .3);
}
html[data-theme="night"] .phase-chip { color: var(--amber-soft); border-color: rgba(240, 180, 80, .35); background: rgba(240, 180, 80, .14); }
.phase-chip[data-phase="playing"] { color: #96294c; border-color: rgba(184, 48, 90, .35); background: rgba(184, 48, 90, .1); }
html[data-theme="night"] .phase-chip[data-phase="playing"] { color: #ffc0d4; border-color: rgba(240, 102, 143, .4); background: rgba(240, 102, 143, .14); }
.phase-chip[data-phase="finished"] { color: var(--muted); border-color: var(--line-strong); background: var(--paper-2); }

.screen[hidden] { display: none !important; }
.screen.is-active { animation: screenIn .32s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* =============================== WAITING ================================ */
.wait-card { max-width: 660px; margin: 1.2rem auto 0; padding: 2rem 1.8rem 2.2rem; text-align: center; }
.wait-card .stage-sub { margin-inline: auto; }
.stage-title { font-size: clamp(1.5rem, 3vw, 2.1rem); margin-top: .5rem; }
.stage-sub { color: var(--muted); font-size: .92rem; margin-top: .6rem; max-width: 60ch; line-height: 1.7; }
.code-share {
  margin: 1.6rem auto 0; padding: 1.2rem 1.2rem 1.35rem;
  border-radius: var(--radius-sm); border: 1px dashed rgba(160, 106, 18, .4);
  background: rgba(240, 201, 136, .2); max-width: 430px;
}
html[data-theme="night"] .code-share { border-color: rgba(240, 180, 80, .4); background: rgba(240, 180, 80, .1); }
.code-share-label { font-family: var(--font-ui); font-size: .68rem; letter-spacing: .18em; text-transform: uppercase; color: var(--amber); }
.code-share-value {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(1.5rem, 6vw, 2.1rem);
  letter-spacing: .2em; margin: .35rem 0 .85rem; color: var(--text);
}
.code-share-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.code-share .field-help { margin-top: .8rem; }

.wait-visual { margin-top: 1.9rem; display: grid; place-items: center; }
.wait-board {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  width: 132px; height: 132px;
}
.wait-sq {
  border-radius: 4px; background: var(--paper-2);
  border: 1px solid var(--line);
  animation: waitPulse 3.4s ease-in-out infinite;
  animation-delay: var(--d, 0ms);
}
.wait-sq--a { background: rgba(184, 48, 90, .22); border-color: rgba(184, 48, 90, .25); }
@keyframes waitPulse {
  0%, 100% { opacity: .45; transform: scale(.94); }
  45% { opacity: 1; transform: scale(1); }
}

.wait-status { list-style: none; margin: 1.6rem auto .3rem; padding: 0; display: grid; gap: .55rem; max-width: 360px; text-align: left; }
.wait-status li {
  display: flex; align-items: center; gap: .6rem;
  font-size: .88rem; color: var(--muted-2);
  padding: .55rem .8rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper);
  transition: color .2s, border-color .2s, background .2s;
}
.wait-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: 0 0 auto; }
.wait-status li.is-done { color: var(--text); border-color: rgba(26, 127, 90, .4); background: rgba(26, 127, 90, .08); }
.wait-status li.is-done .wait-dot { background: var(--good); box-shadow: 0 0 10px rgba(26, 127, 90, .7); }

/* ================================= PLAY ================================= */
.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.1rem;
  align-items: start;
  max-width: 1100px;
  margin-inline: auto;
}
.board-card { padding: 1.1rem 1.2rem 1.25rem; width: 100%; }
.board-shell {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 18px;
  gap: 4px;
  width: 100%;
  max-width: 660px;
  margin: .2rem auto 0;
}
.coords { display: grid; color: var(--muted-2); font-family: var(--font-ui); font-size: .68rem; font-weight: 600; }
.coords--rank { grid-column: 1; grid-row: 1; grid-template-rows: repeat(8, minmax(0, 1fr)); align-items: center; justify-items: center; }
.coords--file { grid-column: 2; grid-row: 2; grid-template-columns: repeat(8, minmax(0, 1fr)); align-items: center; justify-items: center; }

.board {
  grid-column: 2; grid-row: 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 40px -30px rgba(58, 40, 22, .9), inset 0 0 0 1px var(--line);
  user-select: none;
  touch-action: manipulation;
}

.sq {
  position: relative;
  padding: 0; margin: 0; border: 0;
  display: block;
  cursor: default;
  background: var(--sq-light);
  transition: box-shadow .18s ease;
}
.sq--dark { background: var(--sq-dark); }
.sq--light { background: var(--sq-light); }

.piece-holder {
  position: absolute; inset: 6%;
  display: grid; place-items: center;
  transition: transform .12s ease, filter .18s ease;
  pointer-events: none;
}
body[data-screen="screenPlay"] .sq[data-sq] { cursor: pointer; }

/* highlights */
.sq.is-last { box-shadow: inset 0 0 0 999px var(--hl-last); }
.sq.is-selected { box-shadow: inset 0 0 0 4px var(--hl-sel); }
.sq.is-check { animation: checkPulse 1.5s ease-in-out infinite; }
.sq.is-check-new { animation: checkBurst .9s ease-out; }

.sq.is-target::after {
  content: '';
  position: absolute; inset: 38%;
  border-radius: 50%;
  background: var(--hl-move);
  opacity: .5;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .18);
  animation: dotIn .18s ease both;
}
.sq.is-capture::after {
  content: '';
  position: absolute; inset: 5%;
  border-radius: 50%;
  border: 2.5px solid var(--hl-capture);
  opacity: .8;
  animation: dotIn .18s ease both;
}
@keyframes dotIn { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); } }

.sq:hover .piece-holder { transform: translateY(-2px); }
.sq:focus-visible { outline: 3px solid var(--berry); outline-offset: -3px; }

@keyframes checkPulse {
  0%, 100% { background-color: var(--sq-light); }
  50% { background-color: var(--hl-check); }
}
.sq--dark.is-check { animation-name: checkPulseDark; }
@keyframes checkPulseDark {
  0%, 100% { background-color: var(--sq-dark); }
  50% { background-color: var(--hl-check); }
}
@keyframes checkBurst {
  0% { box-shadow: inset 0 0 0 0 rgba(214, 60, 44, .9); }
  60% { box-shadow: inset 0 0 0 14px rgba(214, 60, 44, 0); }
  100% { box-shadow: inset 0 0 0 0 rgba(214, 60, 44, 0); }
}

/* motion */
.piece--slide { animation: pieceSlide .28s cubic-bezier(.22, .61, .36, 1) both; }
@keyframes pieceSlide {
  from { transform: translate(var(--dx, 0), var(--dy, 0)); }
  to { transform: translate(0, 0); }
}
.sq.is-landed::before {
  content: '';
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 3px rgba(240, 201, 136, .95);
  animation: landGlow .42s ease-out both;
  pointer-events: none;
}
@keyframes landGlow {
  from { opacity: 1; }
  to { opacity: 0; }
}
.piece-ghost { animation: ghostOut .42s ease-out both; }
@keyframes ghostOut {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.55); }
}

/* player strips */
.player-strip {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .55rem .6rem;
  min-height: 36px;
  max-width: 660px;
  margin-inline: auto;
}
.player-strip:last-child { padding: .65rem .55rem .2rem; }
.ps-dot {
  width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  transition: box-shadow .3s ease, transform .3s ease;
}
.ps-dot--w { background: #fffdf8; }
.ps-dot--b { background: #2b2118; }
html[data-theme="night"] .ps-dot--w { background: #f2f7fb; }
html[data-theme="night"] .ps-dot--b { background: #16212c; }
.ps-dot.is-live { box-shadow: 0 0 0 3px rgba(184, 48, 90, .22); animation: dotLive 1.8s ease-in-out infinite; }
@keyframes dotLive { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

.ps-captured { flex: 1 1 auto; min-width: 0; display: inline-flex; align-items: center; gap: 0; flex-wrap: wrap; }
.ps-name { font-family: var(--font-ui); font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 18ch; flex: 0 0 auto; }
.ps-name em { font-style: normal; color: var(--muted-2); font-weight: 400; font-size: .8em; }
.ps-captured .cap { width: 18px; height: 18px; display: inline-grid; place-items: center; opacity: .9; margin-right: -3px; }
.ps-captured .cap .piece { width: 100%; height: 100%; }
.ps-score {
  font-family: var(--font-ui); font-size: .78rem; font-weight: 700;
  color: var(--good); background: rgba(26, 127, 90, .1);
  border: 1px solid rgba(26, 127, 90, .28);
  padding: .1rem .4rem; border-radius: 6px;
}

/* side panel */
.side { display: grid; gap: .9rem; }
.turn-card { padding: 1rem 1.1rem 1.1rem; display: grid; gap: .25rem; transition: border-color .25s, box-shadow .25s; }
.turn-card.is-mine {
  border-color: rgba(184, 48, 90, .45);
  box-shadow: 0 0 40px -24px rgba(184, 48, 90, .8);
}
.turn-card.is-check { border-color: rgba(178, 58, 44, .55); }
.turn-kicker { font-family: var(--font-ui); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-2); }
.turn-state { font-family: var(--font-display); font-weight: 700; font-size: 1.24rem; }
.turn-card.is-mine .turn-state { color: var(--berry); }
.turn-sub { color: var(--muted); font-size: .85rem; line-height: 1.5; }

.moves-card { padding: 1rem 1.05rem 1.1rem; }
.moves-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; }
.board-title { font-family: var(--font-ui); font-size: 1rem; letter-spacing: .01em; }
.board-meta { font-family: var(--font-ui); font-size: .74rem; color: var(--muted-2); letter-spacing: .04em; }
.move-list {
  list-style: none; margin: .8rem 0 0; padding: 0;
  max-height: 340px; overflow-y: auto;
  display: grid; gap: 2px;
  font-variant-numeric: tabular-nums;
}
.move-list::-webkit-scrollbar { width: 8px; }
.move-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }
.move-row {
  display: grid; grid-template-columns: 30px 1fr 1fr; gap: .3rem;
  padding: .3rem .45rem; border-radius: 7px;
  font-size: .88rem;
}
.move-row:nth-child(odd) { background: var(--paper-2); }
.mv-no { color: var(--muted-2); font-family: var(--font-ui); font-size: .78rem; }
.mv-san { font-family: var(--font-ui); font-weight: 600; color: var(--text); }
.mv-san.is-last { color: var(--berry); }
.move-empty { color: var(--muted-2); font-size: .86rem; padding: .4rem; list-style: none; }

.actions-card { padding: .75rem; display: flex; gap: .5rem; }
.actions-card .btn { flex: 1 1 auto; }

.draw-banner { padding: .9rem 1rem; display: grid; gap: .6rem; border-color: rgba(240, 201, 136, .8); }
.draw-banner[hidden] { display: none; }
.draw-banner p { font-size: .88rem; }
.draw-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ================================ RESULT ================================ */
.over-screen {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 1.2rem;
  background: rgba(246, 241, 232, .66);
  backdrop-filter: blur(4px) saturate(105%);
  -webkit-backdrop-filter: blur(4px) saturate(105%);
  animation: fadeIn .25s ease both;
  overflow-y: auto;
}
html[data-theme="night"] .over-screen { background: rgba(9, 15, 22, .7); }
.over-screen[hidden] { display: none; }
.over-screen.is-active .over-card { animation: cardRise .34s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes cardRise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.over-card { max-width: 680px; width: 100%; padding: 2.2rem 1.9rem 2.3rem; text-align: center; box-shadow: var(--shadow); }
.over-card.is-win { border-color: rgba(240, 201, 136, .9); box-shadow: 0 0 70px -30px rgba(184, 48, 90, .6); }
.over-card.is-loss { border-color: var(--line-strong); }
.over-title { font-size: clamp(1.9rem, 4.6vw, 2.8rem); margin-top: .5rem; }
.over-card.is-win .over-title {
  background-image: linear-gradient(96deg, var(--berry), #d4486f 50%, var(--amber));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.over-sub { color: var(--muted); margin-top: .6rem; font-size: .96rem; line-height: 1.65; }
.over-stats { display: grid; gap: .55rem; margin-top: 1.6rem; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.stat {
  padding: .75rem .5rem; border-radius: 12px;
  border: 1px solid var(--line); background: var(--paper);
  display: grid; gap: .2rem;
}
.stat b { font-family: var(--font-display); font-size: 1.2rem; line-height: 1.1; }
.stat span { font-family: var(--font-ui); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-2); }

/* ============================== PROMOTION =============================== */
.promo {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: rgba(28, 20, 12, .45);
  backdrop-filter: blur(3px);
  animation: fadeIn .18s ease both;
}
.promo[hidden] { display: none; }
.promo-card { padding: 1.2rem 1.2rem 1.1rem; display: grid; gap: .9rem; text-align: center; width: min(360px, calc(100vw - 2rem)); }
.promo-title { font-size: 1.15rem; }
.promo-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.promo-opt {
  display: grid; justify-items: center; gap: .2rem;
  padding: .5rem .2rem .4rem; cursor: pointer;
  background: var(--paper); border: 1px solid var(--line-strong); border-radius: 12px;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.promo-opt svg { width: 100%; height: auto; max-width: 44px; }
.promo-opt span { font-family: var(--font-ui); font-size: .68rem; letter-spacing: .04em; color: var(--muted); }
.promo-opt:hover { transform: translateY(-2px); border-color: var(--berry); background: var(--panel); }
.promo-opt:focus-visible { outline: 2px solid var(--berry); outline-offset: 2px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ================================= TOAST ================================ */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 18px);
  padding: .7rem 1.15rem; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line-strong);
  color: var(--text); font-size: .88rem; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
  z-index: 80; max-width: min(90vw, 460px); text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast--warn { border-color: rgba(184, 48, 90, .6); }
.toast--hit { border-color: rgba(26, 127, 90, .65); }

/* ================================= FOOTER =============================== */
.foot {
  width: min(1180px, calc(100% - 2.5rem)); margin: 2.4rem auto 0; margin-top: auto;
  padding: 1.3rem 0 2.1rem; border-top: 1px solid var(--line);
}
.foot-line { display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: space-between; font-size: .78rem; color: var(--muted-2); }
.foot-brand a { color: var(--berry); text-decoration: none; }
.foot-brand a:hover { text-decoration: underline; }

/* =============================== RESPONSIVE ============================= */
@media (max-width: 1040px) {
  .play-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: .9rem; }
  .home-hero { grid-template-columns: minmax(0, 1fr) 300px; gap: 2rem; }
  .hero-board-note { display: none; }
}

@media (max-width: 860px) {
  .home-hero { grid-template-columns: 1fr; gap: 0; }
  .hero-board-wrap { display: none; }
}

@media (max-width: 900px) {
  .play-layout { grid-template-columns: 1fr; }
  .side { order: 2; }
  .board-card { order: 1; }
  .moves-card .move-list { max-height: 190px; }
  .steps { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .wrap, .topbar, .foot { width: calc(100% - 1.6rem); }
  .brand-sub { display: none; }
  .kanda span:last-child { display: none; }
  .theme-toggle-label { display: none; }
  .theme-toggle { padding: .42rem .55rem; }
  .hero { padding-top: 2.2rem; }
  .hero-actions .btn, .hero-actions .inline-form { width: 100%; }
  .hero-actions .btn { justify-content: center; }
  .role-sub { display: none; }
  .codepill-code { letter-spacing: .08em; font-size: .88rem; }
  .board-card { padding: .6rem .6rem .7rem; }
  .play-layout { gap: .8rem; }
  .player-strip { padding: .35rem .2rem .45rem; }
  .ps-name { font-size: .86rem; max-width: 12ch; }
  .ps-captured .cap { width: 14px; height: 14px; }
  .wait-card, .over-card { padding: 1.6rem 1.2rem 1.8rem; }
  .coords { font-size: .6rem; }
  .board-shell { grid-template-columns: 14px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 14px; }
  .statusbar { gap: .45rem; padding-bottom: .8rem; }
  .statusbar-left { gap: .4rem; width: 100%; justify-content: space-between; }
  .statusbar-right { width: 100%; justify-content: space-between; }
  .codepill-label { display: none; }
  .codepill { padding: .45rem .6rem; gap: .4rem; }
  .codepill-code { font-size: .82rem; }
  .phase-chip { font-size: .68rem; padding: .38rem .65rem; }
  .role-chip { font-size: .8rem; padding: .4rem .6rem; }
  .turn-state { font-size: 1.12rem; }
  .actions-card { padding: .6rem; }
}

/* ============================ MOTION PREFERENCES ======================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* Turn status stays above the board even when the side panel falls below it. */
.board-turn { border-radius:12px; padding:.8rem 1rem; margin-bottom:.7rem; font:700 .94rem/1.3 var(--font-ui); background:var(--paper-2); color:var(--muted); border:1px solid var(--line); }
.board-turn.is-mine { background:#a42352; color:#fff; border-color:#a42352; box-shadow:0 6px 20px rgba(184,48,90,.28); font-size:1.15rem; letter-spacing:.02em; }
.board-tools { display:flex; flex-wrap:wrap; gap:.5rem; margin-bottom:.4rem; }
.board-tools .btn { min-height:42px; }
.board-tools .btn[hidden], .rematch-board-note[hidden] { display:none; }
.rematch-board-note { margin:.4rem 0; font-size:.85rem; color:var(--berry); font-weight:700; }
.turn-flash { position:fixed; z-index:90; top:18%; left:50%; transform:translate(-50%,-12px); width:max-content; max-width:calc(100% - 2rem); padding:1rem 1.5rem; border:2px solid #fff; border-radius:16px; background:#a42352; color:#fff; font:800 clamp(1.4rem,4vw,2.4rem)/1.2 var(--font-ui); text-align:center; box-shadow:0 12px 38px #35132670; opacity:0; pointer-events:none; transition:opacity .2s, transform .2s; }
.turn-flash span { color:#ffe096; }
.turn-flash.is-on { opacity:1; transform:translate(-50%,0); }
.over-card.is-win .over-title,.over-card.is-loss .over-title { font-size:clamp(2.4rem,7vw,4.3rem); font-weight:700; }
.rematch-status { min-height:1.4em; margin:1rem 0 0; color:var(--berry); font-weight:700; font-size:.9rem; }
.rematch-overlay { position:fixed; inset:0; z-index:100; display:grid; place-items:center; overflow:auto; padding:1rem; background:rgba(22,16,20,.68); }
.rematch-overlay[hidden] { display:none; }
.rematch-card { width:min(460px,100%); padding:2rem; text-align:center; box-shadow:var(--shadow); }
.rematch-icon { display:grid; place-items:center; margin:0 auto 1rem; width:60px; height:60px; border-radius:18px; background:var(--paper-2); color:var(--berry); font-size:2rem; }
.rematch-card h2 { font-size:clamp(1.8rem,5vw,2.5rem); margin:.8rem 0; }
.rematch-card p { color:var(--muted); line-height:1.7; }
.rematch-actions { display:flex; justify-content:center; flex-wrap:wrap; gap:.6rem; margin-top:1.4rem; }
.rematch-actions .btn { min-height:48px; }
@media(max-width:620px) { .board-turn { font-size:1rem; padding:.75rem; } .board-turn.is-mine { font-size:1.2rem; } .board-tools .btn { flex:1 1 auto; } .rematch-card { padding:1.5rem; } .rematch-actions .btn { width:100%; } .turn-flash { top:12%; } }
