/* そらの本棚 — 読書画面。本文に集中できるよう、Web書体は読み込まない。 */

:root {
  --paper: #FBFAF7;
  --ink: #1B1D22;
  --sub: #6A6F7B;
  --accent: #2E4A8F;
  /* 浮かせる操作（上のボタン・下のメニュー）の面 */
  --glass: rgba(255, 255, 255, .8);
  --glass-edge: rgba(27, 29, 34, .08);
  --lift: 0 18px 40px -14px rgba(18, 26, 58, .3), 0 2px 8px rgba(18, 26, 58, .08);
  /* 下から出る設定・目次の面 */
  --sheet: #FDFCF9;
  --line: rgba(27, 29, 34, .1);
  --well: rgba(27, 29, 34, .07);
  --well-on: #FFFFFF;
  --track: rgba(27, 29, 34, .14);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --foot: 28px;
  color-scheme: light;
}
body[data-theme='sepia'] {
  --paper: #F3E8D1; --ink: #43382B; --sub: #7A6950; --accent: #7A4F1D;
  --glass: rgba(252, 245, 230, .82); --glass-edge: rgba(67, 56, 43, .12);
  --sheet: #FBF3E2; --line: rgba(67, 56, 43, .14); --well: rgba(67, 56, 43, .09); --well-on: #FFFBF1; --track: rgba(67, 56, 43, .2);
}
body[data-theme='night'] {
  --paper: #0E1430; --ink: #D9DCE8; --sub: #A9B0CC; --accent: #AFC0FF;
  --glass: rgba(34, 43, 92, .82); --glass-edge: rgba(255, 255, 255, .12);
  --lift: 0 18px 40px -14px rgba(0, 0, 0, .6), 0 2px 8px rgba(0, 0, 0, .3);
  --sheet: #171F48; --line: rgba(255, 255, 255, .12); --well: rgba(255, 255, 255, .09); --well-on: rgba(255, 255, 255, .2); --track: rgba(255, 255, 255, .22);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
/* 読書画面は自前でページを送る。ダブルタップや2本指での拡大は起こさない。 */
html { touch-action: none; }
.contents-list, .settings { touch-action: pan-y; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Hiragino Sans', 'Yu Gothic', 'Noto Sans JP', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  transition: background-color .25s ease, color .25s ease;
}
h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--lift);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
}

/* ---------- 本文 ---------- */

.stage {
  position: fixed;
  top: env(safe-area-inset-top);
  bottom: calc(var(--foot) + env(safe-area-inset-bottom));
  left: 50%;
  width: min(100%, 960px);
  transform: translateX(-50%);
  /* 引いている間に横へ並べる隣のページは、本文の幅の外では見せない。 */
  overflow: hidden;
}
.pages { position: absolute; inset: 0; will-change: transform; }
/* 枠は2つ重ね、組み終えた方だけを見せる。 */
.pages iframe { position: absolute; inset: 0; display: block; width: 100%; height: 100%; border: 0; background: transparent; visibility: hidden; }

.foot {
  position: fixed;
  left: 50%;
  bottom: env(safe-area-inset-bottom);
  width: min(100%, 960px);
  height: var(--foot);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 26px;
  font-size: 11px;
  color: var(--sub);
  pointer-events: none;
}
.foot span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot span:last-child { flex: none; font-variant-numeric: tabular-nums; }

.notice {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
  color: var(--sub);
}
.notice[hidden] { display: none; }
.notice a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 22px; border: 1px solid var(--line); border-radius: 22px; color: var(--ink); text-decoration: none; }

/* ---------- 浮かせた操作 ---------- */

.bar {
  position: fixed;
  z-index: 2;
  visibility: hidden;
  opacity: 0;
  transition: transform .32s var(--ease), opacity .2s ease, visibility 0s .32s;
}
body[data-chrome='on'] .bar { visibility: visible; opacity: 1; transition: transform .32s var(--ease), opacity .2s ease; }

/* 上は1本のバーに、戻る・書名・ロゴをまとめる。 */
.bar.top {
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  width: min(100% - 24px, 560px);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 28px;
  transform: translate(-50%, -160%);
}
body[data-chrome='on'] .bar.top { transform: translate(-50%, 0); }
.round {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--ink);
  text-decoration: none;
  transition: background-color .2s ease, transform .2s var(--ease);
}
@media (hover: hover) { .round:hover { background: var(--well); } }
.round:active { transform: scale(.93); }
.book-title {
  flex: 1;
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-weight: 600;
}

.dock {
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: min(100% - 24px, 560px);
  padding: 10px 14px 10px;
  border-radius: 30px;
  transform: translate(-50%, 130%);
}
body[data-chrome='on'] .dock { transform: translate(-50%, 0); }

.seek { display: flex; align-items: center; gap: 6px; }
.step {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transition: background-color .2s ease, transform .2s var(--ease);
}
@media (hover: hover) { .step:hover { background: var(--well); } }
.step:active { transform: scale(.92); }
.step:disabled { opacity: .3; cursor: default; }
#seek-percent { flex: none; min-width: 46px; direction: ltr; text-align: center; font-size: 16px; font-variant-numeric: tabular-nums; }

