:root {
  --paper: #faf8f4;
  --ink: #1c1a17;
  --muted: #8b8681;
  --rule: #e2ddd4;
  --bar-bg: rgba(250, 248, 244, 0.92);
  --measure: 34rem;
  --bar-h: 3.25rem;
  --gutter: 2.25rem;
  --fs: 1.0625rem;
  --lh: 1.72;
}

:root[data-theme="dark"] {
  --paper: #14161a;
  --ink: #ddd8d0;
  --muted: #6f7580;
  --rule: #262a31;
  --bar-bg: rgba(20, 22, 26, 0.92);
}

:root[data-size="1"] { --fs: 0.9375rem; --lh: 1.68; }
:root[data-size="2"] { --fs: 1.0625rem; --lh: 1.72; }
:root[data-size="3"] { --fs: 1.1875rem; --lh: 1.76; }
:root[data-size="4"] { --fs: 1.375rem;  --lh: 1.78; }


* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: var(--paper);
  transition: opacity 0.55s ease;
}

.splash[hidden] { display: none; }
.splash.leaving { opacity: 0; pointer-events: none; }

.wordmark {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: clamp(2.75rem, 12vw, 5.5rem);
  font-weight: 400;
  line-height: 1.05;
  text-align: center;
  color: var(--ink);
}

.enter {
  padding: 0.55rem 1.6rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 0.6875rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.enter:hover { color: var(--ink); border-color: var(--muted); }

.resume {
  margin-top: -1.25rem;
  padding: 0.3rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
}

.resume[hidden] { display: none; }
.resume:hover { color: var(--ink); }

.splash .wordmark,
.splash .enter,
.splash .resume { opacity: 0; }

.splash.ready .wordmark { animation: rise 1.3s ease forwards; }
.splash.ready .enter { animation: rise 0.9s ease 0.85s forwards; }
.splash.ready .resume { animation: rise 0.9s ease 1.05s forwards; }

@keyframes rise {
  from { opacity: 0; transform: translateY(0.7rem); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .splash.ready .wordmark,
  .splash.ready .enter,
  .splash.ready .resume { animation: none; opacity: 1; }
  .splash { transition: none; }
}

.running-head {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: env(safe-area-inset-top);
  font-size: 0.6875rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
  z-index: 2;
}

#viewport {
  position: fixed;
  top: 2.75rem;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  overflow: hidden;
}

#window {
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
}

#flow {
  height: 100%;
  column-fill: auto;
  transition: transform 0.22s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
  font-size: var(--fs);
  line-height: var(--lh);
  text-align: justify;
  hyphens: auto;
}

#flow.no-anim { transition: none; }

#flow p {
  margin: 0 0 0.35em;
}

.cn {
  float: left;
  font-size: 2.45em;
  line-height: 0.9;
  padding: 0.05em 0.11em 0 0;
  font-feature-settings: "lnum";
}


.vn {
  font-size: 0.62em;
  vertical-align: 0.42em;
  color: var(--muted);
  margin-right: 0.18em;
  font-family: system-ui, sans-serif;
  letter-spacing: 0;
}

.edge {
  position: fixed;
  top: 2.75rem;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
  width: 22%;
  z-index: 1;
  cursor: pointer;
}

.edge-prev { left: 0; }
.edge-next { right: 0; }

.bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-inline: 0.5rem;
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--rule);
  z-index: 3;
}

.bar-mid {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.ctl {
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  width: 2.75rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.ctl:hover { color: var(--ink); }
.ctl:active { background: var(--rule); }

.ctl-text {
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  font-weight: 500;
}

#size .size-a { font-size: 0.75rem; }
#size .size-b { font-size: 1rem; }

.ctl svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}

.ctl svg .moon { display: none; fill: currentColor; stroke: none; }
:root[data-theme="dark"] .ctl svg .sun { display: none; }
:root[data-theme="dark"] .ctl svg .moon { display: block; }

.finder {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 0.45rem);
  right: 0.75rem;
  z-index: 5;
  font-family: system-ui, sans-serif;
}

.finder-field {
  position: relative;
  width: 9.5rem;
  margin-left: auto;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  transition: width 0.18s ease, border-color 0.15s ease;
}

.finder-field:focus-within { border-color: var(--muted); }

.finder-field svg {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.8rem;
  height: 0.8rem;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.7;
  stroke-linecap: round;
  pointer-events: none;
}

.finder-input {
  display: block;
  width: 100%;
  height: 1.9rem;
  padding: 0 0.7rem 0 1.7rem;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8125rem;
  outline: none;
}

.finder-input::placeholder { color: var(--muted); }
.finder-input::-webkit-search-cancel-button { display: none; }

.finder-panel {
  position: absolute;
  top: 2.35rem;
  right: 0;
  width: 20rem;
  max-height: min(62vh, 27rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.3rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 0.625rem;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
}

.finder-panel[hidden] { display: none; }

.sect {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0.6rem 0.3rem;
  font-size: 0.625rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 0.4rem;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

.row > span {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.6875rem;
}

.row.res {
  flex-direction: column;
  align-items: stretch;
  gap: 0.1rem;
}

.row.res b { font-weight: 500; font-size: 0.75rem; }

.row.res span {
  margin-left: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--muted);
}

.row:hover, .row.on, .cell:hover, .cell.on { background: var(--rule); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.15rem, 1fr));
  gap: 0.2rem;
  padding: 0.3rem;
}

.cell {
  height: 2.15rem;
  border: 0;
  border-radius: 0.35rem;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.empty {
  padding: 1.1rem 0.6rem;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}

.sheet[hidden] { display: none; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
}

.sheet-panel {
  width: min(22rem, 100%);
  margin-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 0.5rem);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  padding: 0.375rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.opt {
  display: flex;
  width: 100%;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  background: none;
  border: 0;
  border-radius: 0.5rem;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
}

.opt:hover { background: var(--rule); }
.opt[aria-checked="true"]::after { content: "·"; margin-left: auto; color: var(--muted); }
.opt span { color: var(--muted); font-size: 0.75rem; }
.opt[disabled] { opacity: 0.4; cursor: default; }
.opt[disabled]:hover { background: none; }

@media (max-width: 600px) {
  :root { --gutter: 1.5rem; }
  #flow { text-align: left; }

  .finder { left: 0.75rem; }
  .finder-field { width: 2rem; }
  .finder.open .finder-field { width: 100%; }
  .finder-panel { width: auto; left: 0; }
  :root[data-finding] .running-head { opacity: 0; }
}
