.panel {
  position: fixed;
  z-index: 12;
  top: calc(var(--topbar-h) + 4px);
  right: 12px;
  bottom: 12px;
  width: var(--panel-w);
  display: none;
  flex-direction: column;
  background: linear-gradient(180deg, var(--parch-light), var(--parch));
  border: 2px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 10px 30px var(--shadow), inset 0 0 0 5px var(--parch), inset 0 0 0 6px var(--ink-soft);
  overflow: hidden;
}

body.panel-open .panel {
  display: flex;
}

.panel__bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 8px 18px;
}

.panel__crumb {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wax);
  line-height: 1.35;
}

.panel__crumb button {
  all: unset;
  cursor: pointer;
  text-decoration: underline dotted;
}

.panel__icon {
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  width: 36px;
  height: 36px;
  border: 1px solid var(--ink-soft);
  border-radius: 50%;
  background: var(--parch-light);
  font-size: 18px;
  line-height: 1;
}

.panel__grip {
  display: none;
}

/* Drag the left edge to resize the side panel; double-click to flip between normal and wide. */
.panel__resizer {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  left: 0;
  width: 14px;
  cursor: col-resize;
  touch-action: none;
}

.panel__resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 4px;
  width: 4px;
  height: 52px;
  margin-top: -26px;
  border-radius: 2px;
  background: var(--ink-soft);
  opacity: 0;
  transition: opacity 0.15s;
}

.panel:hover .panel__resizer::after,
.panel__resizer:hover::after,
.panel.is-resizing .panel__resizer::after {
  opacity: 0.55;
}

.panel.is-resizing {
  user-select: none;
}

@media (max-width: 760px), (max-height: 520px) and (orientation: landscape) {
  .panel__resizer {
    display: none;
  }
}

.panel__scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 22px 28px;
  overscroll-behavior: contain;
}

.panel h2,
.panel h3,
.panel h4 {
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  line-height: 1.2;
  margin: 1.1em 0 0.4em;
}

.panel h2 {
  margin-top: 0.2em;
  font-size: 24px;
}

.panel h3 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--wax);
  border-bottom: 1px solid var(--parch-dark);
  padding-bottom: 4px;
}

.panel h4 {
  font-size: 16px;
}

.panel p,
.panel li {
  margin: 0.5em 0;
}

.panel ul,
.panel ol {
  padding-left: 1.3em;
}

.panel .lede {
  font-style: italic;
  color: var(--ink-soft);
}

.panel blockquote {
  margin: 0.8em 0;
  padding: 2px 14px;
  border-left: 3px solid var(--gold);
  color: var(--ink-soft);
}

.panel code {
  font-size: 0.9em;
  background: var(--parch-dark);
  padding: 0 4px;
  border-radius: 3px;
}

.panel pre {
  overflow-x: auto;
  padding: 10px 12px;
  background: var(--parch-dark);
  border-radius: 4px;
}

.panel pre code {
  background: none;
  padding: 0;
}

.panel table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  font-size: 15px;
}

.panel th,
.panel td {
  border: 1px solid var(--parch-dark);
  padding: 4px 8px;
}

.panel mark {
  background: rgba(184, 137, 47, 0.35);
}

