:root {
  color-scheme: dark;
  --paper: #f6f3ed;
  --gold: #d4ba83;
  --line: #4d584b;
  --panel: #141f19;
  --pad: clamp(16px, 4.2vw, 52px);
  --header-height: 64px;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-height) + 18px); }
body {
  margin: 0;
  color: var(--paper);
  background: var(--panel) repeating-linear-gradient(100deg, #9bc39218 0 1px, transparent 1px 46px);
  font: 16px/1.55 Arial, Helvetica, sans-serif;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
img { display: block; max-width: 100%; height: auto; }
h1, h2, h3, p { margin: 0; }

header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  height: var(--header-height);
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--line);
  background: #111a15;
}
header img { width: clamp(116px, 26vw, 202px); filter: invert(1); }
header a { padding-block: 10px; }
header a:last-child { text-align: right; }
header a, .label, .deck-count, article small {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
main { max-width: 900px; margin-inline: auto; padding: clamp(22px, 5vw, 54px) var(--pad) 48px; }
.story-title { text-align: center; margin-bottom: 17px; }
.label, article small { color: var(--gold); }
h1 {
  margin-top: 5px;
  font-size: clamp(2rem, 7vw, 4.6rem);
  line-height: .98;
  letter-spacing: -.065em;
  text-transform: uppercase;
}

.chapter-index { border-block: 1px solid var(--line); margin-bottom: 10px; }
.chapter-index summary { cursor: pointer; padding: 10px 0; min-height: 44px; }
.chapter-index ol {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 20px;
  list-style: none;
  padding: 0 0 10px;
  margin: 0;
}
.chapter-index a { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.chapter-index a span, .chapter-index a[aria-current] { color: var(--gold); }

.deck-controls {
  position: sticky;
  top: var(--header-height);
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  background: var(--panel);
}
.deck-controls button {
  min-height: 44px;
  padding: 0 13px;
  color: var(--paper);
  border: 1px solid #777959;
  border-radius: 8px;
  background: #212d23;
  font: inherit;
  cursor: pointer;
  justify-self: start;
}
.deck-controls button:last-child { justify-self: end; }
.deck-controls button:hover { background: #344335; }
.deck-controls button[aria-disabled="true"] { opacity: .45; cursor: default; }
.deck-count { color: var(--gold); white-space: nowrap; }
.swipe-hint { margin-block: 7px 11px; color: #dadbcf; text-align: center; font-size: .875rem; }

.story-cards { position: relative; }
.story-cards.is-deck {
  isolation: isolate;
  touch-action: pan-y pinch-zoom;
  cursor: grab;
}
.story-cards.is-deck:active { cursor: grabbing; }
.story-cards.is-deck::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 5px 8px -7px;
  border: 1px solid #566153;
  border-radius: 15px;
  background: #233227;
  box-shadow: 0 6px 0 -2px #344335;
}
article {
  padding: clamp(14px, 3.4vw, 28px);
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #101612;
}
.is-deck article { margin: 0; user-select: none; }
article h2 {
  margin: 3px 0 13px;
  font-size: clamp(1.6rem, 4vw, 2.75rem);
  line-height: 1.03;
  letter-spacing: -.045em;
}
article h3 { font-size: 1.35rem; line-height: 1.15; margin: 4px 0 10px; }
article img {
  width: 100%;
  max-height: min(48svh, 540px);
  object-fit: contain;
  border-radius: 6px;
  background: #0a100d;
  -webkit-user-drag: none;
}
article p { max-width: 64ch; margin-top: 13px; font-size: clamp(1rem, 2vw, 1.2rem); }
article section { margin-top: 22px; padding-top: 15px; border-top: 1px solid var(--line); }
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 15px;
  padding: 25px var(--pad);
  background: #0a100d;
}
footer strong { font-size: clamp(1.35rem, 4vw, 2.45rem); letter-spacing: -.035em; }
body { overflow-x: clip; }

@media (max-width: 520px) {
  :root { --header-height: 56px; }
  header a { font-size: .64rem; letter-spacing: .06em; }
  .chapter-index ol { grid-template-columns: 1fr; max-height: 40svh; overflow-y: auto; }
  .deck-controls button { padding-inline: 8px; font-size: .875rem; }
}

.story-cards { scroll-margin-top: 53px; }

#story-editor-open {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  color: var(--gold);
  background: transparent;
  cursor: pointer;
  font-size: 1.05rem;
  opacity: .68;
}
#story-editor-open:hover, #story-editor-open:focus-visible { opacity: 1; }
.story-editor {
  width: min(480px, calc(100% - 28px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--paper);
  background: var(--panel);
}
.story-editor::backdrop { background: #080e0bd9; }
.story-editor header {
  position: static;
  display: flex;
  justify-content: space-between;
  padding: 0 0 8px;
  height: auto;
  background: transparent;
}
.story-editor h2 { font-size: 1.35rem; }
.story-editor [role="status"]:not(:empty) { margin: 12px 0; color: var(--gold); }
.story-editor form { display: grid; gap: 12px; margin-top: 12px; }
.story-editor label { display: grid; gap: 4px; }
.story-editor input, .story-editor textarea, .story-editor button {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--paper);
  background: #111812;
  font: inherit;
}
.story-editor input, .story-editor textarea { width: 100%; padding: 8px; }
.story-editor button { min-height: 44px; padding: 0 12px; cursor: pointer; }
.story-editor button[type="submit"] {
  color: #142017;
  background: var(--gold);
  font-weight: 700;
}
.story-editor button:disabled { opacity: .55; cursor: wait; }
.story-cards article p { white-space: pre-wrap; }

.deck-controls button:focus-visible{outline:2px solid var(--gold);outline-offset:3px}
.story-cards:focus-visible{outline:2px solid var(--gold);outline-offset:4px}
