:root {
  --bg: #1c1d21;
  --panel: #24262b;
  --panel-2: #2c2f35;
  --line: #3a3d44;
  --text: #e8e6e1;
  --muted: #9a9ca3;
  --accent: #e3b25b;
  --accent-ink: #1c1d21;
  --paper: #fffefb;
  --ink: #111;
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Courier Prime', 'Courier New', Courier, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--ui);
  display: flex; flex-direction: column; overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 4px; border-radius: 3px; }

/* ---------------- Felső sáv ---------------- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 18px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-family: var(--mono);
}
.brand-name { font-weight: 600; }
.brand-sub { color: var(--muted); font-size: 12px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.format-switch { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg {
  background: none; border: 0; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
}
.seg small { font-size: 10.5px; opacity: .8; }
.seg.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }

.actions { margin-left: auto; display: flex; gap: 8px; }
.btn {
  list-style: none; cursor: pointer; padding: 7px 14px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel-2); user-select: none;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { border-color: #555a63; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 230px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,.4); display: flex; flex-direction: column;
}
.menu-pop button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-pop button:hover { background: var(--panel-2); }
.settings { padding: 12px; gap: 10px; min-width: 280px; }
.settings label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12.5px; }
.settings label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13.5px; }
.settings select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px; }

/* ---------------- Munkaterület ---------------- */
.workspace { flex: 1; display: grid; grid-template-columns: 250px minmax(340px, 1fr) minmax(420px, 1.25fr); min-height: 0; }
.pane { min-height: 0; }
.mobile-tabs { display: none; }

.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tabs button { flex: 1; background: none; border: 0; padding: 10px 4px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.side-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.side-body { flex: 1; overflow: auto; padding: 8px; }
.scene-list, .char-list { list-style: none; margin: 0; padding: 0; }
.scene-list li, .char-list li { padding: 7px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; }
.scene-list li:hover, .char-list li:hover { background: var(--panel-2); }
.scene-list .sn { color: var(--accent); font-family: var(--mono); min-width: 20px; }
.scene-list .sh { flex: 1; font-family: var(--mono); }
.scene-list .sp, .char-list .cc { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.char-list li { flex-direction: column; gap: 1px; }
.char-list .cn { font-family: var(--mono); font-weight: 700; }
li.empty { color: var(--muted); cursor: default !important; background: none !important; }
.help { font-size: 12.5px; color: var(--muted); }
.help p { margin: 6px 4px 10px; }
.help b { color: var(--text); }
.help table { border-collapse: collapse; width: 100%; }
.help th { text-align: left; color: var(--text); font-weight: 600; padding: 4px; border-bottom: 1px solid var(--line); }
.help td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help td code { display: inline-block; margin: 1px 0; color: var(--text); }
.stats { border-top: 1px solid var(--line); padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12.5px; color: var(--muted); }
.stats b { color: var(--text); font-size: 15px; }
.stats .fine { grid-column: 1 / -1; margin: 4px 0 0; font-size: 10.5px; }

/* ---------------- Szerkesztő ---------------- */
.editor-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.toolbar button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12.5px; }
.toolbar button:hover { border-color: var(--accent); }
#editor {
  flex: 1; width: 100%; resize: none; border: 0; outline: 0; padding: 22px 26px;
  background: var(--bg); color: var(--text); font: 15.5px/1.7 var(--ui); tab-size: 4;
}
#editor::placeholder { color: #6a6d74; }
.statusbar { display: flex; gap: 12px; align-items: center; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--panel); font-size: 12px; color: var(--muted); }
#status-type { color: var(--accent); }
.suggest { background: var(--panel-2); color: var(--text); padding: 1px 8px; border-radius: 10px; border: 1px solid var(--accent); }
.save-state { margin-left: auto; }

