/* ------------------------------------------------------------------ *
 * Creature Chess — stylesheet
 *
 * Design goals, in order:
 *   1. A seven-year-old can tell instantly whose turn it is, which creature
 *      is selected, and where it may go.
 *   2. Big touch targets — this gets played on a tablet.
 *   3. The board still looks like a real chess board, so the skills transfer.
 * ------------------------------------------------------------------ */

:root {
  --ember: #ff9a45;
  --ember-deep: #e2611b;
  --frost: #5a9bf0;
  --frost-deep: #2f6ecb;

  --ink: #1b1a3a;
  --ink-soft: #4a4870;
  --paper: #fffaf0;
  --paper-dim: #f2e9dc;

  --square-light: #f5e2bb;
  --square-dark: #c58a53;

  --pick: #3aa9ff;
  --go: #37c26b;
  --danger: #ef4444;
  --gold: #ffce3d;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(10, 8, 40, .28);
  --shadow-sm: 0 4px 12px rgba(10, 8, 40, .18);

  --font: 'Baloo 2', 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 600px at 12% -10%, #4b3aa0 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #2b6fb8 0%, transparent 55%),
    linear-gradient(170deg, #221c52 0%, #171436 60%, #120f2b 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.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;
}

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--paper); color: var(--ink); padding: 10px 16px; border-radius: 12px;
}
.skip-link:focus { left: 12px; }

/* ------------------------------------------------------------------ *
 * Top bar
 * ------------------------------------------------------------------ */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(12px, 3vw, 28px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  background:
    linear-gradient(#ff6b4a 0 50%, #f7f4ef 50% 100%);
  border: 3px solid #23204a;
  box-shadow: var(--shadow-sm), inset 0 0 0 3px rgba(255, 255, 255, .25);
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 13px; height: 13px; border-radius: 50%;
  background: #f7f4ef; border: 3px solid #23204a;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-name {
  font-size: clamp(20px, 3.4vw, 30px); font-weight: 800; color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.brand-tagline { font-size: 13px; color: #c9c4ee; font-weight: 500; }

.topbar-actions { display: flex; gap: 8px; flex: none; }

/* ------------------------------------------------------------------ *
 * Buttons and form controls
 * ------------------------------------------------------------------ */

.btn {
  font: inherit; font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 16px; min-height: 46px;
  border-radius: 14px; border: 3px solid #23204a;
  background: var(--paper); color: var(--ink);
  box-shadow: 0 4px 0 #23204a;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #23204a; }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: 0 4px 0 #23204a; transform: none; }

.btn-primary { background: var(--gold); }
.btn-primary:hover { background: #ffd95f; }

.btn-ghost {
  background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .35);
  box-shadow: none;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .2); }
.btn-ghost:active { transform: translateY(2px); box-shadow: none; }

.btn-icon { padding: 11px 13px; }
#btn-sound .icon-off { display: none; }
#btn-sound[aria-pressed="false"] .icon-on { display: none; }
#btn-sound[aria-pressed="false"] .icon-off { display: inline; }

.select {
  font: inherit; font-weight: 700; font-size: 15px; width: 100%;
  padding: 11px 14px; min-height: 46px;
  border-radius: 14px; border: 3px solid #23204a; background: var(--paper); color: var(--ink);
  cursor: pointer;
}
.select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px;
  padding: 5px; border-radius: 16px; background: var(--paper-dim); border: 3px solid #23204a;
}
.segmented button {
  font: inherit; font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 8px; min-height: 42px;
  border: 0; border-radius: 11px; background: transparent; color: var(--ink-soft); cursor: pointer;
}
.segmented button[aria-checked="true"] {
  background: #fff; color: var(--ink); box-shadow: var(--shadow-sm);
}
.segmented button:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }

.team-swatch { width: 15px; height: 15px; border-radius: 50%; border: 2px solid #23204a; }
.team-swatch.team-w { background: var(--ember); }
.team-swatch.team-b { background: var(--frost); }

.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--frost-deep); cursor: pointer; flex: none; }

