/* Resigns — daily "convert the resignation" chess game. Same chassis as Bibi
   and Beeb: grayscale chrome, mobile-first, one accent. Resigns's accent is the
   brand BLUE, and the board is cornflower-tinted with brand-orange highlights.
   Piece art lives in Resigns.pieces.css (CC BY-SA). */

:root {
  --white: #ffffff;
  --g50: #f4f4f3;
  --g100: #e4e4e2;
  --g200: #c9c9c5;
  --g400: #9a9a95;
  --g600: #6b6b66;
  --g700: #454542;
  --g800: #262625;
  --black: #0f0f0e;
  --accent: #3f6fd6; /* cornflower, darkened to clear AA large-text on the light bg */
  --accent-soft: rgba(63, 111, 214, 0.12);

  /* board: cornflower squares, orange (brand) move highlights */
  --sq-light: #e8edf7;
  --sq-dark: #8fa7d5;
  --coord-on-light: #6f87b8;
  --coord-on-dark: #eef2fa;
  --hl-last: rgba(252, 107, 68, 0.36);
  --hl-sel: rgba(252, 107, 68, 0.58);
  --hint: rgba(18, 28, 56, 0.26);
  --hover: rgba(255, 255, 255, 0.55);

  --radius: 12px;
  --maxw: 460px;
}

/* Dark mode: Bibi/Beeb's inverted warm grayscale. The board keeps its colors
   (it's content, not chrome), slightly dimmed. Set on <html> by the no-flash
   head script. */
:root[data-theme="dark"] {
  --white: #211f1c;
  --g50: #141312;
  --g100: #1c1b18;
  --g200: #35332f;
  --g400: #7c7a73;
  --g600: #9c9a92;
  --g700: #c7c5be;
  --g800: #e8e6e0;
  --black: #f7f5f1;
  --accent: #82a7f7;
  --accent-soft: rgba(130, 167, 247, 0.14);
}
:root[data-theme="dark"] .board { filter: brightness(0.9) saturate(0.95); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--g50);
  color: var(--g700);
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 14px 14px 0;
}
.hidden { display: none !important; }

/* ---- header ---- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 10px;
}
.brand { line-height: 1; }
.wordmark {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.tagline {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--g400);
  margin-top: 3px;
}
.stats { text-align: right; line-height: 1.2; }
.stat-row { font-size: 12px; color: var(--g400); }
#day-value { font-size: 20px; font-weight: 800; color: var(--g800); display: block; white-space: nowrap; }
#streak { font-size: 12px; color: var(--g600); min-height: 14px; }
.chances {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 6px;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--g200); }
.dot.live { background: var(--g800); }
.dot.spent { background: var(--g100); box-shadow: inset 0 0 0 1px var(--g200); }
body.freeplay #chances,
body.freeplay #streak { display: none; }

/* ---- the game card: what you're playing (tap for details) ---- */
.game-card {
  appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--white);
  border: 1px solid var(--g200);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin: 0 0 10px;
  cursor: pointer;
}
.game-card:active { background: var(--g50); }
.game-event {
  display: block;
  font-size: 14px;
  font-weight: 800;
  color: var(--g800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-meta { display: block; font-size: 12px; color: var(--g600); margin-top: 1px; }
.game-meta .chev { color: var(--g400); }

/* ---- player strips ---- */
.player {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 3px 2px;
  font-size: 14px;
}
.pcolor {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1.5px var(--g600);
}
.pcolor.w { background: #fff; }
.pcolor.b { background: #1b1b1a; box-shadow: none; }
:root[data-theme="dark"] .pcolor.b { box-shadow: inset 0 0 0 1.5px var(--g400); }
.pname {
  font-weight: 800;
  color: var(--g800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.ptitle {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.pelo { font-size: 13px; color: var(--g600); }
.pmat { font-size: 12px; font-weight: 700; color: var(--g600); }
.pright { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--g100);
  color: var(--g600);
  white-space: nowrap;
}
.pill.you { background: var(--accent-soft); color: var(--accent); }
.pill.flag { background: transparent; padding: 3px 0; color: var(--g400); }
.pill.engine.thinking::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 0.9s ease-in-out infinite;
}
@keyframes pulse {
  50% { opacity: 0.2; transform: scale(0.6); }
}

/* ---- board ---- */
.board-wrap {
  position: relative;
  width: 100%;
  /* On short screens the board gives way so the buttons stay above the fold. */
  max-width: max(240px, calc(100vh - 336px));
  max-width: max(240px, calc(100dvh - 336px));
  margin: 0 auto;
}
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.sq { position: relative; background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before,
.sq.sel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--hl-last);
}
.sq.sel::before { background: var(--hl-sel); }
.sq.check {
  background-image: radial-gradient(
    ellipse at center,
    rgba(255, 0, 0, 0.9) 0%,
    rgba(231, 0, 0, 0.55) 30%,
    rgba(169, 0, 0, 0) 80%
  );
}
/* legal-move hints: a dot on empty squares, a ring on captures */
.sq.hint::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, var(--hint) 19%, transparent 21%);
  z-index: 3;
  pointer-events: none;
}
.sq.hint.cap::after { background: radial-gradient(circle, transparent 58%, var(--hint) 60%, var(--hint) 72%, transparent 74%); }
.sq.hover::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--hover);
  z-index: 3;
}
/* coordinates live inside the edge squares */
.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  z-index: 1;
  color: var(--coord-on-light);
}
.sq.dark .coord { color: var(--coord-on-dark); }
.coord.rank { top: 3px; left: 3px; }
.coord.file { bottom: 2px; right: 3px; }

