/* ── Midnight chess club ─────────────────────────────────────────── */
:root {
  --bg: #0c1310;
  --ink: #eae1cb;
  --muted: #93a08d;
  --gold: #d3a94f;
  --gold-bright: #e9c876;
  --danger: #c96a55;
  --light-sq: #ecd9ad;
  --dark-sq: #8f6136;
  --sq-label-on-light: #7a5230;
  --sq-label-on-dark: #ecd9ad;
  --board-w: min(92vw, 560px);
  --sq: calc(var(--board-w) / 8);
  --serif: "Fraunces", Georgia, "Iowan Old Style", serif;
}

* { box-sizing: border-box; margin: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 28px 18px 40px;
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", serif;
  background:
    radial-gradient(1100px 700px at 50% -12%, #1a2a21 0%, var(--bg) 62%),
    var(--bg);
  position: relative;
}
/* felt grain */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

header {
  width: min(960px, 94vw);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  animation: rise .5s ease both;
}
h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  letter-spacing: .01em;
}
h1 .knight { color: var(--gold); }

/* connection chip */
.chip {
  font-size: .8rem;
  padding: 5px 12px 5px 24px;
  border-radius: 999px;
  border: 1px solid rgba(234, 225, 203, .18);
  color: var(--muted);
  position: relative;
  white-space: nowrap;
}
.chip::before {
  content: "";
  position: absolute; left: 10px; top: 50%;
  width: 7px; height: 7px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: var(--gold);
}
.chip[data-state="waiting"]::before { animation: pulse 1.4s ease infinite; }
.chip[data-state="ok"]::before { background: #7fb069; }
.chip[data-state="err"]::before { background: var(--danger); }

/* share card */
#sharecard {
  width: min(960px, 94vw);
  border: 1px solid rgba(211, 169, 79, .45);
  background: rgba(211, 169, 79, .07);
  border-radius: 10px;
  padding: 16px 18px;
  animation: rise .5s .08s ease both;
}
.share-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--gold-bright);
}
.share-sub { color: var(--muted); font-size: .92rem; margin-top: 2px; }
.linkrow { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
#link {
  flex: 1 1 260px;
  min-width: 0;
  font: .85rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(234, 225, 203, .18);
  border-radius: 7px;
  padding: 10px 12px;
}

/* layout */
main { display: flex; flex-direction: column; align-items: center; gap: 22px; width: 100%; }
#layout {
  display: flex;
  gap: 30px;
  align-items: flex-start;
  justify-content: center;
  width: min(960px, 94vw);
  animation: rise .5s .14s ease both;
}

/* board + the fallen-piece trays that flank it */
#boardwrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 auto;
}
.tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  width: var(--board-w);
  min-height: calc(var(--sq) * .86); /* reserved for a full-size glyph, so the board doesn't jump */
  padding: 2px 4px;
}
.fallen {
  font-size: calc(var(--sq) * .74); /* same size as the pieces still on the board */
  line-height: 1;
}
/* A captured piece, cloned and flown from its square into the owner's drawer. */
.fallen.flying {
  position: fixed;
  z-index: 60;
  margin: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: transform .5s cubic-bezier(.35, .8, .35, 1);
  will-change: transform;
}
/* No square underneath here, so the felt has to carry both colors: the board's
   near-black would vanish against it, so Black's losses go wood-brown instead. */
.fallen.w { color: #f0e6cd; text-shadow: 0 1px 2px rgba(0, 0, 0, .45); }
.fallen.b { color: #6b5138; }

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: var(--board-w);
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 6px solid #3a2a1a;
  outline: 1px solid rgba(211, 169, 79, .35);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .85), 0 2px 0 rgba(233, 200, 118, .12) inset;
  flex: 0 0 auto;
}
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.square.light { background: var(--light-sq); color: var(--sq-label-on-light); }
.square.dark  { background: var(--dark-sq);  color: var(--sq-label-on-dark); }

.square[data-file]::after,
.square[data-rank]::before {
  position: absolute;
  font: 600 calc(var(--sq) * .16)/1 Georgia, serif;
  opacity: .6;
}
.square[data-file]::after { content: attr(data-file); right: 5%; bottom: 4%; }
.square[data-rank]::before { content: attr(data-rank); left: 5%; top: 4%; }

/* Last move: a soft tint on the square it left, and a bright ring on the square
   it landed on — steady (not a fleeting blink), so the last-moved piece is easy
   to find without being distracting. */
.square.last { box-shadow: inset 0 0 0 100vmax rgba(233, 200, 118, .18); }
.square.last-to {
  box-shadow: inset 0 0 0 max(3px, calc(var(--sq) * .06)) var(--gold-bright),
              inset 0 0 0 100vmax rgba(233, 200, 118, .26);
}
.square.selected { box-shadow: inset 0 0 0 3px var(--gold); }
.square.check {
  background-image: radial-gradient(circle at 50% 50%, rgba(214, 69, 49, .8), rgba(214, 69, 49, 0) 68%);
}
.square.hint { cursor: pointer; }
.square.hint::after {
  content: "";
  position: absolute;
  width: 30%; height: 30%;
  border-radius: 50%;
  background: rgba(20, 14, 4, .28);
  right: auto; bottom: auto;
}
.square.capture-hint { cursor: pointer; box-shadow: inset 0 0 0 calc(var(--sq) * .07) rgba(20, 14, 4, .3); }

