/* ===================================================================
   Театр Рыбалова — Main Stylesheet
   A warm, professional theme for theater actors.
   =================================================================== */

/* --- Custom Properties --- */
:root {
  /* Colors */
  --color-bg: #faf9f6;
  --color-bg-alt: #f4f1ec;
  --color-surface: #ffffff;
  --color-text: #2c2c2c;
  --color-text-muted: #6b6b6b;
  --color-text-light: #999;

  --color-brown-dark: #5c2d0e;
  --color-brown: #8b4513;
  --color-brown-light: #b87333;
  --color-brown-bg: #faf5ef;

  --color-navy: #1a4a7a;
  --color-navy-light: #2a6ab0;
  --color-navy-bg: #edf3fa;

  --color-purple: #7b5ea7;
  --color-purple-light: #9a7cc7;
  --color-purple-bg: #f5f0fa;

  --color-gold: #7a5f00;
  --color-gold-light: #a88a00;
  --color-gold-bg: #fdf8e8;

  --color-green: #2d7a3a;
  --color-green-bg: #ecf7ee;

  --color-red: #b33030;
  --color-red-bg: #fdeaea;

  --color-orange: #a85d00;
  --color-orange-bg: #fff5e6;

  --color-border: #e5e0d8;
  --color-border-light: #f0ece6;
  --color-shadow: rgba(92, 45, 14, 0.08);
  --color-shadow-strong: rgba(92, 45, 14, 0.15);

  /* Typography */
  --font-serif: Georgia, "Times New Roman", "Noto Serif", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", Consolas, monospace;

  --text-xs: clamp(0.7rem, 0.65rem + 0.2vw, 0.75rem);
  --text-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
  --text-base: clamp(0.95rem, 0.9rem + 0.25vw, 1.0625rem);
  --text-lg: clamp(1.05rem, 1rem + 0.3vw, 1.2rem);
  --text-xl: clamp(1.2rem, 1.1rem + 0.5vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 1.3rem + 0.8vw, 2rem);
  --text-3xl: clamp(1.8rem, 1.5rem + 1.2vw, 2.5rem);

  --lh-tight: 1.3;
  --lh-normal: 1.7;
  --lh-relaxed: 1.85;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 56px;
  --max-content: 780px;
  --max-page: 1400px;

  /* Borders */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}


/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-brown);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--color-brown-dark); }
a:focus-visible {
  outline: 2px solid var(--color-brown);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:focus-visible {
  outline: 2px solid var(--color-brown);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

input, select, textarea {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-brown);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.12);
}

img { max-width: 100%; display: block; }

::selection {
  background: rgba(139, 69, 19, 0.15);
  color: var(--color-brown-dark);
}


/* --- Header / Navigation --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 4px var(--color-shadow);
}

.nav {
  display: flex;
  align-items: center;
  max-width: var(--max-page);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: var(--header-height);
  gap: var(--space-md);
}

.nav__logo {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-brown-dark);
  font-weight: 600;
  font-size: var(--text-sm);
  white-space: nowrap;
}
.nav__logo:hover { color: var(--color-brown); }

/* Right side: play title and menu slot */
.nav__play-info {
  flex: 1;
  text-align: right;
  font-weight: 700;
  color: var(--color-brown-dark);
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: var(--space-sm);
}
.nav__menu-slot {
  flex-shrink: 0;
  min-width: 28px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.nav__icon { flex-shrink: 0; }

.nav__links {
  display: flex;
  gap: var(--space-xs);
}

.nav__link {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}
.nav__link:hover {
  color: var(--color-brown-dark);
  background: var(--color-brown-bg);
}
.nav__link.active {
  color: var(--color-brown-dark);
  background: var(--color-brown-bg);
  font-weight: 600;
}

/* Burger menu (mobile) */
.nav__burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  padding: 6px;
}
.nav__burger span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--color-text);
  border-radius: 2px;
  transition: all var(--transition-fast);
}
.nav__burger[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.nav__burger[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}
.nav__burger[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

@media (max-width: 640px) {
  .nav__links {
    display: none;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-sm) var(--space-lg);
    box-shadow: 0 4px 12px var(--color-shadow);
  }
  .nav__links.open { display: flex; }
  .nav__burger { display: flex; }
}


/* --- Main Content --- */
.app-main {
  min-height: calc(100vh - var(--header-height));
}


/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 16px var(--color-shadow-strong);
  pointer-events: auto;
  animation: toast-in 0.3s ease forwards;
  max-width: 360px;
}
.toast.toast--success { border-left: 3px solid var(--color-green); }
.toast.toast--error   { border-left: 3px solid var(--color-red); }
.toast.toast--info    { border-left: 3px solid var(--color-navy); }
.toast.toast--warning { border-left: 3px solid var(--color-orange); }

