/* =====================================================================
 * styles.css — Chess game UI (responsive, self-contained, no assets).
 * ===================================================================== */
:root {
  --bg: #14161b;
  --bg-1: #1b1f27;
  --bg-2: #232834;
  --line: #2c323e;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #e0a24a;
  --accent-2: #6ea8fe;
  --danger: #e2604f;
  --good: #5bbf7a;

  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sel: rgba(255, 214, 79, 0.55);
  --last: rgba(255, 232, 120, 0.40);
  --check: rgba(226, 80, 60, 0.85);

  --radius: 12px;
  --anim: 180ms;
  --board-px: 360px;

  --pf: #f6f4ee;
  --ps: #2b2723;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding:
    max(6px, env(safe-area-inset-top))
    max(6px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
}

/* ---- Top bar ---- */
#topbar {
  width: 100%;
  max-width: 980px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 0 0 auto;
  min-height: 30px;
}
.status-pill {
  background: var(--bg-1);
  border: 1px solid var(--line);
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.status-pill.check { border-color: var(--danger); color: #ffd2cc; }
.status-pill.win { border-color: var(--good); color: #cdeed6; }
.thinking {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.thinking::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  animation: pulse 0.9s infinite ease-in-out;
}
@keyframes pulse { 0%,100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ---- Play area ---- */
#play {
  flex: 1 1 auto;
  width: 100%;
  max-width: 980px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#board-wrap {
  position: relative;
  width: var(--board-px);
  height: var(--board-px);
  flex: 0 0 auto;
}
#board {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
#squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.sq {
  position: relative;
  width: 100%;
  height: 100%;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq .coord {
  position: absolute;
  font-size: clamp(7px, 1.6vmin, 11px);
  font-weight: 700;
  opacity: 0.65;
  pointer-events: none;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 2px; top: 1px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

/* highlights */
.sq.sel::after,
.sq.last::after {
  content: "";
  position: absolute;
  inset: 0;
}
.sq.last::after { background: var(--last); }
.sq.sel::after { background: var(--sel); }
.sq.suggest::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 4px var(--accent-2);
  border-radius: 2px;
  animation: pulse 1s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}
.sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--check) 0%, rgba(226, 80, 60, 0) 70%);
}
.sq .hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.sq .hint::after {
  content: "";
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.32);
}
.sq.cap .hint::after {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 6px solid rgba(20, 20, 20, 0.32);
  box-sizing: border-box;
}

/* pieces overlay */
#pieces {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transform: translate(0, 0);
  transition: transform var(--anim) ease;
  will-change: transform;
  z-index: 2;
}
.piece.dragging {
  transition: none;
  z-index: 10;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.5));
}
.piece.fading {
  transition: opacity 160ms ease;
  opacity: 0;
}
.piece svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, 0.35));
}
.piece.w { --pf: #f6f4ee; --ps: #2b2723; }
.piece.b { --pf: #454649; --ps: #08080a; }
.pc * {
  fill: var(--pf);
  stroke: var(--ps);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.pc .slit { fill: none; }
.pc .eye { fill: var(--ps); stroke: none; }

/* ---- Side panel ---- */
#side {
  width: var(--board-px);
  max-width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tray-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tray-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  font-size: 12px;
}
.tray-label {
  color: var(--muted);
  min-width: 44px;
  font-weight: 600;
}
.tray-pieces {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  line-height: 1;
  min-height: 18px;
}
.tray-pieces .cap {
  width: 18px;
  height: 18px;
  margin-right: -3px;
}
.cap svg { width: 100%; height: 100%; display: block; }
.cap.w, .promo-btn.w { --pf: #f6f4ee; --ps: #2b2723; }
.cap.b, .promo-btn.b { --pf: #454649; --ps: #08080a; }
.material { color: var(--good); font-weight: 700; font-size: 12px; min-width: 24px; text-align: right; }
#movelist {
  display: none;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  overflow-y: auto;
  max-height: 120px;
  line-height: 1.6;
}
#movelist .mv { display: inline-block; min-width: 46px; }
#movelist .num { color: var(--muted); }

/* ---- Controls ---- */
#controls {
  flex: 0 0 auto;
  width: 100%;
  max-width: 980px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ctrl {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  transition: background 120ms ease, border-color 120ms ease;
}
.ctrl:hover { background: var(--bg-2); }
.ctrl:active { transform: translateY(1px); }
.ctrl:disabled { opacity: 0.4; cursor: default; }
.ctrl.alert { border-color: var(--accent); color: var(--accent); }

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 30;
  padding: 16px;
}
.overlay.hidden { display: none; }
.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  width: min(380px, 92vw);
  max-height: 92%;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.game-title {
  margin: 0 0 2px;
  font-size: 34px;
  letter-spacing: 1px;
  font-weight: 800;
}
.subtitle { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.opt-group { margin: 12px 0; text-align: left; }
.opt-group.hidden { display: none; }
.opt-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.seg {
  display: flex;
  gap: 6px;
  background: var(--bg-2);
  padding: 4px;
  border-radius: 10px;
}
.seg-btn {
  flex: 1 1 0;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 7px;
  padding: 9px 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.seg-btn.active { background: var(--accent); color: #1a1206; }
.primary {
  margin-top: 16px;
  width: 100%;
  background: var(--accent);
  color: #1a1206;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.4px;
}
.primary:active { transform: translateY(1px); }
.ghost {
  margin-top: 8px;
  width: 100%;
  background: transparent;
  color: var(--accent-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.ghost.hidden { display: none; }

/* promotion */
.promo-card { width: min(320px, 92vw); }
.promo-title { font-size: 14px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
.promo-row { display: flex; gap: 8px; justify-content: center; }
.promo-btn {
  width: 64px;
  height: 64px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  padding: 6px;
}
.promo-btn:hover { border-color: var(--accent); }
.promo-btn svg { width: 100%; height: 100%; }

/* game over */
.score-block { margin: 14px 0 8px; }
.score-label { font-size: 12px; color: var(--muted); }
.big-score {
  font-size: 44px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.best-line { font-size: 12px; color: var(--muted); }
.eligible {
  margin: 6px 0;
  font-size: 12px;
  color: var(--good);
  font-weight: 600;
}
.eligible.hidden { display: none; }

/* toast */
.toast {
  position: absolute;
  bottom: calc(58px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 25;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}
.toast.hidden { display: none; }

/* ---- Wide layout: board centered with side panel ---- */
@media (min-width: 640px) {
  #play {
    flex-direction: row;
    align-items: center;
    gap: 18px;
  }
  #side {
    width: clamp(180px, 26vw, 260px);
    align-self: stretch;
    justify-content: center;
  }
  #movelist { display: block; flex: 1 1 auto; max-height: none; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  .piece, .piece.fading { transition: none; }
}

/* ---------- Publisher brand ---------- */
.fh-brand { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; opacity: 1; color: var(--text); }
.fh-logo { width: 26px; height: 26px; fill: var(--accent); flex: 0 0 auto; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45)); }
.fh-brand span { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; line-height: 1; }
