/* =========================================================================
   Telly — design system
   Procreate × Spotify × Apple: OLED surfaces, frosted pills, spring motion.
   ========================================================================= */

:root {
  --bg: #0A0A0C;
  --bg-2: #121216;
  --bg-3: #1A1A20;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #F5F5F7;
  --text-2: rgba(235, 235, 245, 0.62);
  --text-3: rgba(235, 235, 245, 0.34);
  --accent: #1ED760;
  --accent-ink: #04170B;
  --danger: #FF6B5E;

  --glass-bg: rgba(30, 30, 36, 0.55);
  --glass-bg-strong: rgba(24, 24, 30, 0.78);
  --glass-blur: blur(20px) saturate(180%);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 12px 40px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 520ms;
  --dur-fast: 260ms;

  --radius-pill: 999px;
  --radius-card: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --ui-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;

  /* Template-driven (set from JS) */
  --t-bg: #0A0A0C;
  --t-active: #FFFFFF;
  --t-upcoming: #FFFFFF;
  --t-up-op: 0.45;
  --t-past-op: 0.15;
  --t-word-op: 0.5;
  --t-word-up: rgba(255,255,255,.5);
  --t-font: "Inter", var(--ui-font);
  --t-fs: 52px;
  --t-lh: 1.35;
  --t-col: 78vw;
  --t-align: left;
  --t-mirror: 1;

  --noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 1.2 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--t-bg);
  color: var(--text);
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  transition: background-color var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid rgba(255,255,255,.55); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd { font: 600 10.5px/1 var(--ui-font); padding: 3px 6px; border-radius: 6px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1); color: var(--text-2); letter-spacing: .02em; }
[hidden] { display: none !important; }

/* ----- Tactile noise overlay ----- */
.noise {
  position: fixed; inset: 0; z-index: 90; pointer-events: none;
  background-image: var(--noise); background-size: 220px 220px;
  opacity: 0.03; mix-blend-mode: overlay;
}

/* ----- Glass ----- */
.glass {
  position: relative;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  box-shadow: var(--glass-shadow);
  isolation: isolate;
}
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background-image: var(--noise); background-size: 180px 180px; opacity: .035; mix-blend-mode: overlay;
}

/* ----- Pills ----- */
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius-pill);
  font-size: 13.5px; font-weight: 550; letter-spacing: -0.005em; white-space: nowrap;
  color: var(--text);
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
button.pill:hover { background-color: rgba(52, 52, 60, 0.62); }
button.pill:active { transform: scale(0.96); }
.pill--icon { width: 40px; padding: 0; justify-content: center; font-weight: 650; font-size: 15px; }
.pill--ghost { background: transparent; }
button.pill--ghost:hover { background: rgba(255,255,255,.07); }
.pill--badge { color: var(--text-2); font-variant-numeric: tabular-nums; padding: 0 14px; }
.pill--badge svg { width: 16px; height: 16px; }
.pill--template .swatch {
  width: 16px; height: 16px; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,.2) inset;
}
.pill--template .chev { width: 12px; height: 12px; opacity: .6; stroke-width: 1.8; }