.seek input {
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  --paint: to right;
}
.seek[dir='rtl'] input { --paint: to left; }
.seek input::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(var(--paint), var(--accent) var(--fill, 0%), var(--track) var(--fill, 0%));
}
.seek input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 34px;
  height: 24px;
  margin-top: -9px;
  border: 0;
  border-radius: 12px;
  background: #FFFFFF;
  box-shadow: 0 2px 6px rgba(18, 26, 58, .28), 0 0 0 .5px rgba(18, 26, 58, .1);
  transition: transform .15s var(--ease);
}
.seek input:active::-webkit-slider-thumb { transform: scale(1.08); }
.seek input::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(var(--paint), var(--accent) var(--fill, 0%), var(--track) var(--fill, 0%));
}
.seek input::-moz-range-thumb {
  width: 34px;
  height: 24px;
  border: 0;
  border-radius: 12px;
  background: #FFFFFF;
  box-shadow: 0 2px 6px rgba(18, 26, 58, .28), 0 0 0 .5px rgba(18, 26, 58, .1);
}

.actions { display: flex; gap: 4px; padding-top: 2px; }
.actions button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  padding: 6px 0 4px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  transition: background-color .2s ease, transform .2s var(--ease);
}
@media (hover: hover) { .actions button:hover { background: var(--well); } }
.actions button:active { transform: scale(.96); }
.letters { display: inline-flex; align-items: baseline; height: 26px; font-size: 24px; font-weight: 500; line-height: 26px; letter-spacing: -.04em; }
.letters small { font-size: 17px; }

/* ---------- 下から出る面（目次・表示設定・読了） ---------- */

.sheet {
  width: min(100% - 24px, 460px);
  max-height: min(84vh, 680px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--glass-edge);
  border-radius: 30px;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 30px 80px -24px rgba(10, 14, 32, .55);
  overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: rise .32s var(--ease); }
.sheet::backdrop { background: rgba(10, 14, 32, .32); }
@keyframes rise { from { opacity: 0; transform: translateY(28px); } }
.sheet::before { content: ''; flex: none; align-self: center; width: 44px; height: 5px; margin-top: 9px; border-radius: 3px; background: var(--track); }
.sheet-head { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 16px 14px; }
.sheet-head h2 { grid-column: 2; font-size: 18px; font-weight: 700; letter-spacing: .02em; }
.sheet-head form { grid-column: 3; justify-self: end; margin: 0; }
.sheet-head button { min-height: 46px; padding: 0 20px; border-radius: 23px; color: var(--accent); font-weight: 700; box-shadow: 0 6px 16px -8px rgba(18, 26, 58, .3); }

.contents-list { overflow-y: auto; overscroll-behavior: contain; padding: 0 10px 16px; }
.contents-list button {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 8px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  line-height: 1.5;
  transition: background-color .15s ease;
}
@media (hover: hover) { .contents-list button:hover { background: var(--well); } }
.contents-list button[aria-current] { background: var(--well); color: var(--accent); font-weight: 700; }
.contents-list p { padding: 16px 14px; color: var(--sub); }

.settings { display: flex; flex-direction: column; gap: 14px; padding: 6px 22px 26px; overflow-y: auto; }
.setting { min-width: 0; margin: 0; padding: 0; border: 0; }
.setting::after { content: ''; display: block; clear: both; }
.setting .name { float: left; width: 62px; padding: 0; color: var(--sub); font-size: 16px; line-height: 48px; }
.segment, .swatches { margin-left: 74px; }
.segment { display: flex; padding: 3px; border-radius: 16px; background: var(--well); }
.segment label { position: relative; flex: 1; min-width: 0; }
.segment input, .swatches input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segment span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 13px;
  transition: background-color .2s ease, box-shadow .2s ease;
}
.segment input:checked + span { background: var(--well-on); box-shadow: 0 1px 4px rgba(18, 26, 58, .16); font-weight: 600; }
.segment input:focus-visible + span, .swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.stepper button { flex: 1; min-height: 42px; padding: 0; border: 0; border-radius: 13px; background: transparent; transition: background-color .15s ease; }
@media (hover: hover) { .stepper button:hover { background: var(--well); } }
.stepper button:active { background: var(--well-on); }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper output { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 19px; font-variant-numeric: tabular-nums; }
.small-a { font-size: 14px; }
.large-a { font-size: 22px; }

.swatches { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.swatches label { position: relative; }
.swatches span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  border: 1.5px solid transparent;
  border-radius: 15px;
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  font-weight: 600;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.swatch-paper { background: #FFFFFF; color: #1B1D22; border-color: rgba(27, 29, 34, .14); }
.swatch-sepia { background: #F3E8D1; color: #43382B; border-color: #D9C7A0; }
.swatch-night { background: #0E1430; color: #D9DCE8; border-color: #2A3468; }
.swatches input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }

.finished-links { display: flex; flex-direction: column; gap: 10px; padding: 6px 22px 26px; }
.finished-links > * {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: 16px;
  background: var(--well);
  font-weight: 600;
  text-decoration: none;
}
.finished-links .primary { background: var(--accent); color: var(--paper); }

@media (max-width: 560px) {
  .sheet { width: 100%; max-width: none; max-height: 86vh; margin: auto 0 0; border-width: 1px 0 0; border-radius: 30px 30px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .settings { padding-inline: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
