/**
 * Naming Molecules & Compounds Lab styles.
 *
 * Page-local palette per the house lab convention (see thermal-energy.css).
 * WCAG 2.1 AA: 0.75rem minimum font size, 44px touch targets on primary
 * controls, correctness never conveyed by color alone (every feedback
 * state pairs a color with an icon/prefix and text), :focus-visible rings
 * on every interactive element, reduced-motion respected.
 *
 * Two custom component families to know about:
 *   .nm-bucket / .nm-atom - the PhET-style build workbench: buckets of
 *     shaded, per-element-sized atom circles (size via --nm-atom-d, set
 *     inline by builder-render.js from elements.js `d`).
 *   .nm-piece - jigsaw puzzle pieces for the naming step. The socket
 *     notch on the left edge is a radial-gradient background layer in the
 *     container's color (--nm-socket, set by .nm-name-track/.nm-name-bank);
 *     the tab on the right edge is an ::after circle in the piece's own
 *     color. Pieces laid flush in the track (gap: 0) therefore look
 *     plugged together: each tab paints over the next piece's socket
 *     (the ::after carries z-index 2 inside the track's stacking context,
 *     so it wins over the later sibling's background). Suffix pieces have
 *     no tab (a name ends there); "whole" pieces (water, ozone) have
 *     neither tab nor socket - they stand alone.
 */
:root {
  --bg: #f4f0fb;
  --paper: #fff;
  --ink: #211a35;
  --muted: #625a7a;
  --line: #ddd3f0;

  --accent: #7c3aed;
  --accent-bg: #f5f0ff;
  --good: #16a36a;
  --good-bg: #eafbf3;
  --bad: #e03131;
  --bad-bg: #fff1f1;
  --hint-bg: #fff9db;
  --hint-border: #f5c518;
}

* { box-sizing: border-box; }

/* A class selector setting `display` is an AUTHOR-stylesheet rule; the
 * native `hidden` attribute is only a UA-stylesheet rule
 * ([hidden]{display:none}), and UA rules always lose to author rules of
 * equal specificity regardless of source order - so `el.hidden = true` on
 * an element whose class sets its own `display` would silently render
 * anyway without this override. */
[hidden] { display: none !important; }

.nm-wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px 24px; }
.nm-wrap, .nm-wrap * { font-family: 'Inter', system-ui, sans-serif; }

/* HERO ------------------------------------------------------------------ */
.nm-hero { padding: 14px 16px 8px; text-align: center; }
.nm-hero-title { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.nm-eyebrow {
  display: inline-block; font-family: 'Space Grotesk', sans-serif; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; font-size: .72rem; color: #fff;
  background: var(--accent); padding: 5px 12px; border-radius: 6px;
}
.nm-hero h1 {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.05; letter-spacing: -.02em; color: var(--ink);
}
.nm-hero .nm-sub { max-width: 680px; margin: 6px auto 0; color: var(--muted); font-size: .95rem; font-weight: 500; }

/* PROSE ------------------------------------------------------------------ */
.nm-prose {
  background: var(--paper); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 20px; margin: 16px 0; box-shadow: 0 6px 20px rgba(33, 26, 53, .04);
}
.nm-prose h2 {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.3rem;
  color: var(--ink); margin-bottom: 10px;
}
.nm-prose h3 {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.05rem;
  color: var(--ink); margin: 14px 0 6px;
}
.nm-prose p { font-size: 1rem; line-height: 1.65; color: var(--ink); margin-bottom: 10px; }
.nm-prose p:last-child { margin-bottom: 0; }
.nm-prose ul { margin: 0 0 10px 20px; }
.nm-prose li { font-size: 1rem; line-height: 1.6; color: var(--ink); margin-bottom: 4px; }
.nm-callout {
  background: var(--accent-bg); border-left: 4px solid var(--accent); border-radius: 8px;
  padding: 10px 14px; margin: 12px 0; font-size: .95rem; color: var(--ink);
}
.nm-example-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 12px 0; }
.nm-example {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fbfaff;
  font-size: .95rem; line-height: 1.55;
}
.nm-example strong { font-family: 'Space Grotesk', sans-serif; color: var(--accent); }