/* ----- HUD layout ----- */
.hud {
  position: fixed; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px calc(16px + var(--safe-r)) 14px calc(16px + var(--safe-l));
  pointer-events: none;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.hud > * { pointer-events: auto; }
.hud-top { top: 0; padding-top: calc(14px + var(--safe-t)); }
.hud-bottom { bottom: 0; padding-bottom: calc(18px + var(--safe-b)); justify-content: center; }
.hud-group { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.hud-group--center { justify-content: center; flex: 0 1 auto; }
.hud-group--end { justify-content: flex-end; }

/* Segmented control */
.segmented {
  display: inline-flex; position: relative; padding: 4px; border-radius: var(--radius-pill); height: 40px;
}
.segmented button {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600; color: var(--text-2);
  transition: color var(--dur-fast) var(--ease);
}
.segmented button svg { width: 16px; height: 16px; }
.segmented button[aria-checked="true"] { color: #0A0A0C; }
.seg-thumb {
  position: absolute; top: 4px; left: 0; height: 32px; width: 0; border-radius: var(--radius-pill);
  background: #F5F5F7; box-shadow: 0 2px 10px rgba(0,0,0,.35);
  transition: transform var(--dur) var(--ease), width var(--dur) var(--ease);
}

/* Dock */
.dock {
  display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: var(--radius-pill);
}
.dock-sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 4px; }
.bp-glyph { font: 700 13px/1 ui-monospace, "JetBrains Mono", Menlo, monospace; color: var(--accent); letter-spacing: -.04em; }
.stepper { display: flex; align-items: center; height: 40px; border-radius: var(--radius-pill); }
.stepper button { width: 34px; height: 34px; border-radius: 50%; font-size: 18px; color: var(--text-2); transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.stepper button:hover { background: rgba(255,255,255,.08); color: var(--text); }
.stepper button:active { transform: scale(.9); }
.stepper-val { display: flex; align-items: baseline; gap: 4px; min-width: 70px; justify-content: center; font-variant-numeric: tabular-nums; }
.stepper-val b { font-size: 15px; font-weight: 650; }
.stepper-val small { font-size: 10.5px; font-weight: 650; color: var(--text-3); letter-spacing: .06em; }

.play-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 22px 0 18px; margin-left: 4px;
  border-radius: var(--radius-pill); background: #F5F5F7; color: #0A0A0C;
  font-size: 15px; font-weight: 700; letter-spacing: -.01em;
  box-shadow: 0 6px 24px rgba(255,255,255,.12), 0 2px 6px rgba(0,0,0,.4);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.play-btn svg { fill: currentColor; stroke: none; width: 20px; height: 20px; }
.play-btn:hover { transform: scale(1.04); box-shadow: 0 8px 32px rgba(255,255,255,.2), 0 2px 6px rgba(0,0,0,.4); }
.play-btn:active { transform: scale(.95); }
.play-btn--round { width: 52px; height: 52px; padding: 0; justify-content: center; margin: 0 6px; }
.play-btn--round svg { width: 24px; height: 24px; }
.play-btn--round .i-pause { display: none; }
body.playing .play-btn--round .i-play { display: none; }
body.playing .play-btn--round .i-pause { display: block; }

/* ----- Canvas ----- */
.canvas { position: fixed; inset: 0; overflow: hidden; }

.edit-view, .perform-view {
  position: absolute; inset: 0;
  will-change: transform, opacity;
}
.edit-scroll {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; scroll-behavior: auto;
  padding: calc(96px + var(--safe-t)) 20px calc(140px + var(--safe-b));
  mask-image: linear-gradient(to bottom, transparent 0, #000 88px, #000 calc(100% - 120px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 88px, #000 calc(100% - 120px), transparent 100%);
}
.edit-column { max-width: 680px; margin: 0 auto; }

/* Editor */
.editor {
  outline: none; min-height: 50vh;
  font-family: var(--t-font);
  font-weight: var(--t-fw-edit, 500);
  font-size: clamp(17px, 0.45vw + 15px, 20px);
  line-height: 1.6;
  color: var(--t-active);
  caret-color: var(--accent);
  text-align: start; /* each line aligns to its own direction (blocks are dir=auto) */
  word-wrap: break-word;
  -webkit-user-select: text; user-select: text;
}
.editor .blk {
  position: relative; padding: 5px 0 5px 0; min-height: 1.6em;
  border-radius: 8px;
  transition: background-color 600ms var(--ease);
}
.editor .blk + .blk { margin-top: 2px; }
.editor .blk.is-start::before {
  content: ""; position: absolute; left: -26px; top: calc(5px + 0.8em - 6px);
  width: 0; height: 0; border-style: solid; border-width: 6px 0 6px 9px;
  border-color: transparent transparent transparent var(--accent);
  opacity: .9; filter: drop-shadow(0 0 6px rgba(30,215,96,.6));
}
.editor .blk.flash { background: rgba(30,215,96,.14); }
.editor.is-empty::before {
  /* the space after \A ends the escape, so the next letter isn't read as part of a character code */
  content: "Paste or type your script…\A Type // for a breakpoint.";
  white-space: pre-wrap; position: absolute; pointer-events: none; color: var(--t-upcoming); opacity: .35;
}
.editor .bp {
  display: flex; align-items: center; gap: 12px; margin: 18px 0; height: 26px;
  -webkit-user-select: none; user-select: none; cursor: default;
}
.editor .bp::before, .editor .bp::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--t-upcoming) 30%, var(--t-upcoming) 70%, transparent);
  opacity: .22;
}
.editor .bp span {
  display: inline-flex; align-items: center; gap: 7px;
  height: 26px; padding: 0 12px; border-radius: 999px;
  font: 650 11px/1 var(--ui-font); letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); background: rgba(30,215,96,.1); border: 1px solid rgba(30,215,96,.25);
  transition: transform var(--dur-fast) var(--ease);
}
.editor .bp.pop span { animation: bpPop 520ms var(--ease); }
.editor .bp.is-start span { background: var(--accent); color: var(--accent-ink); }
@keyframes bpPop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ----- Perform stage ----- */
.perform-view { opacity: 0; pointer-events: none; touch-action: none; }
.stage-mirror { position: absolute; inset: 0; transform: scaleX(var(--t-mirror)); }
.lyrics {
  position: absolute; left: 50%; top: 0;
  width: var(--t-col); max-width: 1500px;
  transform: translate3d(-50%, 0, 0);
  font-family: var(--t-font);
  font-size: var(--fs-eff, var(--t-fs));
  line-height: var(--t-lh);
  text-align: var(--t-align);
  font-weight: var(--t-fw, 700); letter-spacing: var(--t-ls, -0.015em);
  /* optional extra thickness beyond the font's heaviest weight (Max Accessibility) */
  -webkit-text-stroke-width: var(--t-stroke, 0px);
  will-change: transform;
}
.lyrics.anim { transition: transform 700ms var(--ease); }
.ln {
  margin: 0 0 0.42em; color: var(--t-upcoming);
  opacity: calc(var(--t-up-op) * 0.35);
  transform-origin: var(--origin, left) center;
  transition: opacity 600ms var(--ease), color 600ms var(--ease), transform 700ms var(--ease);
  text-wrap: pretty;
}
.lyrics.align-center .ln { --origin: center; }
.ln.d1 { opacity: var(--t-up-op); }
.ln.d2 { opacity: calc(var(--t-up-op) * 0.72); }
.ln.past { opacity: var(--t-past-op); transform: scale(.985); }
.ln.active { opacity: 1; color: var(--t-active); }
.ln .w { display: inline; }
/* Word-level */
/* Word-level karaoke: words breathe in once and stay lit (no wipe, no flicker). */
.mode-word .ln.active { color: var(--t-word-up); }
.mode-word .ln .w {
  display: inline-block;
  transform-origin: 50% 80%;
  transition: color var(--wd, 420ms) cubic-bezier(0.33, 0, 0.2, 1);
}
.mode-word .ln .w.on { color: var(--t-active); }
.mode-word.sweep-smooth .ln.active .w.on { animation: breathe var(--wd, 420ms) cubic-bezier(0.22, 1, 0.36, 1) both; }
.mode-word.sweep-snap .ln .w { transition: none; }
@keyframes breathe {
  0%   { transform: translateY(0.045em) scale(0.985); text-shadow: 0 0 0 transparent; }
  45%  { transform: translateY(-0.01em) scale(1.012); text-shadow: 0 0 0.42em var(--t-glow, rgba(255,255,255,.3)); }
  100% { transform: none; text-shadow: 0 0 0 transparent; }
}
.ln.end-mark { text-align: center; opacity: .25; letter-spacing: .4em; font-size: .5em; padding-top: 1em; }
.ln.end-mark.active { opacity: .7; color: var(--t-upcoming); }

.chapter {
  display: flex; align-items: center; gap: .5em; margin: .2em 0 .9em;
  font: 650 max(11px, .2em)/1 var(--ui-font); letter-spacing: .14em; text-transform: uppercase;
  color: var(--t-upcoming); opacity: .3;
  transition: opacity 600ms var(--ease);
}
.chapter::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .4; }
.chapter.past { opacity: .08; }

.perform-fade { position: absolute; left: 0; right: 0; pointer-events: none; z-index: 2; }
.perform-fade--top { top: 0; height: 22vh; background: linear-gradient(var(--t-bg) 10%, transparent); }
.perform-fade--bottom { bottom: 0; height: 26vh; background: linear-gradient(transparent, var(--t-bg) 90%); }

/* ----- State visibility ----- */
body[data-state="edit"] .perform-view { opacity: 0; pointer-events: none; }
body:not([data-state="edit"]) .edit-view { opacity: 0; pointer-events: none; }
body:not([data-state="edit"]) .perform-view { opacity: 1; pointer-events: auto; }
body:not([data-state="edit"]) #editTop { opacity: 0; transform: translateY(-24px); pointer-events: none; }
body:not([data-state="edit"]) #editDock { opacity: 0; transform: translateY(24px); pointer-events: none; }
body:not([data-state="edit"]) #editTop > *, body:not([data-state="edit"]) #editDock > * { pointer-events: none; }

