:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --border: #e3e1dc;
  --text: #1f1d1a;
  --muted: #6d6a63;
  --accent: #1f6feb;
  --marked: #fff3bf;
  --highlight: #ffd43b;
  --danger: #c92a2a;
  --radius: 6px;

  /* One colour per annotation, cycled. Ten hues that stay apart from each
     other and carry enough contrast for a 3px bar. */
  --mark-0: #e8590c;
  --mark-1: #1971c2;
  --mark-2: #2f9e44;
  --mark-3: #9c36b5;
  --mark-4: #c2255c;
  --mark-5: #0c8599;
  --mark-6: #b38600;
  --mark-7: #4263eb;
  --mark-8: #5c940d;
  --mark-9: #6741d9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2023;
    --border: #34363a;
    --text: #e8e6e3;
    --muted: #9a978f;
    --accent: #6ea8fe;
    --marked: #3d3a1f;
    --highlight: #8a7420;
    --danger: #ff8787;

    --mark-0: #ff922b;
    --mark-1: #4dabf7;
    --mark-2: #51cf66;
    --mark-3: #da77f2;
    --mark-4: #f783ac;
    --mark-5: #22b8cf;
    --mark-6: #ffd43b;
    --mark-7: #748ffc;
    --mark-8: #a9e34b;
    --mark-9: #9775fa;
  }
}

* { box-sizing: border-box; }

/* `display` set by a class beats the `hidden` attribute's UA style, so the
   filtered-out tree rows need saying twice. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.korean {
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

a { color: var(--accent); }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 14px; }
.topbar form { margin: 0; }
.who { color: var(--muted); }

button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

/* Generic bits */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.narrow { max-width: 380px; margin: 48px auto; }
.meta, .hint, .description { color: var(--muted); font-size: 13px; }
.breadcrumb { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.empty { color: var(--muted); }
.error { color: var(--danger); }
.status { font-size: 13px; color: var(--muted); }
.status.error { color: var(--danger); }

input[type="text"], input[type="password"], input[type="search"], textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
button.primary {
  margin-top: 16px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

/* Corpus and sentence lists */

.corpus-list { list-style: none; padding: 0; display: grid; gap: 12px; }
.corpus-name { font-size: 17px; font-weight: 600; text-decoration: none; }
progress { width: 100%; height: 6px; margin-top: 10px; }

.sentence-list { padding-left: 24px; }
.sentence-list li { padding: 5px 0; border-bottom: 1px solid var(--border); }
.sentence-list li.done a { color: var(--muted); }
.sentence-list a { text-decoration: none; }
.sentence-list a:hover { text-decoration: underline; }
.sentence-list .marks { float: right; color: var(--muted); font-size: 12px; }

/* Annotation screen */

.sentence-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.counter { color: var(--muted); font-size: 13px; }
.pager { display: flex; gap: 14px; font-size: 13px; }
.pager .disabled { color: var(--border); }

.sentence {
  --lane-count: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  padding-bottom: calc(20px + var(--lane-count) * 5px);
  font-size: 30px;
  /* The strut opens up enough leading for the lane bars below each line. */
  line-height: calc(1.9em + var(--lane-count) * 5px);
  white-space: pre-wrap;
  cursor: text;
}
.sentence-context {
  margin: 0 0 6px;
  padding: 0 22px;
  font-size: 18px;
  color: var(--muted);
}
.sentence-context .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-right: 6px;
}

.ch {
  position: relative;
  display: inline-block;
  line-height: 1.35;
  border-radius: 2px;
}
.ch.marked { background: var(--marked); }
.ch.highlighted {
  background: color-mix(in srgb, var(--highlight-colour) 30%, transparent);
}
/* One bar per annotation covering this character, in that annotation's lane. */
.ch .bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  bottom: calc(-6px - var(--lane) * 5px);
  border-radius: 2px;
}

.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px 2px;
  font-size: 13px;
  color: var(--muted);
}
.selection-bar .label { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }
.selection-bar .picked { font-size: 18px; color: var(--text); }
code { font-size: 12px; color: var(--muted); }

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}
@media (max-width: 820px) { .panes { grid-template-columns: 1fr; } }

.pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

/* A checkbox that reads as one line, not as a form field with a label above. */
.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 4px;
  padding: 2px 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.toggle input { margin: 0; cursor: pointer; }
.toggle:hover { color: var(--text); }

/* With levels kept open the level row is a heading, so its caret is dropped -
   clicking it still collapses that one group until the next search. */
.tree.levels-expanded .group.level > .twisty .caret { visibility: hidden; }

.tree {
  margin-top: 6px;
  max-height: 460px;
  overflow-y: auto;
}
.group > .children { display: none; padding-left: 15px; }
.group.open > .children { display: block; }

.twisty {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.twisty:hover { background: var(--marked); }
.caret::before {
  content: "▸";
  display: inline-block;
  color: var(--muted);
  transition: transform 120ms;
}
.group.open > .twisty .caret::before { transform: rotate(90deg); }
.group-label { flex: 1; }
.group.level > .twisty .group-label { color: var(--muted); font-size: 13px; }

.point {
  display: grid;
  grid-template-columns: minmax(96px, 34%) 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 4px 6px;
  border-left: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.point:hover { background: var(--marked); border-left-color: var(--accent); }
/* The query hit the pattern itself, not just a description. */
.point.pattern-match { border-left-color: var(--accent); }
.point.pattern-match .pattern { font-weight: 600; }
.glosses {
  min-width: 0;
  border-left: 1px solid var(--border);
  padding-left: 10px;
}
.gloss {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
}
.gloss.ko { color: var(--text); }
.gloss.en { color: var(--muted); }
.point:hover .gloss { white-space: normal; }

.pattern { font-size: 17px; }
.point-head { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; min-width: 0; }
.nikl { font-size: 12px; color: var(--muted); }
.level {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 6px;
}

.annotation-list { list-style: none; margin: 0 0 10px; padding: 0; }
.annotation-list > li {
  border: 1px solid var(--border);
  border-left: 3px solid var(--mark-colour);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--mark-colour);
}
.annotation-list > li:hover { border-color: var(--accent); }
.annotation-list .row { display: flex; align-items: baseline; gap: 8px; }
.annotation-list .row .pattern { flex: 1; }
.annotation-list .spans { list-style: none; margin: 6px 0 0; padding: 0; }
.annotation-list .spans li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
  font-size: 13px;
}
.annotation-list button {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 1px 7px;
  cursor: pointer;
}
.annotation-list button:hover { color: var(--text); border-color: var(--accent); }
.annotation-list button.delete:hover, .annotation-list button.delete-span:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.complete-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}
.complete-bar label { margin: 0; color: var(--text); font-size: 14px; }
