/* Web version of Markdown Viewer: the look of the Mac app, glass bars over calm content. */

:root {
  color-scheme: light dark;
  --bg: #efeeeb;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.1);
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.85);
  --accent: #0a66d6;
  --selected: rgba(255, 255, 255, 0.95);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.08);
  font-family: -apple-system, system-ui, "Segoe UI", sans-serif;
  font-size: 13px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #19191b;
    --surface: #1f1f21;
    --text: #e9e9eb;
    --muted: #a1a1a6;
    --line: rgba(255, 255, 255, 0.1);
    --glass: rgba(44, 44, 46, 0.6);
    --glass-strong: rgba(44, 44, 46, 0.9);
    --accent: #4aa3ff;
    --selected: rgba(255, 255, 255, 0.16);
    --shadow: 0 1px 1px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
    --bg: #19191b;
    --surface: #1f1f21;
    --text: #e9e9eb;
    --muted: #a1a1a6;
    --line: rgba(255, 255, 255, 0.1);
    --glass: rgba(44, 44, 46, 0.6);
    --glass-strong: rgba(44, 44, 46, 0.9);
    --accent: #4aa3ff;
    --selected: rgba(255, 255, 255, 0.16);
    --shadow: 0 1px 1px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
/* Elements with their own display (grid, flex) must still disappear when hidden. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
body {
  display: flex; flex-direction: column; overflow: hidden; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

/* Toolbar */
.toolbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  margin: 8px 10px 0; padding: 6px 8px; border-radius: 22px; z-index: 5;
}
.group { display: flex; align-items: center; gap: 4px; min-width: 0; }
.group.end { justify-content: flex-end; }
.icon {
  display: grid; place-items: center; width: 34px; height: 30px; border: 0; border-radius: 15px;
  background: transparent; cursor: pointer;
}
.icon:hover { background: var(--line); }
.title {
  min-width: 0; flex: 1; max-width: 360px; font: 600 14px -apple-system, system-ui, sans-serif;
  border: 0; background: transparent; color: var(--text); padding: 4px 8px; border-radius: 8px;
}
.title:focus { outline: none; background: var(--line); }
.segmented { display: flex; gap: 2px; padding: 3px; border-radius: 17px; background: var(--line); }
.segmented button {
  width: 40px; height: 26px; border: 0; border-radius: 13px; background: transparent; cursor: pointer; display: grid; place-items: center;
}
.segmented button.active { background: var(--selected); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); color: var(--accent); }

