:root {
  --bg: #0d0f12;
  --panel: #14181d;
  --panel-2: #1a1f26;
  --line: #262d36;
  --text: #e6e9ee;
  --muted: #8b96a5;
  --accent: #4da3ff;
  --accent-2: #2b7fd4;
  --good: #37c68b;
  --warn: #e8b04b;
  --bad: #e76161;
  --raw: #7c8b9d;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: #3a4553; background: #20262e; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
button.ghost { background: transparent; }
button.wide { width: 100%; margin-top: 8px; }
input, select, textarea { outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(13, 15, 18, .96);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  padding: 8px 14px 6px;
}
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-main { min-height: 34px; }
.row-sub { margin-top: 6px; justify-content: space-between; }

.brand { display: flex; align-items: center; gap: 8px; min-width: 210px; }
.brand strong { letter-spacing: .2px; }
.brand .muted { font-size: 12px; font-family: var(--mono); max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px rgba(231,97,97,.12); }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px rgba(55,198,139,.14); }
.dot.warn { background: var(--warn); }

.meter { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; max-width: 420px; }
.meter-bar { position: relative; flex: 1; height: 12px; background: #0a0c0f; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: linear-gradient(90deg, var(--good), #8fd14f 55%, var(--warn) 80%, var(--bad)); transition: width 40ms linear; }
.meter-peak { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; opacity: .55; left: 0; transition: left 120ms linear; }
.meter-db { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 62px; text-align: right; }
.meter-ascii { font-family: var(--mono); font-size: 11px; color: var(--good); letter-spacing: 1px; }

.controls { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.controls button, .controls select { padding: 5px 9px; font-size: 12.5px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 4px 11px; border-radius: 99px; border: 1px solid var(--line); background: transparent; font-size: 12.5px; color: var(--muted); }
.tab.active { background: #17334f; border-color: #2a5c8f; color: #cfe6ff; }
.tab .k { font-family: var(--mono); opacity: .7; margin-right: 4px; }

.status { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.chip { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); }
.chip.on { color: var(--good); border-color: #235c44; }
.chip.off { color: var(--muted); }
#sessionPicker { max-width: 230px; font-size: 12px; padding: 3px 8px; }

/* ---------- canvas ---------- */
main { padding: 16px 14px 90px; max-width: 1080px; margin: 0 auto; }
.empty { text-align: center; margin-top: 60px; }

.live { position: sticky; bottom: 12px; background: #12202e; border: 1px solid #24507c; border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; display: flex; gap: 10px; align-items: baseline; }
.live-tag { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; color: var(--accent); letter-spacing: 1px; }
#liveText { color: #9dc7f0; font-style: italic; }

.chunk { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin-bottom: 10px; transition: border-color .12s ease; }
.chunk:hover { border-color: #323c49; }
.chunk.deleted { opacity: .45; border-style: dashed; }
.chunk-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.chunk-head .id { color: #a9b6c6; }
.chunk-head .tools { margin-left: auto; display: flex; gap: 4px; opacity: .35; transition: opacity .12s; }
.chunk:hover .tools, .chunk.deleted .tools { opacity: 1; }
.chunk-head .tools button { padding: 1px 7px; font-size: 11px; font-family: system-ui, sans-serif; }
.chunk-body { padding: 9px 12px 10px; }
.chunk-text { outline: none; white-space: pre-wrap; word-wrap: break-word; }
.chunk-text[contenteditable="true"]:focus { background: #0f1419; border-radius: 6px; box-shadow: 0 0 0 1px #2a5c8f inset; padding: 4px 6px; margin: -4px -6px; }
.chunk-text.locked { color: #b9c3cf; font-family: var(--mono); font-size: 13px; }
.chunk-meta { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 6px; font-family: var(--mono); }
.chunk-meta .tag { border: 1px solid var(--line); border-radius: 99px; padding: 0 7px; }
.chunk-meta .tag.warn { color: var(--warn); border-color: #5a4720; }

.lineage { border-top: 1px dashed var(--line); padding: 8px 12px 12px; font-size: 12.5px; }
.lineage table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.lineage th, .lineage td { text-align: left; padding: 3px 8px 3px 0; vertical-align: top; border-bottom: 1px solid #1c2229; }
.lineage th { color: var(--muted); font-weight: 500; }
.lineage td.stage-name { white-space: nowrap; color: #9fb4c9; }
.lineage .ops { margin-top: 8px; color: var(--muted); }
.lineage .ops code { color: #cfe6ff; background: #10161d; border-radius: 4px; padding: 1px 5px; }
.lineage .ops li { margin: 2px 0; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px 16px 40px; overflow-y: auto; z-index: 40;
  box-shadow: -18px 0 40px rgba(0,0,0,.45);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer h2 { font-size: 16px; margin: 0 0 6px; }
.drawer h3 { font-size: 13px; margin: 20px 0 8px; color: #c3cddb; text-transform: uppercase; letter-spacing: .6px; }
.field { display: block; margin: 9px 0; font-size: 12px; color: var(--muted); }
.field input, .field textarea { display: block; width: 100%; margin-top: 3px; color: var(--text); }
.check { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin: 10px 0; }
.list { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.list li { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; margin-bottom: 6px; background: var(--panel-2); }
.list li .row2 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.list .terms { color: var(--muted); font-size: 11.5px; margin-top: 3px; word-break: break-word; }
.list button { padding: 0 7px; font-size: 11px; }
.list .empty-item { color: var(--muted); border-style: dashed; }
.gloss-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }
.gloss-add input { padding: 5px 8px; font-size: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #1d2b3a; border: 1px solid #2f4c69; color: #d8e8f8;
  padding: 9px 16px; border-radius: 99px; font-size: 13px; z-index: 60;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.toast.bad { background: #3a1e1e; border-color: #6b3030; color: #f2c7c7; }

@media (max-width: 720px) {
  .meter { order: 3; flex-basis: 100%; max-width: none; }
  .controls { width: 100%; margin-left: 0; }
  .brand .muted { display: none; }
}

/* ---------- access lock ---------- */
.lock {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 13, .88); backdrop-filter: blur(3px);
  padding: 20px;
}
.lock-card {
  width: min(430px, 94vw);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 22px 18px; box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.lock-card h2 { margin: 0 0 6px; font-size: 17px; }
.lock-card p { margin: 0 0 12px; font-size: 13px; }
.lock-card input { width: 100%; padding: 9px 11px; font-family: var(--mono); }
.lock-card code { background: #10161d; border-radius: 4px; padding: 1px 4px; }
