:root {
  --bg: #f3ede4;
  --bg-dark: #161513;
  --ink: #1a1917;
  --muted: #675f55;
  --accent: #ff6a3d;
  --accent-2: #1bc0b5;
  --card: rgba(255, 248, 241, 0.86);
  --shadow: 0 24px 60px rgba(20, 16, 12, 0.2);
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255, 244, 232, 0.9) 0%, rgba(240, 220, 200, 0.7) 45%, transparent 70%),
    linear-gradient(135deg, #e5d2bf 0%, #f0e3d2 40%, #d7c1ad 100%);
  min-height: 100vh;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right))
    calc(36px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-radius: 24px;
  padding: 24px 28px;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.75) 0%, rgba(255, 232, 208, 0.9) 55%, rgba(255, 214, 200, 0.9) 100%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  animation: float-in 0.6s ease;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
}

h1 {
  margin: 0 0 8px;
  font-size: 40px;
}

.sub {
  margin: 0;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.control-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: none;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 106, 61, 0.35);
  transition: transform 0.2s ease;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
  box-shadow: none;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.theme-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

body[data-theme="dark"] .theme-icon {
  fill: currentColor;
}

body[data-theme="dark"] .theme-icon .rays {
  display: none;
}

.status {
  font-size: 14px;
  color: var(--muted);
}

.arena {
  display: grid;
  grid-template-columns: 1.1fr 0.6fr;
  gap: 24px;
  margin-top: 28px;
}

.board-shell {
  padding: 20px;
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  animation: float-in 0.6s ease 0.1s both;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-auto-rows: 1fr;
  gap: 4px;
  background: #1e1b18;
  padding: 8px;
  border-radius: 20px;
  aspect-ratio: 1 / 1;
}

.square {
  border: none;
  border-radius: 10px;
  font-size: 28px;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  width: 100%;
  aspect-ratio: 1 / 1;
  transition: box-shadow 0.2s ease;
  line-height: 1;
  touch-action: manipulation;
}

.square.light {
  background: linear-gradient(140deg, #f4ddc3 0%, #f0d2b1 100%);
}

.square.dark {
  background: linear-gradient(140deg, #b27a55 0%, #9c6847 100%);
}

.square.selected {
  box-shadow: inset 0 0 0 3px var(--accent-2), var(--glow);
}

.square.move {
  box-shadow: inset 0 0 0 3px var(--accent), var(--glow);
}

.square:hover {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18);
}

.piece.white {
  color: #151515;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.piece.black {
  color: #0f0f0f;
  opacity: 0.85;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.panel {
  background: #171513;
  color: #f6f0e8;
  border-radius: 24px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
  animation: float-in 0.6s ease 0.2s both;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel h2 {
  margin: 0;
  font-size: 20px;
}

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}

.move-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.move {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  gap: 8px;
  font-size: 14px;
  color: #f0e6db;
}

.move span {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 8px;
}

.hint {
  font-size: 13px;
  color: #b9afa3;
  line-height: 1.4;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 9, 0.65);
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: #fff9f2;
  padding: 28px 32px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.overlay-card h3 {
  margin: 0 0 8px;
}

body[data-theme="dark"] {
  --bg: #141312;
  --bg-dark: #0d0c0b;
  --ink: #f1ebe4;
  --muted: #b7aca0;
  --accent: #ff8a5c;
  --accent-2: #22d2c7;
  --card: rgba(24, 21, 19, 0.9);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

body[data-theme="dark"] {
  background:
    radial-gradient(circle at top, rgba(42, 36, 30, 0.95) 0%, rgba(26, 22, 18, 0.85) 45%, transparent 70%),
    linear-gradient(135deg, #0f0e0d 0%, #1c1916 40%, #2a241f 100%);
}

body[data-theme="dark"] .hero {
  background: linear-gradient(120deg, rgba(30, 26, 23, 0.9) 0%, rgba(42, 33, 26, 0.9) 55%, rgba(54, 40, 32, 0.9) 100%);
  border-color: rgba(255, 255, 255, 0.08);
}

body[data-theme="dark"] .board-shell {
  border-color: rgba(255, 255, 255, 0.08);
}

body[data-theme="dark"] .board {
  background: #0f0d0c;
}

body[data-theme="dark"] .square.light {
  background: linear-gradient(140deg, #d9c6b0 0%, #cdb59a 100%);
}

body[data-theme="dark"] .square.dark {
  background: linear-gradient(140deg, #8f5d3f 0%, #7b4f35 100%);
}

body[data-theme="dark"] .panel {
  background: #0f0d0c;
  color: #efe6db;
}

body[data-theme="dark"] .move span {
  background: rgba(255, 255, 255, 0.06);
}

body[data-theme="dark"] .overlay-card {
  background: #151311;
  color: #f2ece4;
}

body[data-theme="dark"] .piece.white {
  text-shadow:
    0 0 0.5px rgba(255, 255, 255, 0.7),
    0 2px 10px rgba(0, 0, 0, 0.6);
}

body[data-theme="dark"] .piece.black {
  text-shadow:
    0 0 1px rgba(255, 255, 255, 0.4),
    0 2px 10px rgba(0, 0, 0, 0.7);
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .controls {
    align-items: flex-start;
  }

  .arena {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .page {
    padding: calc(18px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
      calc(28px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }

  h1 {
    font-size: 30px;
  }

  .hero {
    padding: 18px 20px;
    gap: 16px;
  }

  .control-row {
    width: 100%;
    justify-content: flex-start;
  }

  .btn {
    padding: 10px 16px;
  }

  .board-shell {
    padding: 14px;
  }

  .board {
    gap: 3px;
    padding: 6px;
  }

  .square {
    font-size: 22px;
    border-radius: 8px;
  }

  .panel {
    padding: 16px;
  }

  .move-list {
    max-height: 240px;
  }
}