/* LEVEL BAR --------------------------------------------------------------- */
.nm-levelbar { margin: 18px 0; }
.nm-tier-group { margin-bottom: 14px; }
.nm-tier-title {
  font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: .85rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
}
.nm-tier-row { display: flex; flex-wrap: wrap; gap: 6px; }
.nm-level-btn {
  min-width: 44px; min-height: 44px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font-size: .85rem; font-weight: 600; cursor: pointer;
}
.nm-level-btn.is-active { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.nm-level-btn.is-solved::after { content: '✓'; margin-left: 4px; color: var(--good); }
.nm-level-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* LAB SHELL --------------------------------------------------------------- */
.nm-panel {
  background: var(--paper); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px; margin-top: 16px; box-shadow: 0 8px 28px rgba(33, 26, 53, .05);
}
.nm-panel h2 { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.2rem; margin-bottom: 4px; }
.nm-panel-sub { color: var(--muted); font-size: .9rem; margin-bottom: 12px; }

.nm-zone { margin-top: 18px; }
.nm-zone-h { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.05rem; color: var(--ink); margin-bottom: 4px; }
.nm-zone-sub { color: var(--muted); font-size: .9rem; margin-bottom: 12px; max-width: 72ch; }

/* GOAL HEADER -------------------------------------------------------------- */
.nm-goal {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--accent-bg);
}
.nm-goal-target { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.nm-goal-label {
  font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: .78rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
}
.nm-goal-formula {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.55rem; color: var(--accent);
}
.nm-goal-formula sub { font-size: .6em; }
.nm-goal-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.nm-badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 700; letter-spacing: .02em;
  border: 1px solid transparent;
}
.nm-badge-element  { background: #e8f6ec; color: #1b6b34; border-color: #2f9e44; }
.nm-badge-covalent { background: #e7f0fb; color: #12467e; border-color: #1971c2; }
.nm-badge-ionic    { background: #fdeee0; color: #7c3f0a; border-color: #d9730d; }

.nm-chip {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; color: var(--muted);
  border: 1px dashed var(--muted); background: var(--paper);
}
.nm-chip.is-done { color: #0c5c3c; background: var(--good-bg); border: 1px solid var(--good); }

/* BUILD STAGE --------------------------------------------------------------- */
.nm-build-stage {
  position: relative; min-height: 340px; border: 1px dashed var(--line); border-radius: 14px;
  background: #fbfaff; touch-action: none; overflow: hidden;
}
.nm-bond-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.nm-bond-line { stroke: var(--muted); stroke-width: 4; stroke-linecap: round; }

.nm-build-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  padding: 8px 18px; border-radius: 999px; z-index: 5;
  background: var(--good); color: #fff;
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 6px 18px rgba(22, 163, 106, .35); white-space: nowrap;
}

.nm-atom {
  position: absolute; transform: translate(-50%, -50%);
  width: var(--nm-atom-d, 44px); height: var(--nm-atom-d, 44px);
  border-radius: 50%; border: 2px solid rgba(0, 0, 0, .18); cursor: grab;
  background:
    radial-gradient(circle at 32% 30%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 48%),
    var(--nm-tile-fill, #ccc);
  color: var(--nm-tile-ink, #111);
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: calc(var(--nm-atom-d, 44px) / 2.9);
  display: flex; align-items: center; justify-content: center; z-index: 1;
  box-shadow: 0 3px 8px rgba(33, 26, 53, .18);
}
.nm-atom:active { cursor: grabbing; }
.nm-atom[aria-pressed="true"] { box-shadow: 0 0 0 4px var(--accent); }
.nm-atom:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* BUCKETS ------------------------------------------------------------------- */
.nm-kit { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 12px; }
.nm-bucket {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 88px; min-height: 44px; padding: 10px 14px 12px; cursor: grab;
  border: 1px solid var(--line); border-radius: 10px 10px 26px 26px;
  background: linear-gradient(180deg, #ffffff, #efe9fa);
  touch-action: none;
}
.nm-bucket:active { cursor: grabbing; }
.nm-bucket.is-empty { opacity: .45; cursor: not-allowed; }
.nm-bucket:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.nm-bucket-atom {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .15);
  background:
    radial-gradient(circle at 32% 30%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 48%),
    var(--nm-tile-fill, #ccc);
  color: var(--nm-tile-ink, #111);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1rem;
}
.nm-bucket-label { font-size: .78rem; font-weight: 600; color: var(--ink); }
.nm-bucket-count { font-size: .75rem; font-weight: 600; color: var(--muted); }

/* BUILD CONTROLS ------------------------------------------------------------ */
.nm-build-controls {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 12px;
}
.nm-readout { font-size: .88rem; color: var(--muted); min-height: 1.4em; }
.nm-readout-formula { font-weight: 700; color: var(--ink); }
.nm-btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.nm-build-controls .nm-btn-row { margin-top: 0; }

/* IONIC PANEL --------------------------------------------------------------- */
.nm-ionic-panel { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: center; padding: 16px; }
.nm-ion-tray { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; min-width: 170px; background: #fbfaff; }
.nm-ion-sym { display: block; font-weight: 700; font-family: 'Space Grotesk', sans-serif; margin-bottom: 6px; }
.nm-ion-count { display: inline-block; min-width: 2ch; font-size: 1.4rem; font-weight: 700; margin: 0 8px; }
.nm-ion-add, .nm-ion-remove {
  min-width: 44px; min-height: 44px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--paper); font-size: 1.2rem; font-weight: 700; cursor: pointer;
}
.nm-ion-add:focus-visible, .nm-ion-remove:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.nm-ionic-charge { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.1rem; }
.nm-ionic-charge.is-balanced { color: #0c5c3c; }

/* BUTTONS --------------------------------------------------------------- */
.nm-btn {
  min-height: 44px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); font-weight: 600; font-size: .9rem; cursor: pointer;
}
.nm-btn:hover { border-color: var(--accent); color: var(--accent); }
.nm-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.nm-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.nm-btn-primary:hover { color: #fff; opacity: .92; }

/* FEEDBACK ---------------------------------------------------------------- */
.nm-feedback { margin-top: 10px; padding: 10px 12px; border-radius: 8px; font-size: .92rem; min-height: 1.4em; }
.nm-feedback:empty { padding: 0; margin-top: 0; }
.nm-feedback-good { background: var(--good-bg); color: #0c5c3c; border: 1px solid var(--good); }
.nm-feedback-bad { background: var(--bad-bg); color: #7a1414; border: 1px solid var(--bad); }
.nm-feedback-hint { background: var(--hint-bg); color: #6b5900; border: 1px solid var(--hint-border); }

/* NAME STEP: PUZZLE PIECES -------------------------------------------------- */
.nm-name-track {
  --nm-socket: #fbfaff;
  min-height: 64px; border: 2px dashed var(--line); border-radius: 12px; padding: 10px 12px;
  background: #fbfaff;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 0; margin-bottom: 8px;
}
.nm-track-empty { color: var(--muted); font-size: .88rem; margin: 0; }

.nm-name-preview { min-height: 1.4em; font-size: .95rem; color: var(--muted); margin: 0 0 12px 4px; }
.nm-name-preview strong { color: var(--ink); font-family: 'Space Grotesk', sans-serif; font-size: 1.05rem; }

.nm-name-bank {
  --nm-socket: #f4effc;
  display: flex; flex-wrap: wrap; gap: 10px 14px; padding: 12px;
  background: #f4effc; border-radius: 12px;
}

.nm-piece {
  --pw: 9px;                       /* connector (plug) radius */
  --piece-bg: var(--paper);
  --piece-border: #94a3b8;
  --piece-ink: var(--ink);
  position: relative;
  min-height: 44px;
  padding: 8px 16px 8px calc(12px + var(--pw));
  border: 1.5px solid var(--piece-border);
  border-radius: 10px;
  color: var(--piece-ink);
  font-weight: 600; font-size: .95rem; cursor: pointer;
  /* socket notch: a container-colored circle centered on the left edge,
     drawn as a background layer so nothing paints outside the piece */
  background:
    radial-gradient(circle var(--pw) at 0 50%, var(--nm-socket, var(--paper)) 97%, transparent 100%),
    var(--piece-bg);
}
/* the tab: a piece-colored circle protruding from the right edge */
.nm-piece::after {
  content: ''; position: absolute; top: 50%; right: calc(-1 * var(--pw) + 1px);
  width: calc(var(--pw) * 2 - 3px); height: calc(var(--pw) * 2 - 3px);
  transform: translateY(-50%); border-radius: 50%;
  background: var(--piece-bg);
  border: 1.5px solid var(--piece-border);
  z-index: 2; pointer-events: none;
}
.nm-piece-text { position: relative; z-index: 3; }
.nm-piece:hover { --piece-border: var(--accent); }
.nm-piece:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* role coloring (paired with the aria-label role names, never color alone) */
.nm-piece-prefix  { --piece-bg: #e7f0fb; --piece-border: #1971c2; --piece-ink: #12467e; }
.nm-piece-suffix  { --piece-bg: #fdeee0; --piece-border: #d9730d; --piece-ink: #7c3f0a; }
.nm-piece-element { --piece-bg: #f3ecff; --piece-border: #7c3aed; --piece-ink: #4c1d95; font-weight: 700; }
.nm-piece-stem    { --piece-bg: #ffffff; --piece-border: #94a3b8; }
.nm-piece-whole   { --piece-bg: #fff9db; --piece-border: #c99700; --piece-ink: #6b5900; font-weight: 700; }

/* a suffix ends the name: no tab, rounded end */
.nm-piece-suffix { border-radius: 10px 22px 22px 10px; }
.nm-piece-suffix::after { display: none; }
/* a whole word stands alone: no tab, no socket, fully rounded */
.nm-piece-whole { border-radius: 999px; padding-left: 16px; background: var(--piece-bg); }
.nm-piece-whole::after { display: none; }

/* in the track, pieces sit flush so each tab plugs into the next socket */
.nm-name-track .nm-piece { margin-right: 0; }
.nm-name-track .nm-piece + .nm-piece { margin-left: 0; }
.nm-name-bank .nm-piece { margin-right: var(--pw); } /* room for the tab between bank pieces */

/* MISC -------------------------------------------------------------------- */
.nm-build-unavailable {
  background: var(--hint-bg); border: 1px solid var(--hint-border); border-radius: 10px;
  padding: 12px 14px; margin-top: 18px; font-size: .92rem; color: #6b5900;
}
.nm-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}
.nm-copyright { text-align: center; font-size: .75rem; color: var(--muted); padding: 16px 0 4px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
