/* =========================================================
   Numpad Sequence Memory — tool-specific styles.
   Layered on /tools/_shared/tool.css. No tokens, no fonts —
   only the widget body. Everything theme-able pulls from
   shared CSS vars so dark/light works automatically.
   ========================================================= */

/* ---------- Stats row ---------- */
.np-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-8);
  margin-bottom: var(--space-4);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}
.np-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 80px;
}
.np-stat-num {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.1;
}
.np-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Status line ---------- */
.np-status {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  min-height: 1.5em;
  margin-bottom: var(--space-5);
}
.np-status.is-watch { color: var(--accent); }
.np-status.is-input { color: var(--text); }
.np-status.is-good  { color: var(--success); }
.np-status.is-over  { color: var(--danger); }

/* ---------- Numpad grid ----------
   True full-keyboard numpad order:
     7 8 9
     4 5 6
     1 2 3
     0 0 0   (zero spans the bottom row)
   Source order in the HTML is 0–9; CSS grid areas reorder
   them visually so the digit map and the keyboard map agree. */
.np-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-template-areas:
    "k7 k8 k9"
    "k4 k5 k6"
    "k1 k2 k3"
    "k0 k0 k0";
  gap: 12px;
  max-width: 340px;
  aspect-ratio: 3 / 4;
  margin: 0 auto var(--space-6);
}
.np-key[data-digit="0"] { grid-area: k0; }
.np-key[data-digit="1"] { grid-area: k1; }
.np-key[data-digit="2"] { grid-area: k2; }
.np-key[data-digit="3"] { grid-area: k3; }
.np-key[data-digit="4"] { grid-area: k4; }
.np-key[data-digit="5"] { grid-area: k5; }
.np-key[data-digit="6"] { grid-area: k6; }
.np-key[data-digit="7"] { grid-area: k7; }
.np-key[data-digit="8"] { grid-area: k8; }
.np-key[data-digit="9"] { grid-area: k9; }

/* ---------- Numpad key ---------- */
.np-key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 56px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.12s ease,
              border-color 0.18s ease,
              color 0.12s ease,
              box-shadow 0.18s ease,
              transform 0.06s ease;
}

/* Dim the keys during idle / watch / game-over so the lit key
   pops. During input we let them sit at full strength. */
.np-grid[data-phase="idle"]  .np-key,
.np-grid[data-phase="watch"] .np-key,
.np-grid[data-phase="over"]  .np-key {
  opacity: 0.85;
}
.np-grid[data-phase="input"] .np-key { opacity: 1; }
.np-grid[data-phase="input"] .np-key:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.np-grid[data-phase="input"] .np-key:active {
  transform: translateY(1px);
}

/* The lit state — used both when the game flashes a key during
   sequence playback AND when the player presses one. */
.np-key.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  box-shadow:
    0 0 0 3px var(--accent-ring),
    0 0 24px 4px var(--accent-ring);
  transform: translateY(-1px);
}

/* Wrong-input flash. */
.np-key.is-wrong {
  background: var(--danger);
  border-color: var(--danger);
  color: #FFFFFF;
  animation: np-wrong 0.45s ease;
}
@keyframes np-wrong {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.np-key:disabled { cursor: default; }

/* Reduced motion: drop the lift/shake; keep the colour change so
   the lit and wrong states stay legible. */
@media (prefers-reduced-motion: reduce) {
  .np-key,
  .np-grid[data-phase="input"] .np-key:hover,
  .np-grid[data-phase="input"] .np-key:active,
  .np-key.is-active { transform: none; }
  .np-key.is-wrong { animation: none; }
}

/* The 0 key reads better with a slightly smaller digit since it
   stretches across the full row. */
.np-key[data-digit="0"] { font-size: 26px; }

/* ---------- Sound-mode selector (segmented) ----------
   The shared reset zeroes margin and padding but not the
   fieldset border or the legend's default float-y placement,
   so this block undoes both. */
.np-sound {
  border: none;
  margin: 0 0 var(--space-5);
  padding: 0;
}
.np-sound-label {
  display: block;
  width: 100%;
  float: none;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--space-2);
}
.np-segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
  max-width: 340px;
  margin: 0 auto;
}
.np-segment {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.np-segment:hover { color: var(--text); }
.np-segment input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.np-segment:has(input:checked) {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
}
.np-segment:has(input:focus-visible) {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

/* ---------- Controls ---------- */
.np-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.np-controls-row {
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
}
.np-controls-row .btn {
  flex: 1;
  min-height: 40px;
  font-size: 13px;
}

/* Mute button toggles its icon visibility based on aria-pressed. */
.np-icon-muted { display: none; }
#np-btn-mute[aria-pressed="true"] .np-icon-sound { display: none; }
#np-btn-mute[aria-pressed="true"] .np-icon-muted { display: inline-block; }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .np-grid { max-width: 100%; gap: 10px; }
  .np-stats { gap: var(--space-6); }
  .np-stat-num { font-size: 24px; }
  .np-key { font-size: 24px; }
  .np-key[data-digit="0"] { font-size: 22px; }
}
