/* =============================================================================
   Sigilizer — standalone stylesheet
   -----------------------------------------------------------------------------
   Design system inherited from chaos-sphere-generator: black glass panels,
   #4fc3f7 cyan accent, purple→cyan gradient CTAs, SF Mono micro-type.
   Sections:
     1. Reset + body defaults + scene canvas
     2. Body-state visibility (state-intent / state-mantras / state-glyph)
     3. Intent screen (hero)
     4. Mantra screen
     5. Glyph caption + hints
     6. Glass control panel + tabs (cp-* / ctrl-*)
     7. Form controls (cs-* sliders, toggles, selects, colors, pills)
     8. Buttons (cp-btn / cp-btn-start / cta-gradient / text-link)
     9. Thumbnail grid
    10. Toast
    11. Welcome modal (wm-*)
    12. Tooltip
    13. Reduced motion
    14. Mobile / touch
   ========================================================================== */

/* ---- 1. Reset + body defaults + scene canvas ----------------------------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #eee;
  font-family: 'SF Mono', 'Fira Code', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  -webkit-text-size-adjust: 100%;
}

#scene-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  /* 100vh on iOS Safari is the LARGE viewport (incl. hidden URL bar area);
     the drawing buffer is sized from innerHeight, so a vh-sized canvas CSS
     stretches the buffer. 100dvh tracks the actual visible viewport so CSS
     and buffer stay 1:1. Falls back to 100vh where dvh is unsupported. */
  height: 100vh;
  height: 100dvh;
  display: block;
  background: #000;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* "Know more" link bottom-right */
#know-more-link {
  position: fixed;
  bottom: 12px;
  right: 16px;
  color: rgba(255, 255, 255, 0.35);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  text-decoration: none;
  z-index: 10000;
  transition: color 0.2s;
}
#know-more-link:hover { color: rgba(79, 195, 247, 0.8); }

/* "Start over" — know-more's twin, bottom-left. A button in link's
   clothing: same face, same register. Only shown once there is something
   to start over from (mantras / glyph states, below). */
#start-over-link {
  position: fixed;
  bottom: 12px;
  left: 16px;
  display: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.35);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  z-index: 10000;
  transition: color 0.2s;
}
#start-over-link:hover { color: rgba(79, 195, 247, 0.8); }
body.state-mantras #start-over-link,
body.state-glyph   #start-over-link { display: block; }

/* Soft cyan focus ring for keyboard users; invisible for pointer clicks. */
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 1px solid rgba(79, 195, 247, 0.6);
  outline-offset: 2px;
}

/* ---- 2. Body-state visibility -------------------------------------------- */
/* Exactly one of state-intent / state-mantras / state-glyph is on <body>.
   Everything stateful defaults to hidden; the state class opts it in. The
   charging / controls-hidden rules live BELOW the state rules — identical
   specificity, so source order lets them win while charging. */
#intent-screen,
#mantra-screen,
#controls-panel,
#glyph-caption { display: none; }

body.state-intent  #intent-screen  { display: flex; }
body.state-mantras #mantra-screen  { display: flex; }
body.state-glyph   #controls-panel { display: flex; }
body.state-glyph   #glyph-caption  { display: flex; }
body.state-glyph   #glyph-caption.dismissed { display: none; }
.dismissed { display: none; }

/* Charging: nothing but the canvas and the burning glyph. */
body.charging #controls-panel,
body.charging #know-more-link,
body.charging #start-over-link,
body.charging #glyph-caption { display: none; }

/* Hide-controls toggle (H key) */
body.controls-hidden #controls-panel,
body.controls-hidden #know-more-link,
body.controls-hidden #start-over-link { display: none; }

/* ---- 3. Intent screen (hero) --------------------------------------------- */
/* pointer-events pass through the empty space so the idle particle scene
   underneath stays alive; only the interactive elements catch the pointer. */
#intent-screen {
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9500;
  pointer-events: none;
  padding: max(24px, env(safe-area-inset-top))
           max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom))
           max(16px, env(safe-area-inset-left));
}
#intent-screen input,
#intent-screen button,
#intent-screen a { pointer-events: auto; }

