:root {
  color-scheme: light;
  --bg: #f1f0e8;
  --ink: #24262a;
  --muted: #6a6b63;
  --panel: #fffdf6;
  --line: #c9c5b8;
  --line-strong: #8a8578;
  --cell: clamp(24px, calc((100vw - 64px) / var(--cols, 9)), 40px);
  --gap: 2px;
  --green: #3d7b5f;
  --gold: #c38a27;
  --red: #d34836;
  --blue: #2f6fb1;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(36, 38, 42, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(36, 38, 42, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 47%, var(--ink) 47% 53%, transparent 53%),
    linear-gradient(45deg, transparent 0 47%, var(--ink) 47% 53%, transparent 53%),
    #e6d39b;
  box-shadow: 4px 4px 0 #b8c6b6;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1;
  font-weight: 800;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.difficulty {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.78);
  box-shadow: 0 1px 0 rgba(36, 38, 42, 0.06);
}

.difficulty-button,
.new-game-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.difficulty-button {
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.difficulty-button:hover,
.difficulty-button:focus-visible {
  border-color: var(--line);
  background: #f7f1df;
  outline: none;
}

.difficulty-button.is-active {
  background: var(--ink);
  color: #fffdf6;
}

.game-panel {
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.92);
  box-shadow: 0 14px 40px rgba(50, 45, 35, 0.12);
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}

.scorebar {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr)) auto;
  gap: 8px;
  align-items: stretch;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f1df;
  padding: 8px 10px;
  display: grid;
  gap: 3px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.metric strong {
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  line-height: 1;
}

.new-game-button {
  min-width: 138px;
  padding: 0 14px;
  background: #d7e0d4;
  border-color: #9aab96;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.new-game-button:hover,
.new-game-button:focus-visible {
  background: #c9d7c4;
  border-color: var(--green);
  outline: none;
}

.new-game-button:active,
.cell:active {
  transform: translateY(1px);
}

.reset-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  position: relative;
}

.reset-icon::after {
  content: "";
  position: absolute;
  right: -4px;
  top: -3px;
  width: 7px;
  height: 7px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(28deg);
}

.status-line {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.status-line p {
  margin: 0;
  font-size: 14px;
}

.status-line #statusMessage {
  color: var(--ink);
  font-weight: 700;
}

.board-frame {
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #777064;
  padding: 10px;
  outline: none;
}

.board {
  --board-width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--gap));
  width: var(--board-width);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  gap: var(--gap);
  margin: 0 auto;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  min-width: var(--cell);
  min-height: var(--cell);
  border: 1px solid #858074;
  border-radius: 4px;
  background: linear-gradient(145deg, #ece7d8, #cfc7b7);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.58);
  font-weight: 900;
  line-height: 1;
  padding: 0;
  position: relative;
  user-select: none;
}

.cell:hover,
.cell:focus-visible {
  border-color: #3d7b5f;
  outline: 2px solid rgba(61, 123, 95, 0.35);
  outline-offset: -2px;
}

.cell.is-revealed {
  background: #f6f2e8;
  border-color: #d3cab9;
  cursor: default;
  box-shadow: inset 0 0 0 1px rgba(36, 38, 42, 0.04);
}

.cell.is-flagged::before,
.cell.is-mine::before {
  content: "";
  width: calc(var(--cell) * 0.62);
  height: calc(var(--cell) * 0.62);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.cell.is-flagged::before {
  background-image: url("assets/flag.svg");
}

.cell.is-mine::before {
  background-image: url("assets/mine.svg");
}

.cell.is-exploded {
  background: #f0b4aa;
  border-color: var(--red);
}

.cell.is-false-flag::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-top: 3px solid var(--red);
  transform: rotate(-45deg);
}

.cell.is-question {
  color: var(--gold);
}

.cell.number-1 { color: #2f6fb1; }
.cell.number-2 { color: #3d7b5f; }
.cell.number-3 { color: #d34836; }
.cell.number-4 { color: #6a4aa1; }
.cell.number-5 { color: #a85f24; }
.cell.number-6 { color: #16817a; }
.cell.number-7 { color: #2e2f35; }
.cell.number-8 { color: #777064; }

.game-panel.is-won {
  border-color: var(--green);
}

.game-panel.is-lost {
  border-color: var(--red);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    padding: 12px 0;
    gap: 10px;
  }

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

  h1 {
    font-size: 28px;
  }

  .difficulty {
    width: 100%;
  }

  .difficulty-button {
    flex: 1;
    padding: 0 8px;
    font-size: 14px;
  }

  .scorebar {
    grid-template-columns: repeat(3, 1fr);
  }

  .new-game-button {
    grid-column: 1 / -1;
  }

  .status-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}