.toast.leaving {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(12px) scale(0.96); }
}


/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 540px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: var(--space-xl);
  position: relative;
  animation: modal-in 0.25s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal__close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  font-size: 1.5rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}
.modal__close:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.modal__content h2 {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  color: var(--color-brown-dark);
  margin-bottom: var(--space-lg);
}


/* ===================================================================
   PAGE: Library
   =================================================================== */

.library {
  max-width: var(--max-page);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

.library__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.library__title {
  font-size: var(--text-2xl);
  color: var(--color-brown-dark);
}

.library__controls {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.library__search {
  width: clamp(200px, 30vw, 320px);
  padding-left: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m13 13-3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.7rem center;
}

.library__sort {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
}

/* Play Cards */
.play-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
}

.play-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  position: relative;
  overflow: hidden;
}
.play-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-brown), var(--color-gold-light));
  opacity: 0;
  transition: opacity var(--transition-normal);
}
.play-card:hover {
  border-color: var(--color-brown-light);
  box-shadow: 0 4px 16px var(--color-shadow);
  transform: translateY(-2px);
}
.play-card:hover::before { opacity: 1; }

.play-card__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-brown-dark);
  line-height: var(--lh-tight);
}

.play-card__author {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

.play-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: var(--space-sm);
}

.play-card__characters {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-text-light);
}

/* Status Badges */
.badge {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge--ready      { background: var(--color-green-bg); color: var(--color-green); }
.badge--processing { background: var(--color-orange-bg); color: var(--color-orange); }
.badge--created    { background: var(--color-bg-alt);    color: var(--color-text-muted); }
.badge--error      { background: var(--color-red-bg);    color: var(--color-red); }

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-muted);
}
.empty-state__icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.3;
}
.empty-state__title {
  font-size: var(--text-xl);
  color: var(--color-text);
  margin-bottom: var(--space-sm);
}
.empty-state__text {
  font-size: var(--text-base);
  max-width: 400px;
  margin: 0 auto;
  line-height: var(--lh-relaxed);
}
.empty-state__text a {
  color: var(--color-brown);
  text-decoration: underline;
  text-underline-offset: 2px;
}


/* ===================================================================
   PAGE: Reader
   =================================================================== */

.reader {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* --- Reader Toolbar: compact navigation row above text --- */
.reader__toolbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 6px var(--space-lg);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: relative;
  z-index: 30;
  flex-wrap: nowrap;
  min-height: 38px;
}

/* Inline toggle switch (compact, for toolbar) */
.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: 4px 8px;
  border-radius: 14px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.inline-toggle:hover { background: rgba(139, 69, 19, 0.05); }
.inline-toggle input { display: none; }
.inline-toggle__slider {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 16px;
  background: #d4cec4;
  border-radius: 16px;
  transition: background 0.2s;
}
.inline-toggle__slider::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.inline-toggle input:checked + .inline-toggle__slider {
  background: var(--color-brown);
}
.inline-toggle input:checked + .inline-toggle__slider::before {
  transform: translateX(12px);
}
.inline-toggle input:checked ~ .inline-toggle__label {
  color: var(--color-brown-dark);
  font-weight: 600;
}

.reader__play-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-brown-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}

.toolbar-spacer {
  flex: 1;
}

/* Act nav — minimal ‹ Д.1 › */
.act-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.act-nav__btn {
  font-size: 16px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
}
.act-nav__btn:hover { color: var(--color-brown); }
.act-nav__label {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  min-width: 24px;
  text-align: center;
}

.toolbar__act-select { display: none; }
.toolbar__act-select-deprecated {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  padding: 3px 24px 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%236b6b6b' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  max-width: 160px;
  flex-shrink: 0;
  transition: border-color var(--transition-fast);
}
.toolbar__act-select:hover,
.toolbar__act-select:focus {
  border-color: var(--color-brown);
  color: var(--color-brown-dark);
  outline: none;
}

