:root {
  --bg: #0c0c10;
  --bg-elevated: #15151c;
  --fg: #f4f1ea;
  --fg-dim: #8a8780;
  --fg-faint: #4a4842;
  --accent: #c9a45c;
  --accent-dim: #8a6e3a;
  --orig: #c9a45c;
  --tr: #f4f1ea;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino,
           Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Topbar ─────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
  border-bottom: 1px solid var(--bg-elevated);
  background: var(--bg);
}

.title-block {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  min-width: 0;
}

.title-block h1 {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#opera-subtitle {
  font-size: 0.8rem;
  white-space: nowrap;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

select, button {
  font: inherit;
  color: var(--fg);
  background: var(--bg-elevated);
  border: 1px solid #25252e;
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}
select:hover, button:hover { border-color: var(--accent-dim); }
select:focus, button:focus { outline: 2px solid var(--accent-dim); outline-offset: 1px; }

.chip {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--fg-dim);
  background: var(--bg-elevated);
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  border: 1px solid #25252e;
}
.chip.shifted { color: var(--accent); border-color: var(--accent-dim); }

.iconbtn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}
.iconbtn.primary {
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.05rem;
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--bg);
}
.iconbtn.primary:hover { background: var(--accent); border-color: var(--accent); }

.muted { color: var(--fg-dim); }

/* ── Stage layout (landscape-first) ─────────────── */

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
}

/* ── Surtitles strip ────────────────────────────── */

.surtitles {
  flex: 1 1 auto;
  padding: 2rem 2rem 4rem;
  background: var(--bg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
}

.line {
  width: 100%;
  max-width: 80ch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  transition: opacity 200ms ease;
}

.line .speaker {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
  text-transform: uppercase;
  font-family: var(--sans);
  min-height: 0.9rem;
}
.line .speaker:empty { display: none; }

.line .orig {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.35rem;
  line-height: 1.35;
  color: var(--orig);
  margin: 0;
  white-space: pre-wrap;
}

.line .tr {
  font-family: var(--serif);
  font-size: 2.4rem;
  line-height: 1.3;
  color: var(--tr);
  margin: 0;
  white-space: pre-wrap;
}

.line-current { opacity: 1; }
.line-prev, .line-next {
  opacity: 0.32;
}
.line-prev .orig, .line-next .orig { font-size: 1.05rem; }
.line-prev .tr,   .line-next .tr   { font-size: 1.45rem; }

/* Compact mode (default): only the current line is visible. */
.line-prev, .line-next { display: none; }
body.expanded .line-prev,
body.expanded .line-next { display: flex; }

/* When no libretto loaded, hide the surtitles strip entirely. */
body:not(.has-libretto) .surtitles { display: none; }

/* ── Bottom bar (scrubber + timecodes) ──────────── */

.bottombar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.4rem 0.9rem;
  background: var(--bg);
  border-top: 1px solid var(--bg-elevated);
}

.timecode {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  min-width: 5ch;
  text-align: center;
}

#scrubber {
  flex: 1 1 auto;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--bg);
  transition: background 150ms;
}
#scrubber:hover::-webkit-slider-thumb { background: var(--accent); }
#scrubber::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--bg);
}
#scrubber:hover::-moz-range-thumb { background: var(--accent); }

/* ── Help dialog ────────────────────────────────── */

dialog {
  border: 1px solid #25252e;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--fg);
  padding: 1.5rem 1.8rem;
  max-width: 26rem;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }

dialog h2 {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0 0 0.8rem 0;
}

dialog table { border-collapse: collapse; width: 100%; }
dialog td {
  padding: 0.25rem 0.5rem 0.25rem 0;
  font-size: 0.9rem;
  vertical-align: top;
}
dialog td:first-child { white-space: nowrap; color: var(--fg-dim); }

kbd {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.78rem;
  background: #1c1c25;
  border: 1px solid #2a2a35;
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0.05rem 0.4rem;
  color: var(--fg);
}

.dialog-hint {
  font-size: 0.8rem;
  margin: 1rem 0 1rem 0;
  line-height: 1.4;
}

dialog form { text-align: right; }
dialog form button {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--bg);
  padding: 0.4rem 1rem;
}
dialog form button:hover { background: var(--accent); }

/* ── Narrow / portrait fallback ─────────────────── */

@media (max-aspect-ratio: 1/1) {
  .surtitles { padding: 1rem 1rem 1.4rem; }
  .line .tr { font-size: 1.25rem; }
  .line .orig { font-size: 0.9rem; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.6rem 0.8rem; }
  .topbar-controls { flex-wrap: wrap; }
}
