/* ============================================================
   Notch Prompter by Vlad — Apple-style glass interface
   Design language: translucent materials, hairline separators,
   SF type scale, iOS segmented controls. No glow, no gradients-as-decoration.
   ============================================================ */

/* Bundled so the "Dyslexia" typeface renders even when the OS lacks the font. */
@font-face {
  font-family: "OpenDyslexic3";
  src: url("../fonts/OpenDyslexic3-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #000000;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.10);
  --hairline: rgba(255, 255, 255, 0.12);
  --hairline-strong: rgba(255, 255, 255, 0.22);

  --text-1: rgba(255, 255, 255, 0.94);
  --text-2: rgba(255, 255, 255, 0.58);
  --text-3: rgba(255, 255, 255, 0.36);

  --accent: #0a84ff;            /* system blue */
  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 24px;

  --blur: saturate(180%) blur(30px);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", system-ui, sans-serif;

  --reader-w: 340px;
  --reader-h: 150px;
  --font-px: 20px;
  --notch-top: 0px;
  --mx: 1; --my: 1;
  --glass-opacity: 0.15;        /* reader card fill — driven by the Glass opacity slider */

  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { border: none; background: none; cursor: pointer; }

/* keyboard focus — visible only for keyboard users, matching macOS */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; }
  #scroll { scroll-behavior: auto; }
}
a { color: var(--text-2); text-decoration: none; border-bottom: 1px solid var(--hairline); }
.ic { width: 22px; height: 22px; display: block; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------- COMPOSER */

#composer {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
#composer.dropping {
  box-shadow: inset 0 0 0 2px var(--accent, #4c8dff);
}
.shell {
  max-width: 680px;
  margin: 0 auto;
  padding: 56px 22px calc(56px + env(safe-area-inset-bottom));
}

.masthead { margin-bottom: 28px; }
.masthead h1 {
  font-family: "SF Pro Display", var(--font);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.025em;
}
.masthead h1 .by { font-weight: 400; color: var(--text-3); letter-spacing: -0.01em; }
.masthead p {
  margin-top: 8px;
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.45;
  max-width: 44ch;
}

/* editor */
.editor-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-l);
  overflow: hidden;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.editor-wrap { position: relative; }
/* B5 (#29) — annotation highlight backdrop behind the (transparent-text) textarea.
   Metrics MUST match #script exactly so glyphs line up. */
.hl-backdrop {
  position: absolute; inset: 0; margin: 0; pointer-events: none; overflow: hidden;
  padding: 20px; font: inherit; font-size: 17px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
  color: var(--text-1);
}
.hl-backdrop .ann { color: var(--accent); font-style: italic; }
#script {
  position: relative;
  display: block;
  width: 100%;
  min-height: 220px;
  resize: vertical;
  background: transparent;
  border: none;
  outline: none;
  padding: 20px;
  font-size: 17px;
  line-height: 1.6;
  color: transparent;            /* the visible glyphs come from .hl-backdrop */
  caret-color: var(--text-1);
}
#script::placeholder { color: var(--text-3); -webkit-text-fill-color: var(--text-3); }
.editor-tools {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--hairline);
  flex-wrap: wrap;
}
.tool {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: var(--radius-s);
  color: var(--text-2);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.tool:hover { background: var(--surface-2); color: var(--text-1); }
.tool.recording { color: #ff453a; }
.tool.recording .ic { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.tool .ic { width: 17px; height: 17px; }

/* settings panel */
.panel {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-l);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  padding: 6px 20px;
}
.field { padding: 18px 0; border-top: 1px solid var(--hairline); }
.field:first-child { border-top: none; }
.panel-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 0 4px; border-top: 1px solid var(--hairline); }
.preview {
  background: #000; border: 1px solid var(--hairline); border-radius: var(--radius-s);
  height: 110px; overflow: hidden; padding: 14px 16px;
  -webkit-mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
}
#pv-scroll { height: 100%; overflow: hidden; }
#pv-text { font-weight: 600; line-height: 1.45; color: #fff; }
#pv-text .w.ann { font-style: italic; }
.pages-bar { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-top: 1px solid var(--hairline); }
.page-chip { display: flex; align-items: center; gap: 4px; }
.page-label {
  flex: 1; text-align: left; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 7px 10px; border-radius: var(--radius-s); color: var(--text-2); font-size: 13px;
  background: var(--surface-2, rgba(255,255,255,0.04));
}
.page-label:hover { color: var(--text-1); }
.chip-btn {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: var(--radius-s);
  color: var(--text-2); font-size: 12px;
}
.chip-btn:hover:not(:disabled) { background: var(--surface-2, rgba(255,255,255,0.06)); color: var(--text-1); }
.chip-btn:disabled { opacity: 0.3; }
.muted { color: var(--text-3); font-weight: 400; }
dialog.about {
  max-width: 420px; padding: 24px; border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-l); background: var(--surface, #141416); color: var(--text-1);
}
dialog.about::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog.about h2 { font-size: 19px; margin-bottom: 12px; }
dialog.about p { color: var(--text-2); font-size: 14px; line-height: 1.5; margin-bottom: 12px; }
dialog.about .tool { border: 1px solid var(--hairline); margin-top: 4px; }
dialog.pagepick {
  min-width: 280px; max-width: 90vw; max-height: 70vh; overflow-y: auto; padding: 10px;
  border: 1px solid var(--hairline-strong); border-radius: var(--radius-l);
  background: var(--surface, #141416); color: var(--text-1);
}
dialog.pagepick::backdrop { background: rgba(0, 0, 0, 0.5); }
.pp-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: var(--radius-s); color: var(--text-2); font-size: 14px;
}
.pp-item:hover { background: var(--surface-2, rgba(255,255,255,0.06)); color: var(--text-1); }
.pp-item.current { color: var(--text-1); box-shadow: inset 0 0 0 1px var(--hairline-strong); }
.pp-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--hairline-strong); }
.pp-item.read .pp-dot { background: #30d158; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.grid2 .field { border-top: 1px solid var(--hairline); }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.flabel {
  display: block;
  font-size: 13px;
  font-weight: 590;
  letter-spacing: -0.01em;
  color: var(--text-1);
  margin-bottom: 12px;
}
.flabel em { color: var(--text-2); font-style: normal; font-weight: 400; float: right; font-variant-numeric: tabular-nums; }
.fhint { margin-top: 9px; font-size: 12.5px; color: var(--text-3); line-height: 1.45; }