/* ------------------------------------------------------------------ *
 * Layout
 * ------------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: clamp(14px, 2.2vw, 26px);
  align-items: start;
  padding: 0 clamp(12px, 3vw, 28px) 24px;
  max-width: 1240px; margin: 0 auto;
}

.board-column { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* ------------------------------------------------------------------ *
 * Player strips
 * ------------------------------------------------------------------ */

.player-strip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius);
  background: rgba(255, 255, 255, .09);
  border: 2px solid rgba(255, 255, 255, .14);
  color: #fff; min-height: 54px;
  transition: background .2s ease, border-color .2s ease;
}
.player-strip.is-turn {
  background: rgba(255, 255, 255, .19);
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 206, 61, .25);
}

.player-id { display: flex; align-items: center; gap: 8px; flex: none; }
.player-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff3; }
.player-dot[data-team="w"] { background: var(--ember); }
.player-dot[data-team="b"] { background: var(--frost); }
.player-name { font-weight: 800; font-size: 16px; }
.player-role { font-size: 12px; color: #cfc9f2; font-weight: 600; }

.captures { display: flex; flex-wrap: wrap; gap: 1px; flex: 1 1 auto; min-width: 0; }
.captures svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3)); }
.capture-chip { display: block; line-height: 0; animation: pop-in .25s ease; }

.score { font-weight: 800; font-size: 15px; color: var(--gold); flex: none; }

.thinking { display: inline-flex; gap: 3px; margin-left: 6px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); animation: blink 1s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ------------------------------------------------------------------ *
 * The board
 * ------------------------------------------------------------------ */

.board-wrap {
  position: relative;
  width: 100%;
  max-width: min(100%, 74vh);
  margin: 0 auto;
  aspect-ratio: 1;
}

.board-glow {
  position: absolute; inset: -14px; border-radius: 28px; z-index: 0;
  background: radial-gradient(closest-side, rgba(120, 160, 255, .35), transparent 75%);
  filter: blur(8px);
}

.board {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%;
  border: 6px solid #4a2f18;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 255, 255, .18);
  touch-action: manipulation;
}

.square {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border: 0; padding: 0; margin: 0;
  background: var(--square-light);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.square.dark { background: var(--square-dark); }
.square:focus-visible { outline: 4px solid var(--gold); outline-offset: -4px; z-index: 4; }

.square .piece {
  width: 92%; height: 92%;
  display: block; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3));
  animation: piece-in .18s ease;
}
.square .piece svg { width: 100%; height: 100%; display: block; }

/* Coordinates, drawn inside the edge squares like a real board. */
.square .coord {
  position: absolute; font-size: clamp(8px, 1.5vw, 12px); font-weight: 800;
  color: rgba(60, 35, 10, .55); pointer-events: none;
}
.square.dark .coord { color: rgba(255, 245, 225, .7); }
.square .coord.file { right: 3px; bottom: 1px; }
.square .coord.rank { left: 3px; top: 1px; }
.board.no-coords .coord { display: none; }

/* Little chess letter badge for beginners learning notation. */
.square .letter {
  position: absolute; top: 2px; right: 3px;
  font-size: clamp(9px, 1.6vw, 13px); font-weight: 800;
  color: #fff; background: rgba(28, 24, 62, .78);
  border-radius: 6px; padding: 0 4px; pointer-events: none;
}
.board:not(.show-letters) .letter { display: none; }

/* --- square states --- */

.square.last-move::after {
  content: ''; position: absolute; inset: 0;
  background: rgba(255, 206, 61, .38);
  box-shadow: inset 0 0 0 3px rgba(255, 206, 61, .8);
  pointer-events: none;
}

.square.selected::after {
  content: ''; position: absolute; inset: 0;
  background: rgba(58, 169, 255, .3);
  box-shadow: inset 0 0 0 4px var(--pick);
  pointer-events: none;
}

.square.hint-from::after,
.square.hint-to::after {
  content: ''; position: absolute; inset: 0;
  box-shadow: inset 0 0 0 5px #a855f7;
  background: rgba(168, 85, 247, .22);
  animation: pulse 1s ease-in-out 3;
  pointer-events: none;
}

