/* Atkinson Hyperlegible Next (Braille Institute; SIL Open Font License, see fonts/) */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/AtkinsonHyperlegibleNext-VF.ttf") format("truetype");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/AtkinsonHyperlegibleNext-Italic-VF.ttf") format("truetype");
  font-weight: 200 800; font-style: italic; font-display: swap;
}
:root {
  --bg: #0b0b0e;
  --panel: #16161b;
  --panel-2: #1f1f26;
  --line: #2c2c35;
  --text: #f4f4f6;
  --muted: #9a9aa6;
  --accent: #ff9f33;
  --green: #32d074;
  --red: #ff453a;
  --radius: 14px;
  --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);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px; border-radius: 10px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1000; }
.btn.danger { color: var(--red); }
.btn.big { min-height: 48px; padding: 0 22px; font-size: 17px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; padding: 0 4px; }

/* ---------- Library ---------- */
#library {
  display: flex; flex-direction: column; height: 100dvh;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
  max-width: 900px; margin: 0 auto;
}
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.01em; }
.brand img { border-radius: 7px; }
.script-bar { display: flex; gap: 8px; margin: 8px 0 12px; }
.script-bar select {
  flex: 1; min-width: 0; min-height: 40px; border-radius: 10px; padding: 0 12px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); font: inherit; font-weight: 600;
}
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.title-input {
  font: inherit; font-size: 22px; font-weight: 800; padding: 14px 16px 10px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--text); outline: none;
}
.text-input {
  flex: 1; min-height: 0; resize: none; border: 0; outline: none; padding: 14px 16px;
  background: transparent; color: var(--text); font: inherit; font-size: 17px; line-height: 1.55;
}
.editor-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }
.action-bar { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 12px; }
.action-bar #btnStart { margin-left: auto; }
.install-hint {
  margin-top: 10px; padding: 10px 14px; border-radius: 12px; background: var(--panel-2); color: var(--muted); font-size: 14px;
}
@media (max-width: 520px) {
  .hint { display: none; }
  .action-bar { gap: 4px; }
  .action-bar .btn.ghost { padding: 0 8px; }
  .action-bar #btnStart { flex: 1; min-width: 0; padding: 0 14px; }
}

/* ---------- Prompter ---------- */
#prompter { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }

.status {
  position: absolute; z-index: 5; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 16px) 6px calc(var(--safe-l) + 16px);
  height: calc(var(--safe-t) + 34px);
  font-size: 13px; font-weight: 700; color: var(--muted); pointer-events: none;
}
.status-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.status svg { width: 13px; height: 13px; }
.play-badge { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.play-badge.playing { color: var(--green); }
.rec-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--red); font-variant-numeric: tabular-nums; }
.rec-badge i { width: 9px; height: 9px; border-radius: 50%; background: var(--red); box-shadow: 0 0 8px var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.toast { color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }
.meter { display: flex; align-items: center; gap: 6px; }
.meter.speaking { color: var(--green); }
.meter-bar { position: relative; width: 54px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.14); overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(255,255,255,.5); border-radius: 3px; }
.meter.speaking .meter-fill { background: var(--green); }
.meter-tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); }

.stage {
  position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; top: calc(var(--safe-t) + 34px);
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 4%, #000 72%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 4%, #000 72%, transparent 100%);
}
.scroller { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.script-text {
  --font: 34px;
  font-size: var(--font); line-height: 1.35; font-weight: var(--weight, 600); letter-spacing: -.005em;
  padding: 0 calc(var(--margin, 6%) + var(--safe-r)) 0 calc(var(--margin, 6%) + var(--safe-l));
  color: #fff; overflow-wrap: break-word;
  font-family: ui-rounded, -apple-system, "SF Pro Rounded", system-ui, sans-serif;
}
.script-text.mirror { transform: scaleX(-1); }
.script-text section { padding-bottom: 1.1em; }
.script-text h4 {
  margin: 0 0 .35em; font-size: max(11px, .45em); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 900;
}
.script-text p { margin: 0 0 .55em; white-space: pre-line; }
.script-text .end { color: var(--muted); font-size: .5em; letter-spacing: .1em; text-transform: uppercase; padding-bottom: 60vh; }
.empty-msg { color: var(--muted); font-size: 20px; padding: 20px 6%; }

.countdown {
  position: absolute; z-index: 6; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.82); font-size: 120px; font-weight: 900; color: #fff;
  font-family: ui-rounded, -apple-system, system-ui, sans-serif;
}

