/*
 * Visual direction: restrained grayscale, big plain headline, borderless pill controls,
 * light / dark / system switch. The board is the only place with colour.
 */
:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #6a6a6a;
  --line: #dcdcdc;
  --pill: #e8e8e8;
  --pill-ink: #1a1a1a;
  --solid: #1a1a1a;
  --solid-ink: #ffffff;
  --focus: #2563eb;
  --cell-unknown: #d4d4d4;
  --cell-unknown-edge: #bcbcbc;
  --cell-open: #f0f0f0;
  --safe: #2e9e5b;
  --safe-bg: #d8f1e2;
  --mine: #d64545;
  --mine-bg: #fadcdc;
  --guess: #f59e0b;
  --cell: 30px;
  --btn-h: 40px;
  --n1: #1d4ed8;
  --n2: #15803d;
  --n3: #dc2626;
  --n4: #1e3a8a;
  --n5: #9a3412;
  --n6: #0f766e;
  --n7: #111827;
  --n8: #6b7280;
}

:root[data-theme="dark"] {
  --bg: #141414;
  --surface: #1e1e1e;
  --ink: #ececec;
  --muted: #a0a0a0;
  --line: #333333;
  --pill: #2c2c2c;
  --pill-ink: #ececec;
  --solid: #f2f2f2;
  --solid-ink: #141414;
  --focus: #6b9bff;
  --cell-unknown: #404040;
  --cell-unknown-edge: #2e2e2e;
  --cell-open: #262626;
  --safe: #4cc982;
  --safe-bg: #1c3a2a;
  --mine: #ff7a7a;
  --mine-bg: #4a2323;
  --n1: #7aa2ff;
  --n2: #5fd08a;
  --n3: #ff7a7a;
  --n4: #a5b4fc;
  --n5: #fdba74;
  --n6: #5eead4;
  --n7: #e5e7eb;
  --n8: #9ca3af;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]):not([data-skin="classic"]):not([data-skin="sky"]) {
    --bg: #141414;
    --surface: #1e1e1e;
    --ink: #ececec;
    --muted: #a0a0a0;
    --line: #333333;
    --pill: #2c2c2c;
    --pill-ink: #ececec;
    --solid: #f2f2f2;
    --solid-ink: #141414;
    --focus: #6b9bff;
    --cell-unknown: #404040;
    --cell-unknown-edge: #2e2e2e;
    --cell-open: #262626;
    --safe: #4cc982;
    --safe-bg: #1c3a2a;
    --mine: #ff7a7a;
    --mine-bg: #4a2323;
    --n1: #7aa2ff;
    --n2: #5fd08a;
    --n3: #ff7a7a;
    --n4: #a5b4fc;
    --n5: #fdba74;
    --n6: #5eead4;
    --n7: #e5e7eb;
    --n8: #9ca3af;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}

a { color: var(--ink); text-underline-offset: 3px; }

.wrap { max-width: 1000px; margin: 0 auto; padding: 0 20px; }

/* top bar: pills on the left, theme switch on the right */
.topbar { padding: 14px 0 0; }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar-left, .theme, .skins { display: flex; gap: 8px; align-items: center; }

/* parts that only the Classic and Sky skins use */
.hero { position: relative; }
.hero-bg, .win-title, .win-menu, .led-row { display: none; }

.pill, .theme button, .skins button {
  font: inherit; font-size: 14px; line-height: 1; color: var(--pill-ink); background: var(--pill);
  border: 0; border-radius: 4px; padding: 9px 12px; text-decoration: none; cursor: pointer;
}
.pill:hover, .theme button:hover, .skins button:hover { filter: brightness(0.96); }
.pill.brand { font-weight: 600; }
.theme button[aria-pressed="true"], .skins button[aria-pressed="true"] { background: var(--solid); color: var(--solid-ink); }

h1 {
  font-size: clamp(36px, 7vw, 64px);
  line-height: 1.04;
  font-weight: 500;
  letter-spacing: -0.035em;
  margin: 26px 0 10px;
}
h2 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; margin: 44px 0 10px; }
h3 { font-size: 17px; margin: 24px 0 6px; }
.lead { color: var(--muted); font-size: 18px; margin: 0 0 22px; max-width: 62ch; }

.tool { background: var(--surface); border-radius: 8px; padding: 18px; }

.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field input, .field select {
  font: inherit; font-size: 15px; color: var(--pill-ink); background: var(--pill);
  border: 0; border-radius: 4px; padding: 0 10px; height: 40px;
}
.field input[type="number"] { width: 78px; }
.field select { min-width: 200px; }