.intent-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.intent-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: 0 0 8px;
}
.intent-title img {
  display: block;
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 0 10px rgba(79, 195, 247, 0.45));
}
.intent-title h1 {
  margin: 0;
  font-size: clamp(26px, 6vw, 42px);
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-indent: 0.3em;  /* recenter: letter-spacing adds a trailing gap */
  text-shadow:
    0 0 18px rgba(79, 195, 247, 0.55),
    0 0 60px rgba(126, 60, 229, 0.35);
}

#intent-input {
  width: min(560px, 88vw);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  color: #fff;
  font-family: inherit;
  font-size: 18px;
  padding: 14px 18px;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
#intent-input::placeholder { color: rgba(255, 255, 255, 0.35); }
#intent-input:focus {
  outline: none;
  border-color: rgba(79, 195, 247, 0.7);
  background: rgba(79, 195, 247, 0.06);
  box-shadow:
    0 0 0 3px rgba(79, 195, 247, 0.15),
    0 0 24px rgba(79, 195, 247, 0.18);
}

/* ---- 4. Mantra screen ----------------------------------------------------- */
#mantra-screen {
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  z-index: 9500;
  overflow-y: auto;
  /* The whole screen catches the pointer: pointer-events:none on a scroll
     container kills touch scrolling on iOS (nothing behind it is
     interactive during this state anyway). */
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
  padding: max(40px, env(safe-area-inset-top)) 16px
           max(56px, env(safe-area-inset-bottom));
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
/* Center when content fits, degrade to a normal scroll when it doesn't —
   plain justify-content:center makes overflow unreachable off the top. */
#mantra-screen::before { content: ''; margin-bottom: auto; }
#mantra-screen::after  { content: ''; margin-top: auto; }

#mantra-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  /* 100%, not vw units: 100vw includes the scrollbar, so any vw-based
     width overflows the padded scroll container by a few px and lets the
     whole list pan sideways on phones. */
  width: min(720px, 100%);
  margin-bottom: 18px;
}
@media (min-width: 700px) {
  #mantra-cards { grid-template-columns: 1fr 1fr; }
}

.mantra-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 22px 20px;
  color: #e8f4ff;
  font-family: inherit;
  font-size: 18px;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  text-align: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.mantra-card:hover {
  border-color: rgba(79, 195, 247, 0.5);
  background: rgba(79, 195, 247, 0.04);
}
.mantra-word { white-space: nowrap; }

/* Screen title above the cards. */
#mantra-title {
  margin: 0 0 18px;
  font-size: 12px;
  font-weight: bold;
  color: #9ab8cc;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-align: center;
}

/* "Draw this one" — hidden until hover, overlaid so cards never jiggle.
   The mantra dims underneath so the CTA reads cleanly. */
.mantra-draw {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.15s, transform 0.15s;
}
@media (hover: hover) {
  .mantra-card:hover .mantra-draw,
  .mantra-card:focus-visible .mantra-draw {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
  }
  .mantra-card:hover .mantra-word,
  .mantra-card:focus-visible .mantra-word { opacity: 0.25; }
}
.mantra-word { transition: opacity 0.15s; }

/* No hover on touch: the CTA sits statically under the mantra instead. */
@media (hover: none) {
  /* All six CTAs are visible at once here — the gradient reads as a wall
     of buttons. Dress them like the panel's quiet cp-btn-start instead.
     Double-class selector: .cta-gradient is declared LATER in the sheet,
     so a bare .mantra-draw loses the background war on source order. */
  .mantra-draw.cta-gradient {
    position: static;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    margin-top: 4px;
    background: rgba(79, 195, 247, 0.12);
    border: 1px solid rgba(79, 195, 247, 0.3);
    color: #4fc3f7;
    font-size: 12px;
    font-weight: bold;
    padding: 9px 20px;
  }
  .mantra-draw.cta-gradient:hover { transform: none; box-shadow: none; }
}

.mantra-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  pointer-events: auto;
}
/* Normal-sized buttons on desktop — .cp-btn's width:100% is a panel habit
   that reads wrong on an open screen. Mobile re-stretches them below. */
.mantra-actions .cp-btn {
  width: auto;
  margin-bottom: 0;
  padding: 9px 22px;
}
@media (max-width: 700px) {
  .mantra-actions { width: 100%; flex-direction: column; }
  .mantra-actions .cp-btn { width: 100%; }
}
#more-variations,
#back-to-intent {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ccc;
  font-family: inherit;
  font-size: 11px;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.15s;
}
#more-variations:hover,
#back-to-intent:hover {
  border-color: rgba(79, 195, 247, 0.5);
  color: #4fc3f7;
}