/* Gear button */
.toolbar__gear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
  flex-shrink: 0;
  opacity: 0.7;
}
.toolbar__gear:hover {
  opacity: 1;
  color: var(--color-text-muted);
}
.toolbar__gear.active {
  background: var(--color-brown);
  color: #fff;
  border-radius: var(--radius-md);
}

/* --- Gear dropdown panel --- */
.toolbar__dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 4px 16px var(--color-shadow);
  padding: var(--space-md) var(--space-lg);
  z-index: 29;
  animation: dropdown-in 0.15s ease;
}
.toolbar__dropdown[hidden] { display: none; }

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.toolbar__section {
  margin-bottom: var(--space-md);
}
.toolbar__section:last-child { margin-bottom: 0; }

.toolbar__section--row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.toolbar__field--nav {
  display: flex;
  align-items: flex-end;
}

.toolbar__label {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-switch__slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d4cec4;
  border-radius: 20px;
  transition: background 0.2s;
}
.toggle-switch__slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-switch__slider {
  background: var(--color-brown);
}
.toggle-switch input:checked + .toggle-switch__slider::before {
  transform: translateX(16px);
}

/* Mode select in dropdown */
.toolbar__mode-select {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 6px 32px 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%235a4a3a' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 130px;
  transition: border-color var(--transition-fast);
}
.toolbar__mode-select:hover, .toolbar__mode-select:focus {
  border-color: var(--color-brown);
  outline: none;
}

/* Act/scene navigation select */
.toolbar__nav-select {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 6px 32px 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%235a4a3a' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 180px;
  max-width: 320px;
  transition: border-color var(--transition-fast);
}
.toolbar__nav-select:hover, .toolbar__nav-select:focus {
  border-color: var(--color-brown);
  outline: none;
}
.toolbar__nav-select option.act-option {
  font-weight: 700;
  color: var(--color-brown-dark);
}
.toolbar__nav-select option.scene-option {
  font-weight: 400;
  color: var(--color-text);
}

/* Search input in dropdown */
.toolbar__search-input {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  min-width: 160px;
  max-width: 280px;
  transition: border-color var(--transition-fast);
}
.toolbar__search-input:focus {
  border-color: var(--color-brown);
  outline: none;
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.12);
}

/* Action buttons row */
.toolbar__actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  padding-top: var(--space-sm);
  border-top: 1px solid var(--color-border-light);
}