.piece {
  font-size: calc(var(--sq) * .74);
  line-height: 1;
  transform: translateY(-2%);
}
.piece.w { color: #f6efdc; text-shadow: 0 2px 3px rgba(0, 0, 0, .55); -webkit-text-stroke: 1px rgba(58, 42, 26, .65); }
.piece.b { color: #241a12; text-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 0 1px rgba(246, 239, 220, .25); }
.piece.mine { cursor: pointer; transition: transform .12s ease; }
.square:hover .piece.mine { transform: translateY(-6%) scale(1.04); }
.piece.just-moved { animation: land .32s ease; }

/* side panel */
#panel {
  flex: 0 1 300px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#role {
  font-family: var(--serif);
  color: var(--gold-bright);
  font-weight: 500;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .14em;
}
#status {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.25;
  min-height: 1.6em;
}
#substatus { color: var(--muted); font-size: .92rem; min-height: 1.2em; }
#playername {
  font: .95rem/1.4 var(--serif);
  color: var(--ink);
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(234, 225, 203, .18);
  border-radius: 7px;
  padding: 9px 12px;
}
#playername:focus { outline: none; border-color: var(--gold); }
#players { color: var(--muted); font-size: .9rem; letter-spacing: .02em; }

#moves {
  list-style-position: inside;
  margin-top: 6px;
  padding: 12px 14px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid rgba(234, 225, 203, .14);
  border-radius: 8px;
  background: rgba(0, 0, 0, .25);
  font-size: .95rem;
  columns: 2;
  column-gap: 18px;
}
#moves li { padding: 2px 0; break-inside: avoid; }
#moves li::marker { color: var(--gold); font-size: .85em; }
#moves:empty { display: none; }

/* turn-alert toggle — reads as a checkbox, borrows the connection chip's dot */
.notify {
  align-self: flex-start;
  position: relative;
  padding: 4px 0 4px 20px;
  border: 0;
  background: none;
  font: .85rem/1.3 Georgia, "Iowan Old Style", serif;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  transition: color .15s ease;
}
.notify::before {
  content: "";
  position: absolute; left: 0; top: 50%;
  width: 9px; height: 9px;
  border-radius: 50%;
  transform: translateY(-50%);
  border: 1px solid currentColor;
  transition: background .15s ease;
}
.notify:hover:not(:disabled) { color: var(--ink); }
.notify[aria-pressed="true"] { color: var(--gold); }
.notify[aria-pressed="true"]::before { background: var(--gold); }
.notify:disabled { cursor: default; opacity: .65; }

.actions { display: flex; gap: 10px; margin-top: 8px; }

/* buttons */
.btn {
  font-family: var(--serif);
  font-weight: 500;
  font-size: .95rem;
  padding: 9px 18px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.gold { background: var(--gold); color: #211708; }
.btn.gold:hover { background: var(--gold-bright); }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(201, 106, 85, .5); }
.btn.danger:hover { background: rgba(201, 106, 85, .12); }

/* promotion overlay */
#promo {
  position: fixed; inset: 0;
  background: rgba(5, 9, 7, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade .15s ease both;
  z-index: 10;
}
#promo[hidden] { display: none; }
.promo-card {
  background: #17231c;
  border: 1px solid rgba(211, 169, 79, .5);
  border-radius: 12px;
  padding: 20px 24px;
  text-align: center;
  animation: pop .18s ease both;
}
.promo-card p {
  font-family: var(--serif);
  font-weight: 700;
  margin-bottom: 14px;
}
#promo-buttons { display: flex; gap: 10px; }
.promo-piece {
  font-size: 2.6rem;
  line-height: 1;
  width: 64px; height: 64px;
  border-radius: 9px;
  border: 1px solid rgba(234, 225, 203, .2);
  background: rgba(236, 217, 173, .08);
  cursor: pointer;
  transition: background .12s ease, transform .12s ease;
}
.promo-piece:hover { background: rgba(211, 169, 79, .25); transform: translateY(-2px); }
.promo-piece.w { color: #f6efdc; text-shadow: 0 2px 3px rgba(0,0,0,.55); }
.promo-piece.b { color: #241a12; text-shadow: 0 0 1px rgba(246,239,220,.4); background: rgba(236, 217, 173, .35); }

footer { color: var(--muted); font-size: .8rem; text-align: center; opacity: .75; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { from { transform: scale(.72); } }
@keyframes land {
  0%   { transform: translateY(-2%) scale(1.32); }
  55%  { transform: translateY(-2%) scale(.95); }
  100% { transform: translateY(-2%) scale(1); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { 50% { opacity: .25; } }

@media (max-width: 900px) {
  #layout { flex-direction: column; align-items: center; }
  #panel { width: var(--board-w); flex-basis: auto; }
  #moves { max-height: 180px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
