/* ════════════════════════════════════════════════════════════════════
   components.css — buttons, chips, inputs, modals, tooltips, dice,
   bars. The shared vocabulary of the whole app.
   ════════════════════════════════════════════════════════════════════ */

/* ── icons ── */
.icon {
  display: inline-flex;
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
  vertical-align: -0.2em;
}
.icon svg { width: 100%; height: 100%; }
.icon-btn .icon { width: 1.2em; height: 1.2em; }

/* ── buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  padding: 0.55em 1.1em;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  font-weight: 600;
  font-size: 0.95rem;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}
.btn:hover { border-color: var(--faint); background: var(--card-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow: 0 4px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #ffffff); border-color: transparent; }

.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--card)); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--dim); }
.btn-ghost:hover { color: var(--text); background: var(--card); border-color: var(--line); }

.btn-big { font-size: 1.1rem; padding: 0.8em 1.7em; }
.btn-small { font-size: 0.84rem; padding: 0.35em 0.85em; }

/* the Map button — the one topbar action players should never miss */
.btn-map {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 18%, transparent);
}
.btn-map .icon { color: var(--accent); }
.btn-map:hover {
  background: color-mix(in srgb, var(--accent) 24%, var(--card));
  border-color: var(--accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 30%, transparent);
  transform: translateY(-1px);
}

/* read-aloud topbar toggle — lit when it's actively reading each turn */
.btn-tts.on {
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--text);
}
.btn-tts.on .icon { color: var(--accent); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1px solid transparent;
  color: var(--dim);
  font-size: 1rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }

/* ── chips ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.32em 0.85em;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  font-size: 0.88rem;
  font-weight: 550;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
button.chip:hover { border-color: var(--faint); transform: translateY(-1px); }
.chip.active {
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  border-color: var(--accent);
  color: var(--text);
}
.chip-status { border-color: color-mix(in srgb, var(--warn) 55%, transparent); color: var(--warn); font-size: 0.8rem; }
.chips-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }

/* ── help "?" + tooltip ── */
.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: var(--dim);
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: 0.15em;
  margin-left: 0.15em;
}
.help:hover { border-color: var(--accent); color: var(--accent); }

