/* Look & feel follows Markpad (md.dc1.thevry.co): same palette, toolbar, panes,
   preview typography. Fonts are local-only because the CSP forbids CDNs. */
:root {
  --bg: #0f1117;
  --bg-secondary: #161822;
  --bg-tertiary: #1c1e2e;
  --bg-hover: #232640;
  --border: #2a2d44;
  --text: #e2e4f0;
  --text-muted: #8b8fa8;
  --text-dim: #5c6080;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.15);
  --success: #00b894;
  --danger: #e17055;
  --warning: #fdcb6e;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 150ms ease;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

.app { display: flex; flex-direction: column; height: 100vh; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); z-index: 100; flex-shrink: 0; flex-wrap: wrap; }
.main-area { display: flex; flex: 1; overflow: hidden; }
.logo { font-weight: 700; font-size: 16px; color: var(--accent-light); letter-spacing: -0.5px; user-select: none; cursor: pointer; padding: 4px 8px; }
.logo span { color: var(--text-dim); font-weight: 400; }
.toolbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-tertiary); color: var(--text); font-size: 13px; cursor: pointer; transition: all var(--transition); white-space: nowrap; font-family: inherit; }
.btn:hover { background: var(--bg-hover); border-color: var(--text-dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-light); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.rec-on { background: var(--danger); border-color: var(--danger); color: #fff; }
.rec-clock { font-size: 13px; color: var(--text-dim); min-width: 3.2em; }
.btn.rec-on { font-weight: 600; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn .icon { font-size: 15px; line-height: 1; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input.field, select.field { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; padding: 5px 8px; outline: none; font-family: inherit; }
input.field:focus, select.field:focus { border-color: var(--accent); }
#ep-title { background: none; border: none; color: var(--text); font-size: 14px; font-weight: 500; outline: none; padding: 4px 8px; border-radius: var(--radius); min-width: 120px; max-width: 280px; }
#ep-title:hover { background: var(--bg-tertiary); }
#ep-title:focus { background: var(--bg-tertiary); outline: 1px solid var(--accent); }

/* mode toggle (Edit <-> Preview, whole screen) */
.mode-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mode-toggle button { background: var(--bg-tertiary); color: var(--text-muted); border: 0; padding: 5px 12px; font-size: 12px; cursor: pointer; font-family: inherit; }
.mode-toggle button.active { background: var(--accent); color: #fff; }

/* Sidebar (Markpad's doc list + our widgets) */
.sidebar { width: 290px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; transition: width var(--transition), opacity var(--transition); }
.sidebar.collapsed { width: 0; opacity: 0; pointer-events: none; }
.side-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.side-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.doc-list { display: flex; flex-direction: column; gap: 2px; max-height: 30vh; overflow-y: auto; }
.doc-item { padding: 8px 10px; border-radius: var(--radius); cursor: pointer; transition: background var(--transition); border-left: 3px solid transparent; }
.doc-item:hover { background: var(--bg-hover); }
.doc-item.active { background: var(--accent-glow); border-left-color: var(--accent); }
.doc-item-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-item-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 10px; border: 1px solid var(--border); text-transform: uppercase; letter-spacing: .5px; }
.badge.draft { color: var(--text-muted); }
.badge.recorded { color: var(--warning); border-color: var(--warning); }
.badge.published { color: var(--success); border-color: var(--success); }
.badge.synthetic { color: #fff; background: var(--danger); border-color: var(--danger); }

/* Timer widget */
.timer-display { font-family: var(--mono); font-size: 40px; font-weight: 500; text-align: center; letter-spacing: 2px; padding: 6px 0; cursor: pointer; border-radius: var(--radius); user-select: none; }
.timer-display:hover { background: var(--bg-hover); }
.timer-display.running { color: var(--success); }
.timer-display.paused { color: var(--warning); }
.timer-display.finished { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.timer-status { text-align: center; font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 6px; }
.small { font-size: 12px; color: var(--text-muted); }
.mono { font-family: var(--mono); }
.peer-line { font-size: 12px; margin: 4px 0; display: flex; gap: 6px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); display: inline-block; flex-shrink: 0; }
.dot.on { background: var(--success); }
.dot.rec { background: var(--danger); animation: blink 1s steps(2) infinite; }
.verified { color: var(--success); }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { accent-color: var(--accent); }

/* Editor / preview: ONE of them fills the whole area (no split view) */
.editor-area { display: flex; flex: 1; overflow: hidden; }
.pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.pane-header { padding: 8px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); background: var(--bg-tertiary); border-bottom: 1px solid var(--border); flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; }
.editor-wrap { position: relative; flex: 1; display: flex; overflow: hidden; }
#editor, .editor-mirror { width: 100%; padding: 24px; font-family: var(--mono); font-size: 14px; line-height: 1.7; tab-size: 2; white-space: pre-wrap; overflow-wrap: break-word; word-wrap: break-word; }
#editor { flex: 1; background: var(--bg); color: var(--text); border: none; outline: none; resize: none; overflow-y: scroll; }
.editor-mirror { position: absolute; top: 0; left: 0; visibility: hidden; pointer-events: none; height: auto; }
.editor-mirror > div { min-height: 1.7em; }
#preview-scroll { flex: 1; overflow-y: scroll; background: var(--bg); position: relative; }
#preview { padding: 24px 32px; max-width: 980px; margin: 0 auto; position: relative; }

/* Preview content styling (Markpad) */
.md h1 { font-size: 2em; font-weight: 700; margin: 0 0 16px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.md h2 { font-size: 1.5em; font-weight: 600; margin: 24px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.25em; font-weight: 600; margin: 20px 0 8px; }
.md h4, .md h5, .md h6 { font-size: 1.1em; font-weight: 600; margin: 16px 0 8px; }
.md p { margin: 0 0 16px; line-height: 1.7; }
.md a { color: var(--accent-light); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md img { max-width: 100%; border-radius: var(--radius); margin: 8px 0; }
.md blockquote { border-left: 4px solid var(--accent); padding: 8px 16px; margin: 0 0 16px; background: var(--accent-glow); border-radius: 0 var(--radius) var(--radius) 0; color: var(--text-muted); }
.md code { font-family: var(--mono); font-size: 0.9em; background: var(--bg-tertiary); padding: 2px 6px; border-radius: 4px; }
.md pre { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-x: auto; margin: 0 0 16px; }
.md pre code { background: none; padding: 0; }
.md ul, .md ol { margin: 0 0 16px; padding-left: 24px; }
.md li { margin-bottom: 4px; line-height: 1.7; }
.md table { border-collapse: collapse; width: 100%; margin: 0 0 16px; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.md th { background: var(--bg-tertiary); font-weight: 600; }
.md tr:nth-child(even) { background: var(--bg-secondary); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.md li:has(> input[type=checkbox]) { list-style: none; margin-left: -20px; }
.md li > input[type=checkbox] { margin-right: 8px; accent-color: var(--accent); }

.status-bar { display: flex; align-items: center; gap: 16px; padding: 4px 16px; font-size: 11px; color: var(--text-dim); background: var(--bg-secondary); border-top: 1px solid var(--border); flex-shrink: 0; }

/* Modal + toast (Markpad) */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 500; }
.modal-overlay.show { display: flex; }
.modal { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; width: min(560px, 92vw); box-shadow: var(--shadow); }
.modal h3 { margin-bottom: 12px; font-size: 16px; }
.modal p { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }
.modal .field { width: 100%; margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
textarea.share-url { width: 100%; height: 84px; font-family: var(--mono); font-size: 11px; background: var(--bg-tertiary); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; resize: none; word-break: break-all; }
.toast { position: fixed; bottom: 32px; right: 24px; padding: 12px 20px; border-radius: var(--radius); font-size: 13px; font-weight: 500; z-index: 1000; transform: translateY(100px); opacity: 0; transition: all 300ms ease; box-shadow: var(--shadow); max-width: 420px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--accent); color: white; }

/* Landing / enrol states */
.center-card { margin: 10vh auto; max-width: 560px; padding: 32px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); line-height: 1.6; }
.center-card h2 { margin-bottom: 12px; }
.center-card p { color: var(--text-muted); font-size: 14px; margin-bottom: 10px; }

/* Replay viewer */
.replay-controls { display: flex; gap: 8px; align-items: center; padding: 8px 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.replay-controls input[type=range] { flex: 1; min-width: 200px; accent-color: var(--accent); }
.desktop { position: relative; flex: 1; overflow: hidden; background: repeating-linear-gradient(45deg, #11131b, #11131b 12px, #13151f 12px, #13151f 24px); }
.win { position: absolute; border: 1px solid var(--border); border-radius: 8px; background: #0b0d12; box-shadow: var(--shadow); overflow: hidden; }
.win.host_a { border-color: #6c5ce7; }
.win.host_b { border-color: #00b894; }
.win.blurred { opacity: .7; }
.win-chrome { position: absolute; left: 0; right: 0; top: 0; font-size: 11px; padding: 3px 8px; color: var(--text-muted); background: #1a1c28; white-space: nowrap; overflow: hidden; }
.win-viewport { position: absolute; overflow: hidden; background: var(--bg); }
.win-content { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.win-content .editor-text { font-family: var(--mono); font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: break-word; padding: 24px; color: var(--text); }
.cursor { position: absolute; width: 14px; height: 14px; margin: -3px 0 0 -3px; border-radius: 50%; border: 2px solid #fff; z-index: 5; pointer-events: none; }
.cursor.host_a { background: #6c5ce7; }
.cursor.host_b { background: #00b894; }
.replay-side { width: 340px; border-left: 1px solid var(--border); background: var(--bg-secondary); overflow-y: auto; font-size: 12px; }
.ev-log { font-family: var(--mono); font-size: 11px; }
.ev-log div { padding: 2px 10px; border-bottom: 1px solid #1d2030; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-log div.cur { background: var(--accent-glow); }
.legend { display: flex; gap: 12px; font-size: 12px; align-items: center; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.full { width: 100%; margin-bottom: 8px; }
.w70 { width: 70px; }
.mt8 { margin-top: 8px; }
.light { font-weight: 400; }
.card-wrap { flex: 1; overflow: auto; }
.w90 { width: 90px; }
.host-a-sw { background: #6c5ce7; }
.host-b-sw { background: #00b894; }
.win-sidebar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bg-secondary); border-right: 1px solid var(--border); }
.win-toolbar { position: absolute; left: 0; right: 0; top: 0; background: var(--bg-secondary); border-bottom: 1px solid var(--border); }
.win-pane { position: absolute; overflow: hidden; background: var(--bg); }
.win-timer { position: absolute; color: var(--text); font-family: var(--mono); }
.win-label { position: absolute; left: 6px; bottom: 4px; font-size: 11px; color: #fff; background: rgba(0,0,0,.55); padding: 2px 6px; border-radius: 4px; z-index: 6; }
.preview-pad { padding: 24px 32px; max-width: 980px; margin: 0 auto; }