/* ---------------- Előnézet ---------------- */
.preview-pane { display: flex; flex-direction: column; background: #3a3c42; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.zoom { display: flex; align-items: center; gap: 6px; }
.zoom button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.preview-scroll { flex: 1; overflow: auto; padding: 24px 16px 60px; }
.pages { --zoom: .8; zoom: var(--zoom); display: flex; flex-direction: column; align-items: center; gap: 24px; }

.page {
  position: relative; background: var(--paper); color: var(--ink); flex: none;
  box-shadow: 0 4px 18px rgba(0,0,0,.35); font-family: var(--mono); font-size: 12pt; line-height: 1;
}
.pnum { position: absolute; top: .5in; right: 1in; font-size: 12pt; }
.page .body { position: absolute; top: 1in; right: 0; }
.ln { position: relative; height: calc(1in / 6); line-height: calc(1in / 6); white-space: pre; cursor: text; }
.ln.blank { cursor: default; }
.ln.scene, .ln.character, .ln.transition, .ln.more, .ln.section { text-transform: none; }
.ln.scene { font-weight: 700; }
.ln.note, .ln.synopsis { color: #8a7a3a; font-style: italic; }
.ln.half { position: absolute; top: 0; height: 100%; }
.ln.dual, .ln.avrow { position: relative; }
.snum { position: absolute; top: 0; font-weight: 400; }
.body.us .snum-l { left: -.75in; }
.body.us .snum-r { left: 6.25in; }
.body.av .snum-l { left: -.6in; }
.body.av .snum-r { display: none; }
.ln.active, .ln.active .ln { background: rgba(227,178,91,.28); }
.ln:not(.blank):hover { background: rgba(227,178,91,.12); }

/* Elemtípus-címkék a margón (csak képernyőn) */
.show-types .ln[data-tag]::before {
  content: attr(data-tag); position: absolute; left: -1.38in; top: 0; width: 1.2in; text-align: right;
  font: 600 6.5pt/calc(1in / 6) var(--ui); letter-spacing: .04em; color: #b3a17a; pointer-events: none;
}
.show-types .body.av .ln[data-tag]::before { left: -.95in; width: .82in; }
.show-types .body.av .ln.half.right[data-tag]::before { content: none; }
.show-types .body.av .ln.half.right[data-tag] { box-shadow: inset 2px 0 0 transparent; }

/* Kéthasábos oldal */
.av-head { position: relative; height: calc(1in / 6); font-weight: 700; letter-spacing: .1em; }
.av-head span { position: absolute; top: 0; left: 0; }
.av-rule { height: calc(1in / 6); border-top: 1px solid #222; margin-top: calc(1in / 12); height: calc(1in / 12); }
.av-divider { position: absolute; top: calc(1in / 6); bottom: 0; border-left: 1px solid #bbb; }
.av-page .body { bottom: 1in; }
.body.av .ln.full { background: var(--paper); z-index: 1; }
.body.av .ln.full.active { background: #f3e2bd; }
.body.av .ln.character { font-weight: 700; }

/* Címoldal */
.title-page { font-family: var(--mono); }
.tp-center { position: absolute; top: 3.3in; left: 1in; right: 1in; text-align: center; line-height: calc(1in / 6); }
.tp-series { margin-bottom: calc(1in / 6); }
.tp-title { font-weight: 700; text-decoration: underline; margin-bottom: calc(1in / 6); }
.tp-episode { margin-bottom: calc(1in / 6); }
.tp-credit { margin-top: calc(2in / 6); }
.tp-author { margin-top: calc(1in / 6); }
.tp-source { margin-top: calc(2in / 6); }
.tp-contact { position: absolute; left: 1.5in; bottom: 1in; line-height: calc(1in / 6); }
.tp-date { position: absolute; right: 1in; bottom: 1in; line-height: calc(1in / 6); text-align: right; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--panel-2); border: 1px solid var(--accent); padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* ---------------- Keskeny képernyő ---------------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 210px 1fr 1.1fr; }
}
@media (max-width: 860px) {
  .topbar { gap: 10px; padding: 8px 10px; }
  .brand { min-width: 0; }
  .actions { margin-left: 0; width: 100%; }
  .actions .menu:last-child { margin-left: auto; }
  .format-switch { order: 3; width: 100%; }
  .seg { flex: 1; }
  .mobile-tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel); }
  .mobile-tabs button { flex: 1; background: none; border: 0; padding: 10px; color: var(--muted); border-bottom: 2px solid transparent; }
  .mobile-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
  .workspace { display: block; position: relative; }
  .pane { display: none !important; height: 100%; }
  .pane.active { display: flex !important; }
  .menu-pop { right: auto; left: 0; }
  .actions .menu:last-child .menu-pop { left: auto; right: 0; }
  .pages { --zoom: .45 !important; }
}

/* ---------------- Nyomtatás / PDF ---------------- */
@media print {
  body { background: #fff; display: block; overflow: visible; height: auto; }
  .topbar, .mobile-tabs, .sidebar, .editor-pane, .preview-bar, .toast { display: none !important; }
  .workspace { display: block; }
  .pane.editor-pane, .pane.sidebar { display: none !important; }
  .pane.preview-pane, .preview-scroll { display: block !important; overflow: visible; padding: 0; background: #fff; height: auto; }
  .pages { zoom: 1 !important; gap: 0; display: block; }
  .page { box-shadow: none; margin: 0; break-after: page; page-break-after: always; overflow: hidden; }
  .page:last-child { break-after: auto; page-break-after: auto; }
  .ln.active, .ln:hover { background: none !important; }
  .show-types .ln[data-tag]::before { content: none !important; }
  .ln.note, .ln.synopsis { color: #555; }
}

/* ===================== Nézetek ===================== */
.loading-screen, .login-view, .home-view, .editor-view { display: none; }
body.view-loading .loading-screen { display: flex; }
body.view-login .login-view { display: flex; }
body.view-home .home-view { display: flex; }
body.view-editor .editor-view { display: flex; }
.home-view, .editor-view { flex-direction: column; flex: 1; min-height: 0; }
.loading-screen { flex: 1; align-items: center; justify-content: center; gap: 12px; color: var(--muted); }

.muted { color: var(--muted); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn.danger:hover { border-color: #d46a5c; color: #f0a093; }
.btn:disabled { opacity: .6; cursor: default; }
button.btn { cursor: pointer; }
kbd { font: 11px var(--ui); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 8px; }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; width: auto; }
.menu-pop button { display: flex; justify-content: space-between; align-items: center; }
.back-btn { white-space: nowrap; }
.save-state[data-state="dirty"], .save-state[data-state="saving"] { color: var(--accent); }
.save-state[data-state="error"] { color: #f0a093; }
.form-error { color: #f0a093; margin: 0; font-size: 13px; }

/* Belépés */
.login-view { flex: 1; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 28px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; font-size: 13px; }
.brand-mark.big { width: 52px; height: 52px; font-size: 20px; border-radius: 12px; align-self: center; }
.login-card input, .field input, .field select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; outline: 0; width: 100%;
}
.login-card input:focus, .field input:focus, .field select:focus { border-color: var(--accent); }
.login-card .btn { padding: 10px; }

/* Nyitóoldal */
.store-badge { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; align-self: center; }
.store-badge.warn { color: var(--accent); border-color: var(--accent); }
.home-scroll { flex: 1; overflow: auto; }
.home-inner { max-width: 1100px; margin: 0 auto; padding: 28px 22px 60px; }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.home-head h1 { margin: 0; font-size: 26px; font-weight: 600; }
.home-actions { display: flex; gap: 8px; }
.notice { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: 8px; padding: 10px 14px; margin-bottom: 18px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notice.warn { border-left-color: var(--accent); }
.notice.info { border-left-color: #6fa3d8; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 50px 20px; background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; }
.empty-state p { margin: 0 0 8px; }
.empty-state .btn { margin-top: 10px; }
.project-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; transition: border-color .15s, transform .15s;
}
.project-card:hover, .project-card:focus-visible { border-color: var(--accent); transform: translateY(-2px); outline: 0; }
.pc-paper { height: 118px; background: #34363c; position: relative; overflow: hidden; }
.pc-paper::before { content: ''; position: absolute; left: 50%; top: 16px; width: 120px; height: 140px; margin-left: -60px; background: var(--paper); box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.pc-paper i { position: absolute; height: 3px; background: #c9c5bb; left: calc(50% - 46px); width: 92px; }
.pc-paper i:nth-child(1) { top: 32px; width: 60px; background: #888; }
.pc-paper i:nth-child(2) { top: 46px; }
.pc-paper i:nth-child(3) { top: 54px; }
.pc-paper i:nth-child(4) { top: 68px; width: 70px; }
.pc-paper i:nth-child(5) { top: 82px; }
.pc-paper i:nth-child(6) { top: 90px; }
.pc-paper.us i.c { left: calc(50% - 6px); width: 26px; background: #999; }
.pc-paper.us i.d { left: calc(50% - 26px); width: 54px; }
.pc-paper.av::after { content: ''; position: absolute; left: 50%; top: 26px; height: 120px; border-left: 1px solid #bbb; }
.pc-paper.av i { width: 40px; }
.pc-paper.av i.c, .pc-paper.av i.d { left: calc(50% + 6px); width: 38px; }
.pc-body { padding: 14px 16px 6px; flex: 1; }
.pc-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; word-break: break-word; }
.pc-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.chip.warn { color: var(--accent); border-color: var(--accent); }
.pc-stats { font-size: 12.5px; color: var(--text); min-height: 18px; }
.pc-date { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pc-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 14px; }
.pc-actions .danger { margin-left: auto; }

/* Új projekt ablak */
.modal { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(0,0,0,.55); }
.modal form { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); flex: 1; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.modal .chk { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.type-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; color: var(--text); position: relative; }
.type-card input { position: absolute; opacity: 0; }
.type-card:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.type-card small { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.tc-mini { display: block; height: 46px; background: var(--paper); border-radius: 4px; position: relative; margin-bottom: 6px; }
.tc-mini i { position: absolute; height: 3px; background: #bbb; left: 10px; width: 70%; }
.tc-mini i:nth-child(1) { top: 8px; width: 40%; background: #777; }
.tc-mini i:nth-child(2) { top: 18px; }
.tc-mini i:nth-child(3) { top: 26px; }
.tc-mini i:nth-child(4) { top: 36px; }
.tc-mini.us i.c { left: 45%; width: 16%; }
.tc-mini.us i.d { left: 28%; width: 42%; }
.tc-mini.av::after { content: ''; position: absolute; left: 50%; top: 4px; bottom: 4px; border-left: 1px solid #bbb; }
.tc-mini.av i { width: 36%; }
.tc-mini.av i:nth-child(2), .tc-mini.av i:nth-child(4) { left: calc(50% + 8px); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 860px) {
  .type-choice { grid-template-columns: 1fr; }
  .editor-view .topbar .brand { flex: 1; min-width: 0; }
}
@media print {
  .home-view, .login-view, .loading-screen, dialog { display: none !important; }
  body.view-editor .editor-view { display: block !important; }
}