.square.in-check::before {
  content: ''; position: absolute; inset: 0; z-index: 2;
  background: radial-gradient(closest-side, rgba(239, 68, 68, .75), transparent 72%);
  animation: pulse 1.1s ease-in-out infinite;
  pointer-events: none;
}

/* Move hints: a fat dot for a quiet move, a ring for a capture. */
.board.show-helpers .square.can-move::before {
  content: ''; position: absolute; z-index: 3;
  width: 30%; height: 30%; border-radius: 50%;
  background: rgba(55, 194, 107, .85);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .55);
  pointer-events: none;
  animation: pop-in .16s ease;
}
.board.show-helpers .square.can-capture::before {
  width: 88%; height: 88%; border-radius: 50%;
  background: transparent;
  border: 7px solid rgba(239, 68, 68, .82);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .4);
}

.square.drop-target::after {
  content: ''; position: absolute; inset: 0; z-index: 3;
  box-shadow: inset 0 0 0 5px #fff;
  background: rgba(255, 255, 255, .22);
  pointer-events: none;
}

/* The piece being dragged follows the finger/pointer. */
.drag-ghost {
  position: fixed; z-index: 60; pointer-events: none;
  width: 84px; height: 84px; margin: -42px 0 0 -42px;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .45));
  transform: scale(1.12);
}
.drag-ghost svg { width: 100%; height: 100%; }
.square.dragging .piece { opacity: .28; }

@keyframes pop-in { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes piece-in { from { transform: translateY(-6%) scale(.9); } to { transform: none; } }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.board.locked .square { cursor: default; }

/* ------------------------------------------------------------------ *
 * Sidebar cards
 * ------------------------------------------------------------------ */

.sidebar { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--paper);
  border: 3px solid #23204a;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.card-title {
  margin: 0 0 10px; font-size: 17px; font-weight: 800; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}

