:root {
  color-scheme: light;
  --ink: #1e2e20;
  --muted: #5c664a;
  --paper: #fff2d6;
  --paper-deep: #f2d7a7;
  --wood: #a96f3a;
  --wood-dark: #67431f;
  --sage: #7d954f;
  --sage-deep: #49652f;
  --berry: #b94335;
  --clay: #d98f59;
  --sky: #2d6fb4;
  --gold: #d9a522;
  --violet: #72509b;
  --shadow: 0 20px 50px rgb(47 35 17 / 0.22);
  --soft-shadow: 0 10px 24px rgb(47 35 17 / 0.18);
  --radius: 18px;
  --cell-size: clamp(2.25rem, 6.8vw, 3.2rem);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #8ca45c;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgb(255 244 218 / 0.1), rgb(100 115 56 / 0.18)),
    url("./assets/garden-table.png") center / cover fixed,
    #8ca45c;
}

button {
  font: inherit;
}

.app {
  width: min(100%, 1380px);
  margin: 0 auto;
  padding: clamp(0.75rem, 2vw, 1.4rem);
}

.topbar,
.card,
.board-shell {
  border: 2px solid rgb(103 67 31 / 0.32);
  background: rgb(255 242 214 / 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) auto auto auto;
  gap: 0.9rem;
  align-items: center;
  border-radius: 24px;
  padding: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand img {
  width: 3rem;
  height: 3rem;
  border-radius: 14px;
  box-shadow: var(--soft-shadow);
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.9rem, 4vw, 3.7rem);
  line-height: 0.95;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.controls,
.stats,
.toggles {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.pill,
.icon-button,
.mode-button {
  min-height: 2.6rem;
  border: 2px solid rgb(103 67 31 / 0.25);
  border-radius: 999px;
  color: var(--ink);
  background: linear-gradient(#fff8e7, #f0d6a5);
  box-shadow: 0 4px 0 rgb(103 67 31 / 0.2);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.pill {
  padding: 0 1.05rem;
  font-weight: 800;
}

.icon-button,
.mode-button {
  padding: 0 0.95rem;
  font-weight: 800;
}

.pill:hover,
.icon-button:hover,
.mode-button:hover {
  transform: translateY(-1px);
}

.pill:focus-visible,
.icon-button:focus-visible,
.mode-button:focus-visible,
.cell:focus-visible {
  outline: 4px solid rgb(45 111 180 / 0.42);
  outline-offset: 3px;
}

.pill.is-active,
.mode-button.is-active,
.mode-button[aria-pressed="true"] {
  color: #fff9e8;
  background: linear-gradient(#8cac54, #4f7432);
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 0.28), 0 4px 0 rgb(38 67 24 / 0.28);
}

.stat {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 0.45rem;
  align-items: center;
  min-width: 7rem;
  padding: 0.45rem 0.75rem;
  border: 2px solid rgb(103 67 31 / 0.16);
  border-radius: 16px;
  background: rgb(255 250 235 / 0.72);
}

.stat span:first-child {
  grid-row: span 2;
  font-size: 1.45rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(14rem, 18rem) minmax(0, 1fr) minmax(13rem, 17rem);
  gap: 1rem;
  align-items: start;
  margin-top: 1rem;
}

.card {
  border-radius: var(--radius);
  padding: 1rem;
}

.card h2,
.card h3 {
  margin: 0 0 0.8rem;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.05;
}

.card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.steps {
  display: grid;
  gap: 0.8rem;
  margin: 0;
}

.steps div {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.55rem;
  align-items: start;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgb(103 67 31 / 0.18);
}

.steps div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.steps dt {
  font-size: 1.45rem;
  font-weight: 900;
  text-align: center;
}

.steps dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.board-shell {
  overflow: hidden;
  border-radius: 28px;
  padding: clamp(0.55rem, 1.4vw, 1rem);
  background:
    linear-gradient(rgb(255 247 226 / 0.78), rgb(238 204 146 / 0.86)),
    radial-gradient(circle at 50% 0%, rgb(255 255 255 / 0.55), transparent 45%);
}

.board-scroll {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.35rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell-size));
  gap: 0.22rem;
  width: max-content;
  margin: 0 auto;
  padding: clamp(0.45rem, 1vw, 0.8rem);
  border: 4px solid rgb(103 67 31 / 0.46);
  border-radius: 22px;
  background: linear-gradient(#8a5c2e, #b47a3f);
  box-shadow: inset 0 6px 10px rgb(255 255 255 / 0.18), inset 0 -8px 14px rgb(63 38 17 / 0.28);
  touch-action: manipulation;
}

.cell {
  display: grid;
  place-items: center;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 2px solid rgb(103 67 31 / 0.24);
  border-radius: 11px;
  color: var(--ink);
  background:
    radial-gradient(circle at 35% 25%, rgb(255 255 255 / 0.56), transparent 34%),
    linear-gradient(145deg, #e8c895, #c99a62);
  box-shadow: inset 0 3px 0 rgb(255 255 255 / 0.36), inset 0 -4px 0 rgb(89 58 29 / 0.22);
  font-size: calc(var(--cell-size) * 0.55);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: transform 110ms ease, filter 110ms ease, background 140ms ease;
}

.cell:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.cell.is-revealed {
  background:
    radial-gradient(circle at 35% 25%, rgb(255 255 255 / 0.45), transparent 32%),
    linear-gradient(145deg, #fff4d8, #ead3a7);
  box-shadow: inset 0 2px 6px rgb(82 52 26 / 0.2);
  cursor: default;
}

.cell.is-flagged {
  color: var(--berry);
  text-shadow: 0 2px 0 rgb(255 255 255 / 0.55);
}

.cell.is-mine {
  color: #23201c;
  background: linear-gradient(145deg, #e9dac1, #d4b07a);
}

.cell.is-exploded {
  color: #1b1714;
  background: linear-gradient(145deg, #f29a70, #b94335);
  box-shadow: 0 0 0 4px rgb(185 67 53 / 0.28), inset 0 2px 8px rgb(0 0 0 / 0.22);
}

.cell.is-wrong {
  color: #fff8e7;
  background: linear-gradient(145deg, #c75246, #8d342d);
}

.n-1 { color: var(--sky); }
.n-2 { color: var(--sage-deep); }
.n-3 { color: var(--berry); }
.n-4 { color: var(--violet); }
.n-5 { color: #995a21; }
.n-6 { color: #177d82; }
.n-7 { color: #2b2b2b; }
.n-8 { color: #616161; }

.status-card {
  display: grid;
  gap: 0.9rem;
}

.message {
  min-height: 5.2rem;
  display: grid;
  place-items: center;
  padding: 1rem;
  border-radius: 16px;
  color: var(--ink);
  background: rgb(255 250 235 / 0.72);
  border: 2px dashed rgb(103 67 31 / 0.22);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
}

.message[data-state="won"] {
  color: #fff9e8;
  background: linear-gradient(#87a84c, #4f7432);
}

.message[data-state="lost"] {
  color: #fff9e8;
  background: linear-gradient(#d6664d, #9f3a30);
}

.legend {
  display: grid;
  gap: 0.45rem;
  margin: 0;
}

.legend div {
  display: grid;
  grid-template-columns: 1.8rem 1fr;
  gap: 0.55rem;
  align-items: center;
}

.legend dt {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 8px;
  background: #eed2a2;
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 0.35);
  font-weight: 900;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1060px) {
  .topbar,
  .layout {
    grid-template-columns: 1fr;
  }

  .controls,
  .stats,
  .toggles {
    justify-content: flex-start;
  }

  .layout {
    gap: 0.8rem;
  }
}

@media (max-width: 620px) {
  :root {
    --cell-size: clamp(2rem, 10.2vw, 2.8rem);
  }

  body {
    background-attachment: scroll;
  }

  .app {
    padding: 0.55rem;
  }

  .topbar,
  .card,
  .board-shell {
    border-radius: 18px;
  }

  .brand img {
    width: 2.6rem;
    height: 2.6rem;
  }

  .pill,
  .icon-button,
  .mode-button {
    min-height: 2.75rem;
    padding-inline: 0.75rem;
  }

  .stat {
    min-width: 6.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
