/* Picross Solver — minimal, modern, dark-mode aware. No framework. */
:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #f0f2f8; --ink: #0e1325; --muted: #5c6479; --line: #e3e6ef;
  --accent: #4f46e5; --accent-2: #7c3aed; --accent-ink: #ffffff; --accent-soft: #eef0ff;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fff4e0; --bad: #b91c1c; --bad-soft: #fdecec;
  --cell-on: #0e1325; --cell-off: #ffffff; --cell-line: #d5d9e6;
  --shadow: 0 1px 2px rgba(14, 19, 37, .05), 0 10px 28px rgba(14, 19, 37, .07);
  --radius: 20px; --radius-sm: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "SF Pro Text", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090b13; --surface: #121724; --surface-2: #1a2030; --ink: #e9ecf6; --muted: #8e97ad; --line: #252c40;
    --accent: #818cf8; --accent-2: #a78bfa; --accent-ink: #0b0d1c; --accent-soft: #1d2140;
    --ok: #4ade80; --ok-soft: #0f2a1a; --warn: #fbbf24; --warn-soft: #2d2008; --bad: #f87171; --bad-soft: #321313;
    --cell-on: #e9ecf6; --cell-off: #121724; --cell-line: #2b3350;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 10px; }

/* ---- app bar + stepper */
.appbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.logo { width: 28px; height: 28px; }
.pill {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border: 0;
  border-radius: 999px; padding: 7px 14px; cursor: pointer;
}
.steps { max-width: 760px; margin: 0 auto; padding: 14px 18px 0; }
.steps ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; }
.steps li { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; min-width: 0; }
.steps .dot {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); transition: all .25s;
}
.steps .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps li.is-done .dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.steps li.is-current { color: var(--ink); }
.steps li.is-current .dot { background: var(--ink); border-color: var(--ink); color: var(--bg); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.steps li.is-done, .steps li.is-current { cursor: pointer; }

main { max-width: 760px; margin: 0 auto; padding: 8px 14px calc(56px + env(safe-area-inset-bottom)); }
.banner {
  margin: 12px 0 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent);
  font-size: 14px; font-weight: 500;
}

/* ---- panels */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 18px;
  margin: 16px 0; box-shadow: var(--shadow); animation: rise .38s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } html { scroll-behavior: auto; } }
.panel-head { margin-bottom: 14px; }
.panel { scroll-margin-top: 84px; }
h1, h2 { margin: 0; letter-spacing: -.02em; line-height: 1.2; }
h1 { font-size: 28px; } h2 { font-size: 21px; }
h3 { margin: 18px 0 8px; font-size: 14px; font-weight: 700; } h3 small { font-weight: 500; color: var(--muted); margin-left: 12px; }
.lead { color: var(--muted); margin: 10px auto 0; max-width: 34ch; }
.hint { color: var(--muted); font-size: 13.5px; margin: 10px 0; }
.tip { color: var(--muted); font-size: 12.5px; margin: 22px auto 0; max-width: 44ch; }

/* ---- hero */
.hero { padding: 10px; }
.drop {
  text-align: center; padding: 34px 16px 26px; border: 2px dashed var(--line); border-radius: calc(var(--radius) - 6px);
  background: radial-gradient(120% 90% at 50% 0%, var(--accent-soft), transparent 70%); transition: border-color .2s, background .2s;
}
.drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop-ico { width: 54px; height: 54px; color: var(--accent); margin-bottom: 6px; }
.actions { display: flex; gap: 10px; justify-content: center; margin: 22px 0 6px; }
.actions.wrap { flex-wrap: wrap; justify-content: flex-start; margin: 14px 0 0; }
.links { display: flex; flex-wrap: wrap; gap: 4px 18px; justify-content: center; align-items: center; margin: 16px 0 0; color: var(--muted); font-size: 14px; }

/* ---- buttons / inputs */
.ico { width: 20px; height: 20px; flex: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; font-size: 15px;
  min-height: 46px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: transform .08s, box-shadow .2s, background .2s; -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: var(--accent-ink); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--accent); }