.card-status { background: linear-gradient(180deg, #fffdf6, #fdf0d8); }

.status-line { margin: 0 0 4px; font-size: 20px; font-weight: 800; line-height: 1.2; }
.status-line.check { color: var(--danger); }
.coach-line { margin: 0 0 12px; font-size: 14.5px; font-weight: 600; color: var(--ink-soft); min-height: 20px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-actions .btn-primary { grid-column: 1 / -1; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: block; font-size: 14px; font-weight: 800; margin-bottom: 6px; color: var(--ink-soft); }
.field-hint { margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field-toggles { display: flex; flex-direction: column; gap: 2px; }

.move-list {
  margin: 0; padding: 0 0 0 4px; list-style: none;
  max-height: 190px; overflow-y: auto;
  font-variant-numeric: tabular-nums;
  display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px 8px;
  align-content: start;
  font-size: 15px; font-weight: 700;
}
.move-list .move-no { color: var(--ink-soft); }
.move-list .move { padding: 2px 6px; border-radius: 8px; }
.move-list .move.latest { background: var(--gold); }
.move-empty { grid-column: 1 / -1; font-weight: 600; color: var(--ink-soft); font-size: 14px; }

.badge-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.badge {
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center;
  padding: 8px 4px; border-radius: var(--radius-sm);
  background: var(--paper-dim); border: 2px dashed #c9bda6;
  font-size: 10.5px; font-weight: 700; color: var(--ink-soft); line-height: 1.15;
}
.badge .badge-icon { font-size: 22px; filter: grayscale(1); opacity: .45; }
.badge.earned {
  background: linear-gradient(180deg, #fff3c9, #ffe089);
  border: 2px solid var(--gold); color: #6b4a00;
  box-shadow: 0 2px 0 #d9a900;
}
.badge.earned .badge-icon { filter: none; opacity: 1; }
.badge.just-earned { animation: badge-pop .6s ease; }
@keyframes badge-pop { 0% { transform: scale(.6) rotate(-12deg); } 60% { transform: scale(1.18) rotate(6deg); } 100% { transform: none; } }

.footer {
  text-align: center; padding: 4px 16px 28px;
  color: #a9a3d6; font-size: 13px; font-weight: 600;
}
.footer p { margin: 0; }

/* ------------------------------------------------------------------ *
 * Dialogs
 * ------------------------------------------------------------------ */

.dialog {
  border: 4px solid #23204a; border-radius: 22px;
  padding: 22px; max-width: 440px; width: calc(100vw - 32px);
  background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow);
}
.dialog-wide { max-width: 760px; max-height: 86vh; overflow-y: auto; }
.dialog::backdrop { background: rgba(14, 10, 40, .72); backdrop-filter: blur(3px); }
.dialog-title { margin: 0 0 4px; font-size: 22px; font-weight: 800; text-align: center; }
.dialog-sub { margin: 0 0 16px; text-align: center; font-weight: 600; color: var(--ink-soft); }
.dialog-close {
  position: absolute; top: 12px; right: 14px;
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid #23204a; background: var(--paper-dim);
  font-size: 16px; font-weight: 800; cursor: pointer;
}

.promotion-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.promotion-option {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; cursor: pointer;
  border: 3px solid #23204a; border-radius: var(--radius-sm);
  background: var(--paper-dim); font: inherit; font-weight: 700; font-size: 12px;
}
.promotion-option:hover, .promotion-option:focus-visible { background: var(--gold); outline: none; }
.promotion-option svg { width: 100%; max-width: 74px; height: auto; }
.promotion-option .promo-chess { font-size: 11px; color: var(--ink-soft); font-weight: 600; }

.learn-intro { margin: 0 0 16px; font-size: 15.5px; font-weight: 600; line-height: 1.5; }
.learn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.learn-card {
  display: grid; grid-template-columns: 66px 1fr; gap: 10px; align-items: start;
  padding: 10px; border-radius: var(--radius-sm);
  background: var(--paper-dim); border: 2px solid #ded2bb;
}
.learn-card svg { width: 66px; height: 66px; }
.learn-card h4 { margin: 0; font-size: 15px; font-weight: 800; }
.learn-card .learn-chess { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.learn-card p { margin: 4px 0 0; font-size: 13px; font-weight: 600; line-height: 1.35; }
.learn-card .learn-special { color: #7a4bd0; }
.learn-heading { margin: 20px 0 8px; font-size: 17px; font-weight: 800; }
.learn-rules { margin: 0; padding-left: 20px; font-size: 14.5px; font-weight: 600; line-height: 1.5; }
.learn-rules li { margin-bottom: 7px; }

/* ------------------------------------------------------------------ *
 * End-of-game overlay + confetti
 * ------------------------------------------------------------------ */

.result-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center; padding: 20px;
  background: rgba(14, 10, 40, .74); backdrop-filter: blur(4px);
}
.result-overlay[hidden] { display: none; }

.result-card {
  background: var(--paper); border: 4px solid #23204a; border-radius: 24px;
  box-shadow: var(--shadow); padding: 26px 28px; text-align: center; max-width: 400px;
  animation: result-in .35s cubic-bezier(.2, 1.4, .5, 1);
}
@keyframes result-in { from { transform: scale(.7) translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.result-art svg { width: 108px; height: 108px; }
.result-title { margin: 6px 0 6px; font-size: 30px; font-weight: 800; }
.result-sub { margin: 0 0 18px; font-weight: 600; color: var(--ink-soft); font-size: 15px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.confetti {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 80;
}

/* ------------------------------------------------------------------ *
 * Responsive
 * ------------------------------------------------------------------ */

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .board-wrap { max-width: min(100%, 64vh); }
  .sidebar { max-width: 620px; width: 100%; margin: 0 auto; }
}

@media (max-width: 560px) {
  .topbar { padding: 10px 12px; }
  .brand-tagline { display: none; }
  .board-wrap { max-width: 100%; }
  .board { border-width: 4px; border-radius: 10px; }
  .player-strip { padding: 6px 10px; min-height: 48px; }
  .captures svg { width: 21px; height: 21px; }
  .quick-actions { grid-template-columns: 1fr 1fr; }
  .promotion-grid { gap: 6px; }
}

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