:root {
  color-scheme: dark;
  --bg: #12110e;
  --paper: #1c1b17;
  --text: #f3ecdf;
  --muted: #cbbda8;
  --line: #322e27;
  --accent: #e0c17a;
  --danger: #e08a82;
  --sans: "Segoe UI", system-ui, sans-serif;
  --serif: Georgia, "Palatino Linotype", Palatino, serif;
  --measure: min(42rem, calc(100vw - 4rem));
}

* {
  box-sizing: border-box;
}

/* Class rules below set display, which would otherwise beat the UA [hidden] rule. */
[hidden] {
  display: none !important;
}

html {
  font-size: 18px;
}

html[data-text-size="small"] {
  font-size: 16px;
}

html[data-text-size="medium"] {
  font-size: 18px;
}

html[data-text-size="large"] {
  font-size: 21px;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

button,
.fileImport {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
.fileImport:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

h1,
h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
}

h1 {
  font-size: 1.45rem;
  letter-spacing: 0.06em;
}

h2 {
  font-size: 1.25rem;
}

#metaLine,
.hint,
.nodeTag,
.pointsLine {
  margin: 0;
  color: var(--muted);
}

#metaLine {
  margin-top: 2px;
  font-size: 0.92rem;
}

.nodeTag {
  margin-top: 4px;
  font-size: 0.78rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.toolbar button,
.dialogClose,
.fileImport,
.saveTools button,
.slotActions button,
.smallBtn {
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  padding: 8px 10px;
}

.toolbar button:hover,
.dialogClose:hover,
.fileImport:hover,
.saveTools button:hover,
.slotActions button:hover,
.smallBtn:hover {
  background: #26231d;
  color: var(--text);
}

.reader {
  width: var(--measure);
  margin: 0 auto;
  padding: 0 0 4rem;
}

.storyText {
  padding: 2.5rem 0 2rem;
}

/* Focused when a page changes, so keep the ring quiet. */
.storyText:focus,
.storyText:focus-visible {
  outline: none;
}

.storyText p {
  margin: 0 0 1.35em;
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.7;
  max-width: 40em;
}

.textSize {
  display: inline-flex;
  gap: 2px;
  margin-right: 6px;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}

.textSize button {
  padding: 8px 8px;
}

.dock {
  display: grid;
  gap: 10px;
  padding: 1.25rem 0 0;
  border-top: 1px solid var(--line);
}

.choiceArea {
  display: grid;
  gap: 8px;
}

.choiceCard button,
.continueBtn {
  display: flex;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #221f1a;
  border: 1px solid #3d382f;
  border-radius: 12px;
  padding: 13px 14px;
  line-height: 1.4;
}

.choiceKey {
  flex-shrink: 0;
  min-width: 1.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.dockHint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: right;
}

.continueBtn {
  justify-content: center;
  letter-spacing: 0.04em;
}

.choiceCard button:hover,
.continueBtn:hover {
  border-color: var(--accent);
}

.choiceCard.invalid button {
  color: var(--muted);
  border-color: #5a3532;
  background: #241816;
}

.choiceCard .requirement,
.choiceCard .fail {
  margin: 6px 4px 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.choiceCard .fail {
  color: var(--danger);
}

dialog {
  width: min(560px, calc(100% - 24px));
  max-height: min(80vh, 720px);
  margin: auto;
  padding: 18px 18px 20px;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.66);
}

.dialogHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.bookBlock + .bookBlock {
  margin-top: 16px;
}

.bookBlock h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-family: var(--sans);
  font-weight: 600;
}

.chapterRow {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chapterBtn {
  min-width: 40px;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid #3d382f;
  background: #221f1a;
}

.chapterBtn.current {
  border-color: var(--accent);
  color: #1a160f;
  background: var(--accent);
}

.saveTools {
  display: flex;
  gap: 8px;
  margin: 8px 0 14px;
}

.fileImport input {
  display: none;
}

.saveSlots {
  display: grid;
  gap: 10px;
}

.slotRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.slotTitle {
  display: block;
  margin-bottom: 2px;
}

.slotActions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.statsGrid {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.statRow,
.modRow {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
}

.modRow {
  grid-template-columns: 1fr auto auto;
}

.confirmActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.confirmActions button {
  border-radius: 8px;
  border: 1px solid #3d382f;
  background: #221f1a;
  padding: 8px 12px;
}

#confirmOk {
  background: var(--accent);
  color: #1a160f;
  border-radius: 8px;
  border: 0;
  padding: 8px 12px;
}

.statRow .name {
  color: var(--text);
}

.statRow .value {
  min-width: 1.5rem;
  text-align: center;
}

.smallBtn {
  padding: 4px 10px;
  border: 1px solid #3d382f;
}

.debugToggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.85rem;
}

#debugText {
  margin: 10px 0 0;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  color: #d9ccb0;
  font-size: 0.75rem;
}

@media (max-width: 800px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
  }

  .reader {
    width: calc(100% - 1.5rem);
  }

  .storyText {
    padding: 1.5rem 0 1.5rem;
  }

  .storyText p {
    font-size: 1.08rem;
    max-width: none;
  }

  .slotRow {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
