:root {
  --bg: #f6f5f1; --panel: #fff; --ink: #1c1b19; --muted: #6b6860; --line: #d9d6cd;
  --accent: #1d4ed8; --accent-ink: #fff; --danger: #b42318; --radius: 10px;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 var(--ui); color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
[hidden] { display: none !important; }

.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.btn {
  font: inherit; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--ink); cursor: pointer; touch-action: manipulation;
}
.btn:hover { background: #f0eee8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:focus-visible, .title:focus-visible, textarea:focus-visible, summary:focus-visible, .menu button:focus-visible, .doc-item button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, white); outline-offset: 1px;
}
.title { flex: 1; min-width: 0; font: inherit; font-weight: 600; min-height: 44px; padding: 0 10px; border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--ink); }
.title:hover, .title:focus { border-color: var(--line); background: var(--bg); }
.kind { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; white-space: nowrap; }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 190px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 6px; display: flex; flex-direction: column; }
.menu button { font: inherit; text-align: left; min-height: 44px; padding: 0 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; color: var(--ink); }
.menu button:hover { background: var(--bg); }

main { flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px; grid-template-rows: minmax(150px, 38%) 1fr; }
@media (min-width: 820px) { main { grid-template-rows: none; grid-template-columns: minmax(300px, 40%) 1fr; } }
.pane { min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); position: relative; }
.editor { display: flex; flex-direction: column; }
textarea {
  flex: 1; min-height: 0; width: 100%; resize: none; border: 0; border-radius: var(--radius) var(--radius) 0 0; padding: 14px;
  font: 16px/1.5 var(--mono); /* 16px+ stops iOS zooming on focus */ color: var(--ink); background: transparent;
}
textarea::placeholder { color: #a9a59a; opacity: 1; }
.error { margin: 0 12px 8px; padding: 9px 12px; border-radius: 8px; background: #fdecea; color: var(--danger); font-size: 14px; border: 1px solid #f4c3bd; }
.editor-foot { display: flex; align-items: flex-start; gap: 10px; padding: 8px 12px 10px; border-top: 1px solid var(--line); font-size: 14px; }
.help { flex: 1; min-width: 0; color: var(--muted); }
.help summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; }
.help pre { margin: 4px 0 6px; font: 13px/1.5 var(--mono); white-space: pre-wrap; color: var(--ink); }
.status { color: var(--muted); font-size: 13px; padding-top: 9px; white-space: nowrap; }
.status.warn { color: var(--danger); }

.preview { overflow: auto; display: flex; }
.stage { margin: auto; padding: 16px; width: 100%; display: flex; justify-content: center; align-items: center; }
.stage svg { width: 100%; max-width: 1100px; height: auto; max-height: 100%; background: #fff; }
.stage.ghost svg { opacity: .35; }
.stage.stale svg { opacity: .5; filter: grayscale(1); }
.ghost-badge { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; pointer-events: none; }

.drawer { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(360px, 90vw); background: var(--panel); border-right: 1px solid var(--line); box-shadow: 8px 0 30px rgba(0,0,0,.14); display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.new-row { display: flex; gap: 8px; padding: 12px 14px; flex-wrap: wrap; }
.doc-list { list-style: none; margin: 0; padding: 0 8px; overflow: auto; flex: 1; }
.doc-item { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.doc-item.current { background: #e8eefc; }
.doc-item .open { flex: 1; min-width: 0; text-align: left; font: inherit; min-height: 52px; padding: 6px 10px; border: 0; background: none; cursor: pointer; color: var(--ink); }
.doc-item .open small { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.doc-item .open span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .mini { font: inherit; min-width: 44px; min-height: 44px; border: 0; background: none; cursor: pointer; border-radius: 8px; color: var(--muted); }
.doc-item .mini:hover { background: var(--bg); color: var(--ink); }
.drawer-note { margin: 0; padding: 10px 14px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.25); }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; background: #1c1b19; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw; }

@media (max-width: 560px) { .hide-narrow { display: none; } .kind { display: none; } }
@media print {
  body > *:not(main), .editor, .ghost-badge { display: none !important; }
  main { display: block; padding: 0; } .pane { border: 0; } .stage svg { max-width: none; }
}