.perform-hud { opacity: 0; pointer-events: none; }
.perform-hud#performTop { transform: translateY(-24px); flex-direction: column; gap: 10px; }
.perform-hud#performDock { transform: translateY(24px); }
.perform-hud > * { pointer-events: none; }
body.hud-on:not([data-state="edit"]):not([data-state="countdown"]) .perform-hud { opacity: 1; transform: none; }
body.hud-on:not([data-state="edit"]):not([data-state="countdown"]) .perform-hud > * { pointer-events: auto; }
.perform-meta { height: 34px; font-size: 12.5px; color: var(--text-2); gap: 10px; font-variant-numeric: tabular-nums; }
.perform-meta .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.perform-meta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }
.progress { width: min(420px, 70vw); height: 3px; border-radius: 3px; background: rgba(255,255,255,.1); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--text); border-radius: inherit; transition: width 400ms var(--ease); }

/* Paused pills */
.paused-pills {
  position: fixed; z-index: 45; left: calc(18px + var(--safe-l)); bottom: calc(20px + var(--safe-b));
  display: flex; gap: 8px; opacity: 0; transform: translateY(16px) scale(.96); pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
body[data-state="paused"]:not(.hud-on):not(.tut-on) .paused-pills { opacity: 1; transform: none; pointer-events: auto; }
body.mode-tap[data-state="perform"]:not(.hud-on):not(.tut-on) .paused-pills { opacity: .55; transform: none; pointer-events: auto; }
body.mode-tap #resumePill { display: none; }
.paused-pills .pill { height: 44px; padding: 0 14px 0 14px; }
.paused-pills kbd { margin-left: 2px; }
@media (pointer: coarse) { .paused-pills kbd, .hide-touch { display: none; } }

/* Voice pill */
.voice-pill {
  position: fixed; z-index: 44; right: calc(18px + var(--safe-r)); top: calc(16px + var(--safe-t));
  height: 32px; font-size: 12px; color: var(--text-2); padding: 0 12px;
  opacity: 0; transform: translateY(-10px); pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
body.voice-on:not([data-state="edit"]) .voice-pill { opacity: 1; transform: none; }
.voice-pill.hold { color: #FFD166; }
.meter { display: inline-flex; gap: 2px; align-items: center; height: 14px; }
.meter i { width: 3px; height: 100%; border-radius: 2px; background: var(--accent); transform: scaleY(.15); transition: transform 80ms linear; }
.voice-pill.hold .meter i { background: #FFD166; }

/* ----- Feedback pills ----- */
.fb { position: fixed; z-index: 60; pointer-events: none; }
.fb--center { inset: 0; display: grid; place-items: center; }
.fb-orb {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  opacity: 0; transform: scale(.7);
}
.fb-orb svg { width: 38px; height: 38px; fill: var(--text); stroke: none; }
.fb-orb.show { animation: orb 900ms var(--ease) forwards; }
@keyframes orb { 0% { opacity: 0; transform: scale(.7); } 25% { opacity: 1; transform: scale(1); } 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.12); } }

.fb--top { top: calc(20px + var(--safe-t)); left: 50%; transform: translateX(-50%); }
.fb--corner { top: calc(20px + var(--safe-t)); left: calc(18px + var(--safe-l)); }
.fb-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text);
  opacity: 0; transform: translateY(-8px) scale(.96);
  transition: opacity 320ms var(--ease), transform 420ms var(--ease);
}
.fb-pill.show { opacity: 1; transform: none; }
.fb-pill b { font-size: 17px; }
.fb-pill small { color: var(--text-3); font-size: 11px; letter-spacing: .06em; font-weight: 700; }

.toast-wrap {
  position: fixed; z-index: 100; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  display: inline-flex; align-items: center; gap: 12px; min-height: 42px; padding: 6px 8px 6px 16px; border-radius: 999px;
  font-size: 13.5px; font-weight: 550; background: var(--glass-bg-strong); pointer-events: auto;
  opacity: 0; transform: translateY(12px) scale(.97); transition: opacity 360ms var(--ease), transform 460ms var(--ease);
}
.toast:not(:has(button)) { padding-right: 16px; }
.toast.show { opacity: 1; transform: none; }
.toast button { height: 30px; padding: 0 12px; border-radius: 999px; background: rgba(255,255,255,.12); font-weight: 650; font-size: 12.5px; }
.toast button:hover { background: rgba(255,255,255,.2); }

/* ----- Countdown ----- */
.countdown {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; align-content: end; gap: 14px;
  padding-bottom: calc(12vh + var(--safe-b));
  pointer-events: none; opacity: 0; transition: opacity 400ms var(--ease);
}
.countdown.show { opacity: 1; }
body[data-state="countdown"] .ln:not(.active) { opacity: calc(var(--t-up-op) * .5); }
.cd-ring { width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center; position: relative; }
.cd-ring span { font: 700 48px/1 var(--ui-font); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.cd-ring span.tick { animation: cdTick 1000ms var(--ease); }
.cd-ring svg { position: absolute; inset: -1px; width: calc(100% + 2px); height: calc(100% + 2px); transform: rotate(-90deg); stroke-width: 2.5; stroke: var(--accent); }
.cd-ring circle { stroke-dasharray: 352; stroke-dashoffset: 352; }
.countdown::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 45vh; background: linear-gradient(transparent, var(--t-bg) 70%); z-index: -1; }
.cd-ring.run circle { animation: cdArc 1000ms linear; }
@keyframes cdTick { 0% { transform: scale(1.5); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 85% { opacity: 1; } 100% { transform: scale(.85); opacity: .0; } }
@keyframes cdArc { from { stroke-dashoffset: 352; } to { stroke-dashoffset: 0; } }
.cd-hint { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: .08em; text-transform: uppercase; }

/* ----- Menus ----- */
.menu {
  position: fixed; z-index: 80; min-width: 230px; max-width: calc(100vw - 32px); padding: 6px; border-radius: 18px;
  background: var(--glass-bg-strong);
  display: flex; flex-direction: column; gap: 2px;
  opacity: 0; transform: translateY(-6px) scale(.97); transform-origin: top left; pointer-events: none;
  transition: opacity 260ms var(--ease), transform 360ms var(--ease);
}
.menu.open { opacity: 1; transform: none; pointer-events: auto; }
.menu button, .menu .menu-row {
  display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px; border-radius: 12px;
  font-size: 14px; font-weight: 520; text-align: left; width: 100%;
}
.menu button:hover { background: rgba(255,255,255,.08); }
.menu .label { padding: 10px 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.menu .sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu .tpl-sw { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 800; box-shadow: 0 0 0 1px rgba(255,255,255,.14) inset; }
.menu .check { margin-left: auto; color: var(--accent); opacity: 0; }
.menu button[aria-checked="true"] .check { opacity: 1; }
.menu .tag { margin-left: auto; font-size: 10.5px; color: var(--text-3); font-weight: 650; letter-spacing: .04em; }

.scrim {
  position: fixed; inset: 0; z-index: 75; background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease);
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ----- Drawer (customizer) ----- */
.drawer {
  position: fixed; z-index: 82; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b));
  width: min(400px, calc(100vw - 20px)); border-radius: 28px; background: var(--glass-bg-strong);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(calc(100% + 30px)); transition: transform 620ms var(--ease);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; }
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 18px 18px; }
.drawer-foot { padding: 12px 18px 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }

