:root {
  --bg: #fff; --side: #f6f6f7; --text: #222; --muted: #8a8a8f; --line: #dcdcdf;
  --hover: #ececef; --accent: #2563eb; --mark: #fde68a; --indent: 38px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1e1e1e; --side: #181818; --text: #dcddde; --muted: #8b8d91; --line: #3d3d40;
  --hover: #2c2c2f; --accent: #7aa2ff; --mark: #6b5310; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", "Nirmala UI", system-ui, sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; border-radius: 6px; padding: 5px 9px; cursor: pointer; }
button:hover { background: var(--hover); }
input { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#login { max-width: 260px; margin: 18vh auto 0; display: grid; gap: 10px; text-align: center; padding: 0 16px; }
#login button { background: var(--accent); color: #fff; }

#app { display: flex; height: 100dvh; }
#side { width: 260px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side-top { display: grid; gap: 8px; padding: 10px; }
.side-top button { text-align: left; }
#list { overflow: auto; padding: 0 6px 12px; }
.item { display: block; width: 100%; text-align: left; margin-bottom: 2px; overflow-wrap: anywhere; }
.item.on { background: var(--hover); font-weight: 600; }
.hit { display: block; width: 100%; text-align: left; color: var(--muted); padding-left: 22px; font-size: 13px; overflow-wrap: anywhere; }
mark { background: var(--mark); color: var(--text); }
.empty { color: var(--muted); padding: 8px; }

main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 2px; padding: 6px 10px; }
header button { white-space: nowrap; }
.grow { flex: 1; }
#status { color: var(--muted); font-size: 12px; margin-left: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#menu { display: none; }
#page { flex: 1; overflow: auto; display: flex; flex-direction: column; }
#sheet { width: 100%; max-width: 820px; margin: 0 auto; padding: 8px 28px 0; flex: 1; display: flex; flex-direction: column; }
#title { font-size: 30px; font-weight: 700; line-height: 1.3; margin-bottom: 14px; outline: none; padding-left: 24px; overflow-wrap: anywhere; }
#title:empty::before, .text.ph:empty::before { content: attr(data-ph); color: var(--muted); }
#tail { flex: 1; min-height: 35vh; cursor: text; }

/* Outline rows touch each other so the vertical guides stay continuous. */
.row { display: flex; align-items: stretch; }
.guide { flex: none; width: var(--indent); position: relative; }
.guide::before { content: ""; position: absolute; top: 0; bottom: 0; left: 36px; border-left: 1px solid var(--line); }
.row.focus-path .guide:last-of-type::before { border-left-color: var(--muted); }
.twist, .dot { flex: none; height: 31px; display: grid; place-items: center; padding: 0; background: none; }
.twist { width: 24px; color: var(--muted); font-size: 17px; }
.twist span { display: block; transform: rotate(90deg); transition: transform .12s; }
.row.closed .twist span { transform: none; }
button.twist:disabled { visibility: hidden; }
.dot { width: 24px; border-radius: 50%; }
.dot:hover { background: none; }
.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.row.closed .dot::before { box-shadow: 0 0 0 5px var(--hover); background: var(--text); }
.text { flex: 1; min-width: 0; outline: none; padding: 4px 4px; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 31px; font-size: 16px; }
.row.root > .text { font-weight: 600; }
.count { align-self: center; color: var(--muted); font-size: 12px; padding: 0 6px; }

#keys { display: none; }
#shade { display: none; }
#toast { position: fixed; left: 50%; bottom: 64px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }

@media (max-width: 760px) {
  :root { --indent: 22px; }
  .guide::before { left: 20px; }
  #side { position: fixed; z-index: 3; inset: 0 auto 0 0; width: min(84vw, 320px); transform: translateX(-101%); transition: transform .18s; }
  #app.menu-open #side { transform: none; }
  #app.menu-open #shade { display: block; position: fixed; inset: 0; z-index: 2; background: #0006; }
  #menu { display: block; }
  header button span { display: none; }
  #sheet { padding: 4px 10px 0; }
  #title { font-size: 23px; }
  #keys { display: flex; border-top: 1px solid var(--line); }
  #keys button { flex: 1; font-size: 21px; padding: 9px; }
}
