:root {
  color-scheme: light;
  --bg: #f3eee6;
  --bg-accent: #fcf8f1;
  --ink: #1f2431;
  --muted: #5f6978;
  --line: rgba(31, 36, 49, 0.1);
  --line-strong: rgba(31, 36, 49, 0.18);
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --brand: #266a57;
  --brand-strong: #18483c;
  --accent: #d96d41;
  --shadow: 0 24px 64px rgba(31, 36, 49, 0.12);
  --soft-shadow: 0 12px 30px rgba(31, 36, 49, 0.08);
  --focus: rgba(38, 106, 87, 0.26);
  --danger: #c65252;
  --danger-soft: rgba(198, 82, 82, 0.16);
  --chip: rgba(31, 36, 49, 0.05);
  --chip-strong: rgba(217, 109, 65, 0.16);
  --content-width: min(1180px, calc(100% - 28px));
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(218, 157, 107, 0.14), transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(38, 106, 87, 0.12), transparent 22%),
    linear-gradient(180deg, #fbf7f1 0%, var(--bg) 48%, #ece5d8 100%);
}

a {
  color: inherit;
}

button {
  font: inherit;
}

kbd {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(31, 36, 49, 0.08);
  font-size: 0.82em;
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

.site-shell {
  min-height: 100vh;
}

.site-nav {
  width: var(--content-width);
  margin: 0 auto;
  padding: 16px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.site-brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 68% 70%, #de8758 0 22%, transparent 23%),
    radial-gradient(circle at 34% 36%, #2b8c70 0 44%, transparent 45%),
    linear-gradient(135deg, rgba(43, 140, 112, 0.22), rgba(217, 109, 65, 0.18));
  box-shadow: inset 0 0 0 1px rgba(31, 36, 49, 0.08);
}

.site-brand-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand);
}

.site-brand-name {
  display: block;
  font-size: 1.02rem;
  font-weight: 800;
}

.site-links {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.site-links a,
.mini-link {
  padding: 11px 15px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.56);
  color: var(--muted);
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.mini-link {
  cursor: pointer;
}

.site-links a:hover,
.site-links a:focus-visible,
.mini-link:hover,
.mini-link:focus-visible {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.84);
  transform: translateY(-1px);
  outline: none;
}

.wrap {
  width: var(--content-width);
  margin: 0 auto;
  padding: 8px 0 40px;
}

.hero {
  margin-bottom: 18px;
  padding: 22px 24px;
  border: 1px solid rgba(31, 36, 49, 0.08);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.58));
  box-shadow: var(--shadow);
}

.eyebrow,
.panel-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand);
}

.game-name,
.stage-title,
.panel-title {
  margin: 0;
  line-height: 0.98;
}

.game-name {
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  letter-spacing: -0.06em;
}

.intro-copy {
  max-width: 62rem;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.6;
}

.intro-copy-small {
  margin-top: 10px;
  font-size: 0.92rem;
}

.hero-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.hero-chip,
.panel-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.hero-chip-accent {
  background: var(--chip-strong);
  color: var(--accent);
}

.stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(300px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.utility-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.utility-panel {
  padding: 18px;
}

.utility-header {
  margin-bottom: 10px;
}

.utility-refresh {
  cursor: pointer;
}

.utility-copy {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.leaderboard-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.leaderboard-item,
.leaderboard-empty {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(31, 36, 49, 0.08);
}

.leaderboard-empty {
  grid-template-columns: 1fr;
}

.leaderboard-rank {
  color: var(--muted);
  font-weight: 700;
}

.leaderboard-copy {
  min-width: 0;
  display: grid;
}

.leaderboard-name,
.leaderboard-score {
  font-weight: 800;
}

.leaderboard-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-meta {
  font-size: 0.9rem;
  color: var(--muted);
}

.leaderboard-score {
  color: var(--brand-strong);
}

.board-card,
.panel {
  border: 1px solid rgba(31, 36, 49, 0.08);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--soft-shadow);
}

.board-card {
  padding: 22px;
}

.side-stack {
  display: grid;
  gap: 16px;
}

.panel {
  padding: 18px;
}

.board-topline,
.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.stage-title {
  font-size: clamp(1.75rem, 4vw, 2.6rem);
  letter-spacing: -0.05em;
}

.summary-pill {
  min-width: 132px;
  padding: 12px 14px;
  border-radius: 20px;
  background: rgba(38, 106, 87, 0.08);
  text-align: right;
}

.summary-pill-label,
.metric-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.summary-pill-value,
.metric-value {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink);
}

.board-mount {
  margin-top: 18px;
}

.patch-board {
  --board-size: 5;
  display: grid;
  grid-template-columns: repeat(var(--board-size), minmax(0, 1fr));
  gap: 8px;
  max-width: min(100%, 620px);
  margin: 0 auto;
  touch-action: none;
  user-select: none;
}

.patch-cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 18px;
  border: 1px solid rgba(31, 36, 49, 0.1);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(245, 238, 227, 0.88));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 8px 16px rgba(31, 36, 49, 0.04);
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
  touch-action: none;
}

.patch-cell:hover,
.patch-cell:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(31, 36, 49, 0.24);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    0 0 0 4px var(--focus);
  outline: none;
  z-index: 2;
}