/* ---- 5. Glyph caption + hints --------------------------------------------- */
/* "forget the words" — micro-caption floating above the know-more link. */
#glyph-caption {
  position: fixed;
  left: 50%;
  bottom: max(38px, calc(env(safe-area-inset-bottom) + 30px));
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 92vw;
  color: rgba(255, 255, 255, 0.4);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.35em;
  text-align: center;
  z-index: 9000;
}
.caption-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
/* The Will, when a shared link chose to carry it. */
#caption-intent {
  color: rgba(255, 255, 255, 0.25);
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0.12em;
  font-style: italic;
}
#caption-dismiss {
  background: none;
  border: none;
  color: #555;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  transition: color 0.15s;
}
#caption-dismiss:hover { color: #fff; }

/* Copy-the-sigil chip — appears beside the caption and on mantra cards. */
.copy-btn {
  background: none;
  border: none;
  color: #555;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0;
  transition: color 0.15s;
}
.copy-btn:hover { color: #4fc3f7; }
.mantra-card { position: relative; }
.mantra-card .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 14px;
  padding: 6px;
}

/* "(or press and hold the sigil)" — same register, tinted to the accent. */
.charge-hint {
  color: rgba(79, 195, 247, 0.55);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  margin-bottom: 10px;
  animation: hint-pulse 2.4s ease-in-out infinite;
}
@keyframes hint-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ---- 6. Glass control panel + tabs ---------------------------------------- */
.cp-panel {
  position: fixed;
  left: 16px;
  top: 16px;
  flex-direction: column;
  /* Shared backing for the sticky tab bar: must mask content scrolling under
     it, so it's a touch more opaque than the panel — one var so it tracks the
     per-breakpoint panel tone. */
  --cp-sticky-bg: rgba(0, 0, 0, 0.95);
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: #eee;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  z-index: 10000;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  user-select: none;
  min-width: 44px;
  transition: width 0.2s ease;
}

.cp-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  border-radius: 12px 12px 0 0;
}
.cp-tab:hover { background: rgba(255, 255, 255, 0.04); }
.cp-panel.collapsed .cp-tab { border-radius: 12px; border-bottom-color: transparent; }
.cp-panel:not(.collapsed) .cp-tab { border-bottom-color: rgba(255, 255, 255, 0.1); }

.cp-tab-icon  { font-size: 16px; color: #4fc3f7; }
img.cp-tab-icon {
  display: inline-block;
  vertical-align: middle;
  margin-right: 2px;
  filter: drop-shadow(0 0 4px rgba(79, 195, 247, 0.35));
}
.cp-tab-label { font-weight: bold; font-size: 14px; }
.cp-tab-status {
  margin-left: auto;
  font-size: 11px;
  color: #4fc3f7;
  transition: opacity 0.2s;
  opacity: 0.4;
}
.cp-tab-status.active { opacity: 1; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

.cp-help-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #aaa;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 0;
  transition: all 0.15s;
}
.cp-help-btn:hover {
  background: rgba(79, 195, 247, 0.2);
  border-color: rgba(79, 195, 247, 0.4);
  color: #4fc3f7;
}

.cp-body {
  padding: 10px 14px;
  width: 320px;
  max-height: calc(100vh - 80px);
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.cp-panel.collapsed .cp-body { display: none; }
.cp-body::-webkit-scrollbar       { width: 5px; }
.cp-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }

.ctrl-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--cp-sticky-bg);
  padding-bottom: 4px;
}
.ctrl-tab {
  flex: 1;
  /* min-width:0 lets the flex:1 tabs shrink to share the row instead of
     overflowing .ctrl-tabs and poking the last tab past the sticky
     background's right edge (flex items default to min-width:auto). */
  min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #888;
  padding: 5px 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  transition: all 0.15s;
}
.ctrl-tab:hover { background: rgba(255, 255, 255, 0.1); color: #ccc; }
.ctrl-tab.active {
  background: rgba(79, 195, 247, 0.12);
  color: #4fc3f7;
  border-color: rgba(79, 195, 247, 0.3);
}
.ctrl-tab-content        { display: none; }
.ctrl-tab-content.active { display: block; }

/* Actions tab section headers */
.actions-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.actions-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.actions-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(79, 195, 247, 0.7);
  margin-bottom: 8px;
}

