/* ==========================================================
   neur0doku-play.css
   Layout for the actual puzzle screen. Colors come from
   neur0doku-theme.css (--nd-*) — nothing here should hardcode
   a color or reach for a site --token.
   ========================================================== */

.neur0doku-play {
  max-width: 460px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4.5rem;
  position: relative;
  /* play.js's applyZoom() sets the actual scale; this just makes the
     change smooth and anchors it to the top instead of the center. */
  transform-origin: top center;
  transition: transform 0.2s ease;
}

/* ---------- top bar: back + gear ---------- */
.nd-play-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.nd-icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.8rem;
  background: var(--nd-surface);
  border: 1px solid var(--nd-border);
  box-shadow: 0 3px 8px var(--nd-shadow);
  cursor: pointer;
  font-size: 1.2rem;
  text-decoration: none;
  color: var(--nd-text);
}
.nd-icon-btn:hover { transform: translateY(-1px); text-decoration: none; }
.nd-icon-btn:focus-visible { outline: 2px solid var(--nd-focus); outline-offset: 2px; }
.nd-icon-btn img { width: 60%; height: 60%; object-fit: contain; pointer-events: none; }

/* ---------- level header: title + legend/help ---------- */
.nd-level-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.nd-level-title {
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--nd-text);
  margin: 0 0 0.4rem;
}

.nd-stat-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.nd-stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--nd-surface);
  border: 1px solid var(--nd-border);
  font-size: 0.85rem;
  color: var(--nd-text-soft);
}

/* Score chip reuses .nd-stat-chip's shape but stands out a bit more
   (full-strength text, bold) since it's the "hero" stat rather than a
   passive info readout — and needs position:relative so a points toast
   (an absolutely-positioned child, see .nd-points-toast below) can
   anchor to it correctly instead of the page corner. */
.nd-score-chip {
  position: relative;
  font-weight: 800;
  color: var(--nd-text);
}

.nd-stat-icon {
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}

.nd-life-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nd-life-chip img {
  width: 1.6rem;
  height: 1.6rem;
  object-fit: contain;
}

/* ---------- legend + help ---------- */
.nd-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.3rem;
  max-width: 9.5rem;
}

.nd-legend-grid {
  display: grid;
  grid-template-columns: repeat(3, 0.7rem);
  grid-auto-rows: 0.7rem;
  gap: 2px;
  border-radius: 0.4rem;
  overflow: hidden;
  border: 1px solid var(--nd-border);
}
.nd-legend-swatch { width: 100%; height: 100%; }

.nd-help-btn {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 1px solid var(--nd-border);
  background: var(--nd-surface);
  color: var(--nd-text-soft);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nd-help-btn:focus-visible { outline: 2px solid var(--nd-focus); outline-offset: 2px; }

/* ---------- tip icons (inline, next to the help "?") ---------- */
.nd-tip-icon {
  width: 1.6rem;
  height: 1.6rem;
  object-fit: contain;
  border-radius: 0.35rem;
  border: 1px solid var(--nd-border);
}

/* ---------- grid ---------- */
.nd-grid-wrap {
  display: flex;
  justify-content: center;
  margin: 0.75rem 0 1.25rem;
}

.nd-grid {
  display: grid;
  gap: 4px;
  width: fit-content;
  background: var(--nd-surface);
  padding: 8px;
  border-radius: 1rem;
  box-shadow: 0 6px 18px var(--nd-shadow);
}

.nd-cell {
  border-radius: 8px;
  background: var(--nd-cell-bg);
  border: 1px solid var(--nd-border);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  /* Stops the browser from trying to scroll/pinch-zoom the page
     while a finger is dragging across the grid to paint marks. */
  touch-action: none;
}
.nd-cell.interactive { cursor: pointer; }

.nd-mark-img {
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff);
}

/* ---------- status line ---------- */
.nd-status {
  text-align: center;
  font-size: 0.9rem;
  color: var(--nd-text-soft);
  min-height: 1.2rem;
  margin-bottom: 0.5rem;
}
.nd-status.win { color: var(--nd-accent); font-weight: 700; }

/* ---------- bottom toolbar ---------- */
/* In normal document flow now — NOT position:fixed. Fixed
   positioning anchored these to the actual browser viewport edges,
   which looked fine on a narrow phone but drifted way off to the
   sides of the card on a wider screen. This sits between the grid
   and the ad banner instead, scaled to the same 460px column as
   everything else. */
