:root {
  --bg: #111;
  --panel: #1c1c1e;
  --panel2: #2a2a2d;
  --text: #f2f2f2;
  --muted: #9a9a9f;
  --accent: #ff9f0a;
  --danger: #ff453a;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ───── Bars & buttons ───── */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid #000;
}
.bar h1 { margin: 0; font-size: 20px; flex: 1; }
.spacer { flex: 1; }
.btn {
  border: 0; border-radius: 10px; padding: 9px 14px;
  background: var(--panel2); color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #000; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:active { opacity: .7; }

/* ───── Library ───── */
.select-bar { padding-top: 8px; padding-bottom: 8px; background: var(--panel2); }
.select-bar .chk { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.select-bar input[type=checkbox], .list .sel { accent-color: var(--accent); width: 20px; height: 20px; flex-shrink: 0; }
.sel-count { color: var(--muted); font-size: 13px; }
#library.selecting .list .del, #library.selecting .list .go { display: none; }
.list li.selected { outline: 2px solid var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.list { list-style: none; margin: 0; padding: 12px; overflow-y: auto; flex: 1; }
.list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.list li:active { background: var(--panel2); }
.list .info { flex: 1; min-width: 0; }
.list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.list .del { background: transparent; border: 0; color: var(--muted); font-size: 18px; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; flex-shrink: 0; }
.list .del:active { background: var(--panel2); color: var(--danger); }
.list .go { background: var(--accent); color: #000; border: 0; border-radius: 50%; width: 40px; height: 40px; font-size: 16px; flex-shrink: 0; cursor: pointer; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; flex: 1; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 10px calc(10px + var(--safe-bottom)); }
.foot .dot { margin: 0 6px; }
.foot .link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; }
.hint {
  margin: 0 12px 8px; padding: 12px 14px; border-radius: var(--radius);
  background: #2b2416; color: #f0d9a8; font-size: 14px; line-height: 1.45;
}

/* ───── Modal εισαγωγής ───── */
.modal { position: fixed; inset: 0; z-index: 8; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 16px; width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #000; }
.modal-info { margin: 10px 16px 0; color: var(--muted); font-size: 13px; }
.modal .all { margin: 8px 16px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.modal input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; flex-shrink: 0; }
.import-list { list-style: none; margin: 0; padding: 0 16px; overflow-y: auto; flex: 1; }
.import-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #000; }
.import-list input[type=text] { flex: 1; min-width: 0; background: var(--panel2); border: 0; border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.import-list .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid #000; }

/* ───── Editor ───── */
.title-input {
  flex: 1; min-width: 0; background: var(--panel2); border: 0; border-radius: 10px;
  padding: 9px 12px; font-size: 16px; font-weight: 600;
}
#text {
  flex: 1; width: 100%; resize: none; border: 0; outline: 0;
  background: var(--bg); color: var(--text);
  padding: 18px; font-size: 18px; line-height: 1.55;
}
.foot-bar { border-top: 1px solid #000; border-bottom: 0; padding-bottom: calc(10px + var(--safe-bottom)); }
.stats { color: var(--muted); font-size: 13px; }

/* ───── Prompter ───── */
#prompter { background: #000; color: #fff; user-select: none; -webkit-user-select: none; }
#prompter.theme-yellow { color: #ffd60a; }
#prompter.theme-black { background: #fff; color: #000; }

#stage {
  position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab;
}
#stage.dragging { cursor: grabbing; }
#stage.mirror-h { transform: scaleX(-1); }
#stage.mirror-v { transform: scaleY(-1); }
#stage.mirror-h.mirror-v { transform: scale(-1, -1); }

#scroller {
  position: absolute; left: 50%; top: 0;
  transform: translate(-50%, 0);
  will-change: transform;
  font-weight: 600;
  text-align: left;
  word-wrap: break-word;
}
#scroller.center { text-align: center; }
#scroller p { margin: 0 0 .6em; }
#scroller .marker {
  display: block; height: 4px; margin: .8em auto; width: 40%;
  border-radius: 2px; background: var(--accent); opacity: .6;
}
#scroller .done { opacity: .35; }
#prompter.voice #scroller .w.cur { color: var(--accent); }
#prompter.voice.theme-yellow #scroller .w.cur { color: #fff; }
#prompter.voice.theme-black #scroller .w.cur { color: #d97b00; }
.hbtn.on { background: var(--accent); color: #000; }
.voice-status { display: none; color: #ccc; font-size: 14px; padding: 0 10px; white-space: nowrap; }
.voice-status.live { color: var(--accent); font-weight: 600; }
#prompter.voice .voice-status { display: inline; }
#prompter.voice .hbtn-group.speed { display: none; }

#guide {
  position: absolute; left: 0; right: 0; height: 0;
  pointer-events: none; z-index: 1;
}
#guide::before {
  content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px;
  background: var(--accent); opacity: .75;
}
#guide::after {
  content: ""; position: absolute; left: 0; top: -9px;
  border: 9px solid transparent; border-left-color: var(--accent);
}
#guide.off { display: none; }

#countdown {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6);
}
#countdown span { font-size: 30vmin; font-weight: 800; color: #fff; }

