/* ════════════════════════════════════════════════════════════════════════════
   NONOGRAMS — game styles, layered on top of washi.css
   Clue strips and the grid share one CSS grid; JS only sets --cell, and every
   number, border and mark is sized from it.
   ════════════════════════════════════════════════════════════════════════════ */

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  display: flex; flex-direction: column;
  -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── top bar ──────────────────────────────────────────────────────────────── */
.game-header {
  position: relative; z-index: 60; flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  padding-top: calc(var(--sp-3) + env(safe-area-inset-top));
  padding-left: calc(var(--sp-5) + env(safe-area-inset-left));
  padding-right: calc(var(--sp-5) + env(safe-area-inset-right));
  border-bottom: var(--bw-strong) solid var(--ink);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(6px);
}
.game-header .brand { display: flex; align-items: baseline; gap: var(--sp-3); flex-wrap: wrap; }
.game-header .mark { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; }
.game-header .mark-en {
  font-size: 0.6rem; letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--muted);
}

.hud { display: flex; align-items: center; gap: var(--sp-5); margin-left: auto; }
.hud .stat { display: flex; flex-direction: column; align-items: center; gap: 0; }
.hud .stat-num { font-size: var(--fs-lg); font-variant-numeric: tabular-nums; line-height: 1.1; }
.hud .stat-label {
  font-size: 0.58rem; letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--muted);
}

/* ── control strip ────────────────────────────────────────────────────────── */
.controls {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5);
  padding-left: calc(var(--sp-5) + env(safe-area-inset-left));
  padding-right: calc(var(--sp-5) + env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--paper-2);
  overflow-x: auto; scrollbar-width: none;
}
.controls::-webkit-scrollbar { display: none; }
.controls .btn, .controls .select { white-space: nowrap; }
.controls .segmented .btn { font-size: 0.6rem; }
.controls .spacer { flex: 1 1 auto; min-width: var(--sp-2); }
.ctl-label {
  font-size: var(--fs-xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--muted);
}

/* washi styles selects as full-width form fields; here it is a compact toolbar
   control, so shrink to content and leave room for the drawn arrow without the
   `background` shorthand, which would discard the arrow's gradients. */
.select {
  flex: 0 0 auto; width: auto;
  font-family: var(--font-mono); font-size: 0.7rem;
  padding: var(--sp-1) 1.8em var(--sp-1) var(--sp-2);
  background-position: calc(100% - 12px) center, calc(100% - 7px) center;
  border: var(--bw) solid var(--border-strong); border-radius: var(--r);
  background-color: var(--card); color: var(--text);
}

/* ── board area ───────────────────────────────────────────────────────────── */
#board-wrap {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--jade) 8%, transparent), transparent 62%),
    radial-gradient(circle at 10% 92%, var(--accent-soft), transparent 55%),
    radial-gradient(circle at 90% 10%, var(--murasaki-soft), transparent 55%);
}

/* The clue strips and the grid are one grid: `--cw` columns/rows of clues, then
   `--n` columns/rows of cells. Every child is placed explicitly. */
#board {
  --cell: 28px;
  --cw: calc(var(--cell) * 0.66);
  display: grid;
  gap: 0;
  touch-action: none;
}

/* ── clue numbers ─────────────────────────────────────────────────────────── */
.cn {
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 500;
  font-size: calc(var(--cell) * 0.42);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  transition: opacity var(--t), color var(--t);
}
.cn.is-done { opacity: 0.26; }
.cn.is-over { color: var(--accent); font-weight: 700; }

/* A faint stripe behind every other block of five, so the eye can carry a clue
   across to its line on a wide board. It spans the whole strip rather than
   sitting on the numbers themselves, which would leave a ragged edge wherever
   a clue happens to be shorter than its neighbours. */
.band {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  pointer-events: none;
}

/* ── cells ────────────────────────────────────────────────────────────────── */
.cell {
  position: relative;
  background: var(--card);
  border-right: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  cursor: pointer;
}
/* heavier rule every five squares, and around the outside */
.cell.b-l { border-left: 2px solid var(--border-strong); }
.cell.b-t { border-top: 2px solid var(--border-strong); }
.cell.b-r { border-right: 2px solid var(--border-strong); }
.cell.b-b { border-bottom: 2px solid var(--border-strong); }

.cell .ink {
  position: absolute; inset: 8%;
  background: var(--ink);
  border-radius: 2px;
  transform: scale(0.2);
  opacity: 0;
  transition: transform 0.11s cubic-bezier(.2,1.3,.4,1), opacity 0.11s ease;
}
.cell.is-fill .ink { transform: scale(1); opacity: 1; }

/* ruled-out squares get a light cross */
.cell .x {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell) * 0.5); line-height: 1;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.11s ease;
}
.cell.is-blank .x { opacity: 0.55; }

