:root {
  color-scheme: dark;
  --ink: #f2f5fc;
  --muted: #9daac2;
  --accent: #d6fa77;
  --page: #101521;
  --panel: #171e2d;
  --edge: #2a354b;
  --amber: #ffc778;
  --danger: #ff8292;
  --mono: "Space Mono", "Cascadia Mono", Consolas, monospace;
  font-family: Inter, "Yu Gothic UI", "Hiragino Sans", Meiryo, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(ellipse 730px 450px at 47% 13%, #25334c 0%, transparent 78%),
    var(--page);
}
body::before {
  content: "";
  position: fixed;
  inset: 58px 0 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, #9bbdff0b 1px, transparent 1px),
    linear-gradient(#9bbdff0b 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(#000, transparent 83%);
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.topbar { position: relative; border-bottom: 1px solid #283348; background: #111724; }
.topbar-inner {
  max-width: 956px;
  min-height: 58px;
  margin-inline: auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font: bold 14px var(--mono); letter-spacing: .12em; }
.brand-icon {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 7px;
  background: var(--accent);
  color: #1b2730;
}
.topbar-tag { color: var(--muted); font-size: 12px; letter-spacing: .09em; }
.layout { position: relative; max-width: 956px; margin-inline: auto; padding: 40px 24px 60px; }
.intro { margin-bottom: 29px; }
h1 { margin: 0; font: 900 clamp(37px, 7.9vw, 70px)/.99 Inter, "Arial Black", sans-serif; letter-spacing: -.065em; }
h1 span { color: var(--accent); }
.intro p { margin: 14px 0 0; color: var(--muted); font-size: 14px; letter-spacing: .05em; }
.play-area { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 20px; align-items: start; }
.game-panel, .side-panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 17px;
  box-shadow: 0 12px 36px #090c163b;
}
.game-panel { min-width: 0; padding: 18px; }
.scoreboard { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 58px; gap: 10px; margin-bottom: 14px; }
.stat {
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 8px 14px;
  min-height: 64px;
  border: 1px solid #263248;
  border-radius: 10px;
  background: #111725;
}
.stat-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.stat output, .stat time { color: var(--accent); font: bold 23px/1.12 var(--mono); letter-spacing: .03em; white-space: nowrap; }
.stat time { color: var(--ink); }
.stat #best-time { color: var(--amber); }
.reset {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #3a4961;
  border-radius: 10px;
  background: #252f43;
  color: var(--accent);
  font: bold 31px/1 var(--mono);
}
.reset:hover { background: #34425a; }
.board-viewport {
  overflow: auto;
  padding: 9px;
  border: 1px solid #29364c;
  border-radius: 12px;
  background: #0e1420;
  scrollbar-color: #465676 #161e2d;
}
.board {
  --cols: 9;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  min-width: calc(29px * var(--cols) + 4px * (var(--cols) - 1));
  max-width: 500px;
  margin-inline: auto;
}
.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1.18;
  padding: 0;
  border: 1px solid #3c4b64;
  border-radius: 5px;
  background: linear-gradient(#303d55, #273349);
  box-shadow: inset 0 1px #819bcc25, inset 0 -2px #131c2c7a;
  font: bold clamp(13px, 2vw, 21px)/1 var(--mono);
  user-select: none;
  touch-action: manipulation;
}
.cell:focus-visible { position: relative; outline-offset: -2px; z-index: 1; }
.cell:hover:not([data-open]) { border-color: #7c8ca6; background: #3b4a64; }
.cell:active:not([data-open]) { box-shadow: inset 0 2px 3px #0f1625b8; }
.cell[data-open] { border-color: #263248; background: #1a2436; box-shadow: none; cursor: default; }
.cell[data-open]:empty { background: #151e2e; }
.cell[data-number] { cursor: pointer; }
.cell[data-number="1"] { color: #8cbbff; }
.cell[data-number="2"] { color: #b7ec87; }
.cell[data-number="3"] { color: #ff9aab; }
.cell[data-number="4"] { color: #c3abff; }
.cell[data-number="5"] { color: #ffc778; }
.cell[data-number="6"] { color: #74e0db; }
.cell[data-number="7"] { color: #f0b3ec; }
.cell[data-number="8"] { color: #e4eafb; }
.cell[data-flagged] { color: var(--amber); border-color: #775f48; background: #392e32; }
.cell[data-mine] { color: #ff9daa; background: #382533; border-color: #593746; }
.cell[data-hit] { color: #fff0f3; background: #983b50; border-color: #ff8292; }
.cell[data-wrong] { color: var(--danger); border-color: #815062; }
.cell .icon { font-size: clamp(14px, 2.4vw, 21px); }
.status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 23px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 12px;
}
.status-light { flex: none; width: 7px; height: 7px; border-radius: 50%; background: #7383a0; }
.status[data-state="playing"] .status-light, .status[data-state="won"] .status-light {
  background: var(--accent);
  box-shadow: 0 0 10px #c7ff7775;
}
.status[data-state="won"] { color: var(--accent); }
.status[data-state="lost"] { color: var(--danger); }
.status[data-state="lost"] .status-light { background: var(--danger); }

.settings { display: grid; gap: 14px; }
.side-panel { padding: 17px; }
h2 { margin: 0 0 12px; font-size: 13px; letter-spacing: .09em; }
.difficulty { display: grid; gap: 7px; }
.difficulty button, .mode button {
  border: 1px solid #303d54;
  border-radius: 8px;
  background: #212b3d;
  font-size: 12px;
}
.difficulty button:hover, .mode button:hover { background: #2c3850; }
.difficulty button[aria-pressed="true"], .mode button[aria-pressed="true"] {
  border-color: #92aa55;
  background: #d6fa7715;
  color: var(--accent);
}
.difficulty button { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; min-height: 39px; }
.difficulty small { color: var(--muted); font: 11px var(--mono); }
.difficulty button[aria-pressed="true"] small { color: #c9d6a8; }
.mode { display: grid; grid-template-columns: .85fr 1.15fr; gap: 7px; }
.mode button { display: flex; justify-content: center; align-items: center; gap: 6px; min-height: 41px; padding: 4px; font-weight: 600; white-space: nowrap; }
.mobile-mode { display: none; }
.click-setting { display: flex; align-items: center; gap: 9px; min-height: 34px; font-size: .875rem; cursor: pointer; }
.click-setting input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.click-setting input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.setting-help { margin: 7px 0 0; color: var(--muted); font-size: .875rem; line-height: 1.6; }
.guide ul { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.guide li { display: flex; align-items: flex-start; gap: 9px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.guide-tile { display: grid; place-items: center; flex: 0 0 23px; height: 23px; border: 1px solid #334159; border-radius: 5px; background: #253149; font: bold 13px var(--mono); }
.guide-number { color: #8cbbff; }
.guide-flag { color: var(--amber); }
.guide-check { color: var(--accent); }

.icon { display: inline-block; position: relative; flex: none; width: 1em; height: 1em; font-size: 13px; }
.icon-mine {
  background:
    radial-gradient(circle, currentColor 0 43%, transparent 47%),
    linear-gradient(currentColor, currentColor) center / 100% .11em no-repeat,
    linear-gradient(currentColor, currentColor) center / .11em 100% no-repeat,
    linear-gradient(45deg, transparent 45%, currentColor 45% 55%, transparent 55%) center / 78% 78% no-repeat,
    linear-gradient(-45deg, transparent 45%, currentColor 45% 55%, transparent 55%) center / 78% 78% no-repeat;
}
.icon-clock { border: 1.5px solid currentColor; border-radius: 50%; }
.icon-clock::after { content: ""; position: absolute; left: 50%; top: 19%; width: 29%; height: 40%; border: solid currentColor; border-width: 0 0 1px 1px; }
.icon-best { color: var(--amber); font-style: normal; line-height: 1; }
.icon-open { border: 1.5px solid currentColor; border-radius: 3px; }
.icon-open::after { content: ""; position: absolute; inset: 28%; background: currentColor; border-radius: 1px; }
.icon-flag::before { content: ""; position: absolute; left: 18%; top: 9%; width: 11%; height: 84%; background: currentColor; border-radius: 4px; }
.icon-flag::after { content: ""; position: absolute; left: 26%; top: 11%; width: 68%; height: 56%; background: currentColor; clip-path: polygon(0 0, 100% 15%, 73% 53%, 100% 88%, 0 100%); }

@media (min-width: 721px) and (max-width: 850px) {
  .scoreboard { grid-template-columns: repeat(3, minmax(0, 1fr)) 44px; gap: 6px; }
  .stat { padding-inline: 6px; }
  .stat-label { gap: 4px; }
}

@media (max-width: 720px) {
  .layout { max-width: 570px; padding: 32px 15px 36px; }
  .topbar-inner { max-width: 570px; padding-inline: 15px; }
  .intro { margin-bottom: 22px; }
  .intro p { font-size: 13px; }
  .play-area { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .game-panel { padding: 11px; }
  .scoreboard { margin-bottom: 9px; grid-template-columns: repeat(3, minmax(0, 1fr)) 39px; gap: 6px; }
  .stat { padding: 7px 9px; min-height: 53px; }
  .stat output, .stat time { font-size: 19px; }
  .mobile-mode { display: grid; margin-bottom: 9px; }
  .mobile-mode button { min-height: 39px; }
  .desktop-mode { display: none; }
  .board-viewport { padding: 6px; }
  .board { min-width: calc(25px * var(--cols) + 3px * (var(--cols) - 1)); gap: 3px; }
  .cell { border-radius: 4px; aspect-ratio: 1; }
  .settings { gap: 13px; }
}

@media (max-width: 400px) {
  .stat { padding-inline: 5px; }
  .stat-label { gap: 3px; font-size: 10px; white-space: nowrap; }
  .stat-label .icon { font-size: 10px; }
  .stat output, .stat time { font-size: 17px; }
}