/* segmented control (iOS style) */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 11px;
}
.seg button {
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.18s, color 0.18s;
}
.seg button[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text-1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.seg-sub { margin-top: 12px; max-width: 320px; }

/* swatches */
.swatches { display: flex; gap: 10px; }
.sw {
  width: 28px; height: 28px;
  border-radius: 50%;
  outline: 1px solid var(--hairline);
  outline-offset: -1px;
  position: relative;
  transition: transform 0.12s;
}
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text-1); }
.sw:active { transform: scale(0.92); }

/* slider */
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; }
.slider::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.16); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.slider::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.16); }
.slider::-moz-range-thumb { width: 24px; height: 24px; border: none; border-radius: 50%; background: #fff; }

/* select (voice language) */
.select {
  -webkit-appearance: none; appearance: none;
  width: 100%;
  padding: 11px 38px 11px 14px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-1);
  font-size: 14px; font-weight: 500;
  border: 1px solid var(--hairline);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='rgba(255,255,255,0.5)' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.select option { background: #1c1c1e; color: var(--text-1); }

/* switch */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track {
  width: 51px; height: 31px; border-radius: 16px;
  background: rgba(255, 255, 255, 0.16);
  position: relative; flex-shrink: 0; transition: background 0.2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: transform 0.2s;
}
.switch input:checked + .track { background: #34c759; }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch .stext { font-size: 15px; color: var(--text-1); }

/* start button */
.start {
  width: 100%;
  margin-top: 22px;
  padding: 16px;
  border-radius: var(--radius-m);
  background: #fff;
  color: #000;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: opacity 0.15s, transform 0.1s;
}
.start:hover { opacity: 0.9; }
.start:active { transform: scale(0.99); }
.colophon { margin-top: 18px; text-align: center; font-size: 12px; color: var(--text-3); line-height: 1.5; }

/* ---------------------------------------------------------- STAGE */

#stage { position: fixed; inset: 0; background: #000; z-index: 100; }

#reader { position: fixed; overflow: hidden; display: flex; flex-direction: column; }
#scroll {
  flex: 1 1 auto;
  min-height: 0;            /* allow the flex child to shrink and scroll */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  transform: scale(var(--mx), var(--my));
  transform-origin: center;
}
#scroll::-webkit-scrollbar { display: none; }
#text {
  font-size: var(--font-px);
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.01em;
  word-wrap: break-word;
  color: #fff;
}
#text .w { transition: color 0.12s ease; }
#text .w.ann { font-style: italic; }

/* #20 — top/bottom fade in the card modes too (fullscreen has its own, below). */
#reader[data-mode="pinned"] #scroll,
#reader[data-mode="floating"] #scroll {
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
  mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
}

/* pinned: a glass card hugging the notch */
#reader[data-mode="pinned"] {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--reader-w);
  height: calc(var(--reader-h) + var(--notch-top));
  padding: calc(var(--notch-top) + 10px) 18px 6px;
  background: rgba(20, 20, 22, var(--glass-opacity));
  border: 1px solid var(--hairline);
  border-top: none;
  border-radius: 0 0 22px 22px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
#reader[data-mode="pinned"] #text { font-size: var(--font-px); text-align: center; }