@media (hover: hover) {
  .cell:hover { background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
}

/* row/column the pointer is on, so long lines stay readable */
.cell.lit { background: color-mix(in srgb, var(--murasaki) 9%, var(--card)); }
.cell.lit.is-fill { background: var(--card); }

.cell.flash-hint { animation: flash-hint 1.1s ease-out 2; }
.cell.flash-bad  { animation: flash-bad  0.45s ease-out 2; }
@keyframes flash-hint {
  0%, 100% { box-shadow: none; }
  40%      { box-shadow: inset 0 0 0 3px var(--jade); }
}
@keyframes flash-bad {
  0%, 100% { box-shadow: none; }
  40%      { box-shadow: inset 0 0 0 3px var(--accent); }
}

/* ── mode bar ─────────────────────────────────────────────────────────────── */
.modebar {
  flex: 0 0 auto; z-index: 60;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  padding-left: calc(var(--sp-5) + env(safe-area-inset-left));
  padding-right: calc(var(--sp-5) + env(safe-area-inset-right));
  border-top: var(--bw-strong) solid var(--ink);
  background: var(--paper-2);
}
.modebar .spacer { flex: 1 1 auto; }
.mode-toggle .btn {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4); font-size: 0.72rem;
}
.mode-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.5em; height: 1.5em; font-size: 0.85em; line-height: 1;
  flex: 0 0 auto;
}
.mode-ico.fill { width: 1.05em; height: 1.05em; background: currentColor; border-radius: 2px; }
.mode-ico.blank { font-size: 1.1em; opacity: 0.5; }
.mode-toggle .btn[aria-pressed="true"] .mode-ico.blank { opacity: 1; }

/* ── status toast ─────────────────────────────────────────────────────────── */
#status {
  position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(0.5rem);
  z-index: 90; max-width: min(90vw, 34rem);
  padding: var(--sp-2) var(--sp-4);
  border: var(--bw) solid var(--ink); border-radius: var(--r-pill);
  background: var(--card); box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm); text-align: center;
  opacity: 0; pointer-events: none; cursor: pointer;
  transition: opacity var(--t-slow), transform var(--t-slow);
}
#status.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

/* ── overlays ─────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  padding: var(--sp-4);
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  backdrop-filter: blur(3px);
}
.overlay.show { display: flex; }
.modal {
  width: min(30rem, 100%); max-height: 88vh; overflow-y: auto;
  padding: var(--sp-6);
  background: var(--card);
  border: var(--bw-strong) solid var(--ink); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.modal-wide { width: min(38rem, 100%); text-align: left; }
.modal h2 { margin: 0 0 var(--sp-2); font-family: var(--font-display); }
.modal h3 {
  margin: var(--sp-5) 0 var(--sp-2); font-family: var(--font-display);
  font-size: var(--fs-md);
}
.modal .lead { color: var(--ink-2); margin: 0 0 var(--sp-3); }
.win-kanji {
  font-family: var(--font-display); font-size: var(--fs-3xl); font-weight: 700;
  color: var(--accent); line-height: 1;
}
#ov-sub { color: var(--muted); font-size: var(--fs-sm); margin: var(--sp-2) 0 0; }
#ov-buttons, #help-buttons {
  display: flex; gap: var(--sp-3); justify-content: center;
  flex-wrap: wrap; margin-top: var(--sp-5);
}
.rules { margin: 0; padding-left: 1.1rem; font-size: var(--fs-sm); line-height: var(--lh-base); }
.rules li { margin-bottom: var(--sp-2); }
.ink-jade { color: var(--jade); font-weight: 700; }
.ink-accent { color: var(--accent); font-weight: 700; }

/* ── phones ───────────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .game-header { padding-left: var(--sp-3); padding-right: var(--sp-3); gap: var(--sp-2); }
  .game-header .mark { font-size: var(--fs-md); }
  .game-header .mark-en { display: none; }
  .hud { gap: var(--sp-4); }
  .hud .stat-num { font-size: var(--fs-md); }
  .hud .stat[data-opt] { display: none; }

  /* everything must fit a 390px phone, or Help strands off the scroll edge */
  .controls { padding-left: var(--sp-3); padding-right: var(--sp-3); gap: var(--sp-2); }
  .controls .btn { font-size: 0.58rem; padding: var(--sp-1) var(--sp-2); }
  .controls .segmented .btn { font-size: 0.55rem; }
  .controls .select { font-size: 0.62rem; padding: 2px 1.6em 2px var(--sp-1); }
  .ctl-label { display: none; }
  #btn-restart, #btn-theme { display: none; }

  #board-wrap { padding: var(--sp-2); }
  .modebar { padding-left: var(--sp-3); padding-right: var(--sp-3); gap: var(--sp-2); }
  .modebar .btn { font-size: 0.64rem; padding: var(--sp-2) var(--sp-3); }
  .modal { padding: var(--sp-5); }
}

@media (max-height: 480px) {
  .game-header { padding-top: calc(var(--sp-1) + env(safe-area-inset-top)); padding-bottom: var(--sp-1); }
  .controls { padding-top: 2px; padding-bottom: 2px; }
  .modebar { padding-top: var(--sp-2); padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
