:root {
  --bg: #fbfaf6;
  --paper: #ffffff;
  --ink: #1f2a24;
  --muted: #68746c;
  --line: #dfe4dc;
  --header-bg: rgba(251, 250, 246, 0.94);
  --green: #22634d;
  --green-dark: #174838;
  --gold: #c58b2b;
  --red: #a54635;
  --board: #ddb36d;
  --board-line: #7b5528;
  --shadow: 0 18px 42px rgba(35, 45, 39, 0.14);
}

[data-theme="dark"] {
  --bg: #111815;
  --paper: #18231e;
  --ink: #edf3ee;
  --muted: #aab8ae;
  --line: #2d3b34;
  --header-bg: rgba(17, 24, 21, 0.94);
  --green: #68b08e;
  --green-dark: #8bc5a8;
  --gold: #e0b85f;
  --red: #d27868;
  --board: #c89652;
  --board-line: #60421f;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111815;
    --paper: #18231e;
    --ink: #edf3ee;
    --muted: #aab8ae;
    --line: #2d3b34;
    --header-bg: rgba(17, 24, 21, 0.94);
    --green: #68b08e;
    --green-dark: #8bc5a8;
    --gold: #e0b85f;
    --red: #d27868;
    --board: #c89652;
    --board-line: #60421f;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
  }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
.game-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}
.nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
}
.nav-links {
  color: var(--muted);
  font-size: 14px;
}
.nav-links a { text-decoration: none; }
.theme-toggle {
  width: 48px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.theme-toggle-track {
  width: 48px;
  height: 28px;
  display: block;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2ed;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.theme-toggle-thumb {
  width: 22px;
  height: 22px;
  position: absolute;
  left: 3px;
  top: 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffffff;
  color: #5e6870;
  box-shadow: 0 2px 6px rgba(31, 42, 36, 0.24);
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.theme-toggle-icon,
.theme-toggle-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}
.theme-toggle-icon svg {
  fill: currentColor;
}
.theme-toggle[data-resolved-theme="dark"] .theme-toggle-track {
  border-color: #39463f;
  background: #202622;
}
.theme-toggle[data-resolved-theme="dark"] .theme-toggle-thumb {
  transform: translateX(20px);
  background: #2f3732;
  color: #f3f6f1;
}
.game-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 22px;
  align-items: start;
}
.game-panel, .side-panel > div, .actions {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.game-panel { padding: 20px; }
.game-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 6px;
  font-size: clamp(34px, 4vw, 52px);
  line-height: 1;
}
h2 {
  margin-bottom: 10px;
  font-size: 18px;
}
p, li {
  color: var(--muted);
  line-height: 1.55;
}
.score-strip {
  min-width: 190px;
  display: grid;
  gap: 8px;
}
.score-strip span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}
.play-area {
  width: min(100%, 760px);
  margin: 0 auto;
}
.game-board {
  display: grid;
  gap: 6px;
  touch-action: manipulation;
}
.game-cell, .tile, .piece {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--board);
  color: #1f2a24;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
}
.game-cell:hover, .tile:hover, .piece:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0,0,0,.12);
}
.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
.valid {
  box-shadow: inset 0 0 0 3px rgba(34,99,77,.45);
}
.removed {
  visibility: hidden;
  pointer-events: none;
}
.game-intro {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}
.game-intro p {
  max-width: 780px;
  margin-bottom: 10px;
}
.side-panel {
  display: grid;
  gap: 14px;
}
.status-card, .legend { padding: 18px; }
.actions {
  padding: 14px;
  display: grid;
  gap: 10px;
}
.actions button, .actions a {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
}
.actions button:hover, .actions a:hover { background: var(--green-dark); }
.actions button:disabled {
  opacity: .45;
  cursor: default;
}
.legend ul {
  margin: 0;
  padding-left: 18px;
}
@media (max-width: 880px) {
  .game-shell { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .nav, .game-top, .side-panel {
    align-items: flex-start;
    grid-template-columns: 1fr;
    flex-direction: column;
  }
  .score-strip { width: 100%; }
  .game-panel { padding: 14px; }
}