.patch-cell.is-filled {
  background:
    linear-gradient(145deg, hsl(var(--patch-hue, 160) 80% 88%), hsl(var(--patch-hue, 160) 64% 76%));
  border-color: hsla(var(--patch-hue, 160) 42% 40% / 0.28);
}

.patch-cell.is-preview-valid {
  background:
    linear-gradient(145deg, hsl(var(--patch-hue, 28) 92% 86%), hsl(var(--patch-hue, 28) 76% 72%));
  border-color: hsla(var(--patch-hue, 28) 54% 42% / 0.34);
}

.patch-cell.is-preview-invalid {
  background:
    linear-gradient(145deg, rgba(255, 219, 219, 0.94), rgba(244, 174, 174, 0.78));
  border-color: rgba(198, 82, 82, 0.36);
}

.patch-cell.is-anchor::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 14px;
  border: 2px dashed rgba(31, 36, 49, 0.4);
}

.patch-cell.is-conflict,
.patch-cell.is-invalid {
  border-color: rgba(198, 82, 82, 0.74);
  box-shadow: inset 0 0 0 4px var(--danger-soft);
}

.patch-cell.is-solved {
  box-shadow:
    inset 0 0 0 4px rgba(38, 106, 87, 0.16),
    0 10px 18px rgba(31, 36, 49, 0.06);
}

.clue-badge {
  position: absolute;
  inset: 8px auto auto 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 44px;
  padding: 6px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(31, 36, 49, 0.1);
  color: var(--ink);
  box-shadow: 0 6px 14px rgba(31, 36, 49, 0.08);
  pointer-events: none;
}

.clue-badge.is-matched {
  background: rgba(38, 106, 87, 0.12);
  border-color: rgba(38, 106, 87, 0.22);
}

.clue-badge.is-broken {
  background: rgba(198, 82, 82, 0.12);
  border-color: rgba(198, 82, 82, 0.22);
}

.clue-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.clue-value {
  font-size: 0.86rem;
  font-weight: 800;
}

.status-shell {
  margin-top: 18px;
}

.status-text,
.helper-copy,
.panel-footnote {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.board-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.board-actions {
  margin-top: 16px;
}

.mode-groups {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.mode-btn {
  appearance: none;
  border: 1px solid rgba(31, 36, 49, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  padding: 11px 14px;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.mode-btn:hover,
.mode-btn:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(31, 36, 49, 0.18);
  outline: none;
}

.mode-btn-strong {
  background: linear-gradient(180deg, rgba(38, 106, 87, 0.96), rgba(24, 72, 60, 0.96));
  border-color: transparent;
  color: white;
}

.mode-btn.is-active {
  background: rgba(38, 106, 87, 0.12);
  border-color: rgba(38, 106, 87, 0.26);
  color: var(--brand-strong);
}

.mode-btn.mode-btn-strong.is-active {
  background: linear-gradient(180deg, rgba(38, 106, 87, 0.96), rgba(24, 72, 60, 0.96));
  color: white;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(31, 36, 49, 0.08);
}

.helper-copy-tight {
  margin-top: 14px;
  font-size: 0.94rem;
}

.level-rail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.level-pill {
  padding: 12px 10px;
  border: 1px solid rgba(31, 36, 49, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.level-pill.is-static {
  cursor: default;
}

.level-pill strong,
.level-pill span {
  display: block;
}

.level-pill strong {
  font-size: 1rem;
  color: var(--ink);
}

.level-pill span {
  margin-top: 3px;
  font-size: 0.76rem;
}

.level-pill.is-active {
  background: rgba(38, 106, 87, 0.14);
  border-color: rgba(38, 106, 87, 0.24);
}

.level-pill.is-locked {
  cursor: not-allowed;
  opacity: 0.48;
}

.rule-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.panel-footnote {
  margin-top: 14px;
  font-size: 0.94rem;
}

.game-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: var(--content-width);
  margin: 20px auto 0;
  padding: 16px 4px 28px;
  color: var(--muted);
}

.game-footer-copy {
  font-weight: 700;
}

.game-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

@media (max-width: 980px) {
  .stage-grid,
  .utility-grid {
    grid-template-columns: 1fr;
  }

  .site-nav {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .wrap {
    width: min(100%, calc(100% - 20px));
  }

  .hero,
  .board-card,
  .panel {
    border-radius: 24px;
  }

  .hero,
  .board-card {
    padding: 18px;
  }

  .panel {
    padding: 16px;
  }

  .site-links {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    flex-wrap: nowrap;
  }

  .stage-title {
    font-size: 1.9rem;
  }

  .summary-pill {
    min-width: 116px;
  }

  .patch-board {
    gap: 6px;
  }

  .patch-cell {
    border-radius: 16px;
  }

  .clue-badge {
    inset: 6px auto auto 6px;
    min-width: 38px;
    padding: 5px 7px;
    border-radius: 12px;
    gap: 5px;
  }

  .clue-value {
    font-size: 0.78rem;
  }
}

@media (max-width: 520px) {
  .wrap {
    width: min(100%, calc(100% - 14px));
  }

  .hero {
    padding: 16px;
  }

  .game-name {
    font-size: clamp(2.1rem, 11vw, 3rem);
  }

  .hero-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .board-actions,
  .button-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button-row:last-child {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mode-btn,
  .mini-link,
  .site-links a {
    text-align: center;
  }
}

@media (display-mode: standalone) {
  .helper-copy-tight {
    display: none;
  }
}