.toolbar__action-btn {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.toolbar__action-btn:hover {
  border-color: var(--color-brown);
  color: var(--color-brown);
  background: var(--color-brown-bg);
}
.toolbar__action-btn.active {
  background: #2e7d32;
  color: #fff;
  border-color: #2e7d32;
}
.toolbar__action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.toolbar__action-btn svg {
  flex-shrink: 0;
}

/* Character filter in dropdown */
.char-filter {
  flex-shrink: 1;
  min-width: 0;
}

.char-select {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 6px 32px 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%235a4a3a' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 140px;
  max-width: 220px;
  transition: border-color var(--transition-fast);
}
.char-select:hover, .char-select:focus {
  border-color: var(--color-brown);
  outline: none;
}

/* Role navigation arrows */
.role-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.role-nav__btn {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.role-nav__btn:hover { background: var(--color-navy); color: #fff; border-color: var(--color-navy); }
.role-nav__info {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  min-width: 50px;
  text-align: center;
}

/* Role highlight when jumping */
.block--role-highlight {
  animation: role-highlight 2s ease;
}
@keyframes role-highlight {
  0%   { background: rgba(26, 74, 122, 0.15); box-shadow: inset 4px 0 0 var(--color-navy); }
  100% { background: transparent; box-shadow: none; }
}

/* --- Reader Text Area --- */
.reader__content {
  overflow-y: auto;
  padding: var(--space-xl) var(--space-2xl);
  scroll-behavior: smooth;
  scrollbar-width: thin;
}

/* Compare mode: split layout */
.reader__content--compare {
  display: flex;
  gap: 0;
  padding: 0;
  overflow: hidden;
}
.reader__content--compare .reader__scan-panel {
  flex: 0 0 50%;
  overflow-y: auto;
  border-right: 3px solid var(--color-border);
  background: #f0ece4;
  display: flex;
  flex-direction: column;
}
.reader__content--compare .reader__text {
  flex: 0 0 50%;
  overflow-y: auto;
  padding: var(--space-lg) var(--space-xl);
  max-width: none;
}

/* Scan panel */
.reader__scan-panel { display: none; }
.reader__content--compare .reader__scan-panel { display: flex !important; }

.scan-panel__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  background: #e8e2d8;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.scan-panel__nav button {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  cursor: pointer;
  font-size: var(--text-sm);
}
.scan-panel__nav button:hover { background: var(--color-brown); color: #fff; }
.scan-panel__page { font-size: var(--text-sm); color: var(--color-text-muted); min-width: 80px; text-align: center; }

.scan-panel__img-wrap {
  flex: 1;
  overflow: auto;
  padding: var(--space-sm);
  display: flex;
  justify-content: center;
}
.scan-panel__img {
  max-width: 100%;
  height: auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: zoom-in;
  transition: transform 0.2s;
  transform-origin: top left;
}
.scan-panel__img.zoomed {
  max-width: none;
  cursor: zoom-out;
}
.scan-panel__img-wrap {
  touch-action: pan-x pan-y pinch-zoom;
}

/* Compare button active state */
.reader__compare-btn {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.reader__compare-btn:hover { border-color: var(--color-brown); }
.reader__compare-btn.active {
  background: var(--color-brown);
  color: #fff;
  border-color: var(--color-brown);
}

.reader__text {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 var(--space-xl);
}

/* Block types in reader */
.block { margin-bottom: var(--space-lg); }

.block--header {
  text-align: center;
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-brown-dark);
  padding: var(--space-xl) 0 var(--space-md);
  border-bottom: 2px solid var(--color-border-light);
  margin-bottom: var(--space-xl);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.block--scene-title {
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-gold);
  padding: var(--space-lg) 0 var(--space-sm);
  scroll-margin-top: calc(var(--header-height) + 60px);
}

.block--scene-description {
  text-align: center;
  font-style: italic;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  max-width: 600px;
  margin: 0 auto var(--space-lg);
  line-height: var(--lh-relaxed);
}

.block--dialogue {
  margin-bottom: var(--space-xl);
  text-align: center;
}

.dialogue__speaker-row {
  text-align: center;
  margin-bottom: var(--space-xs);
}
.dialogue__speaker {
  position: relative;
  display: inline-block;
  font-weight: 700;
  color: var(--color-navy);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: var(--text-base);
}
.dialogue__reply-num {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 10px;
  font-family: var(--font-sans);
  font-size: 10px;
  color: var(--color-border);
  font-weight: 400;
  white-space: nowrap;
}

.dialogue__original-direction {
  font-style: italic;
  color: #8a7d6b;
  margin-bottom: var(--space-xs);
}

.dialogue__stage-direction {
  font-style: italic;
  color: #8b7ea8;
  margin-bottom: var(--space-sm);
}

/* Auto-highlight () and [] anywhere in text */
.hl-paren {
  font-style: italic;
  color: #8a7d6b;
  background: #f7f5f0;
  padding: 1px 4px;
  border-radius: 3px;
}
.hl-bracket {
  font-style: italic;
  color: #8b7ea8;
  background: #f4f2f8;
  padding: 1px 4px;
  border-radius: 3px;
}

.dialogue__lines {
  line-height: var(--lh-relaxed);
  font-size: var(--text-base);
  text-align: left;
  padding-left: 15%;
  padding-right: 5%;
}
.dialogue__line {
  margin-bottom: 2px;
}

/* Crossed-out lines — hidden by default */
.dialogue__line--crossed {
  display: none;
}
/* Stable padding for all lines — avoids layout shift on toggle */
.dialogue__line {
  padding: 2px 8px;
  margin-left: -8px;
  border-left: 2px solid transparent;
  border-radius: 3px;
  transition: background 0.12s, opacity 0.12s;
}

/* Pure-direction lines: (...) or [...] on their own line — center, no border */
.dialogue__line--direction {
  text-align: center;
  margin-left: 0;
  padding-left: 0;
  padding-right: 0;
  border-left: none;
  color: #8a7d6b;
  font-style: italic;
  font-size: 0.95em;
  margin-top: 4px;
  margin-bottom: 4px;
}

/* When "show crossed" toggle is active — readable view */
body.show-crossed .dialogue__line--crossed {
  display: block;
  color: #2c2c2c;
  opacity: 0.55;
  border-left-color: #c04a4a;
}

/* In show-crossed mode, lines become clickable (cursor only) */
body.show-crossed .dialogue__line {
  cursor: pointer;
}
body.show-crossed .dialogue__line:hover {
  background: rgba(192, 74, 74, 0.08);
}
body.show-crossed .dialogue__line--crossed:hover {
  background: rgba(46, 125, 50, 0.08);
  opacity: 0.9;
}

/* Partial crossing: fragment of text inside a line */
.text-crossed {
  /* underline via box-shadow to avoid affecting line-height */
  box-shadow: inset 0 -2px 0 rgba(192, 74, 74, 0.5);
  background: rgba(192, 74, 74, 0.08);
}
body.show-crossed .text-crossed {
  color: #2c2c2c;
  opacity: 0.7;
}
/* When show-crossed is OFF, hide partial-crossed fragments */
body:not(.show-crossed) .text-crossed {
  display: none;
}

/* Floating button for partial crossing action */
.partial-cross-fab {
  position: absolute;
  z-index: 9999;
  background: var(--color-brown);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  white-space: nowrap;
}
.partial-cross-fab:hover {
  background: var(--color-brown-dark);
}

/* Search highlight */
.search-highlight {
  background: rgba(255, 200, 0, 0.35);
  border-radius: 2px;
  padding: 0 1px;
}


/* ===================================================================
   PAGE: Admin
   =================================================================== */

.admin {
  max-width: var(--max-page);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

.admin__title {
  font-size: var(--text-2xl);
  color: var(--color-brown-dark);
  margin-bottom: var(--space-xl);
}

/* Login */
.login-box {
  max-width: 360px;
  margin: var(--space-3xl) auto;
  background: var(--color-surface);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 8px var(--color-shadow);
}
.login-box h2 {
  font-size: var(--text-xl);
  color: var(--color-brown-dark);
  text-align: center;
  margin-bottom: var(--space-lg);
}

/* Sections */
.admin-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
}

.admin-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
}

.admin-section__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-brown-dark);
}