.nd-bottom-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.nd-toolbar-group {
  display: flex;
  gap: 0.6rem;
}

.nd-power-btn {
  position: relative;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--nd-surface);
  border: 1px solid var(--nd-border);
  box-shadow: 0 4px 10px var(--nd-shadow);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.nd-power-btn:disabled { opacity: 0.4; cursor: default; }
.nd-power-btn:not(:disabled):hover { transform: translateY(-1px); }
.nd-power-btn:focus-visible { outline: 2px solid var(--nd-focus); outline-offset: 2px; }
.nd-power-btn img { width: 60%; height: 60%; object-fit: contain; pointer-events: none; }

.nd-next-level-link {
  color: var(--nd-accent);
  font-weight: 700;
  text-decoration: none;
}
.nd-next-level-link:hover { text-decoration: underline; }

.nd-power-badge {
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--nd-danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Floating "-30" that pops out of a power button (or the score chip,
   for a mistake) and rises/fades — see popPointsToast() in play.js.
   The element it's appended into must be position:relative; .nd-power-btn
   already is, and .nd-score-chip (above) adds it for this too. */
@keyframes nd-points-toast-rise {
  0% { opacity: 0; transform: translate(-50%, 0); }
  15% { opacity: 1; transform: translate(-50%, -0.4rem); }
  100% { opacity: 0; transform: translate(-50%, -1.6rem); }
}
.nd-points-toast {
  position: absolute;
  top: -0.3rem;
  left: 50%;
  transform: translate(-50%, 0);
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--nd-danger);
  pointer-events: none;
  white-space: nowrap;
  animation: nd-points-toast-rise 1.4s ease-out forwards;
}
@media (prefers-reduced-motion: reduce) {
  .nd-points-toast { animation: none; opacity: 0.9; }
}

/* ---------- ad banner placeholder ---------- */
.nd-ad-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-weight: 700;
  color: var(--nd-button-ink);
  background: var(--nd-button-bg);
  border-top: 1px solid var(--nd-button-border);
  z-index: 20;
}

/* ---------- tutorial modal ---------- */
.nd-tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.4);
}
.nd-tutorial-overlay[hidden] { display: none; }

.nd-tutorial-panel {
  position: relative;
  width: min(360px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--nd-surface);
  border-radius: 1.25rem;
  padding: 1.25rem;
  box-shadow: 0 20px 50px var(--nd-shadow);
}

.nd-tutorial-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--nd-border);
  background: var(--nd-bg);
  cursor: pointer;
}

.nd-tutorial-rule {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--nd-border);
  color: var(--nd-text);
  font-size: 0.9rem;
}
.nd-tutorial-rule:first-of-type { border-top: none; }
.nd-tutorial-rule-icon {
  flex-shrink: 0;
  width: 2.6rem;
  height: auto;
  border-radius: 0.4rem;
}

.nd-tutorial-intro-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.nd-tutorial-intro-row-tight {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--nd-border);
}
.nd-tutorial-intro-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--nd-text-soft);
  background: var(--nd-bg);
  border-radius: 0.75rem;
  padding: 0.5rem;
}
.nd-tutorial-intro-icon { width: 2.4rem; height: 2.4rem; object-fit: contain; }
.nd-tutorial-intro-icon-sm {
  width: 1.4rem;
  height: 1.4rem;
  object-fit: contain;
  margin: 0 0.1rem;
}

/* ---------- settings + confirm modals ---------- */
.nd-settings-overlay,
.nd-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.4);
}
.nd-settings-overlay[hidden],
.nd-confirm-overlay[hidden] { display: none; }

.nd-settings-panel,
.nd-confirm-panel {
  position: relative;
  width: min(360px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--nd-surface);
  border-radius: 1.25rem;
  padding: 1.25rem;
  box-shadow: 0 20px 50px var(--nd-shadow);
}

.nd-settings-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--nd-border);
  background: var(--nd-bg);
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
/* var(--nd-surface-soft) — the theme file's own token for "subtle
   highlight," not var(--nd-bg-hover), which doesn't exist. */
.nd-settings-close:hover { background: var(--nd-surface-soft); }

.nd-settings-section { margin-bottom: 1.5rem; }
.nd-settings-section:last-of-type { margin-bottom: 0; }

