:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --surface-2: #f4f4f2;
  --surface-3: #ebebe8;
  --border: #e2e1dd;
  --text: #1b1b1a;
  --text-2: #52514e;
  --text-3: #8a8984;
  --accent: #2a78d6;
  --undated: #a3a29d;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #6250d6;
  --s8: #e34948;
  --radius: 8px;
  --font: ui-sans-serif, -apple-system, 'Segoe UI', Inter, Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-3: #2c2c2a;
    --border: #363633;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8d8c85;
    --accent: #3987e5;
    --undated: #6b6a65;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #0ca30c;
    --s7: #9085e9;
    --s8: #e66767;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2c2c2a;
  --border: #363633;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8d8c85;
  --accent: #3987e5;
  --undated: #6b6a65;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #0ca30c;
  --s7: #9085e9;
  --s8: #e66767;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--surface);
  color: var(--text);
  font: 14px/1.55 var(--font);
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
a {
  color: var(--accent);
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.status {
  margin: auto;
  padding: 24px;
  color: var(--text-2);
  text-align: center;
  max-width: 460px;
}
.status h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 16px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
}
.btn:hover {
  background: var(--surface-2);
}
.btn.icon {
  width: 30px;
  padding: 0;
  justify-content: center;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn[aria-pressed='true'] {
  background: var(--surface-3);
  border-color: var(--text-3);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn svg {
  width: 16px;
  height: 16px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- home ---------- */
.home {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 16px 40px;
}
.home h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.home .sub {
  color: var(--text-2);
  margin: 0 0 20px;
}
.home-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.input {
  flex: 1;
  min-width: 180px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.doc-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.doc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
}
.doc-row:first-child {
  border-top: none;
}
.doc-row:hover {
  background: var(--surface-2);
}
.doc-row .t {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.doc-row .when {
  color: var(--text-3);
  font-size: 12px;
  white-space: nowrap;
}
.muted {
  color: var(--text-3);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 10;
}

/* ---------- viewer ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.top .title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top .back {
  color: var(--text-2);
  text-decoration: none;
}

.bar {
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.bar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 0;
  flex-wrap: wrap;
}
.bar-controls .now {
  flex: 1;
  min-width: 140px;
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-controls .now strong {
  color: var(--text);
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--surface);
  height: 28px;
  padding: 0 9px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-2);
}
.seg button[aria-pressed='true'] {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
}

.track-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  touch-action: pan-x;
}
.track {
  position: relative;
  height: 62px;
  min-width: 100%;
  cursor: pointer;
  user-select: none;
}
.track .line,
.track .fill {
  position: absolute;
  top: 22px;
  height: 2px;
  border-radius: 2px;
}
.track .line {
  background: var(--border);
}
.track .fill {
  background: var(--text-3);
}
.stop {
  position: absolute;
  top: 0;
  width: 36px;
  margin-left: -18px;
  height: 62px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
}
.stop .dot {
  position: absolute;
  top: 23px;
  left: 50%;
  width: var(--d, 10px);
  height: var(--d, 10px);
  border-radius: 50%;
  background: var(--c);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--surface-2);
  transition: transform 0.12s;
}
.stop.future .dot {
  background: var(--surface-2);
  box-shadow: inset 0 0 0 2px var(--c), 0 0 0 2px var(--surface-2);
}
.stop.sel .dot {
  transform: translate(-50%, -50%) scale(1.25);
  box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--c);
}
.stop .lbl {
  position: absolute;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  line-height: 1.2;
  text-align: center;
}
.stop.sel .lbl {
  color: var(--text);
  font-weight: 600;
}
.stop .yr {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--text-3);
  font-weight: 600;
}
.stop:focus-visible {
  outline: none;
}
.stop:focus-visible .dot {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.today {
  display: flex;
  gap: 6px;
  padding: 0 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.today .muted {
  font-size: 12px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip .sw {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  flex-shrink: 0;
}
.chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  flex: 1;
  min-height: 0;
  display: flex;
}
.doc {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 12px 18px 40vh;
  scroll-behavior: smooth;
}
.doc-inner {
  max-width: 760px;
  margin: 0 auto;
}

/* groups */
.grp {
  position: relative;
  margin: 6px 0;
  padding: 2px 10px 2px 14px;
  border-left: 3px solid var(--c);
  border-radius: 0 6px 6px 0;
  transition: opacity 0.18s, background-color 0.18s;
}
.grp.undated {
  --c: var(--undated);
  border-left-style: dashed;
}
.grp.current {
  background: color-mix(in srgb, var(--c) 9%, transparent);
}
.grp.dim {
  opacity: 0.38;
}
.grp.hidden-undated {
  display: none;
}
.grp-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-2);
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
}
.grp-tag .sw {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
}
.grp.undated .grp-tag .sw {
  background: none;
  border: 1.5px dashed var(--undated);
}
.grp-tag:hover {
  color: var(--text);
  text-decoration: underline;
}

.future-stub {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 4px 0;
  padding: 2px 0 2px 14px;
  border: none;
  border-left: 3px dotted var(--c);
  background: none;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  text-align: left;
}
.future-stub:hover {
  color: var(--text);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* blocks */
.b {
  margin: 4px 0;
  word-wrap: break-word;
}
.b.p:empty {
  min-height: 1em;
}
.b.h1 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 10px;
}
.b.h2 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  margin-top: 8px;
}
.b.h3 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 6px;
}
.b.h4,
.b.h5,
.b.h6 {
  font-weight: 600;
}
.b.quote {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  color: var(--text-2);
}
.b.li {
  display: flex;
  gap: 8px;
}
.b.li .mk {
  flex: 0 0 18px;
  color: var(--text-2);
  text-align: right;
}
.b.li.done .tx {
  color: var(--text-3);
  text-decoration: line-through;
}
.b.code {
  font: 12.5px/1.5 var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  white-space: pre-wrap;
}
.b.img img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: var(--surface-2);
}
.b.img .cap {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}
.b.embed a {
  display: block;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.b.tbl {
  overflow-x: auto;
}
.b.tbl table {
  border-collapse: collapse;
  font-size: 13px;
}
.b.tbl td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  vertical-align: top;
}
.b.tbl tr:first-child td {
  background: var(--surface-2);
  font-weight: 600;
}
.b.other {
  color: var(--text-3);
  font-style: italic;
}
code.ic {
  font: 0.92em var(--mono);
  background: var(--surface-3);
  padding: 1px 4px;
  border-radius: 4px;
}
.ref {
  color: var(--text);
  text-decoration: underline dotted;
}
.stamp {
  display: inline-block;
  padding: 0 6px;
  border-radius: 10px;
  border: 1.5px solid var(--c, var(--text-3));
  font-size: 0.88em;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}