/* ---- 7. Form controls (cs-*) ---------------------------------------------- */
.cs-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.cs-label { font-size: 10px; color: #aaa; letter-spacing: 0.5px; }
.cs-slider-wrap { display: flex; align-items: center; gap: 8px; }
.cs-slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.cs-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  background: #4fc3f7;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.cs-slider::-moz-range-thumb {
  width: 12px; height: 12px;
  background: #4fc3f7;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.cs-val {
  font-size: 10px;
  color: #4fc3f7;
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Toggle */
.cs-toggle-wrap { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.cs-toggle      { display: none; }
.cs-toggle-indicator {
  width: 28px; height: 14px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.cs-toggle-indicator::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 10px; height: 10px;
  background: #888;
  border-radius: 50%;
  transition: all 0.2s;
}
.cs-toggle:checked + .cs-toggle-indicator        { background: rgba(79, 195, 247, 0.3); }
.cs-toggle:checked + .cs-toggle-indicator::after { left: 16px; background: #4fc3f7; }
.cs-toggle-label { font-size: 10px; color: #aaa; }

/* Select dropdown */
.cs-select {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ccc;
  padding: 5px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-family: inherit;
  outline: none;
  text-transform: capitalize;
  cursor: pointer;
}
.cs-select:focus { border-color: rgba(79, 195, 247, 0.5); }

/* Color input */
.cs-color {
  -webkit-appearance: none;
  appearance: none;
  width: 36px; height: 22px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
  flex-shrink: 0;
}
.cs-color::-webkit-color-swatch-wrapper { padding: 2px; }
.cs-color::-webkit-color-swatch         { border: none; border-radius: 2px; }
.cs-color::-moz-color-swatch            { border: none; border-radius: 2px; }
.cs-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cs-color-row .cs-label { margin-bottom: 0; flex: 1; }

/* Mode chooser pills (structure: spare/mirror/seal — ink: clean/inked) */
.mode-pills {
  display: flex;
  gap: 4px;
  margin: 6px 0;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px;
  border-radius: 4px;
}
.mode-pill {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.55);
  padding: 5px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
.mode-pill.active {
  background: rgba(79, 195, 247, 0.18);
  color: #4fc3f7;
}

/* ---- 8. Buttons ------------------------------------------------------------ */
.cp-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ddd;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  transition: all 0.15s;
  width: 100%;
  margin-bottom: 6px;
}
.cp-btn:hover { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.25); }

.cp-btn-start {
  background: rgba(79, 195, 247, 0.12);
  border-color: rgba(79, 195, 247, 0.3);
  color: #4fc3f7;
  font-weight: bold;
  padding: 10px 12px;
}
.cp-btn-start:hover { background: rgba(79, 195, 247, 0.22); }
.cp-btn-start.active {
  background: rgba(79, 195, 247, 0.25);
  color: #fff;
  border-color: #4fc3f7;
  animation: pulse 1.5s ease-in-out infinite;
}

/* Gradient primary CTA — "Sigilize it!" / "✦ Draw the Glyph" */
.cta-gradient {
  background: linear-gradient(90deg, #7e3ce5, #4fc3f7);
  color: #fff;
  border: 0;
  padding: 14px 32px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cta-gradient:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(79, 195, 247, 0.35);
}
.cta-gradient:active { transform: translateY(0); }
.mantra-card .cta-gradient { font-size: 13px; padding: 11px 24px; letter-spacing: 0.12em; }

/* Faint text link — "how does it work?" */
.text-link {
  background: none;
  border: 0;
  padding: 4px 6px;
  color: rgba(255, 255, 255, 0.35);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.2s;
}
.text-link:hover {
  color: rgba(79, 195, 247, 0.8);
  text-decoration: underline;
}

/* ---- 9. Thumbnail grid (3×3 sibling glyphs) -------------------------------- */
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.thumb-cell {
  aspect-ratio: 1;
  /* The canvas itself is the grid item; grid stretch alignment would
     otherwise override aspect-ratio and stretch it to the implicit row. */
  width: 100%;
  height: auto;
  align-self: start;
  padding: 0;
  background: #0a0a12;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.thumb-cell:hover  { border-color: rgba(79, 195, 247, 0.6); }
.thumb-cell.active {
  border-color: #4fc3f7;
  box-shadow: 0 0 8px rgba(79, 195, 247, 0.25);
}
.thumb-cell canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- 10. Toast -------------------------------------------------------------- */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0, 0, 0, 0.85);
  color: #4fc3f7;
  border: 1px solid rgba(79, 195, 247, 0.3);
  padding: 10px 32px 10px 18px;
  border-radius: 8px;
  font-size: 11px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  pointer-events: none;
  /* Above the fullscreen state screens so "No will, no Magick!" lands on top. */
  z-index: 20000;
  max-width: calc(100vw - 40px);
  cursor: pointer;
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
#toast.show::after {
  content: '×';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 16px;
  color: #888;
  line-height: 1;
}
#toast:hover::after { color: #fff; }

/* ---- 11. Welcome modal ("how does it work?") -------------------------------- */
#welcome-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 50000;
  opacity: 0;
  pointer-events: none;   /* opacity:0 alone would still swallow clicks */
  transition: opacity 0.4s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#welcome-modal.visible { opacity: 1; pointer-events: auto; }

.wm-card {
  position: relative;
  background: rgba(10, 10, 15, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 32px 36px;
  /* Wide enough that the whole explainer fits without scrolling on a
     desktop viewport; mobile narrows and scrolls below. */
  max-width: 940px;
  width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  color: #ddd;
  font-family: 'SF Mono', 'Fira Code', monospace;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
.wm-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #666;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.15s;
}
.wm-close:hover { color: #eee; }

.wm-title {
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1;
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  margin: 0 0 6px;
}
img.wm-title-icon {
  display: block;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  filter: drop-shadow(0 0 6px rgba(79, 195, 247, 0.35));
}
.wm-subtitle {
  font-size: 12px;
  color: #888;
  margin: 0 0 20px;
  line-height: 1.5;
}

.wm-card p {
  font-size: 12px;
  line-height: 1.65;
  color: #bbb;
  margin: 0 0 14px;
}
.wm-card p strong { color: #eee; }
/* The live AOS worked example: struck letters fade, survivors stay lit. */
.wm-card s, .wm-card del {
  color: #556;
  text-decoration-color: rgba(255, 85, 85, 0.55);
}
.wm-example {
  display: block;
  background: rgba(79, 195, 247, 0.05);
  border: 1px solid rgba(79, 195, 247, 0.15);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0 0 14px;
  font-size: 14px;
  letter-spacing: 0.18em;
  text-align: center;
  color: #e8f4ff;
  font-variant-numeric: tabular-nums;
}

.wm-divider { height: 1px; background: rgba(255, 255, 255, 0.08); margin: 0 0 16px; }

.wm-sections { display: flex; gap: 20px; margin-bottom: 16px; }
.wm-section  { flex: 1; }
.wm-section h3 {
  font-size: 11px;
  color: #888;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: bold;
}
.wm-keys { display: flex; flex-direction: column; gap: 4px; }
.wm-key-row { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.wm-key-row kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 10px;
  font-family: inherit;
  color: #4fc3f7;
  min-width: 48px;
  text-align: center;
}
.wm-key-row span { color: #999; }

/* The app's own sigil beside the glyph/charging story. */
.wm-glyph-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 28px;
  align-items: center;
  margin-bottom: 8px;
}
.wm-sigil-fig {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
img.wm-sigil {
  display: block;
  width: 176px;
  height: 176px;
  border-radius: 16px;
  border: 1px solid rgba(79, 195, 247, 0.2);
  filter: drop-shadow(0 0 14px rgba(79, 195, 247, 0.25));
}
.wm-sigil-fig figcaption {
  text-align: center;
  font-size: 10px;
  color: #888;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.wm-sigil-mantra {
  color: #cfe6ff;
  font-size: 12px;
  letter-spacing: 0.25em;
}

.wm-footer { font-size: 10px; color: #555; text-align: center; margin: 0 0 12px; }
.wm-links  { border-top: 1px solid rgba(255, 255, 255, 0.06); padding-top: 12px; }
.wm-links p {
  font-size: 10px;
  color: #666;
  margin: 0;
  text-align: center;
}
.wm-links a       { color: #4fc3f7; text-decoration: none; transition: color 0.15s; }
.wm-links a:hover { color: #81d4fa; }

/* ---- 12. Tooltip ------------------------------------------------------------ */
/* Custom instant tooltip — native `title` has a ~1s browser delay. */
.tooltip-root {
  position: fixed;
  top: 0; left: 0;
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid rgba(79, 195, 247, 0.35);
  color: #d8e6f5;
  padding: 10px 12px;
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', 'Menlo', monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-width: 340px;
  pointer-events: none;
  z-index: 100000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.08s ease-out, transform 0.08s ease-out;
}
.tooltip-root.visible {
  opacity: 1;
  transform: translateY(0);
}
[data-tooltip] { cursor: help; }

/* ---- 13. Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .cp-tab-status.active,
  .cp-btn-start.active,
  .charge-hint { animation: none; }
  .cta-gradient,
  .cta-gradient:hover,
  .cta-gradient:active { transform: none; transition: box-shadow 0.15s ease; }
}

/* ---- 14. Mobile / touch ------------------------------------------------------ */
@media (max-width: 700px) {
  .hiddenOnMobile { display: none; }

  /* Panel becomes a full-width top strip. Blur off (perf), so more opaque
     than desktop for readability over the busy scene; the sticky tab-bar
     backing stays close in tone so it doesn't read as a darker box. */
  .cp-panel {
    left: 8px;
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    width: auto;
    max-width: calc(100vw - 16px);
    background: rgba(0, 0, 0, 0.82);
    --cp-sticky-bg: rgba(0, 0, 0, 0.9);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .cp-body {
    width: 100%;
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
    padding: 12px 14px;
  }
  .ctrl-tab {
    padding: 8px 4px;
    font-size: 11px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Fat touch targets */
  .cs-slider { height: 8px; border-radius: 4px; }
  .cs-slider::-webkit-slider-thumb { width: 20px; height: 20px; }
  .cs-slider::-moz-range-thumb     { width: 20px; height: 20px; }
  .cs-toggle-indicator { width: 36px; height: 18px; border-radius: 9px; }
  .cs-toggle-indicator::after { width: 14px; height: 14px; }
  .cs-toggle:checked + .cs-toggle-indicator::after { left: 20px; }
  .cs-color { height: 28px; }
  .cp-btn   { padding: 10px 14px; font-size: 12px; }
  .cs-val   { font-size: 11px; }
  .cs-label { font-size: 11px; }
  .cs-toggle-label { font-size: 11px; }
  .mode-pill { padding: 9px 6px; }
  .cs-slider-wrap select,
  .cs-select {
    font-size: 15px !important;
    padding: 9px 10px !important;
    min-height: 38px;
    border-radius: 6px !important;
  }

  /* Hero: tighter type, thumb-reachable input */
  .intent-title img { width: 44px; height: 44px; }
  #intent-input { font-size: 16px; }  /* ≥16px or iOS zooms the viewport */
  .cta-gradient { padding: 14px 28px; font-size: 14px; }

  .mantra-card { font-size: 16px; padding: 18px 16px; }

  #glyph-caption { font-size: 9px; letter-spacing: 0.28em; }
  #know-more-link { bottom: max(8px, env(safe-area-inset-bottom)); right: 10px; font-size: 10px; }
  #start-over-link { bottom: max(8px, env(safe-area-inset-bottom)); left: 10px; font-size: 10px; }

  .wm-card {
    padding: 20px 18px;
    border-radius: 12px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .wm-title    { font-size: 18px; }
  .wm-sections { flex-direction: column; gap: 8px; }
  .wm-example  { font-size: 12px; letter-spacing: 0.12em; }
  .wm-glyph-row { grid-template-columns: 1fr; gap: 16px; }
  .wm-sigil-fig { order: -1; }
  img.wm-sigil { width: 140px; height: 140px; }
}

/* Prevent iOS-style page scroll bounce; opt interactive surfaces back in. */
html, body { overscroll-behavior: none; touch-action: none; }
#controls-panel, #welcome-modal, #mantra-screen, #intent-screen { touch-action: auto; }
.cs-slider, .cs-color, .cs-select, input, button, select, label {
  touch-action: manipulation;
}
