:root {
  --bg: #12110e;
  --bg-2: #1c1a15;
  --bg-3: #2a261e;
  --rail: #16140f;
  --line: #463f34;
  --text: #f7f2e8;
  --muted: #d4c9b6;
  --faint: #b7ab98;
  --amber: #ffb020;
  --amber-2: #ffd27a;
  --amber-ink: #1c1406;
  --open: #ff6a52;
  --counted: #8fd0a8;
  --note: #b7c9f5;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: "Segoe UI", system-ui, sans-serif;
  --serif: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
::selection { background: var(--amber); color: var(--amber-ink); }
input, textarea { caret-color: var(--amber); }
a { color: var(--amber); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-size: inherit; margin: 0; font-weight: inherit; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--amber);
  color: var(--amber-ink);
  padding: 8px 12px;
  z-index: 30;
  border-radius: 8px;
  font-weight: 650;
}
.skip:focus { top: 8px; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  gap: 12px 20px;
  align-items: center;
  padding: 12px 18px;
  background: rgba(18, 17, 14, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.mark {
  width: 36px;
  height: 36px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  flex: none;
}
.mark i {
  display: block;
  background: #3a3428;
  border-radius: 3px;
}
.mark i.hot { background: var(--amber); }
.word {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
}
.word em { font-style: italic; color: var(--amber); font-weight: 600; }
.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.search { position: relative; }
.search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 76px 10px 16px;
  min-height: 42px;
  font-size: 16px;
}
.search input::placeholder { color: var(--faint); }
.search input:hover { border-color: #6a5e48; }
#clear {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: var(--bg-3);
  color: var(--text);
  padding: 6px 10px;
  min-height: 32px;
  border-radius: 999px;
}
#clear[hidden] { display: none; }
#clear:hover { background: #3a3428; }
.tally {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.lamp {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}
.lamp.on { background: var(--open); }
.stat strong { color: var(--text); font-weight: 650; }
.stat.hot strong { color: var(--open); }
.sep { color: var(--faint); }

.sha-band {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--rail);
}
.sha-label {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  white-space: nowrap;
}
.sha-rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: #4a4336 transparent;
  padding: 2px 2px 4px;
}
.sha {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 196px;
  flex: none;
  scroll-snap-align: start;
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px 8px;
  color: var(--text);
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease);
}
.sha code { font-family: var(--mono); font-size: 12px; color: var(--amber); }
.sha small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sha[aria-pressed="true"],
.sha[aria-pressed="true"]:hover {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-ink);
}
.sha[aria-pressed="true"] code,
.sha[aria-pressed="true"] small,
.sha[aria-pressed="true"]:hover code,
.sha[aria-pressed="true"]:hover small { color: var(--amber-ink); }
.sha:hover { border-color: var(--amber); }

.shell {
  display: grid;
  grid-template-columns: 260px minmax(300px, 400px) minmax(0, 1fr);
  gap: 0;
  padding: 0;
  min-height: 0;
}
aside, .list-wrap, .detail-wrap {
  min-height: 0;
  overflow: auto;
  padding: 16px 16px 28px;
  scrollbar-width: thin;
  scrollbar-color: #4a4336 transparent;
}
.list-wrap {
  background: var(--rail);
  border-inline: 1px solid var(--line);
}
.side-group + .side-group { margin-top: 20px; }
.side-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
  color: var(--text);
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
}
.side-label span { color: var(--muted); font-weight: 550; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 6px 9px;
  min-height: 32px;
  font-size: 13px;
  line-height: 1.2;
  color: var(--text);
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease);
}
.chip[aria-pressed="true"],
.chip[aria-pressed="true"]:hover {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-ink);
  font-weight: 650;
}
.chip:hover { border-color: var(--amber); }
.chip[aria-pressed="true"]:focus-visible,
.sha[aria-pressed="true"]:focus-visible,
a.text-btn.primary:focus-visible { outline-color: #fff; }

.gates-group { margin-top: 18px; }
.gates-group summary { cursor: pointer; list-style: none; }
.gates-group summary::-webkit-details-marker { display: none; }
.gates-group summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: auto;
  flex: none;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
}
.gates-group[open] summary::after { transform: rotate(45deg); }
.gate-mini { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.gate-mini li {
  font-size: 13px;
  color: var(--muted);
  padding-left: 16px;
  position: relative;
  line-height: 1.4;
}
.gate-mini .gid { color: var(--text); font-weight: 650; }
.gate-mini li::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--open);
  position: absolute;
  left: 0;
  top: 0.45em;
}
.gate-mini li.is-done { color: var(--faint); }
.gate-mini li.is-done::before { background: var(--counted); }
.fine { color: var(--muted); font-size: 12px; margin: 10px 0 0; line-height: 1.45; }
.keys { margin-top: 18px; }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  color: var(--text);
}