/* Form elements */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-group label {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
}

.form-hint {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-text-light);
  margin-top: var(--space-xs);
}

/* Password mask: использует -webkit-text-security вместо type="password",
   чтобы macOS не блокировал IME (раскладку) — позволяет вводить кириллицу. */
.password-mask {
  -webkit-text-security: disc;
  text-security: disc;
  font-family: text-security-disc, var(--font-sans);
  letter-spacing: 0.1em;
}
.password-mask.revealed {
  -webkit-text-security: none;
  text-security: none;
  font-family: var(--font-sans);
  letter-spacing: normal;
}

/* Password toggle */
.password-wrapper {
  position: relative;
}
.password-wrapper input {
  padding-right: 2.5rem;
}
.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.password-toggle:hover { color: var(--color-text); background: var(--color-bg-alt); }

/* Slider */
.slider-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.slider-wrapper input[type="range"] {
  flex: 1;
  border: none;
  padding: 0;
  accent-color: var(--color-brown);
}
.slider-value {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-brown-dark);
  min-width: 2em;
  text-align: center;
}

/* Buttons */
.btn {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  white-space: nowrap;
}
.btn--primary {
  background: var(--color-brown);
  color: #fff;
}
.btn--primary:hover { background: var(--color-brown-dark); }

.btn--secondary {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn--secondary:hover { background: var(--color-border-light); }

.btn--danger {
  background: var(--color-red-bg);
  color: var(--color-red);
}
.btn--danger:hover { background: #f5d0d0; }

.btn--sm {
  font-size: var(--text-xs);
  padding: 3px 10px;
}

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

/* Table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.admin-table th {
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 2px solid var(--color-border);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}
.admin-table tr:hover td {
  background: var(--color-bg);
}
.admin-table .actions {
  display: flex;
  gap: var(--space-xs);
}

/* Drag & Drop Zone */
.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  text-align: center;
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
  cursor: pointer;
  font-family: var(--font-sans);
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--color-brown);
  background: var(--color-brown-bg);
  color: var(--color-brown);
}

.dropzone__icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-sm);
  opacity: 0.4;
}