/* Camera preview: same shape as the recording, cropped exactly as recorded, with a zoom bar below */
.cam-box {
  position: absolute; z-index: 4; right: calc(var(--safe-r) + 12px); bottom: calc(var(--safe-b) + 128px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.cam-frame {
  position: relative; width: 112px; height: 150px; border-radius: 12px; overflow: hidden; background: #111;
  border: 1px solid rgba(255,255,255,.18); touch-action: none;
}
.cam-frame video { width: 100%; height: 100%; object-fit: cover; display: block; transform-origin: 50% 50%; }
.cam-box.off { opacity: 0; pointer-events: none; }
.cam-box.off .cam-frame { width: 2px !important; height: 2px !important; }
.cam-box.off .zoom-bar { display: none; }
.zoom-bar {
  width: max(150px, 100%); touch-action: pan-x; margin: 0; height: 22px; background: none;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
/* Drawn by hand: Safari's own track is invisible on the black prompter. */
.zoom-bar::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,.35); }
.zoom-bar::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,.35); }
.zoom-bar::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
.zoom-bar::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.zoom-bar::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: #fff; }
#prompter.compact .cam-box {
  right: auto; left: 50%; bottom: auto; transform: translateX(-50%);
  top: calc(var(--safe-t) + var(--band-h, 140px) + 52px);
}
.zoom-chip {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  min-width: 36px; height: 24px; padding: 0 8px; border-radius: 12px; border: 0;
  background: rgba(0,0,0,.55); color: #fff; font: 700 12px/24px -apple-system, system-ui, sans-serif; cursor: pointer;
}

