:root {
  color-scheme: light;
  --ink: #1c1c1e;
  --muted: #797981;
  --line: rgba(28, 28, 30, .08);
  --glass: rgba(255, 255, 255, .76);
  --blue: #007aff;
  --red: #ff3b30;
  --cell-size: 34px;
  --cell-gap: 4px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(175, 214, 255, .32), transparent 30rem),
    radial-gradient(circle at 90% 80%, rgba(218, 195, 255, .25), transparent 28rem),
    linear-gradient(155deg, #f9fafc 0%, #f1f2f6 58%, #eceef4 100%);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  filter: blur(1px);
  pointer-events: none;
  opacity: .42;
}

.ambient-one { top: -140px; left: -80px; background: linear-gradient(135deg, #9bd2ff, #d8eeff); }
.ambient-two { right: -150px; bottom: 5%; background: linear-gradient(135deg, #d7b9ff, #f1e9ff); }

.app-shell {
  position: relative;
  width: min(760px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 0 max(26px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 18px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 25px; line-height: 1; letter-spacing: -.65px; font-weight: 730; }
.brand p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.brand-mark {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(145deg, #202125, #050506);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.28), 0 8px 18px rgba(0,0,0,.16);
}

.brand-mark::before, .brand-mark::after, .brand-mark span::before, .brand-mark span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 8px;
  border-radius: 2px;
  background: #fff;
  transform-origin: 50% 13px;
  transform: translate(-50%, -13px);
}
.brand-mark::after { transform: translate(-50%, -13px) rotate(90deg); }
.brand-mark span::before { transform: translate(-50%, -13px) rotate(45deg); }
.brand-mark span::after { transform: translate(-50%, -13px) rotate(-45deg); }
.brand-mark span { position: absolute; inset: 15px; border-radius: 50%; background: #fff; }

.icon-button, .face-button {
  border: 1px solid rgba(104, 116, 136, .24);
  color: var(--ink);
  background: rgba(255,255,255,.78);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.8), 0 5px 16px rgba(45,55,70,.09);
  cursor: pointer;
}

.icon-button { width: 42px; height: 42px; border-radius: 50%; font-size: 25px; line-height: 1; }
.icon-button:active { transform: scale(.94); }

.game-card, .settings-card, .help-card {
  border: 1px solid rgba(255,255,255,.82);
  background: var(--glass);
  box-shadow: 0 20px 50px rgba(41, 49, 62, .10), inset 0 1px 0 #fff;
  backdrop-filter: blur(26px) saturate(145%);
  -webkit-backdrop-filter: blur(26px) saturate(145%);
}

.game-card { border-radius: 28px; padding: 20px; }

.status-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 18px;
}

.metric { display: flex; align-items: center; gap: 10px; }
.metric-right { justify-content: flex-end; text-align: right; }
.metric strong { display: block; font-size: 18px; letter-spacing: -.25px; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.metric-icon { position: relative; width: 27px; height: 27px; border-radius: 9px; background: #fff; box-shadow: 0 3px 12px rgba(20,30,45,.08); }

.flag-mini::before { content: ""; position: absolute; left: 9px; top: 6px; width: 2px; height: 15px; border-radius: 2px; background: var(--red); }
.flag-mini::after { content: ""; position: absolute; left: 11px; top: 6px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid var(--red); }
.clock::before { content: ""; position: absolute; inset: 6px; border: 1.8px solid var(--blue); border-radius: 50%; }
.clock::after { content: ""; position: absolute; left: 13px; top: 9px; width: 1.8px; height: 7px; border-radius: 2px; background: var(--blue); transform-origin: bottom; transform: rotate(-35deg); }

.face-button { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.face-button:active { transform: scale(.95); }
#face { width: 18px; height: 18px; display: grid; place-items: center; color: #171719; font-size: 10px; border: 2px solid currentColor; border-radius: 50%; }

.board-viewport {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.18) transparent;
  border-radius: 20px;
  background: rgba(228,230,236,.64);
  box-shadow: inset 0 1px 4px rgba(32,36,44,.08);
}

.board {
  display: grid;
  gap: var(--cell-gap);
  width: max-content;
  min-width: 100%;
  justify-content: center;
  padding: 8px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-x pan-y;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  border: 1px solid rgba(104, 116, 136, .28);
  border-radius: 9px;
  color: #242529;
  background: linear-gradient(150deg, rgba(255,255,255,.98), rgba(245,246,249,.9));
  box-shadow: 0 2px 6px rgba(44,53,68,.14), inset 0 1px 0 #fff;
  font-weight: 750;
  font-size: calc(var(--cell-size) * .45);
  line-height: 1;
  cursor: pointer;
  transition: transform .11s ease, background .13s ease, box-shadow .13s ease;
  -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.open) { border-color: rgba(84,98,120,.32); background: #fff; box-shadow: 0 3px 9px rgba(44,53,68,.18), inset 0 1px 0 #fff; }
.cell:focus-visible { outline: 3px solid rgba(0,122,255,.32); outline-offset: 1px; z-index: 2; }
.cell.press-hold { transform: scale(.89); background: #e3efff; box-shadow: inset 0 0 0 2px rgba(0,122,255,.28); }
.cell.open { cursor: default; border-color: rgba(126,134,148,.16); background: rgba(213,216,223,.54); box-shadow: none; transform: none; }
.cell.mine-hit { background: #ffddd9; color: var(--red); animation: pop .26s ease-out; }
.cell.wrong-flag::after { content: "×"; position: absolute; color: var(--red); font-size: 24px; }

.cell[data-count="1"] { color: #007aff; }
.cell[data-count="2"] { color: #2e9f54; }
.cell[data-count="3"] { color: #ff3b30; }
.cell[data-count="4"] { color: #5856d6; }
.cell[data-count="5"] { color: #b14b35; }
.cell[data-count="6"] { color: #00a2a2; }
.cell[data-count="7"] { color: #3a3a3c; }
.cell[data-count="8"] { color: #8e8e93; }

.flag-shape { position: relative; width: 15px; height: 18px; }
.flag-shape::before { content: ""; position: absolute; left: 4px; top: 1px; width: 2px; height: 15px; border-radius: 2px; background: var(--red); }
.flag-shape::after { content: ""; position: absolute; left: 6px; top: 1px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 9px solid var(--red); }
.mine-shape { position: relative; width: 13px; height: 13px; border-radius: 50%; background: currentColor; box-shadow: 0 -7px 0 -5px currentColor, 0 7px 0 -5px currentColor, 7px 0 0 -5px currentColor, -7px 0 0 -5px currentColor; }

.game-message { min-height: 17px; margin: 14px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

.settings-card { margin-top: 14px; border-radius: 24px; padding: 20px; }
.section-heading h2 { margin: 0; font-size: 17px; letter-spacing: -.25px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.preset {
  min-width: 0;
  padding: 12px 8px;
  border: 1px solid rgba(28,28,30,.06);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(246,247,250,.78);
  cursor: pointer;
}
.preset strong, .preset span { display: block; }
.preset strong { font-size: 13px; }
.preset span { margin-top: 4px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.preset.active { color: #fff; border-color: transparent; background: linear-gradient(145deg, #1989ff, #0071e9); box-shadow: 0 7px 14px rgba(0,122,255,.22); }
.preset.active span { color: rgba(255,255,255,.76); }

.custom-settings { display: grid; grid-template-columns: repeat(3, 1fr) auto; align-items: end; gap: 9px; margin-top: 13px; }
.custom-settings label { color: var(--muted); font-size: 10px; }
.custom-settings input {
  width: 100%;
  height: 38px;
  margin-top: 5px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: 0;
  color: var(--ink);
  background: rgba(255,255,255,.72);
  font-size: 13px;
  font-weight: 650;
}
.custom-settings input:focus { border-color: rgba(0,122,255,.45); box-shadow: 0 0 0 3px rgba(0,122,255,.10); }
.apply-button { height: 38px; padding: 0 15px; border: 0; border-radius: 11px; color: #fff; background: #1c1c1e; font-size: 12px; font-weight: 650; cursor: pointer; }
.apply-button:active { transform: scale(.97); }

.help-card { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 14px; padding: 14px 18px; border-radius: 20px; }
.help-item { display: flex; align-items: center; gap: 9px; }
.help-item strong, .help-item small { display: block; white-space: nowrap; }
.help-item strong { font-size: 11px; }
.help-item small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.help-divider { width: 1px; align-self: stretch; background: var(--line); }

.gesture, .mouse, .key-hint { flex: 0 0 auto; width: 27px; height: 27px; border-radius: 9px; background: rgba(234,236,241,.95); }
.gesture { position: relative; }
.gesture::before { content: ""; position: absolute; left: 10px; top: 5px; width: 6px; height: 12px; border: 1.5px solid #4e4f55; border-radius: 5px; }
.tap::after { content: ""; position: absolute; inset: 3px; border: 1px solid rgba(0,122,255,.3); border-radius: 50%; }
.hold::after { content: ""; position: absolute; inset: 2px; border: 1.5px solid var(--blue); border-radius: 50%; border-top-color: transparent; transform: rotate(25deg); }
.mouse { position: relative; border: 1.5px solid #787980; border-radius: 12px; background: transparent; }
.mouse::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 13px; width: 1px; background: #a8a9ae; }
.mouse::after { content: ""; position: absolute; top: 0; width: 50%; height: 10px; background: rgba(0,122,255,.16); }
.mouse.left::after { left: 0; border-radius: 10px 0 3px 0; }
.mouse.right::after { right: 0; border-radius: 0 10px 0 3px; }
.key-hint { display: grid; place-items: center; font-size: 11px; font-weight: 750; box-shadow: inset 0 -2px 0 rgba(0,0,0,.08); }
.mobile-help { display: none; }

footer { padding: 18px 0 0; color: #929298; text-align: center; font-size: 10px; }

@keyframes pop { 0% { transform: scale(.78); } 65% { transform: scale(1.1); } 100% { transform: scale(1); } }

@media (max-width: 620px) {
  :root { --cell-size: 32px; --cell-gap: 3px; }
  .app-shell { width: min(100% - 20px, 520px); padding-top: max(16px, env(safe-area-inset-top)); }
  .topbar { padding-bottom: 13px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand h1 { font-size: 22px; }
  .brand p { font-size: 11px; }
  .icon-button { width: 38px; height: 38px; }
  .game-card { padding: 14px; border-radius: 24px; }
  .status-row { margin-bottom: 13px; }
  .board { justify-content: start; min-width: max-content; }
  .settings-card { padding: 16px; }
  .presets { gap: 6px; }
  .preset { padding: 11px 4px; }
  .preset span { font-size: 9px; }
  .custom-settings { grid-template-columns: repeat(3, 1fr); }
  .apply-button { grid-column: 1 / -1; }
  .help-card { gap: 14px; }
  .desktop-help { display: none; }
  .mobile-help { display: flex; }
}

@media (max-width: 370px) {
  :root { --cell-size: 30px; --cell-gap: 3px; }
  .metric-icon { display: none; }
  .help-card { padding-inline: 10px; gap: 9px; }
}

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