:root {
  --bg: #f7f5f0;
  --panel: #efece5;
  --panel-2: #e6e2d9;
  --text: #22211e;
  --muted: #76726a;
  --line: #d8d3c8;
  --accent: #a8741a;
  --accent-bg: #f1e3c4;
  --sel: #e4dccb;
  --danger: #b3412f;
  --ok: #4d7a45;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  --read: "Iowan Old Style", "Charter", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c; --panel: #1c1f24; --panel-2: #23272d; --text: #e6e3dc; --muted: #8d8a83;
    --line: #2e333a; --accent: #d9a441; --accent-bg: #3a2f1a; --sel: #2c3139; --danger: #e0715e;
    --ok: #8fbf7f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181c; --panel: #1c1f24; --panel-2: #23272d; --text: #e6e3dc; --muted: #8d8a83;
  --line: #2e333a; --accent: #d9a441; --accent-bg: #3a2f1a; --sel: #2c3139; --danger: #e0715e;
  --ok: #8fbf7f; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #16181c; border-color: var(--accent); font-weight: 600; }
button.icon { padding: 0 8px; font-size: 16px; line-height: 24px; }
button.link { background: none; border: 0; color: var(--muted); padding: 2px 0; }
button.link:hover { color: var(--text); }
button.danger { color: var(--danger); }
input[type=search], input[type=password], input:not([type]), select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px;
}
kbd { font: 12px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
[hidden] { display: none !important; }

/* login */
.login { display: grid; place-items: center; height: 100%; }
.login-card { width: min(360px, calc(100% - 32px)); display: grid; gap: 12px; }
.login-card h1 { font: 600 28px var(--read); margin: 0 0 8px; }
.login-card button { padding: 10px; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* layout */
.app { display: grid; grid-template-columns: 250px 340px 1fr; height: 100%; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 8px; }
.brand { font: 600 17px var(--read); }
.tree { flex: 1; overflow: auto; padding: 0 6px 12px; }
.side-foot { display: flex; justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--line); }

.node { display: flex; align-items: center; gap: 2px; border-radius: 6px; padding: 3px 4px; cursor: pointer; user-select: none; }
.node:hover { background: var(--panel-2); }
.node.sel { background: var(--sel); }
.node.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.node .tw { width: 16px; text-align: center; color: var(--muted); font-size: 10px; flex: none; }
.node .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .ct { color: var(--muted); font-size: 12px; }
.node .acts { display: none; gap: 2px; }
.node:hover .acts { display: flex; }
.node:hover .ct { display: none; }
.node .acts button { padding: 0 5px; font-size: 12px; line-height: 18px; background: none; border: 0; color: var(--muted); }
.node .acts button:hover { color: var(--text); }
.node input { width: 100%; padding: 0 4px; }
.tree .sep { height: 1px; background: var(--line); margin: 6px 4px; }

.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.crumb { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb span { color: var(--muted); font-weight: 400; }
.list-tools { display: flex; gap: 6px; }
.list-tools input { flex: 1; min-width: 0; }
.subtoggle { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.notes { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.notes li { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.notes li:hover { background: var(--panel); }
.notes li.sel { background: var(--sel); }
.notes .t { display: flex; gap: 6px; align-items: baseline; }
.notes .t b { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes .m { color: var(--muted); font-size: 12px; display: flex; gap: 8px; margin-top: 2px; }
.notes .p { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-top: 2px; }
.badge { font-size: 11px; border-radius: 4px; padding: 0 5px; }
.badge.raw { background: var(--accent-bg); color: var(--accent); }
.badge.clean { color: var(--ok); border: 1px solid var(--line); }
.kind { width: 14px; flex: none; color: var(--muted); }

.editor { overflow: auto; min-height: 0; }
.empty { color: var(--muted); padding: 40px; }
.ed { max-width: 760px; margin: 0 auto; padding: 24px 32px 80px; display: grid; gap: 14px; }
.ed .title { font: 600 24px var(--read); background: none; border: 0; padding: 0; width: 100%; outline: none; }
.ed .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.ed .meta .grow { flex: 1; }
.ed .save { font-size: 12px; }
.ed .save.err { color: var(--danger); }
.player { display: grid; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.player audio { width: 100%; }
.player .row { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.player .row button.on { border-color: var(--accent); color: var(--accent); }
.sec-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; align-items: center; }
textarea.body, textarea.transcript {
  width: 100%; resize: none; border: 0; outline: none; background: none; overflow: hidden;
  font: 17px/1.65 var(--read); padding: 0; min-height: 200px;
}
textarea.transcript { font-size: 15px; color: var(--muted); min-height: 60px; border-left: 2px solid var(--line); padding-left: 12px; }
textarea.transcript:focus { color: var(--text); }

dialog { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: min(520px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.dlg { display: grid; gap: 10px; }
.dlg h2 { font: 600 17px var(--read); margin: 8px 0 0; }
.hint { color: var(--muted); margin: 0; font-size: 13px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.row.end { justify-content: flex-end; }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
.token { background: var(--panel); padding: 8px; border-radius: 6px; white-space: pre-wrap; word-break: break-all; user-select: all; margin: 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; }
  .side, .list { border-right: 0; border-bottom: 1px solid var(--line); }
  .tree { max-height: 30vh; }
  .notes { max-height: 40vh; }
  .ed { padding: 16px; }
}