.mini-preview {
  position: relative; height: 170px; border-radius: 18px; overflow: hidden; margin-bottom: 18px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset;
}
.mini-preview .mp-inner { position: absolute; inset: 0; transform: scaleX(var(--mp-mirror, 1)); }
.mini-preview .lyrics { width: 86%; font-size: var(--mp-fs, 22px); transition: transform 700ms var(--ease); }
.mini-preview .perform-fade--top { height: 40px; }
.mini-preview .perform-fade--bottom { height: 60px; }
.mini-preview .chapter { display: none; }

.field { margin: 0 0 16px; }
.field > label, .field-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; font-weight: 650; color: var(--text-2); margin-bottom: 8px; }
.field-label output { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.group-title { font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); margin: 22px 0 12px; }
.group-title:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 34px; padding: 0 13px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text-2);
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: #F5F5F7; color: #0A0A0C; border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, #F5F5F7 var(--fill, 50%), rgba(255,255,255,.12) var(--fill, 50%)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: rgba(255,255,255,.12); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 6px; background: #F5F5F7; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.5), 0 0 0 .5px rgba(0,0,0,.1); transition: transform 200ms var(--ease); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }

.color-row { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 6px 0 12px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.color-row + .color-row { margin-top: 6px; }
.color-row span { flex: 1; font-size: 13.5px; font-weight: 550; }
.color-row code { font: 500 12px ui-monospace, Menlo, monospace; color: var(--text-3); text-transform: uppercase; }
.color-row input[type="color"] { -webkit-appearance: none; appearance: none; width: 32px; height: 32px; border: 0; padding: 0; border-radius: 10px; background: none; cursor: pointer; }
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-row input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 10px; box-shadow: 0 0 0 1px rgba(255,255,255,.2) inset; }
.color-row input[type="color"]::-moz-color-swatch { border: 0; border-radius: 10px; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,.14); transition: background-color 300ms var(--ease); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); transition: transform 380ms var(--ease); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }

.text-input {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,.05); color: var(--text); font: 500 14px var(--ui-font); outline: none;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.text-input:focus { border-color: rgba(255,255,255,.3); background: rgba(255,255,255,.08); }
.text-input::placeholder { color: var(--text-3); }
.inline-row { display: flex; gap: 8px; }
.inline-row .text-input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 650; background: rgba(255,255,255,.08); border: 1px solid var(--line);
  transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast);
}
.btn:hover { background: rgba(255,255,255,.14); }
.btn:active { transform: scale(.97); }
.btn--primary { background: #F5F5F7; color: #0A0A0C; border-color: transparent; }
.btn--primary:hover { background: #fff; }
.btn--danger { color: var(--danger); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 11.5px; font-weight: 650; margin-top: 8px; }
.badge--ok { color: var(--accent); background: rgba(30,215,96,.1); }
.badge--warn { color: #FFD166; background: rgba(255,209,102,.1); }
.badge--busy { color: var(--text-2); background: rgba(255,255,255,.06); }
.font-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.font-opt {
  height: 54px; padding: 0 12px; border-radius: 14px; text-align: left; border: 1px solid var(--line); background: rgba(255,255,255,.04);
  display: flex; flex-direction: column; justify-content: center; gap: 3px; overflow: hidden;
}
.font-opt b { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-opt small { font-size: 10.5px; color: var(--text-3); font-family: var(--ui-font); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-opt[aria-pressed="true"] { border-color: rgba(255,255,255,.6); background: rgba(255,255,255,.1); }

.lock-banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 16px;
  background: rgba(255,209,102,.08); border: 1px solid rgba(255,209,102,.2); font-size: 13px; color: #FFE3A3; line-height: 1.4;
}
.lock-banner svg { color: #FFD166; margin-top: 1px; }

/* ----- Modal ----- */
.modal {
  position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: 16px;
  pointer-events: none;
}
.modal-card {
  width: min(640px, 100%); max-height: calc(100vh - 32px - var(--safe-t) - var(--safe-b)); overflow: auto;
  border-radius: 28px; background: var(--glass-bg-strong); padding: 26px;
  opacity: 0; transform: translateY(20px) scale(.97); transition: opacity 360ms var(--ease), transform 560ms var(--ease);
}
.modal.open { pointer-events: auto; }
.modal.open .modal-card { opacity: 1; transform: none; }
.modal-card h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.modal-card .sub { margin: 0 0 18px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head > div { flex: 1; }
.tabs { display: inline-flex; padding: 3px; border-radius: 999px; background: rgba(255,255,255,.06); margin-bottom: 16px; }
.tabs button { height: 30px; padding: 0 14px; border-radius: 999px; font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.tabs button[aria-selected="true"] { background: rgba(255,255,255,.14); color: var(--text); }
.cheat { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.cheat td { padding: 10px 6px; border-top: 1px solid var(--line); vertical-align: middle; }
.cheat td:first-child { color: var(--text); font-weight: 600; width: 44%; }
.cheat td:last-child { color: var(--text-2); text-align: right; }
.cheat kbd + kbd { margin-left: 4px; }
.gesture-ico { display: inline-flex; align-items: center; gap: 6px; }
.gesture-ico i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--text); opacity: .85; }
.help-foot { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.help-foot .btn { flex: 1; }
.small-note { font-size: 12px; color: var(--text-3); margin-top: 14px; line-height: 1.5; }

/* ----- Tutorial ----- */
.tutorial { position: fixed; inset: 0; z-index: 72; pointer-events: none; }
.tut-card {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translate(-50%, 30px);
  width: min(460px, calc(100vw - 32px)); padding: 20px 20px 16px; border-radius: 26px; background: var(--glass-bg-strong);
  opacity: 0; transition: opacity 500ms var(--ease), transform 600ms var(--ease); pointer-events: auto;
}
.tutorial.open .tut-card { opacity: 1; transform: translate(-50%, 0); }
.tut-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tut-dots { display: flex; gap: 6px; }
.tut-dots i { width: 22px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.15); transition: background-color 400ms var(--ease); }
.tut-dots i.on { background: var(--text); }
.tut-dots i.done { background: var(--accent); }
.tut-skip { font-size: 12.5px; font-weight: 650; color: var(--text-3); padding: 6px 4px; }
.tut-skip:hover { color: var(--text); }
.tut-step { display: flex; align-items: center; gap: 16px; }
.tut-ico {
  width: 56px; height: 56px; border-radius: 18px; flex: none; display: grid; place-items: center;
  background: rgba(255,255,255,.08); border: 1px solid var(--line); font-weight: 700; font-size: 13px;
}
.tut-ico svg { width: 28px; height: 28px; }
.tut-ico.pulse { animation: tutPulse 1.8s var(--ease) infinite; }
@keyframes tutPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(30,215,96,.0); } 50% { box-shadow: 0 0 0 8px rgba(30,215,96,.15); } }
.tut-text h3 { margin: 0 0 4px; font-size: 17px; letter-spacing: -.01em; }
.tut-text p { margin: 0; font-size: 13.5px; color: var(--text-2); line-height: 1.45; }
.tut-step.enter { animation: tutIn 520ms var(--ease); }
@keyframes tutIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.tut-done .tut-ico { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tut-actions { margin-top: 14px; display: flex; gap: 8px; }
.tut-actions .btn { flex: 1; }
body.tut-on .paused-pills { display: none; }

/* ----- Responsive ----- */
@media (max-width: 760px) {
  .segmented button span { display: none; }
  .segmented button { padding: 0 12px; }
  .pill--template #templateName { max-width: 26vw; overflow: hidden; text-overflow: ellipsis; }
  #readTime { display: none; }
  .dock .lbl { display: none; }
  .hud { padding-left: calc(12px + var(--safe-l)); padding-right: calc(12px + var(--safe-r)); }
  .hud-group { gap: 6px; }
  .editor .blk.is-start::before { left: -16px; border-width: 5px 0 5px 7px; }
  .edit-scroll { padding-left: 24px; padding-right: 18px; }
}
@media (max-width: 420px) {
  .pill--template #templateName { display: none; }
  .stepper-val { min-width: 56px; }
  .stepper-val small { display: none; }
  .play-btn { padding: 0 16px 0 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ----- Light-template HUD (e.g. Daylight Studio) ----- */
body.light-template :is(#editTop, #editDock, .paused-pills, .fb, .perform-hud, .voice-pill, .countdown, .toast-wrap, #templateMenu, #moreMenu) {
  --text: #18181B;
  --text-2: rgba(24, 24, 27, 0.62);
  --text-3: rgba(24, 24, 27, 0.38);
  --line: rgba(0, 0, 0, 0.08);
  --line-2: rgba(0, 0, 0, 0.12);
  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-bg-strong: rgba(255, 255, 255, 0.82);
  --glass-border: 1px solid rgba(0, 0, 0, 0.07);
  --glass-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 10px 30px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);
  --accent: #0E9F48;
  color: var(--text);
}
body.light-template .play-btn { background: #18181B; color: #F5F4F0; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
body.light-template .seg-thumb { background: #18181B; }
body.light-template .segmented button[aria-checked="true"] { color: #F5F4F0; }
body.light-template button.pill:hover { background-color: rgba(255, 255, 255, 0.85); }
body.light-template .fb-orb svg { fill: #18181B; }
body.light-template kbd { background: rgba(0,0,0,.05); border-color: rgba(0,0,0,.08); }
body.light-template .progress { background: rgba(0,0,0,.1); }
body.light-template .editor .bp span { color: #0E9F48; background: rgba(14,159,72,.08); border-color: rgba(14,159,72,.25); }
body.light-template .editor { caret-color: #0E9F48; }
body.light-template .editor .blk.is-start::before { border-left-color: #0E9F48; filter: none; }
body.hud-on:not([data-state="edit"]):not([data-state="countdown"]) :is(#performTop, #performDock) { transform: none; }
body.hud-on .fb--top { top: calc(92px + var(--safe-t)); }
body.hud-on .fb--corner { top: calc(92px + var(--safe-t)); }

/* Appearance toggle (top-right menu) */
.theme-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 2px 4px 4px; border-radius: 14px; background: rgba(255,255,255,.06); }
.menu .theme-seg button { height: 34px; justify-content: center; gap: 6px; padding: 0 10px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.menu .theme-seg button svg { width: 16px; height: 16px; }
.menu .theme-seg button[aria-checked="true"] { background: #F5F5F7; color: #0A0A0C; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.menu .theme-seg button[aria-checked="false"]:hover { background: rgba(255,255,255,.08); color: var(--text); }
body.light-template .menu button:hover { background: rgba(0,0,0,.06); }
body.light-template .theme-seg { background: rgba(0,0,0,.05); }
body.light-template .menu .theme-seg button[aria-checked="true"] { background: #18181B; color: #F5F4F0; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
body.light-template .menu .theme-seg button[aria-checked="false"]:hover { background: rgba(0,0,0,.06); }
body.light-template .menu .tpl-sw { box-shadow: 0 0 0 1px rgba(0,0,0,.12) inset; }

/* =========================================================================
   Script library (Docs-style)
   ========================================================================= */
.library {
  position: fixed; inset: 0; z-index: 86; pointer-events: none;
  display: grid; place-items: center;
  padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
}
.lib-sheet {
  position: relative; width: min(1180px, 100%); height: 100%; border-radius: 30px; background: var(--glass-bg-strong);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(28px) scale(.975);
  transition: opacity 380ms var(--ease), transform 620ms var(--ease);
}
.library.open { pointer-events: auto; }
.library.open .lib-sheet { opacity: 1; transform: none; }
.lib-head { display: flex; align-items: center; gap: 12px; padding: 20px 20px 14px 26px; }
@media (max-width: 1000px) {
  .lib-head { flex-wrap: wrap; }
  .lib-title { order: 0; flex: 1; }
  .lib-close { order: 1; }
  .lib-search { order: 2; flex: 1; width: auto; min-width: 200px; }
  .lib-actions { order: 3; }
}
.lib-title { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.lib-title h2 { margin: 0; font-size: 26px; font-weight: 750; letter-spacing: -.025em; }
.lib-count { font-size: 13px; color: var(--text-3); font-weight: 600; }
.lib-search {
  display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 14px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line); width: min(320px, 100%); color: var(--text-3);
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.lib-search:focus-within { border-color: rgba(255,255,255,.28); background: rgba(255,255,255,.09); }
.lib-search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); font: 500 14px var(--ui-font); }
.lib-search input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
.lib-actions { display: flex; gap: 8px; align-items: center; }
.lib-actions .btn svg { width: 16px; height: 16px; }
.lib-body { flex: 1; overflow-y: auto; padding: 6px 26px 26px; -webkit-overflow-scrolling: touch; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(214px, 1fr)); gap: 18px; }
.lib-note { margin: 26px 0 0; text-align: center; font-size: 12px; color: var(--text-3); }
.lib-empty { grid-column: 1 / -1; padding: 60px 0; text-align: center; color: var(--text-3); font-size: 14px; }

.doc-card {
  position: relative; display: flex; flex-direction: column; text-align: left; cursor: pointer;
  border-radius: 20px; padding: 8px; background: rgba(255,255,255,.035); border: 1px solid var(--line);
  transition: transform 380ms var(--ease), border-color 260ms var(--ease), background-color 260ms var(--ease), box-shadow 380ms var(--ease);
  outline: none; animation: cardIn 520ms var(--ease) both;
}
.doc-card:hover, .doc-card:focus-visible { transform: translateY(-3px); border-color: rgba(255,255,255,.16); background: rgba(255,255,255,.06); box-shadow: 0 16px 40px rgba(0,0,0,.35); }
.doc-card:active { transform: scale(.98); }
.doc-card.is-active { border-color: rgba(30,215,96,.45); box-shadow: 0 0 0 1px rgba(30,215,96,.25) inset; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.doc-thumb {
  position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; padding: 14px 14px 0;
  font-size: 13px; line-height: 1.28; letter-spacing: -.01em;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06) inset;
}
.doc-thumb-inner { -webkit-mask-image: linear-gradient(#000 55%, transparent 96%); mask-image: linear-gradient(#000 55%, transparent 96%); height: 100%; }
.doc-thumb p { margin: 0 0 .45em; overflow-wrap: anywhere; }
.doc-thumb p:first-child { font-size: 1.12em; }
.doc-thumb--new { display: grid; place-items: center; padding: 0; background: rgba(255,255,255,.03); border: 1.5px dashed rgba(255,255,255,.16); box-shadow: none; color: var(--text-2); }
.doc-thumb--new svg { width: 34px; height: 34px; stroke-width: 1.4; transition: transform 380ms var(--ease); }
.doc-new:hover .doc-thumb--new svg { transform: scale(1.12) rotate(90deg); }
.doc-badge { position: absolute; bottom: 10px; left: 10px; height: 22px; padding: 0 9px; display: inline-flex; align-items: center; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font: 750 10.5px/1 var(--ui-font); letter-spacing: .06em; text-transform: uppercase; }
.doc-info { padding: 11px 40px 6px 6px; min-width: 0; }
/* titles wrap to two lines so the distinguishing end ("… - 3") stays visible on phones */
.doc-title { font-size: 14px; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.doc-meta { margin-top: 3px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.doc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.doc-tags span { height: 20px; padding: 0 8px; display: inline-flex; align-items: center; border-radius: 999px; font-size: 10.5px; font-weight: 650; color: var(--text-2); background: rgba(255,255,255,.06); }
.doc-more {
  position: absolute; right: 8px; bottom: 10px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  color: var(--text-2); opacity: .55; transition: opacity 200ms var(--ease), background-color 200ms var(--ease);
}
.doc-card:hover .doc-more, .doc-more:focus-visible { opacity: 1; }
.doc-more:hover { background: rgba(255,255,255,.1); color: var(--text); }
@media (pointer: coarse) { .doc-more { opacity: 1; } }
.doc-rename { height: 30px; font-size: 13.5px; padding: 0 10px; border-radius: 10px; }
#docMenu { z-index: 92; }
.menu button.danger { color: var(--danger); }

.lib-drop {
  position: absolute; inset: 10px; border-radius: 24px; border: 2px dashed rgba(30,215,96,.6); background: rgba(10,10,12,.82);
  display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity 240ms var(--ease);
}
.lib-drop div { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text); }
.lib-drop svg { width: 36px; height: 36px; color: var(--accent); }
.lib-drop small { color: var(--text-3); }
.lib-sheet.dragging .lib-drop { opacity: 1; }

@media (max-width: 640px) {
  .library { padding: 0; }
  .lib-sheet { border-radius: 0; padding-top: var(--safe-t); }
  .lib-head { padding: 16px 16px 10px; }
  .lib-actions { order: 1; }
  .lib-search { order: 3; flex: none; width: 100%; }
  .lib-actions .btn span { display: none; }
  .lib-actions .btn { width: 42px; padding: 0; }
  .lib-body { padding: 4px 16px 24px; }
  .lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .doc-thumb { font-size: 11px; padding: 10px 10px 0; }
  .doc-tags span:nth-child(n+3) { display: none; }
}

/* ----- Script title (bottom of edit view) ----- */
#editDock { padding-bottom: calc(34px + var(--safe-b)); }
.doc-title-bar {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: calc(9px + var(--safe-b));
  display: flex; justify-content: center; pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.doc-title-btn, .doc-title-input {
  pointer-events: auto; max-width: min(62vw, 520px); height: 20px; padding: 0 8px; border-radius: 6px;
  font: 550 11.5px/20px var(--ui-font); letter-spacing: .01em; color: var(--t-upcoming); opacity: .42;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: opacity 240ms var(--ease), background-color 240ms var(--ease);
}
.doc-title-btn:hover, .doc-title-btn:focus-visible { opacity: .85; background: color-mix(in srgb, var(--t-upcoming) 8%, transparent); }
.doc-title-input { opacity: .9; border: 0; outline: 1px solid color-mix(in srgb, var(--t-upcoming) 25%, transparent); background: color-mix(in srgb, var(--t-upcoming) 6%, transparent); text-align: center; width: min(62vw, 420px); }
body:not([data-state="edit"]) .doc-title-bar { opacity: 0; transform: translateY(10px); }
body:not([data-state="edit"]) .doc-title-bar > * { pointer-events: none; }

/* ----- Master font (options menu) ----- */
#moreMenu { width: 284px; }
.menu .master-row { height: auto; padding: 6px 8px 6px 12px; gap: 12px; }
.mr-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.mr-text b { font-size: 13.5px; font-weight: 600; }
.mr-text small { font-size: 11.5px; color: var(--text-3); }
.menu .master-pick { margin: 2px 0 2px; }
.master-pick .mp-aa { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: rgba(255,255,255,.08); font-size: 13px; font-weight: 700; }
.master-pick .chev-r { margin-left: auto; width: 14px; height: 14px; opacity: .5; }
.master-pick.is-off { opacity: .45; }
body.light-template .master-pick .mp-aa { background: rgba(0,0,0,.06); }
.font-menu { width: 300px; max-height: min(520px, calc(100vh - 90px)); overflow-y: auto; }
.font-menu .fm-head { display: flex; align-items: center; gap: 6px; padding: 4px 4px 6px; }
.font-menu .fm-head b { font-size: 14px; }
.font-menu .fm-back { width: 32px; height: 32px; padding: 0; justify-content: center; }
.font-menu .fm-font { height: 46px; }
.font-menu .fm-font .fm-name { font-size: 17px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-menu .fm-font small { font: 600 10.5px var(--ui-font); color: var(--text-3); }
.font-menu .fm-add { display: flex; gap: 6px; padding: 6px 4px 2px; }
.font-menu .fm-add input { flex: 1; min-width: 0; height: 36px; font-size: 13px; }
.font-menu .fm-add .btn { height: 36px; padding: 0 12px; font-size: 13px; }
.font-menu .fm-status { padding: 2px 6px 4px; }

/* ----- Customizer: typeface locked by master font ----- */
.font-locked { opacity: .32; pointer-events: none; filter: grayscale(1); }
.master-note {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; margin-bottom: 10px; border-radius: 14px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); font-size: 12.5px; color: var(--text-2); line-height: 1.45;
}
.master-note svg { flex: none; margin-top: 1px; color: var(--text); }
.master-note b { color: var(--text); }

/* stroke takes each line's / word's own colour (active, upcoming, lit, unlit) */
.lyrics .ln, .lyrics .w { -webkit-text-stroke-color: currentColor; }

/* =========================================================================
   Multilingual: right-to-left lines and unspaced / cursive scripts
   ========================================================================= */
.ln[dir="rtl"] { --origin: right; }
.lyrics.align-center .ln[dir="rtl"] { --origin: center; }
/* letter-spacing breaks Arabic joining and spreads CJK characters apart */
.ln.script-cursive, .ln.script-cjk { letter-spacing: 0; }
.editor .blk:dir(rtl).is-start::before {
  left: auto; right: -26px;
  border-width: 6px 9px 6px 0; border-color: transparent var(--accent) transparent transparent;
}
@media (max-width: 760px) { .editor .blk:dir(rtl).is-start::before { right: -16px; border-width: 5px 7px 5px 0; } }
body.light-template .editor .blk:dir(rtl).is-start::before { border-right-color: #0E9F48; border-left-color: transparent; }


/* =========================================================================
   Touch & mobile hardening (final pass)
   ========================================================================= */
/* Paused = controls appear (no hidden gestures needed). The 4-finger tap / Tab still
   toggles them while playing. Tap-to-Advance keeps its small corner Edit pill. */
body[data-state="paused"]:not(.tut-on) .perform-hud { opacity: 1; transform: none; }
/* the hidden state offsets these bars by ID, so the visible state must match that specificity */
body[data-state="paused"]:not(.tut-on) :is(#performTop, #performDock) { transform: none; }
body[data-state="paused"]:not(.tut-on) .perform-hud > * { pointer-events: auto; }
body[data-state="paused"]:not(.tut-on) .paused-pills { opacity: 0 !important; pointer-events: none !important; }
body[data-state="paused"] .fb--top, body[data-state="paused"] .fb--corner { top: calc(92px + var(--safe-t)); }
.pd-edit { width: auto; padding: 0 14px 0 12px; gap: 6px; font-size: 13.5px; }

/* No selection loupe / Look Up callout while performing */
.perform-view, .perform-view * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* Fast taps never trigger double-tap zoom; pinch-zoom stays available */
html { touch-action: manipulation; }
button, a, input, label, .doc-card { touch-action: manipulation; }

/* Menus never run off small / landscape screens */
.menu { max-height: calc(100dvh - 24px - var(--safe-t) - var(--safe-b)); overflow-y: auto; overscroll-behavior: contain; }

/* Dynamic viewport + home indicator */
.modal-card { max-height: calc(100dvh - 32px - var(--safe-t) - var(--safe-b)); }
.lib-body { padding-bottom: calc(26px + var(--safe-b)); }

/* On-screen keyboard (iOS / iPadOS): main.js sets --kb to the keyboard height */
:root { --kb: 0px; }
.edit-scroll { padding-bottom: calc(140px + var(--safe-b) + var(--kb)); }
#editDock { transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease); }
body.kb-open[data-state="edit"] #editDock { transform: translateY(calc(-1 * var(--kb) + 20px + var(--safe-b))); }
body.kb-open .doc-title-bar { opacity: 0; pointer-events: none; }

/* Status bar text is always white on iOS home-screen apps: keep it legible on Light */
body.light-template::before {
  content: ""; position: fixed; z-index: 95; left: 0; right: 0; top: 0; height: var(--safe-t);
  background: rgba(0, 0, 0, .78); pointer-events: none;
}

/* Bigger, comfier targets on touch screens (Apple HIG: 44pt) */
@media (pointer: coarse) {
  .pill { height: 44px; }
  .pill--icon { width: 44px; }
  .segmented { height: 48px; }
  .segmented button { height: 40px; }
  .seg-thumb { height: 40px; }
  .stepper { height: 44px; }
  .stepper button { width: 44px; height: 44px; }
  .chip { height: 40px; padding: 0 15px; }
  .toast button { height: 36px; padding: 0 14px; }
  .tabs button { height: 38px; }
  .menu button, .menu .menu-row { min-height: 46px; }
  .menu .theme-seg button { height: 40px; }
  .doc-more { width: 44px; height: 44px; right: 4px; bottom: 6px; }
  .tut-skip { padding: 12px 10px; margin: -12px -6px; }
  .doc-title-btn { height: 30px; line-height: 30px; font-size: 13px; padding: 0 12px; opacity: .55; }
  .doc-title-bar { bottom: calc(4px + var(--safe-b)); }
  /* 16px+ inputs: iOS won't zoom the page when they're focused */
  .text-input, .lib-search input, .doc-rename, .doc-title-input, .font-menu .fm-add input { font-size: 16px; }
  .doc-title-input { height: 30px; }
}
/* hover styles only where hover exists (otherwise they stick after a tap on iOS) */
@media (hover: none) {
  button.pill:hover { background-color: var(--glass-bg); }
  button.pill--ghost:hover { background: transparent; }
  .doc-card:hover { transform: none; box-shadow: none; border-color: var(--line); background: rgba(255,255,255,.035); }
  .doc-card.is-active:hover { border-color: rgba(30,215,96,.45); }
  .play-btn:hover { transform: none; }
}
/* narrow phones: Help moves into the ••• menu so the top bar never overflows */
@media (max-width: 420px) { #helpBtn { display: none; } }
@media (min-width: 421px) { [data-more="help"] { display: none !important; } }

/* =========================================================================
   Library folders
   ========================================================================= */
.lib-title { flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
.lib-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; }
.lib-title-row h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.lib-up { display: none; flex: none; }
.lib-sheet.in-folder .lib-up { display: inline-flex; }
.lib-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; min-height: 0; font-size: 12.5px; color: var(--text-3); }
.lib-crumbs:empty { display: none; }
.crumb { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px; border-radius: 8px; color: var(--text-2); font-weight: 600; max-width: 220px; }
.crumb span, .crumb:not(:has(span)) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb svg { width: 13px; height: 13px; }
.crumb:hover { background: rgba(255,255,255,.08); color: var(--text); }
.crumb-sep { opacity: .5; }

/* folder card: a stack of the scripts inside */
.folder-thumb {
  padding: 0; display: block; overflow: visible;
  background: linear-gradient(160deg, rgba(255,255,255,.07), rgba(255,255,255,.02));
  box-shadow: 0 0 0 1px rgba(255,255,255,.07) inset;
}
.stack-sheet {
  position: absolute; left: 16%; right: 16%; top: 14%; bottom: 10%;
  border-radius: 10px; padding: 9px 10px 0; overflow: hidden;
  font-size: 9.5px; line-height: 1.25; letter-spacing: -.01em;
  box-shadow: 0 6px 18px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.08) inset;
  -webkit-mask-image: linear-gradient(#000 60%, transparent 98%); mask-image: linear-gradient(#000 60%, transparent 98%);
  transition: transform 420ms var(--ease);
}
.stack-sheet p { margin: 0 0 .4em; overflow-wrap: anywhere; }
.stack-sheet.s0 { transform: translate(0, 6%) ; z-index: 3; }
.stack-sheet.s1 { transform: translate(-11%, 2%) rotate(-6deg) scale(.94); z-index: 2; opacity: .85; }
.stack-sheet.s2 { transform: translate(11%, 0) rotate(6deg) scale(.9); z-index: 1; opacity: .7; }
.folder-card:hover .stack-sheet.s1 { transform: translate(-16%, 0) rotate(-9deg) scale(.94); }
.folder-card:hover .stack-sheet.s2 { transform: translate(16%, -2%) rotate(9deg) scale(.9); }
.stack-empty { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 6px; color: var(--text-3); font-size: 12px; font-weight: 600; }
.stack-empty svg { width: 34px; height: 34px; stroke-width: 1.3; }
.folder-tab {
  position: absolute; left: 10px; top: 10px; z-index: 4; width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center; background: rgba(10,10,12,.55); color: var(--text);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 0 0 1px rgba(255,255,255,.1) inset;
}
.folder-tab svg { width: 15px; height: 15px; }
.doc-where { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); }
.doc-where svg { width: 12px; height: 12px; }

/* moving */
.doc-card.is-dragging { opacity: .35; }
.lib-sheet.moving .folder-card, .lib-sheet.moving .crumb, .lib-sheet.moving .lib-up { outline: 1.5px dashed rgba(255,255,255,.18); outline-offset: 2px; }
.drop-hover { outline: 2px solid var(--accent) !important; outline-offset: 2px; background: rgba(30,215,96,.1) !important; }
.folder-card.drop-hover { transform: translateY(-3px) scale(1.02); }
.lib-empty--inline { padding: 26px 0; font-size: 13.5px; line-height: 1.5; }
.move-menu { min-width: 250px; }
.move-menu button[disabled] { opacity: .45; cursor: default; }
.move-menu button span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-hint { padding: 8px 12px 10px; font-size: 12px; color: var(--text-3); line-height: 1.45; }
#folderMenu, #moveMenu { z-index: 92; }
@media (max-width: 640px) {
  .lib-actions .btn span { display: none; }
  .crumb { max-width: 120px; }
}
/* header rows at mid widths: [title … ×] then [search][actions] */
@media (max-width: 1000px) {
  .lib-title { flex: 1 0 calc(100% - 64px); }
  .lib-close { order: 1; }
  .lib-search { order: 2; }
  .lib-actions { order: 3; }
}
@media (max-width: 640px) {
  .lib-actions { order: 3; }
  .lib-search { order: 2; flex: 1 1 auto; width: auto; }
}

/* bottom title: a quiet hint that it's editable */
.doc-title-btn { display: inline-flex; align-items: center; gap: 6px; }
.doc-title-btn .dt-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-title-btn .dt-pen { width: 12px; height: 12px; flex: none; opacity: 0; transform: translateX(-3px); transition: opacity 220ms var(--ease), transform 300ms var(--ease); }
.doc-title-btn:hover .dt-pen, .doc-title-btn:focus-visible .dt-pen { opacity: 1; transform: none; }
.doc-title-btn:hover { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
@media (hover: none) { .doc-title-btn .dt-pen { opacity: .8; transform: none; } }

/* library sort control */
.lib-sort {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px 0 8px; margin-left: 2px;
  border-radius: 999px; font-size: 12px; font-weight: 650; color: var(--text-2); white-space: nowrap;
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.lib-sort svg { width: 14px; height: 14px; }
.lib-sort:hover, .lib-sort[aria-expanded="true"] { background: rgba(255,255,255,.1); color: var(--text); }
.sort-menu { min-width: 220px; }
.sort-dirs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 2px 4px 4px; border-radius: 12px; background: rgba(255,255,255,.06); }
.menu .sort-dirs button { height: 34px; justify-content: center; padding: 0 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); border-radius: 9px; }
.menu .sort-dirs button[aria-pressed="true"] { background: #F5F5F7; color: #0A0A0C; }
#sortMenu { z-index: 92; }
@media (pointer: coarse) { .lib-sort { height: 34px; } .menu .sort-dirs button { height: 40px; } }
@media (max-width: 420px) { .lib-count { display: none; } }
