:root {
  color-scheme: light;
  --ink: #1e2a26;
  --muted: #65726c;
  --line: #cfd9d1;
  --panel: #ffffff;
  --page: #f3f0e7;
  --accent: #146c5d;
  --accent-strong: #0d4b41;
  --field: #e8efd9;
  --field-alt: #dbe9d2;
  --warn: #b85c38;
  --ok: #236b35;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(20, 108, 93, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(184, 92, 56, 0.12), transparent 38%),
    var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fffaf0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:focus-visible {
  outline: 3px solid rgba(20, 108, 93, 0.28);
  outline-offset: 2px;
}

.primary {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.tents-app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 30px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 18px;
  align-items: start;
}

.game-shell,
.rules {
  border: 1px solid rgba(30, 42, 38, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 18px 60px rgba(30, 42, 38, 0.12);
}

.game-shell {
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.1rem;
}

.section-title {
  margin-top: 22px;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.stats span,
.status-row p {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fffaf0;
  font-weight: 800;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffaf0;
}

.segmented button {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented .is-active {
  color: #fff;
  background: var(--accent-strong);
}

.board-wrap {
  overflow: auto;
  padding: 6px;
}

.board {
  --grid-size: 8;
  display: grid;
  grid-template-columns: 42px repeat(var(--grid-size), minmax(34px, 1fr)) 42px;
  width: min(100%, 760px);
  min-width: min(760px, calc(100vw - 52px));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 2px solid var(--ink);
  background: var(--ink);
  gap: 2px;
}

.cell,
.clue,
.corner {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  user-select: none;
}

.cell {
  position: relative;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-height: 0;
  background: var(--field);
  font-size: clamp(1.15rem, 3.3vw, 2rem);
}

.cell:nth-child(odd) {
  background: var(--field-alt);
}

.cell.tree {
  cursor: default;
}

.cell.tent::before,
.cell.solution::before {
  content: "";
  width: 58%;
  height: 58%;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: var(--warn);
}

.cell.mistake {
  background: #ffd9cf;
  box-shadow: inset 0 0 0 4px #c94130;
}

.cell.mistake::after {
  content: "!";
  position: absolute;
  top: 6%;
  right: 8%;
  display: grid;
  place-items: center;
  width: 1.35em;
  height: 1.35em;
  border-radius: 999px;
  color: #fff;
  background: #c94130;
  font-size: 0.72rem;
  font-weight: 900;
}

.cell.solution::before {
  opacity: 0.35;
}

.cell.grass::before {
  content: "";
  width: 48%;
  height: 48%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 65%, #3d8a4d 0 18%, transparent 20%),
    linear-gradient(115deg, transparent 42%, #3d8a4d 43% 56%, transparent 57%),
    linear-gradient(65deg, transparent 42%, #3d8a4d 43% 56%, transparent 57%);
}

.tree-icon {
  width: 62%;
  height: 70%;
  position: relative;
}

.tree-icon::before {
  content: "";
  position: absolute;
  inset: 0 14% 18%;
  border-radius: 50% 50% 44% 44%;
  background: #2f7b45;
  box-shadow: -8px 10px 0 #4f9d54, 8px 12px 0 #276f3b;
}

.tree-icon::after {
  content: "";
  position: absolute;
  left: 42%;
  bottom: 0;
  width: 18%;
  height: 34%;
  border-radius: 3px;
  background: #7a5631;
}

.clue,
.corner {
  color: #fff;
  background: var(--accent-strong);
  font-weight: 900;
}

.clue.satisfied {
  background: var(--ok);
}

.clue.over {
  background: var(--warn);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.status-row p {
  margin: 0;
}

#message {
  flex: 1;
  font-weight: 700;
}

.rules {
  padding: 18px;
}

.rules ul {
  margin: 12px 0 0;
  padding-left: 20px;
  color: var(--muted);
}

.rules li + li {
  margin-top: 9px;
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(30, 42, 38, 0.42);
}

.celebration[hidden] {
  display: none;
}

.celebration-card {
  width: min(420px, 100%);
  border: 1px solid rgba(30, 42, 38, 0.16);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  background: #fffaf0;
  box-shadow: 0 24px 80px rgba(30, 42, 38, 0.25);
}

.celebration-card h2 {
  font-size: 2rem;
}

.celebration-card p {
  margin: 12px 0 18px;
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 860px) {
  .tents-app {
    grid-template-columns: 1fr;
  }

  .rules {
    order: -1;
  }
}

@media (max-width: 560px) {
  .tents-app {
    width: min(100% - 16px, 1120px);
    padding: 12px 0;
  }

  .game-shell,
  .rules {
    padding: 12px;
  }

  .topbar,
  .status-row {
    display: grid;
  }

  .stats {
    justify-content: start;
  }

  .controls > button {
    flex: 1 1 80px;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .board {
    grid-template-columns: 30px repeat(var(--grid-size), minmax(26px, 1fr)) 30px;
  }
}
