:root {
  --bg: #f7f5f2;
  --card-bg: #ffffff;
  --text: #241f1c;
  --muted: #7a7168;
  --border: #e5ded4;
  --accent: #8d2f2f;
  --accent-2: #c96a3d;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Georgia", "Iowan Old Style", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--accent);
  color: white;
}
.topbar h1 { margin: 0; cursor: pointer; }
.logo { display: flex; align-items: center; }
.logo img { height: 52px; width: auto; display: block; }
.breadcrumb { font-size: 0.9rem; opacity: 0.85; }
.user-bar { display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem; }
.user-bar button.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.login-card { max-width: 380px; margin: 3rem auto 0; }
.login-card form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.login-card input { padding: 0.55rem 0.7rem; font-size: 1rem; }
.breadcrumb-link { margin: 0 0 0.75rem; }
.breadcrumb-link a { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.breadcrumb-link a:hover { text-decoration: underline; }
.role-badge {
  display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 10px;
  background: var(--accent-2); color: white; margin-left: 0.5rem; vertical-align: middle;
}
.project-title-row { display: flex; align-items: center; gap: 0.75rem; }
.project-title-row h2 { margin: 0; }

main { max-width: min(1100px, 94vw); margin: 0 auto; padding: 1.5rem; }
#view-rehearsal.view, #view-script-editor.view { max-width: none; }
main:has(#view-rehearsal:not(.hidden)) { max-width: min(1500px, 96vw); }
main:has(#view-script-editor:not(.hidden)) { max-width: min(1700px, 97vw); }

.view.hidden { display: none; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin-top: 0; }
.hint { color: var(--muted); font-size: 0.9rem; }

button {
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}
button.primary, a.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.secondary, a.secondary { background: var(--accent-2); color: white; border-color: var(--accent-2); }
button.small, a.small { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
a.primary, a.secondary { text-decoration: none; display: inline-block; }

input[type="text"], input[type="file"], select, textarea {
  font-family: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: white;
  color: var(--text);
}

#upload-btn { margin-left: 0.75rem; }
.status { color: var(--muted); }
.status.error { color: var(--accent); font-weight: bold; }

.script-list { list-style: none; padding: 0; margin: 0; }
.script-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
  flex-wrap: wrap;
}
.script-list li:last-child { border-bottom: none; }
.script-list .script-title { font-weight: bold; }
.script-list .script-title.clickable { cursor: pointer; }
.script-list .script-meta { color: var(--muted); font-size: 0.85rem; }
.script-list .delete-x { color: var(--muted); background: none; border: none; }
.script-actions { display: flex; align-items: center; gap: 0.4rem; }

.add-member-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.add-member-row select, .add-member-row input { flex: 1; min-width: 140px; }

button.danger { background: white; color: var(--accent); border-color: var(--accent); }
button.danger:hover:not(:disabled) { background: var(--accent); color: white; }

.admin-users-list { display: flex; flex-direction: column; gap: 0.9rem; }
.admin-user-row { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.admin-user-row:last-child { border-bottom: none; }
.admin-user-header { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.admin-user-name { flex: 1; min-width: 140px; font-weight: bold; }
.admin-user-password { min-width: 140px; }
.admin-user-projects { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.5rem; }
.admin-project-checkbox { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--bg);
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.title-input { flex: 1; font-size: 1.2rem; font-weight: bold; min-width: 200px; }
.editor-actions { display: flex; gap: 0.5rem; }
.unpublished-badge {
  background: #f7e2cf; color: var(--accent); border: 1px solid var(--accent-2);
  border-radius: 20px; padding: 0.2rem 0.7rem; font-size: 0.8rem; font-weight: bold;
}
.unsaved-badge {
  background: #fde3e3; color: #b3261e; border: 1px solid #b3261e;
  border-radius: 20px; padding: 0.2rem 0.7rem; font-size: 0.8rem; font-weight: bold;
}

.roles-editor { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.75rem; }
.role-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.25rem 0.5rem;
}
.role-chip .swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.role-chip input { border: none; width: 110px; padding: 0.1rem 0.3rem; }
.role-chip .remove-role { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0 0.2rem; }

.rich-toolbar-card { position: sticky; top: 4.3rem; z-index: 6; padding: 0.6rem 0.9rem; }
.rich-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.rich-toolbar button[data-cmd] { min-width: 2.2rem; font-family: Georgia, serif; }
.toolbar-color-label {
  display: flex; align-items: center; gap: 0.2rem; font-size: 0.85rem;
  border: 1px solid var(--border); border-radius: 6px; padding: 0.2rem 0.4rem; cursor: pointer;
}
.toolbar-color-label input[type="color"] { width: 22px; height: 22px; border: none; padding: 0; background: none; cursor: pointer; }

.editor-layout { display: flex; align-items: flex-start; gap: 1.5rem; }
.editor-scene-sidebar {
  width: 210px; flex-shrink: 0;
  position: sticky; top: 7.8rem;
  z-index: 5;
  max-height: calc(100vh - 8.5rem);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.3rem;
  padding-right: 0.5rem;
}
.editor-scene-sidebar h4 { margin: 0 0 0.3rem; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.editor-scene-sidebar button {
  text-align: left; border: 1px solid var(--border); background: white;
  border-radius: 6px; padding: 0.45rem 0.6rem; font-size: 0.85rem; cursor: pointer;
  line-height: 1.3;
}
.editor-scene-sidebar button:hover { border-color: var(--accent-2); }
.editor-scene-sidebar button.active { border-color: var(--accent); background: #f3e9df; font-weight: bold; }
.editor-main { flex: 1; min-width: 0; }

.lines-editor {
  background: white; border: 1px solid var(--border); border-radius: 8px;
  padding: 1.5rem 2rem; line-height: 1.6;
  max-width: 900px; margin: 0 auto;
}
.doc-line { position: relative; padding: 0.25rem 0 0.25rem 2.1rem; border-radius: 4px; }
.doc-line:hover, .doc-line:focus-within { background: #faf8f5; }
.doc-line.type-heading { text-align: center; font-weight: bold; font-size: 1.15rem; margin-top: 1.3rem; }
.doc-line.type-direction { text-align: center; font-style: italic; color: var(--muted); }
.doc-line.type-direction .editor-line-body, .doc-line.type-heading .editor-line-body { display: inline-block; min-width: 2rem; }
.doc-line.type-dialogue { display: flex; align-items: baseline; gap: 0.7rem; }
.doc-line .speaker-select-inline {
  border: none; background: none; appearance: none; -webkit-appearance: none;
  font-family: inherit; font-weight: bold; font-size: inherit; padding: 0; cursor: pointer;
  flex: 0 0 auto; width: 8rem; text-align: left; text-overflow: ellipsis;
}
.doc-line .editor-line-body { display: inline; min-width: 1.5rem; }
.doc-line.type-dialogue .editor-line-body { display: block; flex: 1 1 auto; text-align: justify; }
.doc-line .editor-line-body:focus { outline: none; }
.doc-line:focus-within { box-shadow: inset 2px 0 0 var(--accent-2); }
.doc-line .direction { color: var(--muted); font-style: italic; }
.direction { color: var(--muted); font-style: italic; }
.doc-line .line-controls {
  position: absolute; left: 0; top: 0.25rem; display: flex; gap: 0.15rem;
  opacity: 0; transition: opacity 0.1s;
}
.doc-line:hover .line-controls, .doc-line:focus-within .line-controls { opacity: 1; }
.doc-line .type-select-inline {
  border: 1px solid var(--border); background: white; border-radius: 4px;
  font-size: 0.65rem; color: var(--muted); cursor: pointer; padding: 0 0.1rem; width: 2.1rem;
}
.doc-line .del-line-inline {
  border: none; background: none; color: var(--muted); cursor: pointer; font-size: 0.7rem; padding: 0 0.15rem;
}
.doc-line .del-line-inline:hover { color: var(--accent); }

@media (max-width: 700px) {
  .editor-layout { flex-direction: column; }
  .editor-scene-sidebar {
    width: 100%; flex-direction: row; overflow-x: auto; overflow-y: visible;
    position: static; max-height: none; padding-right: 0; padding-bottom: 0.5rem;
  }
  .editor-scene-sidebar button { flex-shrink: 0; }
}

.my-role-list { display: flex; flex-direction: column; gap: 0.5rem; }
.my-role-list label {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.my-role-list .swatch { width: 14px; height: 14px; border-radius: 50%; }

.voice-assign { display: flex; flex-direction: column; gap: 0.6rem; }
.voice-assign .voice-row { display: flex; align-items: center; gap: 0.6rem; }
.voice-assign .voice-row .role-name { min-width: 140px; font-weight: bold; }
.voice-assign select { flex: 1; }

.scene-picker { display: flex; flex-direction: column; gap: 0.4rem; }
.scene-picker label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }

#start-rehearsal-btn { display: block; margin: 0 auto; font-size: 1.1rem; padding: 0.7rem 2rem; }

.rehearsal-layout { display: flex; align-items: flex-start; gap: 1.5rem; }
.rehearsal-scene-sidebar {
  width: 210px; flex-shrink: 0;
  position: sticky; top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.3rem;
  padding-right: 0.5rem;
}
.rehearsal-scene-sidebar h4 { margin: 0 0 0.3rem; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.rehearsal-scene-sidebar button {
  text-align: left; border: 1px solid var(--border); background: white;
  border-radius: 6px; padding: 0.45rem 0.6rem; font-size: 0.85rem; cursor: pointer;
  line-height: 1.3;
}
.rehearsal-scene-sidebar button.active { border-color: var(--accent); background: #f3e9df; font-weight: bold; }
.rehearsal-scene-sidebar button.has-my-role { border-left: 4px solid var(--accent-2); padding-left: calc(0.6rem - 3px); }
.rehearsal-scene-sidebar button.has-my-role.active { background: #f7e2cf; }
.rehearsal-main { flex: 1; min-width: 0; }

@media (max-width: 700px) {
  .rehearsal-layout { flex-direction: column; }
  .rehearsal-scene-sidebar {
    width: 100%; flex-direction: row; overflow-x: auto; overflow-y: visible;
    position: static; max-height: none; padding-right: 0; padding-bottom: 0.5rem;
  }
  .rehearsal-scene-sidebar button { flex-shrink: 0; }
}

.rehearsal-toolbar {
  position: sticky; top: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem;
  background: var(--bg); padding: 0.75rem 0; border-bottom: 1px solid var(--border);
  margin-bottom: 1rem; z-index: 5;
}
.icon-btn { font-size: 1.1rem; padding: 0.4rem 0.7rem; }
.rate-label, .toggle-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.mic-blocked-hint { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--accent); font-weight: bold; }
.rehearsal-status { margin-left: auto; font-weight: bold; color: var(--accent); }

.rehearsal-script { display: flex; flex-direction: column; gap: 0.7rem; padding-bottom: 3rem; max-width: 900px; margin: 0 auto; width: 100%; }
.rline { position: relative; padding: 0.6rem 0.9rem; border-radius: 8px; border: 1px solid transparent; }
.rline.direction { font-style: italic; color: var(--muted); text-align: center; border: none; }
.rline.heading { font-weight: bold; text-align: center; font-size: 1.1rem; margin-top: 1rem; border: none; }
.rline-content { display: flex; align-items: baseline; gap: 0.7rem; }
.rline.dialogue .speaker-name { font-weight: bold; flex: 0 0 auto; width: 8rem; text-align: left; }
.rline.dialogue .line-text { flex: 1 1 auto; text-align: justify; }
.rline.dialogue.current { border-color: var(--accent); background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.rline.dialogue.mine { background: #f3e9df; }
.rline.dialogue.mine.hidden-text .line-text { filter: blur(6px); user-select: none; }
.rline.dialogue.past { opacity: 0.45; }
.rline.dialogue { cursor: pointer; transition: background-color 0.1s; }
.rline.dialogue:hover { background: #ece4da; }
.rline.dialogue.current:hover { background: #fff; }

.rehearsal-script.show-changes .rline.changed-line { border-left: 4px solid #e9c46a; background: #fdf6e3; }
.rehearsal-script.show-changes .rline.changed-line.dialogue.mine { background: #f7ecd6; }
.rehearsal-script.show-changes .rline.changed-line.current { background: #fff; }

.line-note-wrap { margin-top: 0.35rem; }
.line-note-btn {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 0.85rem; padding: 0.1rem 0.2rem; opacity: 0.6;
}
.line-note-btn.has-note { opacity: 1; }
.rline:hover .line-note-btn { opacity: 1; }
.line-note {
  margin-top: 0.2rem; padding: 0.4rem 0.6rem; border-radius: 6px;
  background: #e4eef2; border-left: 3px solid #457b9d; color: var(--text);
  font-size: 0.85rem; cursor: text; white-space: pre-wrap;
}
.line-note-input {
  margin-top: 0.2rem; width: 100%; min-height: 2.4rem; font-size: 0.85rem;
  border-left: 3px solid #457b9d; border-radius: 6px;
}

/* ---------------- MOBILE (actor-facing views) ----------------
   Kept as one block at the end of the file so these overrides win the
   cascade against same-specificity rules defined earlier (e.g.
   .rline.dialogue .line-text). Script editor/admin panel are intentionally
   left untouched - director/admin tooling is used at a desk, not on a phone. */
@media (max-width: 700px) {
  /* Breadcrumb squeezed logo/user-bar into overlapping text on narrow
     screens - every view already has its own way back (logo click, or an
     explicit "← ..." link), so it's safe to drop here. */
  .breadcrumb { display: none; }
  .topbar { flex-wrap: wrap; row-gap: 0.4rem; }
  .user-bar { flex-wrap: wrap; }

  main { padding: 1rem; }

  /* Bigger tap targets for the rehearsal transport controls. */
  .icon-btn { min-width: 44px; min-height: 44px; font-size: 1.3rem; padding: 0.5rem; }

  /* role-name + voice select + "Anhören" no longer fit in one row on a phone. */
  .voice-assign .voice-row { flex-wrap: wrap; }
  .voice-assign .voice-row .role-name { flex-basis: 100%; }

  /* An 8rem speaker column leaves too little room for the line itself and
     forces ugly justified text in a narrow strip - stack speaker above line
     instead, which is what actually matters while reading during a rehearsal. */
  .rline-content { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
  .rline.dialogue .speaker-name { width: auto; }
  .rline.dialogue .line-text { text-align: left; }
}