/* minimap */
.mini {
  flex: 0 0 22px;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  padding: 6px 5px;
  gap: 2px;
  cursor: pointer;
}
.mini .seg-m {
  flex: var(--w) 1 0;
  min-height: 3px;
  border-radius: 2px;
  background: var(--c);
  transition: opacity 0.18s;
}
.mini .seg-m.undated {
  background: repeating-linear-gradient(
    135deg,
    var(--undated) 0 2px,
    transparent 2px 4px
  );
}
.mini .seg-m.future {
  opacity: 0.18;
}
.mini .seg-m.dim {
  opacity: 0.45;
}
.mini .seg-m.current {
  box-shadow: 0 0 0 1.5px var(--text);
}
.mini .gap-m {
  flex: 0 0 4px;
}

.empty-dates {
  margin: 10px 12px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 13px;
}

/* compact layout for the in-doc embed */
.embed .top {
  padding: 6px 10px;
}
.embed .top .title {
  font-size: 13px;
}
.embed .doc {
  padding: 8px 12px 40vh;
}
.embed .b.h1 {
  font-size: 20px;
}
.embed .b.h2 {
  font-size: 17px;
}

@media (max-width: 560px) {
  .mini {
    flex-basis: 16px;
    padding: 6px 3px;
  }
  .doc {
    padding: 10px 12px 40vh;
  }
  .hide-sm {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .doc {
    scroll-behavior: auto;
  }
  * {
    transition: none !important;
  }
}

.bar-controls .btn:not(.icon) {
  height: 30px;
  font-size: 12px;
}