.tip-bubble {
  position: fixed;
  z-index: 1400; /* transient + pointer-events-free, so topmost is safe */
  max-width: 280px;
  background: var(--card-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
  padding: 0.55rem 0.8rem;
  font-size: 0.84rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.tip-bubble.show { opacity: 1; }

/* ── forms ── */
.text-input, .prompt-input, .composer-input {
  width: 100%;
  background: var(--bg1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: 0.6rem 0.85rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  resize: none;
}
.text-input:focus, .prompt-input:focus, .composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field-label { display: block; font-weight: 600; font-size: 0.9rem; margin: 0.9rem 0 0.35rem; }

/* segmented control */
.seg {
  display: inline-flex;
  background: var(--bg1);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
}
.seg-item {
  padding: 0.35em 0.95em;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--dim);
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-item:hover { color: var(--text); }
.seg-item.active { background: var(--accent); color: var(--on-accent); }

/* toggle switch */
.toggle {
  width: 3rem;
  height: 1.65rem;
  border-radius: 999px;
  background: var(--bg1);
  border: 1px solid var(--line-strong);
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}
.toggle-knob {
  position: absolute;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: var(--dim);
  transition: left 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.2s ease;
}
.toggle.on { background: var(--accent); border-color: transparent; }
.toggle.on .toggle-knob { left: calc(100% - 1.2rem - 3px); background: var(--on-accent); }

/* range slider */
.slider { accent-color: var(--accent); width: 100%; }
.slider-wrap { display: flex; align-items: center; gap: 0.6rem; min-width: 240px; }

/* ── toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.6rem;
  transform: translate(-50%, 20px);
  z-index: 1200;
  background: var(--card-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: 0.7rem 1.1rem;
  font-size: 0.92rem;
  max-width: min(480px, 90vw);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.toast-warn { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }

/* ── modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(8, 10, 14, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  width: min(440px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-backdrop.show .modal { transform: none; }
.modal-wide { width: min(680px, 94vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem 0.4rem; }
.modal-body { padding: 0.6rem 1.25rem 1rem; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; padding: 0.5rem 1.25rem 1.2rem; }

/* ── appearance panel ── */
.size-row { display: flex; align-items: center; gap: 0.8rem; }
.accent-note { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; margin-top: 0.8rem; }

/* read-aloud (voice) controls in the Appearance panel */
.voice-section { margin-top: 0.4rem; }
.voice-row { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.65rem; }
.voice-row-label { flex: 1 1 auto; font-size: 0.9rem; }
.voice-row .slider { flex: 2 1 0; }
.voice-val { min-width: 3.2ch; text-align: right; font-variant-numeric: tabular-nums; }
.voice-select {
  flex: 2 1 0;
  min-width: 0;
  background: var(--bg1);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: 0.45rem 0.6rem;
}
.voice-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.voice-test { margin-top: 0.85rem; }
.voice-note { margin-top: 0.6rem; }
.swatches { display: flex; gap: 0.55rem; flex-wrap: wrap; align-items: center; }
.swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px var(--card);
  transition: transform 0.12s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { border-color: var(--text); }
.swatch-custom { padding: 0; border: 1px dashed var(--line-strong); background: none; width: 2rem; height: 2rem; border-radius: 50%; cursor: pointer; }

/* ── live (streaming) narration ── */
.entry-live p:last-child::after {
  content: "▍";
  margin-left: 0.08em;
  color: var(--accent);
  animation: caretBlink 0.9s steps(1) infinite;
}
@keyframes caretBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── explainer cards ── */
.explainer {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--r-md);
  padding: 0.85rem 1rem;
  margin: 0.9rem 0;
  animation: screenIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.explainer-icon { color: var(--accent); }
.explainer-icon .icon { width: 1.8rem; height: 1.8rem; }
.explainer-text { flex: 1; font-size: 0.9rem; }
.explainer-text p { color: var(--dim); margin-top: 0.15rem; }

/* ── HP / XP bars ── */
.hp-bar {
  position: relative;
  height: 1.15rem;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.6rem;
}
.hp-fill {
  height: 100%;
  background: var(--good);
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.3s ease;
}
.hp-fill.low { background: var(--danger); }
.hp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
html.light .hp-text { text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5); color: #1b202a; }

.xp-bar {
  height: 0.35rem;
  background: var(--bg1);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.45rem;
}
.xp-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.6s ease; }

/* stat chips */
.stat-grid, .stat-preview { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.7rem; }
.stat-chip {
  font-size: 0.76rem;
  font-weight: 650;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--dim);
  cursor: default;
}

/* ── dice overlay ── */
.dice-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(8, 10, 14, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.dice-overlay.show { opacity: 1; }
.dice-stage { display: flex; flex-direction: column; align-items: center; gap: 1rem; text-align: center; padding: 1rem; }
.dice-label { font-size: 1.05rem; font-weight: 600; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6); }

/* .die = glow + motion (unclipped, so the drop-shadow renders);
   .die-face = the clipped polyhedral shape with the gradient */
.die {
  width: 7.5rem;
  height: 7.5rem;
  filter: drop-shadow(0 14px 34px color-mix(in srgb, var(--accent) 55%, transparent));
  transform-style: preserve-3d;
}
.die-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 92%, #ffffff), color-mix(in srgb, var(--accent) 80%, #000000));
  border-radius: 24%;
}
/* real polyhedral silhouettes */
.die-d4 .die-face { clip-path: polygon(50% 4%, 97% 92%, 3% 92%); border-radius: 0; }
.die-d4 .die-num { transform: translateY(18%); }
.die-d8 .die-face { clip-path: polygon(50% 1%, 97% 50%, 50% 99%, 3% 50%); border-radius: 0; }
.die-d10 .die-face { clip-path: polygon(50% 1%, 94% 42%, 50% 99%, 6% 42%); border-radius: 0; }
.die-d12 .die-face { clip-path: polygon(50% 2%, 97% 37%, 79% 97%, 21% 97%, 3% 37%); border-radius: 0; }
.die-d20 .die-face { clip-path: polygon(50% 1%, 96% 25%, 96% 75%, 50% 99%, 4% 75%, 4% 25%); border-radius: 0; }
.die-num {
  font-size: 2.9rem;
  font-weight: 800;
  color: var(--on-accent);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
}
.die.tumbling { animation: tumble 0.5s linear infinite; }
@keyframes tumble {
  0% { transform: rotate3d(1, 1, 0, 0deg) translateY(0); }
  25% { transform: rotate3d(1, 1, 0, 12deg) translateY(-12px); }
  50% { transform: rotate3d(1, -1, 0, -10deg) translateY(0); }
  75% { transform: rotate3d(-1, 1, 0, 10deg) translateY(-8px); }
  100% { transform: rotate3d(1, 1, 0, 0deg) translateY(0); }
}
.die.settled { animation: settle 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes settle {
  0% { transform: scale(0.85) rotate(-6deg); }
  100% { transform: scale(1) rotate(0); }
}
.die.nat-high { filter: drop-shadow(0 0 34px color-mix(in srgb, #ffd54a 75%, transparent)) drop-shadow(0 10px 24px color-mix(in srgb, var(--accent) 40%, transparent)); }
.die.nat-low { filter: saturate(0.45) brightness(0.8) drop-shadow(0 10px 24px rgba(0, 0, 0, 0.4)); }

.dice-breakdown { font-size: 1.15rem; font-weight: 650; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6); min-height: 1.6em; }
.dice-outcome { font-size: 1rem; font-weight: 700; min-height: 1.4em; }
.dice-outcome.good { color: var(--good); }
.dice-outcome.bad { color: var(--danger); }

/* ── world map overlay ── */
.map-overlay {
  position: fixed;
  inset: 0;
  z-index: 1050; /* below modals (1100) so the rename dialog sits on top */
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--bg0) 92%, transparent);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.map-overlay.show { opacity: 1; }
.map-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--line);
}
.map-head-icon { color: var(--accent); width: 1.4em; height: 1.4em; }
.map-head strong { font-family: var(--serif); font-size: 1.1rem; }
.zoom-minus { font-size: 1.3rem; font-weight: 700; line-height: 1; }
.map-stage { flex: 1; min-height: 0; display: flex; }
.map-svg {
  flex: 1;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.map-svg:active { cursor: grabbing; }
.map-label {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
  user-select: none;
}
.map-loc { cursor: pointer; }
.map-loc:hover .map-label { text-decoration: underline; text-underline-offset: 3px; }
.map-loc:focus-visible { outline: none; }
.map-loc:focus-visible .map-label { text-decoration: underline; }
.map-marker { pointer-events: none; }
.map-callout-text { font-family: var(--sans); font-size: 12.5px; font-weight: 650; }
.map-foot { text-align: center; padding: 0.55rem; border-top: 1px solid var(--line); }
/* (reduced-motion for the marker pulse is handled in JS — CSS can't stop SMIL) */

/* dice popover (manual rolls) */
.dice-pop {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  left: 0;
  z-index: 50;
  background: var(--card-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: 0.8rem;
  width: 270px;
  animation: screenIn 0.18s ease;
}
.dice-menu-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