.dropzone__text {
  font-size: var(--text-sm);
}
.dropzone__hint {
  font-size: var(--text-xs);
  margin-top: var(--space-xs);
}

/* File list */
.file-list {
  list-style: none;
  margin-top: var(--space-md);
}
.file-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  cursor: grab;
}
.file-list__item:active { cursor: grabbing; }
.file-list__item .drag-handle {
  color: var(--color-text-light);
  cursor: grab;
}
.file-list__item .filename { flex: 1; }
.file-list__item .remove-file {
  color: var(--color-red);
  font-size: var(--text-xs);
}

/* Progress bar */
.progress {
  width: 100%;
  height: 8px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--space-md) 0;
}
.progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-brown), var(--color-gold-light));
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
  width: 0%;
}

.progress-status {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

/* Reviewer (scan left, text right) */
.reviewer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 500px;
}

.reviewer__scan {
  background: var(--color-bg-alt);
  padding: var(--space-md);
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.reviewer__scan img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 4px var(--color-shadow);
}

.reviewer__text {
  padding: var(--space-md);
  overflow-y: auto;
}

.reviewer__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.reviewer__nav .page-info {
  color: var(--color-text-muted);
  min-width: 80px;
  text-align: center;
}

/* Editable block in reviewer */
.edit-block {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  margin-bottom: var(--space-sm);
  cursor: text;
  transition: all var(--transition-fast);
  font-size: var(--text-sm);
}
.edit-block:hover {
  border-color: var(--color-border);
  background: var(--color-bg);
}
.edit-block:focus {
  outline: none;
  border-color: var(--color-brown);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

.edit-block[data-type="speaker"] {
  font-weight: 700;
  color: var(--color-navy);
  text-align: center;
}
.edit-block[data-type="stage_direction"] {
  font-style: italic;
  color: var(--color-purple);
}


/* ===================================================================
   Actor Login
   =================================================================== */

.actor-login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height));
  padding: var(--space-lg);
  background: linear-gradient(160deg, var(--color-bg) 0%, var(--color-brown-bg) 100%);
}

.actor-login {
  max-width: 340px;
  width: 100%;
  background: var(--color-surface);
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 24px var(--color-shadow-strong);
  text-align: center;
}

.actor-login__icon {
  color: var(--color-brown-light);
  margin-bottom: var(--space-md);
  opacity: 0.7;
}

.actor-login__title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  color: var(--color-brown-dark);
  margin-bottom: var(--space-lg);
  font-weight: 700;
}

.actor-login__input {
  width: 100%;
  text-align: center;
  font-size: var(--text-base);
  padding: var(--space-md);
  border-radius: var(--radius-md);
}

.actor-login__btn {
  width: 100%;
  padding: var(--space-md);
  font-size: var(--text-base);
  border-radius: var(--radius-md);
  text-align: center;
  justify-content: center;
}

.actor-login__error {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-red);
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-red-bg);
  border-radius: var(--radius-sm);
}

.actor-login__form .form-group {
  margin-bottom: var(--space-md);
}


/* ===================================================================
   Inline Editing in Reader
   =================================================================== */

/* Editable text spans — no edit affordances by default */
.editable-text {
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
  padding: 0 2px;
  display: inline;
}
.editable-text--active {
  display: block;
}

/* Block editing state */
.block--editing {
  outline: 2px solid var(--color-brown);
  outline-offset: 4px;
  background: #fffdf7;
  border-radius: var(--radius-sm);
}

/* Editor inputs */
.block__editor {
  width: 100%;
  font-family: var(--font-serif);
  font-size: inherit;
  line-height: inherit;
  color: var(--color-text);
  border: none;
  background: transparent;
  padding: 2px 4px;
  resize: none;
  outline: none;
}
.block__editor--inline {
  display: block;
  width: 100%;
  font-weight: inherit;
  text-align: inherit;
  color: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}
.block__editor--lines {
  width: 100%;
  min-height: 3em;
  line-height: var(--lh-relaxed);
  font-size: var(--text-base);
  overflow: hidden;
}

/* Dialogue lines — no hover effect */

/* Save indicator */
.block__save-indicator {
  position: absolute;
  top: -6px;
  right: 4px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-text-light);
  background: var(--color-surface);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-light);
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
}
.block__save-indicator--saving {
  color: var(--color-orange);
  border-color: var(--color-orange-bg);
  background: var(--color-orange-bg);
}

