:root {
  --bg: #f4efe5;
  --bg-accent: #eee6d8;
  --panel: rgba(255, 252, 247, 0.94);
  --panel-strong: rgba(255, 253, 249, 0.99);
  --line: rgba(34, 41, 37, 0.12);
  --ink: #1f2724;
  --muted: #66706a;
  --accent: #136f63;
  --accent-strong: #0c524a;
  --accent-soft: #d9f1ec;
  --warn: #c87824;
  --danger: #b9553f;
  --success: #247c53;
  --gold: #c79435;
  --gold-soft: #f5e2b4;
  --shadow: 0 4px 12px rgba(31, 39, 36, 0.05);
  --radius: 18px;
  --board-gap: clamp(0.38rem, 1.2vw, 0.65rem);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
}

body.modal-open {
  overflow: hidden;
}

.page {
  width: min(760px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.8rem 0 1.6rem;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(31, 39, 36, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 0.95rem 1rem;
  position: relative;
}

.hero__top {
  display: flex;
  align-items: start;
  justify-content: center;
  gap: 1rem;
}

.title-block {
  min-width: 0;
  display: grid;
  justify-items: center;
  text-align: center;
}

.eyebrow,
.section-label,
.meta-card__label,
.history-summary {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

h1 {
  margin: 0.15rem 0 0;
  font-size: clamp(2.1rem, 5vw, 3.4rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
}

#rulesButton {
  position: absolute;
  top: 0.9rem;
  right: 1rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.hero__meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.hero__meta--cozy {
  margin-top: 0;
}

.meta-card {
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  background: var(--panel-strong);
  border: 1px solid rgba(31, 39, 36, 0.08);
  min-height: 5rem;
}

.meta-card--pill {
  min-height: 0;
  padding: 0.78rem 0.9rem;
}

.meta-card strong {
  display: block;
  margin-top: 0.45rem;
  font-size: 1.2rem;
}

.meta-card__sub {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-card {
  display: grid;
  align-content: start;
}

.attempt-badges {
  display: flex;
  gap: 0.42rem;
  margin-top: 0.55rem;
}

.attempt-badge {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 999px;
  border: 1px solid rgba(31, 39, 36, 0.16);
  background: rgba(31, 39, 36, 0.06);
}

.attempt-badge--failed {
  background: rgba(200, 120, 36, 0.28);
  border-color: rgba(200, 120, 36, 0.42);
}

.attempt-badge--win {
  background: rgba(36, 124, 83, 0.3);
  border-color: rgba(36, 124, 83, 0.48);
}

.target-card {
  margin-top: 0.85rem;
  padding: 0.9rem;
  border-radius: 14px;
  background: var(--panel-strong);
  border: 1px solid rgba(31, 39, 36, 0.08);
}

.target-card--cozy {
  margin-top: 0;
  padding: 1rem 1rem 0.95rem;
}

.target-text {
  margin: 0.65rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  align-items: center;
  font-size: clamp(1.2rem, 3vw, 1.45rem);
  font-weight: 700;
  letter-spacing: 0.03em;
}

.target-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 2.3rem;
  padding: 0.18rem 0.42rem;
  border-radius: 10px;
  border: 1px solid rgba(31, 39, 36, 0.08);
  background: rgba(255, 255, 255, 0.5);
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.target-char--pending {
  color: rgba(31, 39, 36, 0.72);
}

.target-char--done {
  background: rgba(19, 111, 99, 0.14);
  border-color: rgba(19, 111, 99, 0.28);
  color: var(--accent-strong);
}

.target-char--space {
  min-width: 0.9rem;
  padding: 0;
  border: 0;
  background: transparent;
}

.game-layout {
  display: grid;
  gap: 0.85rem;
  margin-top: 0.85rem;
}

.page-footer {
  padding: 1rem 0 0.2rem;
  text-align: center;
}

.page-footer p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.page-footer a {
  color: var(--muted);
}

.play-panel {
  padding: 0.9rem;
}

.play-panel {
  display: grid;
  gap: 0.9rem;
}

.board-panel {
  display: grid;
  gap: 0.75rem;
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.board-toolbar__actions {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.debug-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(199, 148, 53, 0.18);
  border: 1px solid rgba(199, 148, 53, 0.32);
  color: #8a5a13;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.board-shell {
  position: relative;
  aspect-ratio: 1 / 1;
  width: min(100%, 520px);
  margin: 0 auto;
}

.board-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.route-line {
  stroke: rgba(19, 111, 99, 0.84);
  stroke-width: 10;
  stroke-linecap: round;
}

.route-line--solution {
  stroke: rgba(199, 148, 53, 0.9);
}

.board-grid {
  position: relative;
  z-index: 2;
  display: grid;
  width: 100%;
  height: 100%;
  gap: var(--board-gap);
  grid-template-columns: repeat(var(--board-columns, 7), minmax(0, 1fr));
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid rgba(31, 39, 36, 0.1);
  background: var(--cell-background);
  color: var(--ink);
  font: inherit;
  font-size: clamp(1rem, 3.8vw, 1.55rem);
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
  box-shadow: none;
  --cell-background: #f4ebda;
}

.cell--light {
  --cell-background: #f7f1e5;
}

.cell--dark {
  --cell-background: #d8c8a6;
}

.cell:hover,
.cell:focus-visible {
  transform: none;
  outline: none;
  border-color: rgba(19, 111, 99, 0.45);
}

.cell--selected {
  background: #cfe9e2;
  border-color: rgba(19, 111, 99, 0.45);
  color: var(--accent-strong);
}

.cell--solution {
  background: #ecd29c;
  border-color: rgba(199, 148, 53, 0.5);
  color: #6b4a12;
}

.cell--start {
  border-width: 2px;
  border-color: rgba(199, 148, 53, 0.62);
}

.cell--locked {
  cursor: default;
}

.cell__letter {
  position: relative;
  z-index: 2;
}

.cell__step,
.cell__queen {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55rem;
  min-height: 1.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  z-index: 3;
}

.cell__step {
  top: 0.32rem;
  right: 0.32rem;
  background: rgba(31, 39, 36, 0.82);
  color: #fdf9ef;
}

.cell__queen {
  left: 50%;
  top: 50%;
  min-width: 2rem;
  min-height: 2rem;
  transform: translate(-50%, -50%);
  background: rgba(199, 148, 53, 0.14);
  border: 1px solid rgba(199, 148, 53, 0.32);
  color: #8a5a13;
  font-size: 1rem;
}

#debugNewGameButton {
  width: 100%;
}

.icon-button {
  appearance: none;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid rgba(31, 39, 36, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  border-color: rgba(19, 111, 99, 0.38);
  background: rgba(255, 255, 255, 0.96);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.status-message {
  margin: 0.45rem 0 0;
  font-size: 0.96rem;
  line-height: 1.4;
}

.status-message[data-tone="success"] {
  color: var(--success);
}

.status-message[data-tone="warning"] {
  color: var(--warn);
}

.status-message[data-tone="danger"] {
  color: var(--danger);
}

.button {
  appearance: none;
  border: 1px solid rgba(31, 39, 36, 0.08);
  border-radius: 12px;
  padding: 0.82rem 0.95rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.button:hover,
.button:focus-visible {
  transform: none;
  outline: none;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
  box-shadow: none;
}

.button--primary {
  background: var(--accent);
  color: #f7fbfa;
}

.button--ghost {
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(31, 39, 36, 0.12);
  color: var(--ink);
}

.button--accent {
  background: rgba(190, 137, 48, 0.98);
  color: #fff8ef;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(16, 22, 20, 0.55);
  backdrop-filter: blur(3px);
  z-index: 20;
}

.modal {
  width: min(100%, 520px);
  border-radius: 18px;
  background: #fffaf1;
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(16, 22, 20, 0.12);
  border: 1px solid rgba(31, 39, 36, 0.08);
}

.modal__header,
.modal__footer {
  padding: 1rem 1rem 0;
}

.modal__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.6rem;
}

.modal__body {
  padding: 0.8rem 1rem 0;
  line-height: 1.6;
}

.modal__body p {
  margin: 0;
}

.modal__body p + p {
  margin-top: 0.7rem;
}

.modal-list {
  margin: 0.85rem 0 0;
  padding-left: 1.15rem;
}

.modal-list li + li {
  margin-top: 0.45rem;
}

.modal__footer {
  padding-bottom: 1rem;
}

.modal__footer--stack {
  display: grid;
  gap: 0.7rem;
}

.modal__close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 680px) {
  .page {
    width: min(100%, calc(100% - 1rem));
  }

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

@media (max-width: 560px) {
  .page {
    padding-top: 0.6rem;
  }

  .hero,
  .play-panel {
    padding: 0.9rem;
    border-radius: 16px;
  }

  .hero__top {
    align-items: stretch;
    flex-direction: column;
  }

  #rulesButton {
    position: static;
    width: 100%;
  }

  .target-text {
    gap: 0.32rem;
    font-size: 1.1rem;
  }

  .target-char {
    min-width: 1.7rem;
    min-height: 2rem;
    border-radius: 9px;
  }

  .cell {
    border-radius: 10px;
  }

  .cell__step,
  .cell__queen {
    min-width: 1.35rem;
    min-height: 1.35rem;
    font-size: 0.68rem;
  }

  .cell__queen {
    min-width: 1.7rem;
    min-height: 1.7rem;
    font-size: 0.9rem;
  }
}
