/* Prompter — warstwa UI. Zero frameworków, zero webfontów, system font stack. */

:root {
  --bg: #000000;
  --fg: #EDEDEA;
  --fg-dim: rgba(237, 237, 234, .45);
  --fg-faint: rgba(237, 237, 234, .6);
  --accent: #FFB300;
  --accent-fg: #000000;
  --surface: rgba(255, 255, 255, .06);
  --surface-strong: rgba(255, 255, 255, .14);
  --border: rgba(255, 255, 255, .16);
  --overlay-bg: rgba(0, 0, 0, .72);
  --dot-green: #2ECC71;
  --dot-red: #E5484D;
  --dot-grey: #8A8A85;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --touch: 44px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

/* [hidden] na <svg> nie zawsze daje display:none (kwirk silników wobec
   elementów SVG osadzonych w HTML) — wymuszamy jawnie. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
}

textarea {
  font-family: inherit;
}

/* ---------- Ekrany ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
}

/* ---------- Ekran edycji ---------- */

.edit-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  padding: max(var(--space-3), env(safe-area-inset-top)) max(var(--space-4), env(safe-area-inset-right)) var(--space-2) max(var(--space-4), env(safe-area-inset-left));
}

.app-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-faint);
}

.pill-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  border-radius: var(--radius-pill);
  min-width: var(--touch);
  min-height: 36px;
  padding: 0 var(--space-3);
  cursor: pointer;
}

.pill-btn:focus-visible {
  outline: 2px solid var(--fg-faint);
  outline-offset: 2px;
}

.edit-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  padding: 0 max(var(--space-3), env(safe-area-inset-right)) 0 max(var(--space-3), env(safe-area-inset-left));
}

#text-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #0B0B0B;
  color: var(--fg);
  font-size: 16px;
  line-height: 1.5;
  padding: var(--space-4);
}

#text-input::placeholder {
  color: var(--fg-dim);
}

#text-input:focus-visible {
  outline: 2px solid var(--fg-faint);
  outline-offset: -1px;
}

.edit-bottombar {
  flex: 0 0 auto;
  padding: var(--space-3) max(var(--space-4), env(safe-area-inset-right)) max(var(--space-3), env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
}

.edit-bottombar-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  min-height: var(--touch);
  padding: 0 var(--space-4);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn:focus-visible {
  outline: 2px solid var(--fg-faint);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.word-count {
  margin-inline-start: auto;
  font-size: 13px;
  color: var(--fg-faint);
  white-space: nowrap;
}

.import-feedback {
  margin: 0;
  min-height: 0;
}

.import-feedback:not(:empty) {
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--dot-red);
}

/* ---------- Ekran promptera ---------- */

#stage {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
}

#script {
  max-width: 26ch;
  margin-inline: auto;
  padding: 45vh 6vw 60vh;
  font-size: calc(clamp(26px, 6.5vmin, 64px) * var(--fs-scale, 1));
  line-height: 1.45;
  text-align: left;
}

#script p {
  margin: 0 0 1em;
}

#script span.read {
  opacity: .45;
}

#script span.cur {
  color: #fff;
}

/* ---------- Overlay ---------- */

.overlay-bar {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 1;
  transition: opacity .18s ease;
}

.screen-prompt-overlay-hidden .overlay-bar {
  opacity: 0;
  pointer-events: none;
}

.overlay-top {
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: max(var(--space-2), env(safe-area-inset-top)) max(var(--space-3), env(safe-area-inset-right)) var(--space-2) max(var(--space-3), env(safe-area-inset-left));
}

.overlay-bottom {
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) max(var(--space-3), env(safe-area-inset-right)) max(var(--space-2), env(safe-area-inset-bottom)) max(var(--space-3), env(safe-area-inset-left));
}

.overlay-row-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.overlay-row-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

/* ---------- Przyciski ikonowe ---------- */

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg);
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:focus-visible {
  outline: 2px solid var(--fg-faint);
  outline-offset: 2px;
}

.icon-btn-sm {
  min-width: 40px;
  min-height: 40px;
}

.icon {
  width: 22px;
  height: 22px;
}

#btn-restart {
  grid-column: 1;
  justify-self: start;
}

.play-btn {
  grid-column: 2;
  justify-self: center;
  appearance: none;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-fg);
  width: 64px;
  height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.play-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.play-btn .icon {
  width: 26px;
  height: 26px;
}

.play-btn .icon-play {
  fill: currentColor;
  stroke: currentColor;
}

.play-btn .icon-pause {
  fill: currentColor;
  stroke: none;
}

/* ---------- Status mowy ---------- */

.speech-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--fg-faint);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-grey);
  flex: 0 0 auto;
}

.speech-status[data-state="on"] .status-dot {
  background: var(--dot-green);
  animation: pt-pulse 1.6s ease-in-out infinite;
}

.speech-status[data-state="denied"] .status-dot,
.speech-status[data-state="unsupported"] .status-dot {
  background: var(--dot-red);
}

@keyframes pt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------- Segmentowany przełącznik trybu ---------- */

.segmented {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
}

.segmented-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg-faint);
  font-size: 14px;
  font-weight: 600;
  min-height: 38px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.segmented-btn.is-active {
  background: var(--surface-strong);
  color: #fff;
}

.segmented-btn:focus-visible {
  outline: 2px solid var(--fg-faint);
  outline-offset: 2px;
}

/* ---------- Prędkość ---------- */

.speed-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.speed-value {
  min-width: 60px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-faint);
}

/* ---------- Rozmiar czcionki ---------- */

.font-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.font-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg);
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.font-btn:focus-visible {
  outline: 2px solid var(--fg-faint);
  outline-offset: 2px;
}

.font-glyph {
  font-weight: 600;
  line-height: 1;
}

.font-glyph-sm {
  font-size: 13px;
}

.font-glyph-lg {
  font-size: 20px;
}

/* ---------- Landscape: te same paski, niższe ---------- */

@media (orientation: landscape) and (max-height: 520px) {
  .overlay-top {
    padding-top: max(var(--space-1), env(safe-area-inset-top));
    padding-bottom: var(--space-1);
  }

  .overlay-bottom {
    padding-top: var(--space-1);
    padding-bottom: max(var(--space-1), env(safe-area-inset-bottom));
    gap: var(--space-1);
  }

  .play-btn {
    width: 52px;
    height: 52px;
  }

  #script {
    padding: 30vh 6vw 40vh;
  }
}