.nd-settings-btn {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--nd-border);
  border-radius: 0.8rem;
  background: var(--nd-surface);
  color: var(--nd-text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nd-settings-btn:hover:not(:disabled) { background: var(--nd-bg); }
.nd-settings-btn:disabled { opacity: 0.5; cursor: default; }
.nd-settings-btn.destructive {
  color: #e0645a;
  border-color: #e0645a;
}
.nd-settings-btn.destructive:hover:not(:disabled) {
  background: rgba(224, 100, 90, 0.1);
}

.nd-settings-hint {
  font-size: 0.8rem;
  color: var(--nd-text-soft);
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.nd-confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.nd-btn-secondary,
.nd-btn-destructive {
  padding: 0.6rem 1rem;
  border-radius: 0.8rem;
  border: 1px solid var(--nd-border);
  background: var(--nd-surface);
  color: var(--nd-text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.nd-btn-secondary:hover { background: var(--nd-bg); }
.nd-btn-destructive {
  background: #e0645a;
  color: #fff;
  border-color: #e0645a;
}
.nd-btn-destructive:hover { background: #d55550; }

/* ---------- tutorial note text (plain-prose additions — click/
   double-click/drag mechanics, keyboard shortcuts — alongside the
   existing icon-illustrated rows) ---------- */
.nd-tutorial-note {
  font-size: 0.85rem;
  color: var(--nd-text-soft);
  line-height: 1.4;
  margin: 0 0 0.75rem;
}
.nd-tutorial-note strong { color: var(--nd-text); }
.nd-tutorial-note-divided {
  margin: 0.75rem 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--nd-border);
}

/* ---------- win modal ----------
   Same fixed/centered/backdrop shell idea as the tutorial/settings
   modals above — kept as its own separate copy rather than merged into
   either of those selectors, matching how .nd-tutorial-overlay is
   already separate from .nd-settings-overlay/.nd-confirm-overlay just
   above, rather than risk changing how either existing modal renders. */
.nd-win-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.4);
}
.nd-win-overlay[hidden] { display: none; }

.nd-win-panel {
  position: relative;
  width: min(360px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--nd-surface);
  border-radius: 1.25rem;
  padding: 1.5rem 1.25rem 1.25rem;
  box-shadow: 0 20px 50px var(--nd-shadow);
  text-align: center;
}
.nd-win-panel h2 {
  margin: 0 0 0.5rem;
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--nd-accent);
}

.nd-win-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--nd-border);
  background: var(--nd-bg);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.nd-win-close:hover { background: var(--nd-surface-soft); }

.nd-win-stars {
  font-size: 1.8rem;
  letter-spacing: 0.15em;
  margin: 0 0 0.4rem;
  line-height: 1;
}

.nd-win-score {
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 800;
  font-size: 2rem;
  color: var(--nd-accent);
  margin: 0.25rem 0 0.1rem;
}
.nd-win-time {
  font-size: 0.9rem;
  color: var(--nd-text-soft);
  margin: 0 0 1rem;
}

.nd-win-breakdown {
  background: var(--nd-bg);
  border-radius: 0.8rem;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1.25rem;
  text-align: left;
}
.nd-win-breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--nd-text);
  padding: 0.2rem 0;
}
.nd-win-value-negative { color: var(--nd-danger); font-weight: 700; }
.nd-win-value-positive { color: var(--nd-on-2); font-weight: 700; }
.nd-win-perfect {
  font-size: 0.88rem;
  color: var(--nd-on-2);
  font-weight: 700;
  margin: 0;
}

.nd-win-cta {
  display: block;
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--nd-button-border);
  background: var(--nd-button-bg);
  color: var(--nd-button-ink);
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 4px 10px var(--nd-shadow);
}
.nd-win-cta:hover { background: var(--nd-button-bg-hover); }
.nd-win-cta:focus-visible { outline: 2px solid var(--nd-focus); outline-offset: 2px; }

/* ---------- game over modal's secondary "watch ad" button ----------
   Reuses .nd-win-overlay/.nd-win-panel/.nd-win-cta (restart button) as
   its shell — this is the only genuinely new button, since there's
   nothing else in the codebase styled as a full-width secondary pill
   next to a primary one. */
.nd-gameover-ad-btn {
  display: block;
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--nd-border);
  background: var(--nd-surface);
  color: var(--nd-text-soft);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.nd-gameover-ad-btn:hover { background: var(--nd-bg); }
.nd-gameover-ad-btn:disabled { opacity: 0.6; cursor: default; }
.nd-gameover-ad-btn:focus-visible { outline: 2px solid var(--nd-focus); outline-offset: 2px; }