/* Echo mode (ανάγνωση πρόταση-πρόταση) */
#echoView { display: none; position: absolute; inset: 0; padding: calc(70px + var(--safe-top)) 4% calc(110px + var(--safe-bottom)); flex-direction: column; justify-content: center; text-align: center; overflow: hidden; }
#prompter.echo #echoView { display: flex; }
#prompter.echo #scroller, #prompter.echo #guide { display: none; }
#prompter.echo .hbtn-group.speed { display: none; }
#prompter.echo .voice-status { display: inline; }
.echo-only { display: none; }
#prompter.echo .echo-only { display: inline-flex; }
.echo-prev, .echo-next { opacity: .3; font-size: .45em; line-height: 1.3; font-weight: 500; }
.echo-prev { margin-bottom: 1em; }
.echo-next { margin-top: 1em; }
.echo-cur { font-weight: 600; line-height: 1.3; transition: color .2s; }
#prompter.echo-speaking .echo-cur { color: var(--accent); }
#prompter.echo-listening .echo-cur .ew { opacity: .55; }
#prompter.echo-listening .echo-cur .ew.hit { opacity: 1; color: var(--accent); }
.echo-count { position: absolute; top: calc(44px + var(--safe-top)); left: 0; right: 0; font-size: 14px; color: #888; font-weight: 500; }
.echo-empty { color: #888; font-size: .5em; }
.echo-heard { position: absolute; bottom: calc(100px + var(--safe-bottom)); left: 0; right: 0; font-size: 15px; color: #888; font-weight: 500; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; }
#echoView { font-size: inherit; }
.echo-settings { margin-top: 14px; border-top: 1px solid #000; padding-top: 8px; }
.echo-settings summary { cursor: pointer; font-size: 14px; color: var(--muted); margin-bottom: 4px; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 4; transition: opacity .25s; }
#hud.hidden { opacity: 0; }
.hud-top, .hud-bottom {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; pointer-events: auto;
}
.hud-top { top: 0; padding-top: calc(10px + var(--safe-top)); background: linear-gradient(rgba(0,0,0,.7), transparent); }
.hud-bottom { bottom: 0; justify-content: center; padding-bottom: calc(12px + var(--safe-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75)); }
#hud.hidden .hud-top, #hud.hidden .hud-bottom { pointer-events: none; }
.hud-title { flex: 1; text-align: center; color: #ccc; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbtn {
  border: 0; border-radius: 50%; width: 44px; height: 44px;
  background: rgba(255,255,255,.14); color: #fff; font-size: 17px; cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: inline-flex; align-items: center; justify-content: center;
}
.hbtn:active { background: rgba(255,255,255,.3); }
.hbtn.big { width: 62px; height: 62px; font-size: 26px; background: var(--accent); color: #000; }
.hbtn-group { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.1); border-radius: 30px; padding: 3px; }
.hbtn-group .hbtn { width: 38px; height: 38px; background: transparent; }
.hval { min-width: 26px; text-align: center; font-weight: 700; font-size: 15px; color: #fff; }

#progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.12); z-index: 6; }
#progress i { display: block; height: 100%; width: 0; background: var(--accent); }

/* Όσο είναι ανοιχτό το panel ρυθμίσεων, η σκηνή στενεύει ώστε το κείμενο να μένει ορατό */
@media (min-width: 720px) {
  #prompter.settings-open #stage,
  #prompter.settings-open .hud-top,
  #prompter.settings-open .hud-bottom,
  #prompter.settings-open #progress { right: 360px; }
}

/* Settings panel */
#settings {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100%); z-index: 7;
  background: var(--panel); color: var(--text); overflow-y: auto;
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  box-shadow: -8px 0 30px rgba(0,0,0,.5);
}
.settings-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.settings-head strong { flex: 1; }
.settings-note { color: var(--muted); font-size: 12px; }
#settings .reset { width: 100%; margin-top: 14px; border: 1px solid var(--panel2); }
#settings label { display: block; margin: 12px 0 4px; font-size: 14px; color: var(--muted); }
#settings label output { float: right; color: var(--text); font-weight: 600; }
#settings input[type=range] { width: 100%; margin-top: 6px; accent-color: var(--accent); }
#settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; font-size: 14px; }
#settings .row .chk { margin: 0; color: var(--text); display: flex; align-items: center; gap: 6px; }
#settings .row input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
#settings select { background: var(--panel2); border: 0; border-radius: 8px; padding: 7px 10px; }
.keys { color: var(--muted); font-size: 12px; line-height: 1.7; margin-top: 18px; }
.keys b { color: var(--text); background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-weight: 600; }

@media (max-width: 600px) {
  .bar .lbl { display: none; }
  .bar .btn.ghost { padding: 9px 8px; font-size: 18px; }
}
@media (max-width: 520px) {
  .hbtn { width: 40px; height: 40px; }
  .hbtn.big { width: 56px; height: 56px; }
  #btnFullscreen { display: none; }
}