.list-meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  min-height: 1.2em;
  font-variant-numeric: tabular-nums;
}
#list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.card {
  width: 100%;
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px 12px;
  color: inherit;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.card.open {
  background: #241c18;
  border-color: color-mix(in srgb, var(--open) 48%, var(--line));
}
.card.note { border-color: color-mix(in srgb, var(--note) 32%, var(--line)); }
.card[aria-current="true"] {
  background: #2e281c;
  border-color: var(--amber);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}
.card:hover { border-color: #8a7350; }
.card[aria-current="true"]:hover { border-color: var(--amber-2); }
.card-top { display: flex; gap: 8px; align-items: center; margin-bottom: 5px; }
.stamp {
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 700;
  text-transform: uppercase;
}
.stamp.open { color: var(--open); }
.stamp.counted { color: var(--counted); }
.stamp.note { color: var(--note); }
.surf { color: var(--faint); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.pin-dot {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}
.card .card-title {
  display: block;
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
  text-wrap: balance;
}
.card .path, .meta code, .sha-row code, .fid {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--amber);
  overflow-wrap: anywhere;
}
.card .path { margin: 4px 0 0; }
.blurb {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 28px 16px;
  color: var(--muted);
  background: color-mix(in srgb, var(--bg-2) 70%, transparent);
}
.empty p { margin: 0; color: var(--text); font-size: 16px; }
.empty.is-error {
  border-color: color-mix(in srgb, var(--open) 70%, var(--line));
  background: color-mix(in srgb, var(--open) 10%, var(--bg));
}
.empty button, .text-btn, .back, a.text-btn {
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 36px;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease);
}
.text-btn.primary,
.text-btn.primary:hover {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: var(--amber);
  font-weight: 650;
}
.text-btn.primary:hover { background: var(--amber-2); border-color: var(--amber-2); }
.back:hover, .empty button:hover, .text-btn:hover { border-color: var(--amber); }
.text-btn[aria-pressed="true"],
.text-btn[aria-pressed="true"]:hover {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: var(--amber);
  font-weight: 650;
}

.sheet {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 2px 8px 40px;
  box-shadow: none;
}
.sheet.arrive { animation: arrive 220ms var(--ease); }
@keyframes arrive {
  from { filter: blur(3px); opacity: 0.55; }
  to { filter: blur(0); opacity: 1; }
}
.kicker {
  margin: 10px 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}
.fid { color: var(--faint); }
.sheet h2.title {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-wrap: balance;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; }
.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
  margin: 16px 0 4px;
  padding: 14px 0;
  border-block: 1px solid var(--line);
}
.meta div { min-width: 0; }
.meta div.meta-wide { grid-column: 1 / -1; }
.meta .lbl {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.meta a { color: var(--amber); }
.mismatch {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--open) 14%, var(--bg-2));
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.sha-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.sha-row button {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--amber);
  border-radius: 999px;
  padding: 4px 9px;
  min-height: 28px;
}
.sha-row button:hover { border-color: var(--amber); }
.sha-row button[aria-pressed="true"],
.sha-row button[aria-pressed="true"]:hover {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: var(--amber);
}
.note-box {
  margin-top: 22px;
  max-width: 68ch;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.note-box label { display: block; font-size: 14px; font-weight: 650; color: var(--text); margin-bottom: 6px; }
.note-box .fine { display: inline; margin: 0 0 0 6px; font-weight: 450; }
.note-box textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  line-height: 1.45;
}
.note-box textarea::placeholder { color: var(--faint); }
.note-box textarea:hover { border-color: #6a5e48; }
.prose { margin-top: 16px; max-width: 68ch; font-size: 16px; line-height: 1.55; }
.prose h2 { font-size: 18px; font-weight: 650; margin: 22px 0 8px; letter-spacing: -0.01em; }
.prose h3 { font-size: 15px; font-weight: 650; margin: 18px 0 6px; color: var(--text); }
.prose p { margin: 0 0 10px; }
.prose ul { margin: 0 0 12px; padding-left: 1.2em; }
.prose li { margin: 5px 0; }
.prose li::marker { color: var(--amber); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.prose a { color: var(--amber); }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: #2c281f;
  padding: 1px 5px;
  border-radius: 4px;
  overflow-wrap: anywhere;
}
.table-wrap { overflow-x: auto; margin: 0 0 14px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 1.4; }
.prose th, .prose td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}
.prose th { color: var(--text); font-weight: 650; background: var(--bg-3); }
.prose tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-3) 45%, transparent); }
.sheet h3 {
  margin: 22px 0 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}