/* floating: a draggable glass card */
#reader[data-mode="floating"] {
  width: var(--reader-w);
  height: var(--reader-h);
  padding: 16px 18px;
  background: rgba(20, 20, 22, var(--glass-opacity));
  border: 1px solid var(--hairline);
  border-radius: var(--radius-l);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  cursor: grab;
}
#reader[data-mode="floating"].dragging { cursor: grabbing; }

/* #9 — drag-to-resize handle (height), shown on hover in the card modes. */
.reader-resize {
  position: absolute; left: 50%; bottom: 1px; transform: translateX(-50%);
  width: 48px; height: 12px; cursor: ns-resize; opacity: 0; transition: opacity 0.15s; touch-action: none;
}
.reader-resize::after {
  content: ''; display: block; width: 36px; height: 4px; margin: 4px auto;
  border-radius: 2px; background: var(--hairline-strong);
}
#reader:hover .reader-resize { opacity: 1; }
#reader[data-mode="fullscreen"] .reader-resize { display: none; }

/* fullscreen: full-bleed prompter with fade masks */
#reader[data-mode="fullscreen"] {
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
}
#reader[data-mode="fullscreen"] #scroll {
  padding: 24vh max(40px, 8%);
  -webkit-mask-image: linear-gradient(transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(transparent, #000 12%, #000 88%, transparent);
}
#reader[data-mode="fullscreen"] #text { font-size: clamp(40px, calc(100vw / 14), 96px); }
@media (max-width: 768px) {
  #reader[data-mode="fullscreen"] #text { font-size: clamp(26px, calc(100vw / 10), 60px); }
}

/* reader bottom bar (waveform / spoken tail / clock / mic) — sits in flow BELOW
   the text (its own band), centered, so it never overlaps the script. */
#readerbar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 4px 16px 8px;
}
#reader[data-mode="fullscreen"] #readerbar { padding: 12px max(40px, 8%) calc(20px + env(safe-area-inset-bottom)); }
#wave { display: flex; align-items: center; justify-content: center; gap: 1.5px; height: 28px; width: 140px; flex-shrink: 0; }
.wf { width: 3px; min-height: 3px; border-radius: 1.5px; background: rgba(255, 255, 255, 0.15); align-self: center; transition: height 0.08s ease, background 0.12s ease; }
#spoken { flex: 0 1 auto; min-width: 0; max-width: 45%; font-size: 14px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
#spoken:empty { display: none; }
#elapsed-clock { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
#mic { width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); display: flex; align-items: center; justify-content: center; color: var(--text-3); flex-shrink: 0; cursor: pointer; transition: background 0.15s, color 0.15s; }
#mic:hover { background: rgba(255, 255, 255, 0.16); }
#mic.live { color: #facc15; }
#mic.muted { color: #ff453a; background: rgba(255, 69, 58, 0.16); }
#mic .ic { width: 17px; height: 17px; }

/* done */
#done { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
#done .tick { width: 56px; height: 56px; border-radius: 50%; border: 2px solid #34c759; position: relative; }
#done .tick::after { content: ""; position: absolute; left: 19px; top: 14px; width: 9px; height: 18px; border: solid #34c759; border-width: 0 2px 2px 0; transform: rotate(45deg); }
#done span { font-size: 22px; font-weight: 600; color: var(--text-1); }

/* hints */
#notchhint, #micwarn {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%);
  max-width: 80%; text-align: center;
  font-size: 13px; color: var(--text-2);
  background: rgba(20, 20, 22, 0.7);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 9px 16px;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
#notchhint { cursor: pointer; transition: color 0.15s, border-color 0.15s; }
#notchhint:hover { color: var(--text-1); border-color: var(--hairline-strong); }

/* stage controls */
#topctl, #botctl {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  transition: opacity 0.3s ease;
  z-index: 10;
}
#topctl { top: 0; padding-top: calc(14px + env(safe-area-inset-top)); justify-content: space-between; }
#botctl { bottom: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); justify-content: center; }
#stage.idle #topctl, #stage.idle #botctl { opacity: 0; pointer-events: none; }

/* status + page indicator — pinned to the bottom so they never overlap the
   reader text (the reader hugs the top in pinned mode). Fades with the controls. */
#statuswrap {
  position: absolute; left: 50%; bottom: calc(98px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  z-index: 10; pointer-events: none; transition: opacity 0.3s ease;
}
#stage.idle #statuswrap { opacity: 0; }
#status { font-size: 13px; color: var(--text-2); }
#pageind { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.shint { color: var(--text-3); font-weight: 400; }
.shint code { font-family: ui-monospace, Menlo, monospace; font-size: 0.92em; background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 5px; }
.gctl {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--hairline);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-1);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  transition: background 0.15s, transform 0.1s;
}
.gctl:hover { background: rgba(255, 255, 255, 0.16); }
.gctl:active { transform: scale(0.94); }
.gctl.primary { width: 62px; height: 62px; background: #fff; color: #000; border-color: transparent; }
#speed2wrap { width: 180px; }