/* Saved flash (green) */
.block--saved {
  animation: block-saved-flash 1.2s ease;
}
@keyframes block-saved-flash {
  0%   { background: rgba(45, 122, 58, 0.15); }
  100% { background: transparent; }
}

/* Error flash (red) */
.block--error-flash {
  animation: block-error-flash 1.2s ease;
}
@keyframes block-error-flash {
  0%   { background: rgba(179, 48, 48, 0.15); }
  100% { background: transparent; }
}

/* Remote update flash (blue) */
.block--remote-update {
  animation: block-remote-flash 1.2s ease;
}
@keyframes block-remote-flash {
  0%   { background: rgba(26, 74, 122, 0.15); }
  100% { background: transparent; }
}


/* ===================================================================
   WebSocket Status Indicator
   =================================================================== */

.ws-status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background var(--transition-fast);
  cursor: default;
}
.ws-status--connected {
  background: var(--color-green);
  box-shadow: 0 0 4px rgba(45, 122, 58, 0.4);
}
.ws-status--disconnected {
  background: var(--color-red);
  box-shadow: 0 0 4px rgba(179, 48, 48, 0.3);
}


/* ===================================================================
   Backup List
   =================================================================== */

.backup-list {
  width: 100%;
}
.backup-list td:nth-child(2),
.backup-list th:nth-child(2) {
  white-space: nowrap;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
.backup-list td:nth-child(3),
.backup-list th:nth-child(3) {
  white-space: nowrap;
}


/* ===================================================================
   ZEN MODE (reading mode)
   =================================================================== */

/* Edit mode — cursor only, no hover bg */
.edit-mode .editable-text { cursor: text; }
.edit-mode .dialogue__lines { cursor: text; }

/* Zen mode */
body.zen-mode .app-header { display: none; }
body.zen-mode .reader__toolbar { display: none; }
body.zen-mode .reader {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  height: 100vh;
}
body.zen-mode .reader__content {
  padding: var(--space-2xl) var(--space-3xl);
}

/* Floating exit button in zen mode */
.zen-exit-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--color-text-muted);
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: all var(--transition-fast);
  opacity: 0.5;
}
.zen-exit-btn:hover { opacity: 1; background: var(--color-brown); color: #fff; border-color: var(--color-brown); }
body.zen-mode .zen-exit-btn { display: flex; }

/* ===================================================================
   RESPONSIVE
   =================================================================== */

@media (max-width: 900px) {
  .reader__content {
    padding: var(--space-md);
  }

  /* Mobile compare mode: vertical split (scan top, text bottom) */
  .reader__content--compare {
    flex-direction: column;
  }
  .reader__content--compare .reader__scan-panel {
    flex: 0 0 45%;
    border-right: none;
    border-bottom: 3px solid var(--color-border);
  }
  .reader__content--compare .reader__text {
    flex: 0 0 55%;
    padding: var(--space-sm);
  }

  .reviewer {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  /* Dropdown adjusts for mobile */
  .toolbar__section--row {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar__nav-select,
  .toolbar__search-input,
  .toolbar__mode-select,
  .char-select {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .library__header {
    flex-direction: column;
    align-items: stretch;
  }
  .library__controls {
    flex-direction: column;
  }
  .library__search {
    width: 100%;
  }

  .play-grid {
    grid-template-columns: 1fr;
  }

  .reader__toolbar {
    padding: var(--space-sm);
    gap: var(--space-sm);
  }
  .reader__play-title {
    font-size: var(--text-sm);
    max-width: 200px;
  }
  .toolbar__act-select {
    max-width: 110px;
    font-size: 11px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .admin-table { font-size: var(--text-xs); }
  .admin-table th:nth-child(n+3),
  .admin-table td:nth-child(n+3) { display: none; }

  /* Actor login mobile */
  .actor-login {
    padding: var(--space-lg);
  }

  /* Backup list: hide size column on small screens */
  .backup-list th:nth-child(2),
  .backup-list td:nth-child(2) { display: none; }

  /* Editing: ensure textarea is comfortable on mobile */
  .block__editor--lines {
    font-size: var(--text-sm);
    min-height: 4em;
  }
}


/* ===================================================================
   UTILITIES
   =================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-brown);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-page {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-3xl);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}

.fade-in {
  animation: fade-in 0.3s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
