:root {
  color-scheme: light;
  --paper: #fbf8f1;
  --ink: #211d19;
  --muted: #746e66;
  --line: #d9cfc0;
  --accent: #28665d;
  --accent-soft: #e1efeb;
  --surface: #efe9df;
  --shadow: rgba(36, 30, 22, 0.16);
  --drawer: #f7f2ea;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  width: 100vw;
  height: 100vh;
  padding: 22px 28px 22px 22px;
}

.drawer {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--drawer);
  box-shadow: 0 12px 32px var(--shadow);
}

.drawer-section + .drawer-section {
  margin-top: 24px;
}

.drawer-section-events {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.drawer-section-events-collapsed {
  flex: 0 0 auto;
}

.drawer-section-events-collapsed .event-graph {
  display: none;
}

.drawer-label {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.drawer-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.drawer-heading .drawer-label {
  margin-bottom: 0;
}

.events-collapse-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.events-collapse-toggle:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

.events-collapse-caret {
  display: inline-block;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  transform: rotate(90deg);
}

.drawer-section-events-collapsed .events-collapse-caret {
  transform: rotate(0deg);
}

.drawer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 24px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.eye-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 11px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.eye-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

#current-title-toggle[aria-pressed="false"] .eye-icon::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -2px;
  width: 22px;
  height: 1.5px;
  background: currentColor;
  transform: rotate(-35deg);
  transform-origin: center;
}

.refresh-icon {
  position: relative;
  display: block;
  width: 17px;
  height: 17px;
  border: 1.7px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-18deg);
}

.refresh-icon::after {
  content: "";
  position: absolute;
  right: -2px;
  top: 1px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  transform: rotate(24deg);
}

.icon-button[aria-pressed="true"] {
  color: var(--accent);
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--accent);
  outline: none;
}

.speed-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.22);
}

.speed-button {
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  padding: 0 8px;
}

.speed-button:last-child {
  border-right: 0;
}

.speed-button[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--accent-soft);
  color: #143f39;
}

.speed-button:disabled {
  color: #a99f94;
  cursor: not-allowed;
}

.threshold-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.threshold-header .drawer-label {
  margin-bottom: 0;
}

.threshold-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.threshold-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.reading-time-panel {
  display: grid;
  gap: 8px;
  padding-top: 2px;
}

.reading-time-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.reading-time-row span {
  text-transform: uppercase;
  letter-spacing: 0;
}

.reading-time-row output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.event-graph {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.graph-node {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  column-gap: 2px;
  align-items: center;
  min-width: 0;
  margin: 5px 0;
  padding-left: calc(var(--depth) * 15px);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.graph-toggle,
.graph-toggle-spacer {
  width: 16px;
  height: 20px;
}

.graph-toggle {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transform: rotate(0deg);
}

.graph-toggle[aria-expanded="true"] {
  transform: rotate(90deg);
}

.graph-toggle:hover,
.graph-toggle:focus-visible {
  color: var(--accent);
  outline: none;
}

.graph-jump {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  column-gap: 7px;
  align-items: center;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 3px 4px 3px 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.graph-jump:hover,
.graph-jump:focus-visible {
  background: rgba(40, 102, 93, 0.08);
  outline: none;
}

.graph-dot {
  width: 7px;
  height: 7px;
  border: 1px solid var(--line);
  background: transparent;
}

.graph-title {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-node-read .graph-dot {
  border-color: var(--accent);
  background: var(--accent);
}

.graph-node-partial .graph-dot {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.graph-node-current .graph-jump {
  background: rgba(40, 102, 93, 0.13);
  color: #234b45;
}

.graph-node-current .graph-dot {
  border-color: var(--accent);
  background: var(--accent);
}

.graph-node-current .graph-title {
  font-weight: 650;
}

.spoiler-hidden {
  filter: blur(4px);
  user-select: none;
}

.reader-frame {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
}

.book-page {
  width: min(780px, 100%);
  height: calc(100vh - 44px);
  overflow: hidden;
  padding: clamp(34px, 5vh, 56px) clamp(34px, 5vw, 64px) clamp(64px, 9vh, 104px);
  background: var(--paper);
  box-shadow: 0 18px 42px var(--shadow);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.58;
}

.measure-page {
  position: fixed;
  top: 0;
  left: -10000px;
  visibility: hidden;
  pointer-events: none;
}

.confirm-dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 42px var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(33, 29, 25, 0.32);
}

.confirm-dialog-body {
  padding: 22px;
}

.confirm-dialog h2 {
  margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 23px;
  line-height: 1.2;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.confirm-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.dialog-button {
  min-height: 38px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.42);
  color: var(--ink);
  cursor: pointer;
}

.dialog-button:hover,
.dialog-button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.dialog-button-danger {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper);
}

.reading-block {
  position: relative;
  margin: 0;
  padding-right: 30px;
}

.reading-block + .reading-block {
  margin-top: 1.1em;
}

.hidden-block {
  margin: 0.65em 0;
}

.hidden-block-read .hidden-toggle {
  color: rgba(38, 109, 94, 0.72);
}

.hidden-toggle {
  display: grid;
  grid-template-columns: minmax(24px, 1fr) auto auto minmax(24px, 1fr);
  gap: 9px;
  align-items: center;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(116, 110, 102, 0.78);
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  line-height: 1;
}

.hidden-toggle:hover,
.hidden-toggle:focus-visible {
  color: var(--accent);
  outline: none;
}

.hidden-rule {
  height: 1px;
  background: currentColor;
  opacity: 0.28;
}

.hidden-label {
  white-space: nowrap;
}

.hidden-caret {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
  transform: translateY(-1px);
}

.hidden-block-expanded .hidden-caret {
  transform: translateY(-1px) rotate(180deg);
}

.hidden-content {
  margin-top: 0.9em;
}

.hidden-feedback-row {
  position: relative;
  padding-right: 30px;
}

.feedback-button {
  position: absolute;
  top: 0.18em;
  right: 0;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid rgba(116, 110, 102, 0.38);
  border-radius: 50%;
  background: transparent;
  color: rgba(116, 110, 102, 0.76);
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.reading-block:hover .feedback-button,
.reading-block:focus-within .feedback-button,
.hidden-feedback-row:hover .feedback-button,
.hidden-feedback-row:focus-within .feedback-button,
.feedback-button-active {
  opacity: 1;
  pointer-events: auto;
}

.feedback-button:hover,
.feedback-button:focus-visible,
.feedback-button-active {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.feedback-button-active {
  background: var(--accent-soft);
}

.prose {
  margin: 0 0 0.82em;
  font: inherit;
  line-height: inherit;
}

.empty,
.error {
  margin: 0;
  color: var(--muted);
  font: inherit;
  text-align: center;
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .drawer {
    max-height: 172px;
  }

  .speed-control {
    grid-template-columns: repeat(3, 1fr);
  }

  .event-graph {
    display: none;
  }

  .book-page {
    width: 100%;
    height: calc(100vh - 196px);
    padding: 28px 24px 56px;
    font-size: 18px;
  }
}