.controls {
  position: absolute; z-index: 7; left: 50%; bottom: calc(var(--safe-b) + 12px); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  padding: 8px 10px; border-radius: 22px;
  background: rgba(30,30,36,.82); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.08);
  transition: opacity .25s, transform .25s; width: max-content; max-width: calc(100vw - 16px);
}
.controls.hide { opacity: 0; transform: translate(-50%, 12px); pointer-events: none; }
.controls .row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center; }
.cbtn {
  position: relative; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: transparent; border: 0; color: #fff; cursor: pointer; padding: 0;
}
.cbtn:active { background: rgba(255,255,255,.12); }
.cbtn.main { width: 52px; height: 52px; background: rgba(255,255,255,.12); }
.cbtn.main svg { width: 26px; height: 26px; }
.cbtn.rec { color: var(--red); }
.cbtn.on { color: var(--green); }
.speed { min-width: 34px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; color: #fff; }
@media (max-width: 420px) {
  .cbtn { width: 38px; height: 38px; }
  .controls .row { gap: 2px; }
}
.select-btn select { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; cursor: pointer; }

/* ---------- Sheets ---------- */
dialog.sheet {
  width: min(560px, calc(100vw - 16px)); max-height: calc(100dvh - var(--safe-t) - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text);
  overflow: hidden;
}
dialog.sheet::backdrop { background: rgba(0,0,0,.55); }
.sheet-inner { max-height: calc(100dvh - var(--safe-t) - 26px); overflow-y: auto; padding: 0 18px 22px; -webkit-overflow-scrolling: touch; }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 0 8px; background: var(--panel); }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet h3 { margin: 20px 0 6px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.row-field { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.row-field > input[type=range] { flex: 1; min-width: 80px; accent-color: var(--accent); }
.row-field > select { flex: 1; min-width: 0; min-height: 36px; border-radius: 8px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 0 8px; font: inherit; font-size: 15px; }
.row-field output { min-width: 62px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-field input[type=color] { margin-left: auto; width: 54px; height: 32px; border: 0; background: none; padding: 0; }
.dims { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.dims input { width: 82px; min-height: 34px; border-radius: 8px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 0 8px; font: inherit; font-size: 16px; text-align: right; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.note.small { margin-top: 22px; text-align: center; }

.done-video { width: 100%; max-height: 52dvh; background: #000; border-radius: 12px; margin-top: 4px; }
.done-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.done-actions #btnShare { flex: 1 1 100%; }
.done-actions .btn { flex: 1; }

/* ---------- Compact layout: a few lines just under the camera ---------- */
#prompter.compact .stage {
  top: calc(var(--safe-t) + 4px); bottom: auto; height: var(--band-h, 140px);
  -webkit-mask-image: none; mask-image: none;
}
#prompter.compact .status {
  top: calc(var(--safe-t) + var(--band-h, 140px) + 10px); height: 26px; padding-top: 0;
  border-top: 1px solid rgba(255,255,255,.08); padding-top: 8px;
}
#prompter.compact .script-text p { margin-bottom: .2em; }
#prompter.compact .script-text section { padding-bottom: .45em; }

/* Words already spoken (follow-my-words) */
.script-text .w { transition: opacity .25s; }
.script-text .w.said { opacity: .32; }

.heard {
  flex: 1; min-width: 0; text-align: right; color: var(--muted); font-weight: 600; font-style: italic;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity .3s;
}
.heard.show { opacity: .8; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .btn.primary { min-height: 34px; padding: 0 12px; font-size: 14px; }

.countdown > div { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.countdown small { font-size: 15px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--red); margin-bottom: 14px; }
.countdown b { font-size: 120px; font-weight: 900; }

.muted { color: var(--muted); font-size: 12.5px; }
#packDlg p { line-height: 1.5; }

/* Speech pack download */
.pack-bar { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; margin: 6px 0 10px; }
.pack-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .2s; }
.pack-bar.indeterminate i { width: 35% !important; animation: packslide 1.1s ease-in-out infinite; }
@keyframes packslide { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }
.pack-progress-text { font-variant-numeric: tabular-nums; font-weight: 600; margin: 0; }
.pack-steps { padding-left: 22px; line-height: 1.55; margin: 8px 0; }
.pack-steps li { margin-bottom: 6px; }
.pack-badge { color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Camera & microphone help */
.perm-badge {
  pointer-events: auto; border: 0; border-radius: 10px; padding: 3px 10px; cursor: pointer;
  background: rgba(255, 69, 58, .18); color: #ff8a80; font: 700 12px/1.4 -apple-system, system-ui, sans-serif; white-space: nowrap;
}
.perm-help-btn { width: 100%; margin: 4px 0 8px; }
.perm-intro { margin: 4px 0 10px; line-height: 1.5; }
.perm-status { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.perm-status li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--panel-2); font-size: 14px; }
.perm-status .ok { color: var(--green); font-weight: 700; }
.perm-status .bad { color: var(--red); font-weight: 700; }
.perm-status .ask { color: var(--muted); font-weight: 700; }
.perm-retry { width: 100%; margin-bottom: 14px; }
.perm-section { border: 1px solid var(--line); border-radius: 12px; margin: 8px 0; padding: 0 14px; background: var(--panel); }
.perm-section summary { cursor: pointer; padding: 12px 0; font-weight: 800; }
.perm-section ol { padding-left: 20px; margin: 0 0 12px; line-height: 1.55; font-size: 14.5px; }
.perm-section li { margin-bottom: 9px; }

/* Script typefaces (Settings › Text › Font) */
.script-text.face-atkinson { font-family: "Atkinson Hyperlegible Next", system-ui, sans-serif; }
.script-text strong { font-weight: var(--strong-weight, 800); }
.script-text.face-helvetica { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
.script-text.face-georgia { font-family: Georgia, "Times New Roman", serif; }
