:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.78);
  --panel-strong: #111827;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.22);
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #fb7185;
  --warning: #f59e0b;
  --input: rgba(2, 6, 23, 0.65);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.20), transparent 35rem),
    radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.14), transparent 30rem),
    var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 14px clamp(14px, 3vw, 34px);
  backdrop-filter: blur(18px);
  background: rgba(15, 23, 42, 0.78);
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 800; letter-spacing: .02em; font-size: 20px; }
.subline { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topnav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.user-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: clamp(16px, 2vw, 24px);
  box-shadow: var(--shadow);
}
.panel h1, .panel h2 { margin: 0 0 6px; }
.muted { color: var(--muted); }
.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}
.counter { color: var(--muted); font-size: 14px; white-space: nowrap; }

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr);
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 34px) 34px;
}
.editor-panel { grid-column: 1 / 2; }
.settings-panel { grid-column: 2 / 3; }
.shared-panel { grid-column: 1 / 3; }
.history-panel { grid-column: 1 / 3; }

.title-input,
textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--input);
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(56, 189, 248, 0.85);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.12);
}
.title-input { margin-bottom: 12px; }
.title-input.is-invalid {
  border-color: rgba(251, 113, 133, .9);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, .14);
}
textarea {
  min-height: 430px;
  resize: vertical;
  line-height: 1.55;
}
label span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.switches { display: grid; gap: 12px; margin-top: 18px; color: var(--muted); }
.switches input, .checkbox-label input { width: auto; margin-right: 8px; }
.checkbox-label { display: flex; align-items: center; color: var(--muted); padding-top: 24px; }

.btn, .file-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  color: var(--text);
  background: rgba(255,255,255,.06);
  cursor: pointer;
  font-weight: 650;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover, .file-button:hover { transform: translateY(-1px); background: rgba(255,255,255,.1); text-decoration: none; }
.btn-primary { background: linear-gradient(135deg, #0ea5e9, #22c55e); border-color: transparent; color: white; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.file-button input { display: none; }
.reader-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.job-status { margin-top: 16px; }
.status-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); }
.progress { height: 10px; border-radius: 999px; background: rgba(148, 163, 184, 0.18); overflow: hidden; }
.progress div { height: 100%; background: linear-gradient(90deg, #38bdf8, #22c55e); width: 0%; transition: width .3s ease; }

.inline-player {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255,255,255,.035);
}
.inline-player-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.inline-player-head strong { display: block; font-size: 16px; margin-bottom: 2px; }
.inline-player-head p { margin: 0; }
.player-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.round-btn {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.08);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.round-btn:hover { background: rgba(255,255,255,.13); }
.timebox { color: var(--muted); font-variant-numeric: tabular-nums; }
#timeline { padding: 0; accent-color: var(--accent); }

.jobs-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.job-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,.04);
}
.job-card h3 { margin: 0 0 6px; font-size: 16px; }
.job-meta { color: var(--muted); font-size: 13px; display: grid; gap: 3px; margin-bottom: 10px; }
.job-card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.share-wrap { position: relative; display: inline-flex; }
.share-menu {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2000;
  min-width: 190px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #0f172a;
  box-shadow: var(--shadow);
}
.share-menu button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  background: rgba(255,255,255,.06);
  text-align: left;
  cursor: pointer;
}
.share-menu button:hover { background: rgba(255,255,255,.12); }
.badge { display:inline-flex; padding: 3px 8px; border-radius: 999px; background: rgba(56, 189, 248, .12); color: #bae6fd; font-size: 12px; }
.badge.done { background: rgba(34, 197, 94, .12); color: #bbf7d0; }
.badge.error { background: rgba(251, 113, 133, .12); color: #fecdd3; }
.badge.processing { background: rgba(245, 158, 11, .12); color: #fde68a; }

.login-body { display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  font-weight: 900;
  margin-bottom: 18px;
}
.login-card h1 { margin: 0 0 8px; }

.alert {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,.06);
  margin: 12px 0;
}
.alert-error { border-color: rgba(251, 113, 133, .45); background: rgba(251, 113, 133, .1); color: #fecdd3; }
.hidden { display: none !important; }

.admin-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 34px) 34px;
}
.admin-tabs { display: grid; gap: 10px; align-self: start; position: sticky; top: 88px; }
.tab {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}
.tab.active { border-color: rgba(56,189,248,.7); background: rgba(56,189,248,.12); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.search-row { display: flex; gap: 10px; margin: 14px 0; }
.table-wrap { overflow-x: auto; border-radius: 16px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; font-weight: 700; }
tr:last-child td { border-bottom: 0; }
code, .hint-block {
  background: rgba(2,6,23,.55);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 6px;
}
.hint-block { padding: 16px; white-space: pre-wrap; color: var(--muted); }
.import-box { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.import-box input { max-width: 440px; }
.system-box { display: grid; gap: 10px; margin: 12px 0; }
.system-line { display:flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.system-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.pagination-info { color: var(--muted); font-size: 14px; }
.pagination-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-buttons { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.page-btn.active {
  border-color: rgba(56,189,248,.75);
  background: rgba(56,189,248,.16);
  color: #e0f2fe;
}
.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 960px) {
  .reader-layout, .admin-layout { grid-template-columns: 1fr; }
  .editor-panel, .settings-panel, .shared-panel, .history-panel { grid-column: auto; }
  .admin-tabs { position: static; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .form-grid, .admin-form-grid { grid-template-columns: 1fr; }
  .checkbox-label { padding-top: 0; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topnav { width: 100%; }
  textarea { min-height: 320px; }
  .panel { border-radius: 18px; }
  .panel-title-row { flex-direction: column; }
  .reader-actions .btn, .reader-actions .file-button { width: 100%; }
  .inline-player-head { flex-direction: column; }
  .inline-player-head .btn { width: 100%; }
  .round-btn { width: 44px; height: 44px; }
  .search-row { flex-direction: column; }
}

.compact-title { align-items: flex-start; }
.title-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.small-text { font-size: 13px; line-height: 1.45; }
.advanced-settings {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.advanced-settings h3 { margin: 0 0 6px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 6, 23, .72);
  backdrop-filter: blur(10px);
}
.modal-card {
  position: relative;
  width: min(980px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: clamp(18px, 3vw, 30px);
  box-shadow: var(--shadow);
}
.modal-close {
  position: sticky;
  top: 0;
  float: right;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: rgba(255,255,255,.14); }
.help-card h2 { margin-top: 0; }
.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.help-grid > div,
.help-list p {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  padding: 14px;
}
.help-grid h3 { margin: 0 0 8px; }
.help-grid p, .help-list p { color: var(--muted); line-height: 1.55; }
.help-list { display: grid; gap: 10px; }
.help-list p { margin: 0; }


.help-table {
  width: 100%;
  min-width: 0;
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255,255,255,.035);
}
.help-table th,
.help-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.help-table tr:last-child td { border-bottom: 0; }
.help-table th { color: var(--muted); font-size: 13px; }
.help-note {
  margin-top: 12px;
  border: 1px solid rgba(56, 189, 248, .28);
  border-radius: 16px;
  padding: 12px 14px;
  color: #dbeafe;
  background: rgba(56, 189, 248, .08);
  line-height: 1.55;
}