.menu { position: relative; }
.menu-items {
  position: absolute; right: 0; top: 38px; min-width: 230px; padding: 6px; border-radius: 14px;
  display: flex; flex-direction: column; background: var(--glass-strong);
}
.menu-items button { text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.menu-items button:hover { background: var(--accent); color: #ffffff; }
.menu-items hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

/* Tabs */
.tabs { display: flex; gap: 4px; padding: 6px 12px 0; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.tab {
  display: flex; align-items: center; gap: 6px; min-width: 120px; max-width: 220px; flex: 1 1 0;
  padding: 5px 6px 5px 12px; border-radius: 12px; background: transparent; border: 1px solid transparent;
  cursor: pointer; color: var(--muted);
}
.tab:hover { background: var(--line); }
.tab.active { background: var(--glass-strong); color: var(--text); border-color: var(--line); box-shadow: var(--shadow); }
.tab .name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tab .close { width: 20px; height: 20px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; opacity: 0; display: grid; place-items: center; }
.tab .close svg { width: 12px; height: 12px; }
.tab:hover .close, .tab.active .close { opacity: 0.7; }
.tab .close:hover { background: var(--line); opacity: 1; }
.tab-add { flex: 0 0 auto; min-width: 0; padding: 5px 10px; color: var(--muted); border: 0; background: transparent; border-radius: 12px; cursor: pointer; }
.tab-add:hover { background: var(--line); }

/* Main area */
main { flex: 1; display: flex; min-height: 0; padding: 8px 10px 10px; gap: 8px; }
.sidebar {
  width: 250px; flex-shrink: 0; border-radius: 18px; padding: 10px 6px; overflow-y: auto;
  background: var(--glass); border: 1px solid var(--line); display: flex; flex-direction: column;
}
.sidebar-head { font-weight: 700; color: var(--muted); padding: 4px 10px 8px; }
#doc-list { list-style: none; margin: 0; padding: 0; flex: 1; }
#doc-list li { display: flex; align-items: center; gap: 4px; padding: 7px 10px; border-radius: 10px; cursor: pointer; }
#doc-list li:hover { background: var(--line); }
#doc-list li.active { background: var(--accent); color: #ffffff; }
#doc-list .doc-name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#doc-list .doc-date { font-size: 11px; opacity: 0.6; }
#doc-list .delete { border: 0; background: transparent; cursor: pointer; opacity: 0; width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; color: inherit; }
#doc-list .delete svg { width: 12px; height: 12px; }
#doc-list li:hover .delete { opacity: 0.7; }
.sidebar-note { color: var(--muted); font-size: 11px; padding: 6px 10px 0; margin: 0; }
#doc-list { flex: 0 1 auto; max-height: 45%; overflow-y: auto; }
.outline-head { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
#outline { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
#outline li { padding: 4px 10px; border-radius: 8px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#outline li:hover { background: var(--line); }
#outline li.top { font-weight: 600; }
#outline li.deep { color: var(--muted); }

.panes { flex: 1; position: relative; min-width: 0; border-radius: 18px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.pane { position: absolute; top: 0; bottom: 0; }
.pane iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }
#editor {
  width: 100%; height: 100%; border: 0; resize: none; outline: none; padding: 24px max(24px, calc((100% - 820px) / 2));
  font: 15px/1.6 -apple-system, system-ui, sans-serif; background: var(--surface); color: var(--text); tab-size: 4;
}
.divider { position: absolute; top: 0; bottom: 0; width: 9px; cursor: col-resize; z-index: 2; }
.divider::after { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; width: 1px; background: var(--line); }

/* Drop, toast, dialogs */
.drop-overlay {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 20;
  background: color-mix(in srgb, var(--accent) 18%, transparent); backdrop-filter: blur(6px);
}
.drop-overlay div { padding: 22px 30px; border-radius: 20px; background: var(--glass-strong); font-size: 16px; font-weight: 600; box-shadow: var(--shadow); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 18px; border-radius: 16px;
  background: var(--glass-strong); backdrop-filter: blur(20px); border: 1px solid var(--line); box-shadow: var(--shadow); z-index: 30;
}
dialog { border-radius: 20px; padding: 20px 22px; color: var(--text); min-width: 340px; background: var(--glass-strong); }
dialog::backdrop { background: rgba(0, 0, 0, 0.25); }
dialog h2 { margin: 0 0 14px; font-size: 16px; }
dialog label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0; }
dialog label.check { justify-content: flex-start; }
dialog select, dialog input[type="number"] { font: inherit; padding: 4px 6px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
dialog input[type="number"] { width: 64px; }
dialog .hint { color: var(--muted); font-size: 12px; max-width: 320px; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .buttons button { border: 0; padding: 6px 16px; border-radius: 14px; background: var(--line); cursor: pointer; }
dialog .buttons .primary { background: var(--accent); color: #ffffff; }
#shortcut-table td { padding: 3px 14px 3px 0; }
.pdf-form { display: flex; gap: 22px; }
.pdf-options { width: 300px; }
/* The print frame, scaled down: the first page as it will print (page breaks: browser preview). */
.pdf-preview {
  position: relative; width: 300px; height: 424px; overflow: hidden; flex-shrink: 0;
  background: #ffffff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.15);
}
.pdf-preview iframe { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #ffffff; }
.offscreen-frame { position: fixed; left: -20000px; top: 0; border: 0; }
#shortcut-table td:first-child { font-family: ui-monospace, Menlo, monospace; color: var(--muted); white-space: nowrap; }

/* Phone: compact bar, bigger touch targets, sidebar as a drawer, one pane at a time. */
@media (max-width: 700px) {
  .toolbar { grid-template-columns: auto 1fr auto; gap: 4px; margin: 6px 6px 0; padding: 4px 6px; border-radius: 20px; }
  .toolbar .group:first-child { flex: 0 0 auto; }
  .title { display: none; }
  #modes { justify-self: center; }
  #modes [data-mode="split"] { display: none; }
  .icon { width: 38px; height: 36px; }
  .group.end { gap: 0; }
  .tabs { padding: 6px 8px 0; }
  .tab { min-width: 104px; padding: 6px 4px 6px 10px; }
  .tab .close { opacity: 0.6; width: 26px; height: 26px; }
  main { padding: 6px; gap: 0; }
  .panes { border-radius: 14px; }
  .sidebar {
    position: fixed; z-index: 15; left: 8px; top: calc(8px + env(safe-area-inset-top)); bottom: calc(8px + env(safe-area-inset-bottom));
    width: min(320px, 86vw); background: var(--glass-strong); backdrop-filter: blur(24px); box-shadow: var(--shadow);
  }
  #doc-list li, #outline li { padding-top: 10px; padding-bottom: 10px; }
  #editor { font-size: 16px; padding: 16px; }
  .menu-items { right: -6px; min-width: 250px; }
  .menu-items button { padding: 10px 12px; }
  dialog { min-width: 0; width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow: auto; padding: 16px; }
  .pdf-form { flex-direction: column; align-items: center; }
  .pdf-options { width: 100%; }
  .pdf-preview { width: 210px; height: 297px; }
  dialog select, dialog input[type="number"] { font-size: 16px; }
}