.btn.block { width: 100%; margin-top: 8px; min-height: 52px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; filter: none; transform: none; }
button.link { font: inherit; background: none; border: 0; padding: 4px 2px; color: var(--accent); font-weight: 600; cursor: pointer; border-radius: 6px; }
button.link:hover { text-decoration: underline; }

.status { margin: 8px 0 0; font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok { color: var(--ok); } .status.ok::before { background: var(--ok); }
.status.warn { color: var(--warn); } .status.warn::before { background: var(--warn); }
.status.bad { color: var(--bad); } .status.bad::before { background: var(--bad); }
.status:empty { display: none; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; margin: 6px 0 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.lbl { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 42px; font-size: 20px; border: 0; background: var(--surface-2); color: var(--ink); cursor: pointer; }
.stepper button:active { background: var(--line); }
.stepper input { width: 56px; border: 0; text-align: center; font: inherit; font-weight: 700; background: transparent; color: var(--ink); -moz-appearance: textfield; min-height: 42px; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- stage */
.stage-wrap { position: relative; margin: 6px 0; }
#stage { display: block; margin: 0 auto; border-radius: 14px; background: #000; touch-action: none; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
#loupe { position: absolute; left: 8px; top: 8px; width: 120px; height: 120px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .45); pointer-events: none; }

/* ---- clues */
.issues { margin: 6px 0 4px; padding: 10px 14px 10px 30px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-size: 13.5px; }
.issues:empty { display: none; }
.preview { margin: 8px 0; }
.preview summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); padding: 6px 0; }
.legend { margin-left: 8px; font-weight: 500; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin: 0 4px 0 8px; vertical-align: baseline; }
.legend .g { background: #3cb43c; } .legend .o { background: #ffa000; } .legend .r { background: #e63c3c; }
.preview img { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--line); margin-top: 6px; }
.tabs { display: inline-flex; padding: 4px; border-radius: 14px; background: var(--surface-2); margin: 6px 0 0; }
.tab { font: inherit; font-weight: 600; font-size: 14px; border: 0; background: transparent; color: var(--muted); padding: 8px 18px; border-radius: 10px; cursor: pointer; }
.tab.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.clue-block { display: none; }
.clue-block.is-on { display: block; }
@media (min-width: 700px) {
  .tabs { display: none; }
  #s-clues .clue-block { display: block; }
  #s-clues .clue-block + .clue-block { margin-top: 4px; }
}
.clues { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; max-height: 460px; overflow: auto; padding: 2px; }
@media (min-width: 700px) { .clues { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); max-height: 320px; } }
.clue { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); transition: border-color .15s, background .15s; }
.clue:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.clue span { flex: none; min-width: 26px; font-size: 11.5px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.clue input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 600; font-variant-numeric: tabular-nums; padding: 7px 4px; word-spacing: .6em; letter-spacing: .02em; }
.clue input:focus { outline: none; }
.clue.warn { background: color-mix(in srgb, var(--warn-soft) 55%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 28%, var(--line)); }
.clue.bad { background: color-mix(in srgb, var(--bad-soft) 55%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 28%, var(--line)); }

/* ---- solution */
.board-wrap { overflow: auto; text-align: center; padding: 6px 0; }
#board { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); box-shadow: var(--shadow); background: var(--cell-off); }

/* ---- overlays */
.to-top { position: fixed; right: calc(16px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--accent); box-shadow: var(--shadow); cursor: pointer; }
.to-top[hidden] { display: none; }
.to-top:hover { background: var(--surface-2); }
.to-top .ico { width: 22px; height: 22px; margin: 0; }
#busy { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.busy-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 28px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.busy-card p { margin: 0; font-weight: 600; font-size: 14px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3.5px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 24px); z-index: 40; max-width: min(92vw, 460px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s; box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 420px) {
  h1 { font-size: 25px; }
  .actions { flex-direction: column; align-items: stretch; }
  .steps .lab { display: none; }
  .steps li.is-current .lab { display: inline; }
}