button {
  font: inherit; font-size: 15px; cursor: pointer; color: var(--pill-ink); background: var(--pill);
  border: 0; border-radius: 4px; padding: 0 14px; height: 40px;
}
button:hover { filter: brightness(0.96); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
button.primary { background: var(--solid); color: var(--solid-ink); font-weight: 600; padding: 0 30px; }
button:disabled { opacity: 0.5; cursor: default; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.palette .label { font-size: 13px; color: var(--muted); margin-right: 4px; }
.tile {
  width: 40px; height: 40px; padding: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; border-radius: 4px; background: var(--cell-open);
}
.tile[aria-checked="true"] { outline: 3px solid var(--solid); outline-offset: 1px; }
.tile.t-unknown { background: var(--cell-unknown); box-shadow: inset 0 0 0 2px var(--cell-unknown-edge); }
.tile.n1 { color: var(--n1); } .tile.n2 { color: var(--n2); } .tile.n3 { color: var(--n3); }
.tile.n4 { color: var(--n4); } .tile.n5 { color: var(--n5); } .tile.n6 { color: var(--n6); }
.tile.n7 { color: var(--n7); } .tile.n8 { color: var(--n8); } .tile.n0 { color: var(--muted); }

.hint { font-size: 13px; color: var(--muted); margin: 10px 0 12px; }
.hint summary { cursor: pointer; }
.hint p { margin: 6px 0 0; }

.board-wrap { overflow-x: auto; padding: 6px; border-radius: 6px; background: var(--bg); }
.board { display: grid; width: max-content; margin: 0 auto; gap: 2px; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

.cell {
  position: relative; width: var(--cell); height: var(--cell); display: grid; place-items: center;
  font-weight: 700; font-size: calc(var(--cell) * 0.55); line-height: 1; border-radius: 3px;
  background: var(--cell-unknown); box-shadow: inset 0 0 0 2px var(--cell-unknown-edge); cursor: pointer;
}
.cell:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.cell.open { background: var(--cell-open); box-shadow: none; }
.cell.n1 { color: var(--n1); } .cell.n2 { color: var(--n2); } .cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); } .cell.n5 { color: var(--n5); } .cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); } .cell.n8 { color: var(--n8); }
.cell.flag::after, .cell.res-mine::after {
  content: ""; width: 56%; height: 56%;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 1.5v13' stroke='%23444' stroke-width='1.6' stroke-linecap='round'/%3E%3Cpath d='M4.5 2l8 3.2-8 3.2z' fill='%23d64545'/%3E%3C/svg%3E");
}
.cell.res-safe { background: var(--safe-bg); box-shadow: inset 0 0 0 2px var(--safe); }
.cell.res-safe::after {
  content: ""; width: 50%; height: 50%;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2.5 8.5l3.5 3.5 7.5-8' fill='none' stroke='%232e9e5b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.cell.res-mine { background: var(--mine-bg); box-shadow: inset 0 0 0 2px var(--mine); }
.cell.res-odds { color: var(--ink); font-size: calc(var(--cell) * 0.36); font-weight: 600; }
.cell.res-best { outline: 3px solid var(--guess); outline-offset: -1px; z-index: 1; }

.actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  margin: 14px -18px -18px; padding: 10px 18px; background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
}
.status { color: var(--muted); font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.result { margin: 0 0 12px; padding: 12px 14px; border-radius: 6px; background: var(--bg); display: none; border-left: 4px solid var(--safe); }
.result.show { display: block; }
.result .headline { font-weight: 700; font-size: 19px; margin: 0 0 4px; letter-spacing: -0.01em; }
.result p { margin: 4px 0; }
.result.warn { border-left-color: var(--guess); }
.result.error { border-left-color: var(--mine); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .l-safe::before { background: var(--safe-bg); box-shadow: inset 0 0 0 2px var(--safe); }
.legend .l-mine::before { background: var(--mine-bg); box-shadow: inset 0 0 0 2px var(--mine); }
.legend .l-best::before { background: transparent; box-shadow: inset 0 0 0 2px var(--guess); }

.prose { max-width: 70ch; }
.prose p { margin: 8px 0; }
.prose ol, .prose ul { padding-left: 22px; }
.prose li { margin: 6px 0; }
.faq dt { font-weight: 700; margin-top: 18px; }
.faq dd { margin: 4px 0 0; }

.site-footer { margin-top: 60px; border-top: 1px solid var(--line); padding: 24px 0 40px; color: var(--muted); font-size: 14px; }
.site-footer a { color: var(--muted); margin-right: 18px; }

@media (max-width: 560px) {
  .field select { min-width: 0; width: 100%; }
  .controls .field:first-child { width: 100%; }
  .tile { width: 36px; height: 36px; }
  .tool { padding: 14px; }
  .actions { margin: 14px -14px -14px; padding: 10px 14px; }
}

/* style menu: top-right dropdown. Modern owns the Light / Dark / System options, so they are indented under it. */
.footer-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; }
.style-menu { position: relative; }
.pill { display: inline-flex; align-items: center; min-height: var(--btn-h); }
.style-trigger {
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px; line-height: 1; padding: 0 14px; height: var(--btn-h);
  border-radius: 4px; background: var(--pill); color: var(--pill-ink);
}
.style-trigger .style-current { font-weight: 700; }
.style-trigger .caret { width: 0; height: 0; margin-left: 2px; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; }
.style-trigger[aria-expanded="true"] .caret { transform: rotate(180deg); }
.style-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 210px; padding: 6px; display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--line);
}
.style-pop[hidden] { display: none; }
.style-pop button {
  position: relative; display: flex; align-items: center; width: 100%; height: var(--btn-h); text-align: left; font-size: 14px; line-height: 1.2;
  padding: 0 12px 0 30px; border-radius: 6px; background: transparent; color: var(--ink); box-shadow: none;
}
.style-pop button:hover, .style-pop button:focus-visible { background: var(--pill); filter: none; }
.style-pop button[aria-checked="true"]::before {
  content: ""; position: absolute; left: 11px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--solid);
}
.style-sub { margin: 0 0 4px 18px; padding-left: 8px; border-left: 2px solid var(--line); display: flex; flex-direction: column; }
.style-sub button { padding-left: 28px; }

/* screenshot reader */
.scan { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 14px; }
.scan-hint { font-size: 13px; color: var(--muted); max-width: 52ch; }
.tool.drop { outline: 3px dashed var(--focus); outline-offset: -3px; }
.scan-panel { margin: 0 0 14px; padding: 10px; border-radius: 6px; background: var(--bg); }
.scan-panel[hidden] { display: none; }
.scan-panel canvas { display: block; max-width: 100%; touch-action: none; border-radius: 4px; }
.scan-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.scan-note { font-size: 13px; color: var(--muted); flex: 1 1 260px; }
.cell.check { outline: 2px dashed var(--guess); outline-offset: -3px; }
.result.info { border-left-color: var(--focus); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
