/* 行政バグります！ Webリーダー（読む画面）。画面は暗い灰色の台紙に、ページを大きく置く */
:root {
  --stage-bg: #161616;
  --bar-bg: rgba(22, 22, 22, 0.92);
  --bar-fg: #f1f1f1;
  --bar-sub: #a3a3a3;
  --accent: #538bb0;
  --primary: #1f5b8c;
  --primary-hover: #16446b;
  --gap: 6px;
  --bar-h: 52px;
  --foot-h: 68px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.reader-body { background: var(--stage-bg); color: var(--bar-fg); overflow: hidden; overscroll-behavior: none; }

.reader { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---- ページ ---- */
.stage {
  flex: 1; min-height: 0;
  display: flex; flex-direction: row-reverse; /* 見開きは若いページが右 */
  align-items: center; justify-content: center; gap: var(--gap);
  padding: calc(var(--bar-h) + 8px) 8px calc(var(--foot-h) + 8px);
  touch-action: pinch-zoom; user-select: none; -webkit-user-select: none;
  cursor: pointer;
  transition: padding .2s ease;
}
.page {
  display: block; flex: 0 1 auto; min-width: 0; min-height: 0;
  max-height: 100%; max-width: 100%; height: auto; width: auto;
  object-fit: contain; background: #fff;
  box-shadow: 0 2px 18px rgba(0, 0, 0, .55);
  -webkit-user-drag: none;
}
.stage.is-spread .page { max-width: calc(50% - var(--gap) / 2); }

/* 縦につなげる表示（幅のある画面の標準）。全ページを横幅に合わせて並べる。
   広すぎると1ページが長くなりすぎるので 960px まで */
.stage.is-flow {
  display: block; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: 8px;
  touch-action: pan-y pinch-zoom;
  scrollbar-color: #555 transparent;
}
.stage.is-flow .page { width: min(100%, 960px); max-width: none; max-height: none; height: auto; margin: 0 auto 12px; }
.reader.is-flow .bar-bottom { display: none; }

/* 最後のページの下に置く「おわり」 */
.flow-end { display: grid; place-items: center; padding: 48px 16px 72px; cursor: default; }

/* マウスで読む画面：バーはページの上に重ねて出し入れする（ページの大きさはバーの分を取らない） */
.reader.autohide .stage { padding: 8px; }
/* 縦につなげる表示では、上のバーが絵に重ならないよう、バーの高さぶんを必ず空ける
   （扉絵の題字のように、ページのいちばん上に大事な絵や文字があるため） */

.stage[aria-busy="true"] { background: radial-gradient(circle at center, #262626 0, var(--stage-bg) 60%); }

/* ---- 上下のバー（真ん中タップで隠す） ---- */
.bar { position: absolute; left: 0; right: 0; z-index: 2; background: var(--bar-bg); transition: transform .22s ease, opacity .22s ease; }
.bar-top {
  top: 0; height: var(--bar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
.bar-bottom { bottom: 0; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); }
.reader.ui-hidden .bar-top { transform: translateY(-100%); opacity: 0; }
.reader.ui-hidden .bar-bottom { transform: translateY(100%); opacity: 0; }
.reader.ui-hidden .stage { padding: 8px; }
/* 縦につなげる表示では、上のバーが絵に重ならないよう、バーの高さぶんを必ず空ける
   （扉絵の題字のように、ページのいちばん上に大事な絵や文字があるため） */
.reader .stage.is-flow,
.reader.autohide .stage.is-flow,
.reader.ui-hidden .stage.is-flow { padding-top: calc(var(--bar-h) + 8px); }

.back { color: var(--bar-fg); text-decoration: none; font-size: 15px; white-space: nowrap; padding: 6px 4px; }
.back:hover { color: #fff; text-decoration: underline; }
.title { flex: 1; margin: 0; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.icon-btn { background: none; border: 0; color: var(--bar-fg); font-size: 20px; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, .1); }

/* 進み具合は画面の上端の細い線だけ。右から左へ伸びる（右開き）。バーを隠しても残す */
.progress { position: absolute; top: 0; left: 0; right: 0; z-index: 4; height: 3px; background: rgba(255, 255, 255, .12); display: flex; justify-content: flex-end; pointer-events: none; }
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .2s ease; }

.controls { display: flex; align-items: center; justify-content: center; gap: 18px; }
.nav-btn {
  min-width: 112px; height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .06);
  color: var(--bar-fg); font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .16); }
.nav-btn:disabled { opacity: .35; cursor: default; }
#next { background: var(--primary); border-color: var(--primary); }
#next:hover { background: var(--primary-hover); }
.indicator { min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; font-size: 15px; }

.text-btn { background: none; border: 0; color: var(--bar-sub); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; padding: 4px; }
.text-btn:hover { color: #fff; }

/* 上のバーのページ数（縦につなげる表示だけ。めくる表示は下のバーに出す） */
.top-indicator { display: none; color: var(--bar-sub); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reader.is-flow .top-indicator { display: inline; }

/* ⋯ メニュー：表示の切り替えと操作のしかた */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 46px; width: 260px; padding: 6px;
  background: #262626; border: 1px solid rgba(255, 255, 255, .12); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
}
.menu[hidden] { display: none; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; color: var(--bar-fg); font: inherit; font-size: 14px; padding: 10px 12px; cursor: pointer; }
.menu-item:hover { background: rgba(255, 255, 255, .1); }
.menu-item[hidden] { display: none; }
.menu-hint { margin: 6px 12px 6px; color: var(--bar-sub); font-size: 12px; line-height: 1.7; }

button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- おわり ---- */
.end { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; background: rgba(0, 0, 0, .72); padding: 16px; }
.end[hidden] { display: none; }
.end-card { background: #fff; color: #1e293b; border-radius: 16px; padding: 32px 28px 20px; text-align: center; width: min(420px, 100%); }
.end-title { margin: 0; font-size: 32px; font-weight: 900; letter-spacing: .2em; }
.end-sub { margin: 8px 0 24px; color: #64748b; font-size: 14px; }
/* この話のタグ（tools/build_seo.py が episodes.json の tags から HTML に書く） */
.end-tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: -12px 0 20px; padding: 0; list-style: none; }
.end-tags li { padding: 2px 10px; border-radius: 999px; background: #f1f5f9; color: #475569; font-size: 12px; }
.end-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.btn { display: inline-flex; justify-content: center; align-items: center; height: 46px; border-radius: 10px; font: inherit; font-weight: 700; font-size: 15px; text-decoration: none; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; border: 0; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { border: 2px solid var(--primary); color: var(--primary); background: #fff; }
.btn-ghost:hover { background: var(--primary); color: #fff; }
.end-card .text-btn { color: #64748b; }
.end-card .text-btn:hover { color: #1e293b; }

/* 解説記事への導線（episodes.json の readMore があるときだけ出る） */
.end-read { display: block; margin: 4px 0 14px; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; color: inherit; text-align: left; text-decoration: none; }
.end-read:hover { border-color: var(--primary); background: #fff; }
.end-read-label { display: block; color: var(--primary); font-size: 12px; font-weight: 700; }
.end-read-title { display: block; margin-top: 4px; font-size: 14px; font-weight: 700; line-height: 1.5; }
.end-read-note { display: block; margin-top: 6px; color: #64748b; font-size: 12px; }

.error { position: absolute; inset: auto 16px 50% 16px; text-align: center; color: #fca5a5; }

@media (max-width: 600px) {
  :root { --bar-h: 46px; --foot-h: 84px; }
  .stage { padding-left: 0; padding-right: 0; }
  .nav-btn { min-width: 96px; height: 42px; font-size: 14px; }
  .title { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { .bar, .progress-fill, .stage { transition: none; } }

/* ---- 対訳（英語で読むとき。縦につなげる表示ではページの下、めくる表示は下のシート） ---- */
.script {
  width: min(100%, 960px); margin: 0 auto 16px; padding: 16px 18px 18px;
  background: #1d1d1d; border: 1px solid #2e2e2e; border-radius: 10px;
  cursor: default; user-select: text; -webkit-user-select: text;
  font-size: 15px; line-height: 1.6;
}
.script-head { margin: 0 0 12px; color: var(--bar-sub); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.script-lines { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.script-line { padding-left: 12px; border-left: 3px solid #3c3c3c; }
.script-line.is-caption { border-left-color: var(--accent); }
.sc-en { margin: 0; }
.script-line.is-caption .sc-en { color: #d7d7d7; font-style: italic; }
.sc-ja { margin: 3px 0 0; color: var(--bar-sub); font-size: 13px; }
.sc-note { margin: 8px 0 0; padding: 8px 10px; border-radius: 6px; background: rgba(83, 139, 176, .14); color: #cfe3f0; font-size: 13px; line-height: 1.55; }

.script-btn { min-width: 0; padding: 0 14px; }
.script-sheet {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  padding: 12px; background: rgba(0, 0, 0, .6);
}
.script-sheet[hidden] { display: none; }
.script-sheet .script { width: min(100%, 720px); max-height: 72vh; overflow-y: auto; margin: 0; }
.script-close {
  position: absolute; top: 14px; right: 18px; z-index: 1;
  background: none; border: 0; color: var(--bar-fg); font-size: 26px; line-height: 1; cursor: pointer;
}

/* ---- 表紙の注釈（実在の場所を扱う話だけ。画像には焼かず、テキストで重ねる） ---- */
.cover-note {
  position: fixed; left: 12px; right: 12px; z-index: 3;
  bottom: calc(var(--foot-h) + 12px);
  margin: 0 auto; max-width: 640px;
  padding: 8px 14px; border-radius: 10px;
  background: rgba(0, 0, 0, .6); border: 1px solid rgba(255, 255, 255, .16);
  color: #e5e5e5; font-size: 12px; line-height: 1.6; text-align: center;
  pointer-events: none; transition: opacity .22s ease;
}
.reader.is-flow .cover-note { bottom: 12px; }
.cover-note[hidden] { display: none; }
.reader.ui-hidden .cover-note { opacity: 0; }

/* ---- 言語の切り替え ---- */
.lang-switch {
  position: fixed; right: 12px; bottom: calc(var(--foot-h) + 12px); z-index: 30;
  padding: 5px 12px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 999px;
  background: var(--bar-bg); color: var(--bar-fg); font-size: 13px; font-weight: 700; text-decoration: none;
}
.lang-switch:hover { border-color: var(--accent); }
.reader.is-flow ~ .lang-switch, .reader.is-flow + .lang-switch { bottom: 12px; }
.reader.sheet-open ~ .lang-switch { display: none; } /* 対訳のシートを開いている間は隠す */

/* ---- 対訳をコマの横に並べる（縦につなげる表示で、幅 1100px 以上） ----
   ページは左、対訳は右。対訳はコマの上端の高さから始め、長いときは次のコマへ押し下げる */
.page-row {
  display: grid; grid-template-columns: minmax(0, 900px) minmax(300px, 380px);
  justify-content: center; align-items: start; gap: 20px;
  margin: 0 auto 12px;
}
.page-frame { position: relative; }
.stage.is-flow .page-row .page { width: 100%; margin: 0; }
.script-side { position: relative; cursor: default; user-select: text; -webkit-user-select: text; }
.side-group {
  position: absolute; left: 0; right: 0;
  display: grid; gap: 10px; padding: 12px 14px;
  background: #1d1d1d; border: 1px solid #2e2e2e; border-radius: 10px;
  font-size: 15px; line-height: 1.55;
  transition: border-color .15s ease;
}
.side-group:hover { border-color: var(--accent); }
.panel-hl {
  position: absolute; pointer-events: none; opacity: 0;
  outline: 3px solid var(--accent); outline-offset: -2px; background: rgba(83, 139, 176, .10);
  transition: opacity .15s ease;
}
.page-frame.hl-on .panel-hl { opacity: 1; }