.pieces { position: absolute; inset: 0; pointer-events: none; }
.pc {
  position: absolute;
  left: 0;
  top: 0;
  width: 12.5%;
  height: 12.5%;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  transition: transform 0.18s ease, opacity 0.18s ease;
  z-index: 2;
  will-change: transform;
}
.pieces.no-anim .pc { transition: none; }
.pc.dragging { transition: none; z-index: 20; }
.pc.fading { opacity: 0; }

#board.locked { cursor: default; }

/* promotion picker: a strip over the board */
.promo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 14, 0.45);
  z-index: 30;
  border-radius: 6px;
}
.promo-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--white);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.promo-row button {
  appearance: none;
  width: 58px;
  height: 58px;
  border: 1px solid var(--g200);
  border-radius: 10px;
  background-color: var(--sq-light);
  background-size: 92% 92%;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
}
.promo-row button:active { background-color: var(--sq-dark); }

/* ---- status + moves ---- */
.status {
  text-align: center;
  font-size: 14px;
  color: var(--g700);
  margin: 10px 4px 6px;
  min-height: 38px;
  line-height: 1.4;
}
.status b { color: var(--g800); }
.status.good b { color: var(--accent); }
.status .muted { color: var(--g400); }
.moves {
  position: relative; /* offsetParent for scrollMoves() */
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0 8px;
  min-height: 34px;
  font-size: 13px;
  -webkit-overflow-scrolling: touch;
}
.moves::-webkit-scrollbar { display: none; }
.mv {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 7px;
  color: var(--g700);
  white-space: nowrap;
  background: transparent;
  border: none;
  font: inherit;
}
.mv .n { color: var(--g400); margin-right: 3px; }
.mv.hist { color: var(--g400); }
.mv.cur { background: var(--g800); color: var(--white); }
.mv.cur .n { color: var(--g400); }
.mv.flagged::after { content: " \2691"; color: var(--g400); }

/* ---- controls ---- */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 2px 0 10px;
}
.btn {
  appearance: none;
  border: 1px solid var(--g200);
  background: var(--white);
  color: var(--g700);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.btn:active { background: var(--g50); }
.btn.solid { background: var(--g800); color: var(--white); border-color: var(--g800); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
/* the dark theme's accent is a light blue: dark text keeps it legible */
:root[data-theme="dark"] .btn.accent { color: #0f1626; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---- replay scrubber (winning line / the real game) ---- */
.scrubber {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 10px;
}
.scrubber .round {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--g200);
  background: var(--white);
  color: var(--g800);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
#scrub-range { flex: 1 1 auto; min-width: 40px; accent-color: var(--g700); }
#scrub-close { flex: 0 0 auto; }
.scrub-hint { text-align: center; font-size: 13px; color: var(--g400); padding: 0 4px 12px; }

/* ---- footer ---- */
.footer {
  margin-top: auto;
  padding: 12px 0 16px;
  font-size: 12px;
  color: var(--g400);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.footer a,
.footer .link { color: var(--g600); text-decoration: none; font-weight: 700; }
.link {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.settings-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--g400);
  padding: 4px;
  margin: 0 -4px 0 0;
  line-height: 0;
  border-radius: 8px;
  cursor: pointer;
}
.settings-btn:hover { color: var(--g700); }
.settings-btn svg { display: block; }

/* ---- admin strip (/chess/resigns/admin) ---- */
.admin-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 2px 0 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--g200);
  font-size: 13px;
  color: var(--g600);
}
.admin-bar select {
  font: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--g200);
  border-radius: 8px;
  background: var(--white);
  color: var(--g800);
  max-width: 100%;
}
#admin-game { flex: 1 1 220px; min-width: 0; }
#admin-meta { flex: 1 1 100%; color: var(--g400); }