.link {
  all: unset;
  cursor: pointer;
  color: var(--wax);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.link:hover {
  text-decoration-style: solid;
}

.link--dead {
  color: var(--ink-soft);
  text-decoration: none;
  cursor: default;
}

.tabs {
  display: flex;
  gap: 4px;
  margin: 2px 0 10px;
}

.tab {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid var(--ink-soft);
  border-radius: 3px;
  background: var(--parch-light);
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tab[aria-selected="true"] {
  background: var(--wax);
  border-color: var(--ink);
  color: #f6e7c6;
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.list > li {
  margin: 0;
}

.row {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 9px 4px;
  border-bottom: 1px dotted var(--parch-dark);
  cursor: pointer;
}

.row:hover,
.row:focus-visible {
  background: rgba(184, 137, 47, 0.15);
}

.row__sigil {
  flex: none;
  width: 1.6em;
  text-align: center;
}

.row__text {
  flex: 1;
  min-width: 0;
}

.row__sub {
  display: block;
  font-size: 14px;
  font-style: italic;
  color: var(--ink-soft);
}

.row__count {
  flex: none;
  font-size: 13px;
  color: var(--ink-soft);
}

.npc {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 8px;
}

.npc__seal {
  flex: none;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 3px double var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--parch-light), var(--parch-dark));
  font-size: 36px;
  box-shadow: 0 3px 8px var(--shadow);
}

.npc__name {
  margin: 0;
}

.npc__epithet {
  margin: 0;
  font-style: italic;
  color: var(--ink-soft);
}

.speech {
  position: relative;
  margin: 14px 0 6px;
  padding: 12px 16px;
  background: var(--parch-light);
  border: 1px solid var(--ink-soft);
  border-radius: 10px;
  font-style: italic;
}

.speech::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 30px;
  width: 14px;
  height: 14px;
  background: var(--parch-light);
  border-left: 1px solid var(--ink-soft);
  border-top: 1px solid var(--ink-soft);
  transform: rotate(45deg);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.chip {
  padding: 2px 9px;
  border: 1px solid var(--ink-soft);
  border-radius: 12px;
  font-size: 13px;
  color: var(--ink-soft);
  background: transparent;
}

button.chip {
  cursor: pointer;
}

button.chip:hover {
  background: var(--parch-dark);
}

.stepper {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.btn {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--wax);
  color: #f6e7c6;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: default;
}

.btn--ghost {
  background: var(--parch-light);
  color: var(--ink);
}

.step {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.step[aria-current="step"] .row {
  background: rgba(140, 47, 43, 0.12);
}

.step__n {
  flex: none;
  width: 1.7em;
  height: 1.7em;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--wax);
  color: var(--wax);
  font-size: 13px;
}

.note-body {
  margin-top: 6px;
}

@media (max-width: 760px) {
  .panel {
    top: auto;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: 8px;
    width: auto;
    height: var(--sheet-h, 52vh);
    padding-bottom: env(safe-area-inset-bottom);
    transition: height 0.22s ease;
  }

  .panel.is-dragging-sheet {
    transition: none;
  }

  /* The drag handle: pull the sheet up for reading, down to peek at the map. */
  .panel__grip {
    flex: none;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 28px;
    touch-action: none;
    cursor: grab;
  }

  .panel__grip::before {
    content: "";
    width: 46px;
    height: 5px;
    border-radius: 3px;
    background: var(--ink-soft);
    opacity: 0.55;
  }

  .panel__bar {
    padding-top: 0;
  }

  .panel__scroll {
    padding: 2px 16px 24px;
  }

  .panel__icon {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  .row {
    min-height: 52px;
  }

  button.chip {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
}

.install-hint {
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px dashed var(--ink-soft);
  border-radius: 6px;
  background: var(--parch-light);
  font-size: 15px;
}

/* One link across a bridge: the note it starts from, an arrow, the note it leads to. Always stacked and aligned. */
.bridge-link {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 10px 0 12px;
  border-bottom: 1px dotted var(--ink-soft);
}

.bridge-note {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--parch-light);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.3;
  text-align: left;
}

.bridge-note:hover,
.bridge-note:focus-visible {
  background: var(--parch-dark);
}

.bridge-link__arrow {
  align-self: flex-start;
  display: grid;
  place-items: center;
  width: 28px;
  height: 22px;
  margin-left: 12px;
  color: var(--wax);
}

.bridge-link__arrow::before {
  width: 16px;
  height: 16px;
}

.today {
  margin: 12px 0 8px;
  padding: 10px 12px 6px;
  border: 1px solid var(--ink-soft);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--parch-light), var(--parch));
  box-shadow: inset 0 0 0 3px var(--parch-light);
}

.today__label {
  margin: 0 0 2px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--wax);
}

/* ---- Readability: bigger, upright, more open text for the things you actually read. ---- */
.panel__scroll {
  font-size: 17.5px;
  line-height: 1.6;
}

.note-body {
  font-size: 18px;
  line-height: 1.72;
  letter-spacing: 0.005em;
}

.note-body p,
.note-body li {
  margin: 0 0 0.95em;
}

.note-body li {
  margin-bottom: 0.45em;
}

.note-body h2,
.note-body h3,
.note-body h4 {
  margin-top: 1.5em;
  line-height: 1.3;
}

.lede {
  font-size: 17px;
  line-height: 1.55;
  font-style: normal;
  color: var(--ink-soft);
}

.row__text {
  font-size: 17px;
  line-height: 1.3;
}

.row__sub {
  font-size: 14px;
  font-style: normal;
  line-height: 1.4;
  color: var(--ink-soft);
}

.chip,
button.chip {
  font-size: 14px;
}

.bridge-note {
  font-size: 15.5px;
  line-height: 1.4;
}

.speech,
.npc__epithet {
  font-family: var(--font-flair);
}

.today__label,
.panel__crumb {
  font-size: 12px;
}

/* ---- the reader's trail: progress, recall, and their own threads ---- */

.tab {
  letter-spacing: 0.06em;
  padding-inline: 2px;
}

.trail {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 8px 0 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

.trail__bar {
  display: block;
  height: 6px;
  border: 1px solid var(--ink-soft);
  border-radius: 4px;
  overflow: hidden;
  background: var(--parch-light);
}

.trail__fill {
  display: block;
  height: 100%;
  min-width: 2px;
  background: var(--gold);
}

.field {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 10px 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--ink-soft);
  border-radius: 6px;
  background: var(--parch-light);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  resize: vertical;
}

.field:focus {
  outline: 2px solid var(--wax);
  outline-offset: 1px;
}

.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--wax);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

.memory {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 4px solid var(--gold);
  background: var(--parch-light);
  border-radius: 0 6px 6px 0;
}

.memory p {
  margin: 4px 0;
}

.memory__label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.npc--small .npc__seal {
  width: 52px;
  height: 52px;
  font-size: 26px;
}
