:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #fff;
  --text: #262d32;
  --muted: #81898d;
  --line: #e4e8e9;
  --green: #236c59;
  --covered: #d9e8e0;
  --covered-hover: #c5dfd1;
  --tile-open: #f0f3f2;
  --tile-border: #c9ddd0;
  --red: #c16453;
  --red-soft: #fae8e2;
  --shadow: 0 8px 30px #283e3210;
}

* { box-sizing: border-box; letter-spacing: 0; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button,
a {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 96px));
  min-height: 100dvh;
  margin: auto;
}

.masthead {
  height: 116px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

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

.brand h1 {
  margin: 0 0 3px;
  font-size: 25px;
  font-weight: 650;
}

.brand span,
.home-link {
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.home-link {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  text-decoration: none;
}

.game-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 40px 0 28px;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 10px;
  font-weight: 650;
}

.tiny-square {
  width: 5px;
  height: 5px;
  background: var(--green);
}

.heading-copy h2 {
  margin: 10px 0 0;
  font-size: 23px;
  font-weight: 550;
}

.difficulty {
  display: flex;
  align-items: stretch;
  padding: 4px;
  border-radius: 8px;
  background: #ecefef;
}

.difficulty button {
  min-width: 84px;
  padding: 8px 16px;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 1px 5px #0000000c;
  font-size: 12px;
  font-weight: 650;
}

.difficulty span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.play-area {
  width: 100%;
  max-width: 920px;
  min-width: 0;
  margin: 0 auto;
}

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 0 2px;
}

.counter {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 126px;
}

.counter-symbol {
  width: 42px;
  height: 46px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
}

.flag-symbol {
  background: var(--red-soft);
  color: var(--red);
}

.time-symbol {
  background: #e9edf4;
  color: #617890;
}

.counter-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
}

.counter strong {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 24px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.time-counter {
  justify-content: flex-end;
}

.restart-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 2px 3px #00000003;
  font-size: 24px;
}

.board-stage {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--tile-border) transparent;
  padding: 24px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.canvas-wrap {
  position: relative;
  width: min(100%, 987px);
  min-width: min(100%, 360px);
  aspect-ratio: 30 / 16;
  margin: 0 auto;
  outline: none;
  contain: strict;
  touch-action: manipulation;
}

.board-view-controls {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 14px auto 0;
  max-width: 520px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.board-view-controls input {
  flex: 1;
  min-width: 80px;
  accent-color: var(--green);
}

.zoom-button {
  min-width: 35px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--green);
  font-weight: 650;
}

.zoom-button[aria-pressed="true"] {
  background: var(--green);
  color: #fff;
}

.zoom-button:disabled {
  color: var(--muted);
  opacity: .45;
}

.fit-button {
  padding: 0 10px;
}

#board-zoom-value {
  min-width: 48px;
  color: var(--muted);
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}

.canvas-wrap:focus-visible {
  outline: 3px solid #609eec;
  outline-offset: 4px;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.board-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  font-size: 11px;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #adb5b2;
}

.status[data-state="playing"],
.status[data-state="won"] {
  color: var(--green);
}

.status[data-state="playing"] .status-dot,
.status[data-state="won"] .status-dot {
  background: var(--green);
}

.status[data-state="lost"] {
  color: var(--red);
}

.status[data-state="lost"] .status-dot {
  background: var(--red);
}

.board-spec {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.play-controls {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 28px;
}

.mode-switch {
  display: flex;
  flex-shrink: 0;
  gap: 3px;
  padding: 3px;
  border-radius: 6px;
  background: #e9edec;
}

.mode-switch button {
  width: 35px;
  height: 32px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 17px;
}

.mode-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 1px 3px #00000008;
}

.safe-progress {
  flex: 1;
  max-width: 330px;
  margin-left: auto;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--line);
}

#progress-fill {
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width .25s;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  width: min(920px, 100%);
  margin: 28px auto 32px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.metrics > div {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--green);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 620px) {
  .app-shell {
    width: calc(100% - 36px);
  }

  .masthead {
    height: 88px;
  }

  .brand h1 {
    font-size: 22px;
  }

  .brand img {
    width: 39px;
    height: 39px;
  }

  .home-link {
    padding: 8px 10px;
  }

  .game-heading {
    display: block;
    padding: 28px 0 22px;
  }

  .heading-copy h2 {
    margin-top: 8px;
    font-size: 21px;
  }

  .difficulty {
    width: 100%;
    margin-top: 22px;
  }

  .difficulty button {
    flex: 1;
  }

  .counter {
    min-width: 112px;
    gap: 9px;
  }

  .counter-symbol {
    width: 34px;
    height: 40px;
    font-size: 18px;
  }

  .counter strong {
    font-size: 22px;
  }

  .counter-label {
    font-size: 9px;
  }

  .board-stage {
    padding: 15px 8px;
  }

  .canvas-wrap { min-width: min(100%, 320px); }

  .board-view-controls {
    max-width: none;
    gap: 7px;
  }

  .fit-button {
    padding: 0 8px;
  }

  .play-controls {
    gap: 20px;
    margin-top: 22px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 24px;
  }
}