/* ---- sheets + modal (same as Bibi/Beeb) ---- */
[data-info] { cursor: pointer; }
.backdrop { position: fixed; inset: 0; background: rgba(15, 15, 14, 0.38); z-index: 1050; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--white);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  padding: 26px 20px calc(28px + env(safe-area-inset-bottom));
  max-height: 84vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(110%);
  transition: transform 0.28s ease;
  z-index: 1100;
}
.sheet.open { transform: translateY(0); }
.sheet-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--g400);
  cursor: pointer;
}
.sheet-text h3 { margin: 0 0 8px; font-size: 18px; color: var(--g800); }
.sheet-text p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--g700); }
.sheet-text p:last-child { margin-bottom: 0; }
.sheet-text b { color: var(--g800); }
.sheet-text a { color: var(--accent); }
p.sheet-stat {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--g200);
  font-size: 13px;
  color: var(--g400);
}
p.sheet-stat b { color: var(--g600); }
.sheet-btn { display: block; width: 100%; margin: 6px 0 4px; }
.facts { margin: 0 0 12px; font-size: 14px; line-height: 1.55; }
.facts div { display: flex; gap: 10px; }
.facts dt,
.facts .k { flex: 0 0 74px; color: var(--g400); }
.facts .v { color: var(--g800); }

.setting-row { margin: 0 0 22px; }
.setting-row:last-child { margin-bottom: 0; }
.setting-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--g600);
  margin-bottom: 10px;
}
.segmented {
  display: flex;
  width: 100%;
  border: 1px solid var(--g200);
  border-radius: 999px;
  background: var(--white);
  overflow: hidden;
}
.segmented button {
  appearance: none;
  flex: 1 1 0;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 8px;
  color: var(--g600);
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--g200); }
.segmented button.active { background: var(--g800); color: var(--white); }

.modal-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1200;
}
.modal {
  width: 100%;
  max-width: 340px;
  background: var(--white);
  border-radius: 16px;
  padding: 22px 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-text h3 { margin: 0 0 8px; font-size: 18px; color: var(--g800); }
.modal-text p { margin: 0 0 10px; font-size: 14px; line-height: 1.5; color: var(--g700); }
.modal-text p:last-child { margin-bottom: 0; }
.modal-text .muted { color: var(--g400); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---- the win moment ---- */
.celebrate {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 15, 14, 0.42);
  animation: fade-in 0.25s ease;
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.celebrate-card {
  position: relative;
  width: 100%;
  max-width: 340px;
  text-align: center;
  background: var(--white);
  border-radius: 20px;
  padding: 26px 22px 20px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
  animation: pop-in 0.42s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.celebrate-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--g400);
}
.celebrate-card h2 {
  margin: 6px 0 8px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.celebrate-card p { margin: 0 0 6px; font-size: 15px; line-height: 1.5; color: var(--g700); }
.celebrate-card p.small { font-size: 13px; color: var(--g400); }
.celebrate-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .celebrate, .celebrate-card { animation: none; }
  .pc { transition: none; }
}

/* Short phones (iPhone SE and friends): tighten the chrome around the board. */
@media (max-height: 720px) {
  .wrap { padding-top: 10px; }
  .topbar { margin-bottom: 8px; }
  .wordmark { font-size: 26px; }
  .tagline { display: none; }
  .game-card { padding: 6px 12px; margin-bottom: 6px; }
  .status { margin: 6px 4px 4px; min-height: 0; }
  .moves { padding-bottom: 6px; }
}

@media (max-width: 360px) {
  .wordmark { font-size: 26px; }
  .player { font-size: 13px; }
  .tagline { letter-spacing: 0.1em; }
}