.rules { margin: 0 0 8px; padding-left: 1.25em; }
.rules li { margin: 8px 0; }
.rules li::marker { color: var(--amber); font-variant-numeric: tabular-nums; }
.desk-link {
  display: block;
  width: 100%;
  max-width: 68ch;
  text-align: left;
  margin: 14px 0 8px;
  background: #241c18;
  border: 1px solid color-mix(in srgb, var(--open) 48%, var(--line));
  border-radius: 12px;
  padding: 12px 14px;
  color: inherit;
  transition: border-color 160ms var(--ease);
}
.desk-link:hover { border-color: var(--amber); }
.desk-link strong { display: block; margin-bottom: 4px; font-size: 16px; }
.back { display: none; margin-bottom: 12px; }

.skel {
  height: 96px;
  border-radius: 12px;
  background: linear-gradient(100deg, var(--bg-2) 20%, var(--bg-3) 45%, var(--bg-2) 70%);
  background-size: 200% 100%;
  animation: skel 1.1s ease-in-out infinite;
}
.skel-line { height: 14px; margin-top: 10px; border-radius: 999px; }
.skel-line.short { width: 55%; }
@keyframes skel {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@media (min-width: 861px) {
  body {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
  }
  .shell { height: 100%; }
}

@media (max-width: 1100px) and (min-width: 861px) {
  header {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand tally" "search search";
  }
  .brand { grid-area: brand; }
  .tally { grid-area: tally; justify-self: end; }
  .search { grid-area: search; }
  .shell {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  aside {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
    align-items: flex-start;
    overflow: auto;
    max-height: 34vh;
    border-bottom: 1px solid var(--line);
    padding-bottom: 12px;
  }
  .side-group + .side-group { margin-top: 0; }
  .gates-group { flex: 1 1 320px; }
  .list-wrap { border-left: 0; }
  .keys { display: none; }
  .meta { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  header {
    position: sticky;
    grid-template-columns: 1fr;
    grid-template-areas: "brand" "tally" "search";
    padding: 12px;
    gap: 10px;
  }
  .brand { grid-area: brand; }
  .tally { grid-area: tally; }
  .search { grid-area: search; }
  .word { font-size: 20px; }
  .sha-band {
    display: block;
    padding: 8px 12px 10px;
  }
  .sha-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .sha { width: 168px; }
  .shell { display: block; height: auto; }
  aside, .list-wrap, .detail-wrap { overflow: visible; padding: 12px; }
  .list-wrap { background: transparent; border: 0; padding-top: 0; }
  aside { padding-bottom: 0; }
  .chip { min-height: 44px; }
  .keys { display: none; }
  .gate-mini .gtext {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .detail-wrap { display: none; }
  body.show-detail .detail-wrap {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 8;
    overflow: auto;
    background: var(--bg);
    padding: 12px 14px 40px;
  }
  body.show-detail .back {
    display: inline-flex;
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 44px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
  }
  .sheet { padding: 4px 0 32px; }
  .sheet h2.title { font-size: 28px; }
  .meta { grid-template-columns: 1fr; }
  .text-btn, .back, .empty button, #clear, .sha-row button { min-height: 44px; }
  .card { padding: 13px 13px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
