/*
 * ストーリーモード（story.php）専用のスタイル。
 * 画面の高さは JS (story.js の fitHeight) が --story-vh / --story-chrome に入れる。
 * JSが動かなかったときのために、どちらにも既定値を書いてある。
 */

/* 背景は loginmodal.css の .main-panel（青いグラデ＋top_top.jpg）を
   サイト共通のまま使う。ここで上書きしないこと。 */

/* 再生画面：画面にぴったり収めて、中身はスクロールさせない */
.story-player.main-panel {
    height: calc(var(--story-vh, 1vh) * 100 - var(--story-chrome, 50px));
    min-height: 0;
    overflow: hidden;
}

.content.story {
    height: 100%;
    min-height: 0;
    padding: 0;
}

/* 一覧画面：話が増えるので中でスクロールさせる。
   高さを指定しないと、ナビバーのぶんパネルが画面から食み出して、
   いちばん下の話が画面外に残る（スマホで実際に見切れた） */
.story-index.main-panel {
    height: calc(var(--story-vh, 1vh) * 100 - var(--story-chrome, 50px));
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.content.story.story-index-content {
    height: auto;
    min-height: 100%;
}

.story-root {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

/* ------------------------------------------------------------ 上部バー */

.story-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px;
    background: #0d3c55;
    color: #fff;
    font-size: 13px;
}

/* 進み具合の帯（上のバーのすぐ下） */
.story-progress {
    flex: 0 0 auto;
    height: 5px;
    background: #0a2e42;
}

.story-progress > i {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #7fd3ff, #5ee89a);
    border-radius: 0 3px 3px 0;
    transition: width .35s ease;
}

.story-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

/* 図鑑編は話数のかわりに題名（「エビ・カニ・ヤドカリ編」など）が入り、長いとスマホで右のボタンの下にはみ出していた。札が1つで入りきらないときだけ … で省く（2026-09-28） */
.story-epno {
    flex: 0 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #7fd3ff;
    color: #06293a;
    border-radius: 999px;
    padding: 1px 10px;
    font-weight: 700;
}

.story-eptitle {
    flex: 1 1 0; /* 残りの幅だけ使う（狭いときは、札より先にこちらが … になる） */
    min-width: 0;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.story-topbar-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 「ストーリー一覧へ戻る」は長いので、狭い画面では短い名前に差し替える */
#story_list_btn .label-short {
    display: none;
}

@media (max-width: 560px) {
    #story_list_btn .label-long {
        display: none;
    }

    #story_list_btn .label-short {
        display: inline;
    }
}

/* オート中は色を変える。もう一度押すと元に戻る */
.story-iconbtn.is-on {
    background: #7fd3ff;
    border-color: #7fd3ff;
    color: #06293a;
    font-weight: 700;
}

.story-iconbtn {
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .35);
    color: #fff;
    border-radius: 6px;
    padding: 2px 10px;
    font-size: 12px;
    line-height: 1.6;
}

.story-iconbtn:hover {
    background: rgba(255, 255, 255, .3);
}

/* ------------------------------------------------------------ 図解エリア */

.story-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background:
        radial-gradient(120% 80% at 50% 0%, #ffffff 0%, #dcefff 55%, #bfe0f2 100%);
    cursor: pointer;
}

/* 図解の入れ替えはフェードで。写真は読み込めてから浮かび上がらせる */
.story-visual {
    transition: opacity .18s linear;
    position: absolute;
    inset: 10px 8px 26% 8px;   /* 下は立ち絵と重ならないよう空ける（縦持ち） */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    z-index: 1;
}

.story-visual.is-fading {
    opacity: 0;
}

.visual-photo {
    opacity: 0;
    transition: opacity .25s linear;
}

.visual-photo.is-loaded,
.visual-photo--dummy {
    opacity: 1;
}

/* 立ち絵。縦持ちは顔を基準に切り出してバストアップにする。
   背景画像なので、拡大率(background-size)と顔の位置(--fig-x/--fig-y)を箱の形と無関係に決められる。
   --fig-x / --fig-y は faces.json の bust から story.js が入れる。 */
.story-figure {
    position: absolute;
    bottom: 0;
    width: 50%;
    height: 32%;
    z-index: 2;
    pointer-events: none;
    background-repeat: no-repeat;
    /* 拡大率は箱の「高さ」基準。幅基準にすると画面が広いほど顔が大きくなってしまう */
    background-size: auto 320%;
    background-position: var(--fig-x, 50%) var(--fig-y, 8%);
    transition: filter .25s linear, opacity .25s linear;
    filter: brightness(.72) saturate(.85);
    opacity: .92;
}

.story-figure.is-active {
    filter: none;
    opacity: 1;
    z-index: 3;
}

.story-figure.is-empty {
    display: none;
}

.story-figure--left {
    left: 0;
}

.story-figure--right {
    right: 0;
}

/* --------------------------------------------------------------
   立ち絵の見せ方の試作（縦持ちのみ）。?fig=a〜f で切り替える。
   a = 現状。どれにするか決めたら、選んだものを既定にして残りは消すこと。
   -------------------------------------------------------------- */

/* b: 少し小さくして左右に余白。中央に隙間ができる */
.story-root[data-fig="b"] .story-figure {
    width: 43%;
    height: 27%;
    background-size: auto 300%;
}

.story-root[data-fig="b"] .story-figure--left  { left: 2%; }
.story-root[data-fig="b"] .story-figure--right { right: 2%; }

/* c: 話している方だけ大きく前に出る。聞いている方は小さく沈む */
.story-root[data-fig="c"] .story-figure {
    width: 38%;
    height: 23%;
    background-size: auto 300%;
    transform: translateY(12%);
}

.story-root[data-fig="c"] .story-figure.is-active {
    width: 47%;
    height: 30%;
    transform: translateY(0);
}

.story-root[data-fig="c"] .story-figure--left  { left: 1%; }
.story-root[data-fig="c"] .story-figure--right { right: 1%; }

/* d: 引いて腰から上まで。人の形が分かるが顔は小さめ */
.story-root[data-fig="d"] .story-figure {
    width: 44%;
    height: 34%;
    background-size: auto 185%;
}

/* e: 話している方だけ出す。画面が広く使える */
.story-root[data-fig="e"] .story-figure {
    width: 46%;
    height: 30%;
    background-size: auto 300%;
}

.story-root[data-fig="e"] .story-figure:not(.is-active) {
    display: none;
}

/* f / g: 丸く切り抜いてアイコンのように置く。図解エリアを一番広く取れる
   f = 左右の端にひとつずつ、g = 右端にふたつ並べる */
.story-root[data-fig="f"] .story-figure,
.story-root[data-fig="g"] .story-figure,
.story-root[data-fig="h"] .story-figure {
    width: 26%;
    height: 0;
    padding-bottom: 26%;
    bottom: 8px;
    border-radius: 50%;
    overflow: hidden;
    background-color: #eaf6ff;
    /* 拡大率を下げるほど下（胴や持ち物）まで入る。300%だと肩までしか入らなかった */
    background-size: auto 220%;
    box-shadow: 0 2px 8px rgba(10, 50, 75, .25);
    border: 3px solid #fff;
}

/* 話している方を少し持ち上げて、縁を色づける */
.story-root[data-fig="f"] .story-figure.is-active,
.story-root[data-fig="g"] .story-figure.is-active,
.story-root[data-fig="h"] .story-figure.is-active {
    border-color: #7fd3ff;
    box-shadow: 0 4px 12px rgba(10, 50, 75, .35);
    transform: translateY(-4px);
}

.story-root[data-fig="f"] .story-figure--left  { left: 3%; }
.story-root[data-fig="f"] .story-figure--right { right: 3%; }

/* g: 右端にふたつ。左右の並び順（Cion が左、Vee が右）は保つ */
.story-root[data-fig="g"] .story-figure--left {
    left: auto;
    right: 33%;
}

.story-root[data-fig="g"] .story-figure--right {
    right: 4%;
}

/* 図解の下端は、丸アイコン（高さ26%＋下8px）より上で止める。
   食い込ませると写真の説明が丸に隠れる（iPhoneで実際に起きた）。
   図解を広く使いたいので、よけ幅は丸の大きさで決める。丸を変えたらここも変える。
   入りきらない図解は fitVisual が縮めるので、切れることはない */
.story-root[data-fig="f"] .story-visual,
.story-root[data-fig="g"] .story-visual,
.story-root[data-fig="h"] .story-visual { inset: 8px 8px 29% 8px; }

/* 選択肢が出ている間はステージがさらに縮むので、もう少しよける。
   これは選択肢を台詞ウィンドウに出すとき（?quiz=a）だけ。
   図解に重ねる置き方では、図解の大きさは変えない */
.story-root[data-quiz="a"].has-choices[data-fig="f"] .story-visual,
.story-root[data-quiz="a"].has-choices[data-fig="g"] .story-visual,
.story-root[data-quiz="a"].has-choices[data-fig="h"] .story-visual { inset: 6px 8px 33% 8px; }

/* h: g と同じ右寄せだが、2つを少し重ねる。話している方が前に出る
   （重なりの上下は .is-active の z-index で入れ替わる） */
.story-root[data-fig="h"] .story-figure--left {
    left: auto;
    right: 25%;
}

.story-root[data-fig="h"] .story-figure--right {
    right: 4%;
}

/* 横長画面：立ち絵は左右の余白に全身、図解は中央 */
@media (min-aspect-ratio: 1/1) {
    .story-visual,
    .story-root[data-fig] .story-visual {
        inset: 12px 21% 12px 21%;
    }

    /* 横長では左右の端に置く。
       縦持ちの案（g/h は右端に寄せる）の位置指定をここで打ち消しておかないと、
       PCで左の立ち絵が画面の真ん中に残って図解に重なる */
    .story-figure--left,
    .story-root[data-fig] .story-figure--left {
        left: 0;
        right: auto;
    }

    .story-figure--right,
    .story-root[data-fig] .story-figure--right {
        right: 0;
        left: auto;
    }

    /* 横長は図解エリアが広いので、カードも広く取る。
       5枚くらいまでは横に3列に並べたほうが、縦にはみ出して中でスクロールするより読みやすい */
    .visual-cardgrid {
        grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
        max-width: 780px;
    }

    /* 枚数が多いときは2列に固定する。3列だと最後の行が1枚だけ残って収まりが悪い */
    .visual-cardgrid.is-many {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 560px;
    }

    /* 横長も顔を見せたいのでバストアップ。全身にすると顔が小さく、
       図解の左右に細長い余白ができてしまう（縦持ちの案 a〜h はここでは効かせない） */
    .story-figure,
    .story-root[data-fig] .story-figure {
        width: 20%;
        height: 42%;
        bottom: 0;
        padding-bottom: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background-color: transparent;
        background-size: auto 230%;
        background-position: var(--fig-x, 50%) var(--fig-y, 8%);
        transform: none;
    }

    /* 丸アイコン案の「話している方の飾り」は縦持ちだけのもの。
       横長で残すと、透明な立ち絵の箱に影の輪郭が出て、白い板が置いてあるように見える */
    .story-root[data-fig="f"] .story-figure.is-active,
    .story-root[data-fig="g"] .story-figure.is-active,
    .story-root[data-fig="h"] .story-figure.is-active {
        border: none;
        box-shadow: none;
        transform: none;
    }

    .story-root[data-fig="e"] .story-figure:not(.is-active) {
        display: block;
    }
}

/* ------------------------------------------------------------ 図解：写真 */

/* 写真は枠の高さに収め、キャプションは必ず見えるようにする。
   高さを 100% にしておかないと、写真の max-height が効かずに枠からはみ出し、
   クイズ中のように枠が縮んだときキャプションが立ち絵に隠れる */
.visual-image {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 100%;
}

.visual-photo {
    flex: 0 1 auto;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    /* 小さい写真（コウガイビルは157px）が画面の中で埋もれないよう、この幅までは引き伸ばす。
       ほかの写真はもっと大きいので、この指定では変わらない */
    min-width: min(62%, 240px);
    border-radius: 12px;
    border: 4px solid #fff;
    box-shadow: 0 4px 14px rgba(10, 50, 75, .25);
    object-fit: contain;
    background: #fff;
}

.visual-photo--dummy {
    min-width: 0;
    width: min(46vw, 220px);
    height: min(46vw, 220px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: repeating-linear-gradient(45deg, #f4f9fc 0 10px, #e8f2f8 10px 20px);
    color: #5b7d91;
}

.visual-dummy-icon {
    width: 46%;
    opacity: .8;
}

.visual-dummy-text {
    font-size: 12px;
}

.visual-caption,
.card-foot {
    flex: 0 0 auto;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.visual-cname {
    font-weight: 700;
    color: #0d3c55;
}

.visual-sname {
    font-style: italic;
    color: #4a7089;
    font-size: .9em;
}

/* 総称で扱っている生き物のとき、写真の実際の種名を小さく断る */
.visual-photocap {
    color: #5b7d91;
    font-size: .82em;
}

/* ------------------------------------------------------------ 図解：入れ子の箱 */

.visual-nest {
    width: 100%;
    max-width: 640px;
    margin: auto;
}

.nest-caption {
    text-align: center;
    font-weight: 700;
    color: #0d3c55;
    margin-bottom: 6px;
}

.nest-level {
    border: 2px solid rgba(13, 60, 85, .35);
    border-radius: 10px;
    background: rgba(255, 255, 255, .66);
    padding: 5px 5px 6px 8px;
    margin-top: 4px;
}

.nest-head {
    display: flex;
    align-items: baseline;
    gap: 6px;
    line-height: 1.5;
}

.nest-chip {
    flex: 0 0 auto;
    background: #0d5a7d;
    color: #fff;
    border-radius: 6px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 700;
}

.nest-name {
    font-weight: 600;
    color: #12384d;
    font-size: clamp(13px, 2.1vw, 16px);
}

.nest-level.is-hl {
    border-color: #f08c00;
    background: #fff4dc;
    box-shadow: 0 0 0 2px rgba(240, 140, 0, .22);
}

.nest-level.is-hl > .nest-head > .nest-chip {
    background: #f08c00;
}

.nest-level.is-closed {
    border-style: dashed;
    opacity: .45;
}

/* emphasize_size: 外側の箱ほど余白を大きくして「大きい箱」に見せる */
.visual-nest.is-emph .nest-level {
    padding-top: calc(4px + (7 - var(--depth, 0)) * 2px);
    padding-bottom: calc(5px + (7 - var(--depth, 0)) * 2px);
}

/* ranks_only: 階級名だけを大きく見せる */
.visual-nest.is-rankonly .nest-chip {
    font-size: clamp(14px, 2.6vw, 18px);
    padding: 2px 12px;
}

/* ------------------------------------------------------------ 図解：住所くらべ（compare） */

.visual-compare {
    width: 100%;
    max-width: 620px;
    margin: auto;
    background: rgba(255, 255, 255, .72);
    border-radius: 12px;
    padding: 8px 10px;
}

.compare-head,
.compare-row {
    display: grid;
    grid-template-columns: 2.6em 1fr 1fr;
    gap: 4px;
    align-items: center;
}

/* 見出しは下ぞろえ。写真がある側と無い側で名前の高さがずれないように */
.compare-head {
    align-items: end;
}

.compare-row {
    border-radius: 8px;
    padding: 2px 2px;
    margin-top: 2px;
}

.compare-name {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-weight: 700;
    color: #0d3c55;
    text-align: center;
    font-size: clamp(12px, 2vw, 15px);
    border-bottom: 2px solid #bfe0f2;
    padding-bottom: 3px;
    margin-bottom: 3px;
}

/* くらべる相手の顔。写真がある生き物だけ出る */
.compare-thumb {
    width: clamp(56px, 14vw, 84px);
    height: clamp(56px, 14vw, 84px);
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 30%;   /* 縦長の写真でも顔が入るよう、やや上を見せる */
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(10, 50, 75, .3);
}

.compare-rank-col {
    color: #fff;
    background: #0d5a7d;
    border-radius: 6px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.7;
}

.compare-head .compare-rank-col {
    background: transparent;
}

.compare-cell {
    text-align: center;
    color: #12384d;
    font-size: clamp(11px, 1.9vw, 14px);
    line-height: 1.5;
    background: #fff;
    border-radius: 6px;
    padding: 2px 4px;
}

/* 一致している階級 */
.compare-row.is-shared .compare-cell {
    background: #d8f0dc;
    font-weight: 600;
}

.compare-row.is-shared .compare-rank-col {
    background: #2ea44f;
}

/* 分かれる階級 */
.compare-row.is-split .compare-cell {
    background: #ffe9d6;
    box-shadow: inset 0 0 0 2px #f08c00;
}

.compare-row.is-split .compare-rank-col {
    background: #f08c00;
}

.compare-foot {
    margin-top: 6px;
    text-align: center;
    font-weight: 700;
    color: #2ea44f;
    font-size: clamp(12px, 2vw, 15px);
}

/* ------------------------------------------------------------ 図解：一致の深さ（ladder） */

.visual-ladder {
    width: 100%;
    max-width: 620px;
    margin: auto;
    background: rgba(255, 255, 255, .72);
    border-radius: 12px;
    padding: 8px 10px;
}

.ladder-caption {
    text-align: center;
    font-weight: 700;
    color: #0d3c55;
    margin-bottom: 6px;
    font-size: clamp(12px, 2vw, 15px);
}

.ladder-scale,
.ladder-row {
    display: grid;
    grid-template-columns: 5.5em repeat(7, 1fr);
    gap: 2px;
    align-items: center;
}

.ladder-row {
    margin-top: 3px;
}

.ladder-label {
    font-size: clamp(11px, 1.8vw, 13px);
    color: #12384d;
    font-weight: 600;
    text-align: right;
    padding-right: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ladder-tick {
    font-size: 10px;
    color: #4a7089;
    text-align: center;
}

.ladder-cell {
    height: 1.7em;
    border-radius: 4px;
    background: #eef4f8;
    border: 1px solid #dbe8f0;
    font-size: 10px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ladder-cell.is-shared {
    background: #58b368;
    border-color: #2ea44f;
}

.ladder-cell.is-last {
    background: #2ea44f;
    font-weight: 700;
}

/* 写真を並べて見くらべる（show.taxa に2つ以上。story.js の renderImagePair。2026-09-28） */
.visual-image-pair {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 100%;
}

.visual-image--pair {
    flex: 1 1 0;
    min-width: 0;
}

.visual-image--pair .visual-photo {
    min-width: 0;
    width: 100%;
    object-fit: cover;
    aspect-ratio: 1 / 1;
}

.visual-pair-label {
    flex: 0 0 auto;
    padding: 2px 12px;
    border-radius: 999px;
    background: #0d3c55;
    color: #fff;
    font-weight: 700;
    font-size: clamp(12px, 2vw, 15px);
}

.visual-image--pair .visual-caption {
    font-size: clamp(12px, 2vw, 15px);
}

/* まとめのカードの写真（show.photos） */
.card-photos {
    display: grid;
    grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dotted #bfe0f2;
}

.card-photo {
    margin: 0;
    text-align: center;
}

.card-photo img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(10, 50, 75, .2);
}

.card-photo figcaption {
    margin-top: 3px;
    font-size: clamp(10px, 1.8vw, 13px);
    font-weight: 700;
    color: #0d3c55;
    line-height: 1.3;
}

/* ------------------------------------------------------------ 図解：カード */

.visual-card {
    background: #fff;
    border-radius: 14px;
    border: 3px solid #7fd3ff;
    box-shadow: 0 6px 18px rgba(10, 50, 75, .18);
    padding: 14px 18px;
    max-width: 560px;
    margin: auto;
}

.card-title {
    font-weight: 700;
    color: #0d3c55;
    font-size: clamp(15px, 2.4vw, 19px);
    border-bottom: 2px dotted #bfe0f2;
    padding-bottom: 5px;
    margin-bottom: 8px;
}

.card-row {
    line-height: 1.8;
    color: #12384d;
    font-size: clamp(13px, 2.1vw, 16px);
}

.card-foot {
    margin-top: 8px;
    border-top: 1px dotted #bfe0f2;
    padding-top: 6px;
}

.visual-card--todo {
    border-color: #f0b400;
    background: #fffaf0;
}

.visual-card--todo .card-body {
    font-size: 12px;
    color: #7a6432;
    word-break: break-all;
}

/* ------------------------------------------------------------ 図解：系統樹（story.js の renderTree） */

.visual-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin: auto;
    padding: 8px 10px 6px;
    background: #fff;
    border-radius: 14px;
    border: 3px solid #7fd3ff;
    box-shadow: 0 6px 18px rgba(10, 50, 75, .18);
}

.tree-title {
    font-weight: 700;
    font-size: 14px;
    color: #0d3c55;
}

.tree-box {
    position: relative;
    flex: 0 0 auto;
}

.tree-svg {
    position: absolute;
    left: 0;
    top: 0;
    overflow: visible;
}

.tree-edge {
    fill: none;
    stroke: #5b7f93;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tree-edge.is-hl {
    stroke: #ff8a00;
    stroke-width: 5;
}

.tree-node {
    fill: #fff;
    stroke: #5b7f93;
    stroke-width: 2.5;
}

.tree-node.is-hl {
    fill: #ffcf33;
    stroke: #e07000;
    stroke-width: 3;
}

/* 光らせた分岐点のまわりで、輪がふくらんで消える */
.tree-node-ring {
    fill: none;
    stroke: #ffb300;
    stroke-width: 3;
    transform-box: fill-box;
    transform-origin: center;
    animation: tree-ring 1.4s ease-out infinite;
}

@keyframes tree-ring {
    from { transform: scale(.6); opacity: .9; }
    to   { transform: scale(1.7); opacity: 0; }
}

/* ハサミ1回で切りはなせるまとまり（クレード） */
.tree-clade {
    fill: #fff4c8;
    stroke: #ffcf33;
    stroke-width: 2;
    stroke-dasharray: 6 4;
}

.tree-age {
    font-size: 11px;
    font-weight: 700;
    fill: #b35a00;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 3;
}

.tree-axis {
    stroke: #8aa6b5;
    stroke-width: 2;
}

.tree-axis-head {
    fill: #8aa6b5;
}

.tree-axis-label {
    font-size: 11px;
    fill: #5b7f93;
}

.tree-axis-label.is-now {
    font-weight: 700;
    fill: #0d3c55;
}

/* 先端（写真と名前） */
.tree-tip {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 0 8px 0 2px;
    border-radius: 999px;
    white-space: nowrap;
}

.tree-photo {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #fff;
    box-shadow: 0 1px 4px rgba(10, 50, 75, .3);
    background: #e7f2f8;
}

/* 写真の無い生き物（ヒト・コウモリなど）は、点線の丸だけ */
.tree-photo.is-empty {
    display: inline-block;
    box-sizing: border-box;
    border: 2px dashed #9dbccc;
    box-shadow: none;
}

.tree-name {
    font-size: 14px;
    font-weight: 700;
    color: #12384d;
}

.tree-tip.is-hl .tree-photo {
    border-color: #ffcf33;
    box-shadow: 0 0 0 3px #ff8a00, 0 0 12px rgba(255, 170, 0, .8);
}

.tree-tip.is-hl .tree-name {
    color: #b35a00;
}

.tree-tip.is-hl {
    background: #fff4c8;
}

/* 系統樹を2つ並べて見くらべる（第2話）。縦持ちは上下、横長は左右 */
.visual-tree-pair {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
    margin: auto;
}

.visual-tree-pair .visual-tree {
    margin: 0;
    padding: 6px 8px 4px;
}

/* 根もとが下、先端が上に横に並ぶ形（第5話） */
.visual-tree.is-up .tree-tip {
    flex-direction: column;
    gap: 3px;
    padding: 2px 0;
    border-radius: 12px;
    white-space: normal;
}

.visual-tree.is-up .tree-name {
    font-size: 11px;
    line-height: 1.2;
    text-align: center;
    overflow-wrap: anywhere; /* 「ニホンアマガエル」は1列に収まらないので折り返す */
}

.visual-tree.is-up .tree-name rt {
    display: none;
}

/* ------------------------------------------------------------ 図解：門カード（card_grid / card の phylum） */

.visual-cardgrid {
    width: 100%;
    max-width: 640px;
    margin: auto;
    display: grid;
    /* 縦持ちは2列に収まる幅。横長では下の @media で広げる
       （細くすると写真のぶん文字が潰れて、門の名前が途中で折れる） */
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 6px;
}

.visual-cardgrid.is-solo {
    grid-template-columns: 1fr;
    max-width: 440px;
}

.phylum-card {
    background: #fff;
    border: 2px solid #bfe0f2;
    border-radius: 10px;
    padding: 5px 8px;
}

/* 一覧に並べるときは詰める。カードが多いと自動縮小がかかって
   文字が読めない大きさまで小さくなるため（9枚で7〜10pxになった） */
.visual-cardgrid:not(.is-solo) .phylum-card {
    gap: 6px;
}

.visual-cardgrid:not(.is-solo) .phylum-feature {
    margin-top: 1px;
    line-height: 1.4;
}

.visual-cardgrid:not(.is-solo) .phylum-examples {
    margin-top: 1px;
    line-height: 1.35;
}

/* 「第N話でくわしく」は一覧では出さない（単体で出すときだけ） */
.visual-cardgrid:not(.is-solo) .phylum-episode {
    display: none;
}

/* 枚数が多いときは写真と名前だけ。見わけ方と例は、このあと1枚ずつ出るときに読む */
.visual-cardgrid.is-many .phylum-feature,
.visual-cardgrid.is-many .phylum-examples {
    display: none;
}

.visual-cardgrid.is-many .phylum-card {
    align-items: center;
    padding: 6px 10px;
}

.visual-cardgrid.is-many .phylum-name {
    font-size: clamp(14px, 2.6vw, 17px);
}

.visual-cardgrid.is-many .phylum-thumb {
    width: clamp(40px, 9vw, 52px);
    height: clamp(40px, 9vw, 52px);
}

/* 写真つきのカードは、左に小さな写真・右に文字 */
.phylum-card.has-thumb {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.phylum-body {
    min-width: 0;
    flex: 1 1 auto;
}

.phylum-thumb {
    flex: 0 0 auto;
    /* 名前の横の小さな写真。小さすぎると何の生き物か分からないので、
       枚数がふつう（3〜7枚）のときは下の指定で大きくする */
    width: clamp(34px, 7.5vw, 44px);
    height: clamp(34px, 7.5vw, 44px);
    border-radius: 8px;
    object-fit: cover;
    object-position: 50% 40%;
    border: 1px solid #dbe8f0;
    background: #eef4f8;
}

.visual-cardgrid.is-solo .phylum-thumb {
    width: clamp(56px, 14vw, 84px);
    height: clamp(56px, 14vw, 84px);
    border-radius: 10px;
}

.phylum-card.is-hl {
    border-color: #f08c00;
    background: #fff8ec;
}

/* 1枚だけ大きく出すとき。写真を上に大きく置いて、下に説明 */
.visual-cardgrid.is-solo {
    max-width: 420px;
}

.visual-cardgrid.is-solo .phylum-card {
    border-color: #7fd3ff;
    border-width: 3px;
    background: #fff;
    padding: 14px 18px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    box-shadow: 0 6px 18px rgba(10, 50, 75, .18);
}

.visual-cardgrid.is-solo .phylum-thumb {
    width: 100%;
    height: clamp(120px, 26vh, 220px);
    border-radius: 10px;
    object-position: 50% 45%;
}

.visual-cardgrid.is-solo .phylum-feature {
    font-size: clamp(13px, 2.2vw, 16px);
}

.visual-cardgrid.is-solo .phylum-examples {
    font-size: clamp(12px, 2vw, 14px);
}

/* 「ほかにもある」ことを示す枠 */
.phylum-card.is-more {
    grid-column: 1 / -1;   /* 1行ぶん使って、文字を詰め込まない */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .55);
    border-style: dashed;
    border-color: #9dc4d8;
    text-align: center;
    min-height: 54px;
}

.phylum-more-text {
    color: #3c6379;
    font-size: clamp(12px, 2vw, 15px);
    line-height: 1.6;
    white-space: pre-line;   /* 「（海綿動物門…）」を次の行に落とす */
}

.phylum-name {
    font-weight: 700;
    color: #0d3c55;
    font-size: clamp(13px, 2.1vw, 16px);
    line-height: 1.4;
    word-break: keep-all;   /* 「脊索動物／門」のように途中で折れないように */
}

.visual-cardgrid.is-solo .phylum-name {
    font-size: clamp(16px, 2.8vw, 20px);
    border-bottom: 2px dotted #bfe0f2;
    padding-bottom: 4px;
    margin-bottom: 6px;
}

.phylum-feature {
    color: #12384d;
    font-size: clamp(11px, 1.9vw, 14px);
    line-height: 1.5;
    margin-top: 2px;
}

.phylum-examples {
    color: #4a7089;
    font-size: clamp(10px, 1.8vw, 13px);
    line-height: 1.5;
    margin-top: 2px;
}

.phylum-episode {
    margin-top: 4px;
    display: inline-block;
    background: #e8f6ff;
    color: #0d5a7d;
    border-radius: 999px;
    padding: 0 8px;
    font-size: 10px;
    line-height: 1.7;
}

/* 枚数がふつう（is-few でも is-many でも is-solo でもない）のときは、写真を大きく取る。
   綱や門は名前だけでは見当がつかないので、写真が主役 */
.visual-cardgrid:not(.is-solo):not(.is-many):not(.is-few) .phylum-thumb {
    width: clamp(56px, 14vw, 88px);
    height: clamp(56px, 14vw, 88px);
    border-radius: 10px;
}

.visual-cardgrid:not(.is-solo):not(.is-many):not(.is-few) .phylum-card {
    border-radius: 14px;
    padding: 6px 10px 6px 6px;
    gap: 8px;
}

/* 横長は図解の枠が縦長画面より狭い（立ち絵を左右に置くため）。
   写真を縦持ちと同じだけ大きくすると、説明の列が細くなって1行4〜5文字で折れる。
   横長のときだけ写真を少し小さくして、説明の幅を残す。
   **この指定は上の基本の指定より後に置くこと。**同じ強さなので、前に置くと効かない
   （画面上のほうの @media ブロックに書いて、丸1回ぶん効かなかった） */
@media (min-aspect-ratio: 1/1) {
    .visual-cardgrid:not(.is-solo):not(.is-many):not(.is-few) .phylum-thumb {
        width: clamp(52px, 6vw, 68px);
        height: clamp(52px, 6vw, 68px);
    }
}

/* 2枚だけ並べるときは大きめに */
.visual-cardgrid.is-few {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    max-width: 520px;
}

/* ------------------------------------------------------------ 図解：検索表（key） */

.visual-key {
    width: 100%;
    max-width: 560px;
    margin: auto;
    background: rgba(255, 255, 255, .8);
    border-radius: 12px;
    padding: 10px 12px;
}

.key-title {
    text-align: center;
    font-weight: 700;
    color: #0d3c55;
    font-size: clamp(13px, 2.2vw, 16px);
    margin-bottom: 8px;
}

.key-step + .key-step {
    margin-top: 10px;
    border-top: 1px dotted #bfe0f2;
    padding-top: 8px;
}

.key-q {
    font-weight: 700;
    color: #12384d;
    font-size: clamp(12px, 2vw, 15px);
    background: #e8f6ff;
    border-radius: 8px;
    padding: 3px 10px;
    display: inline-block;
}

.key-branches {
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-left: 10px;
}

.key-branch {
    display: grid;
    grid-template-columns: 4.5em 1.4em 1fr;
    align-items: center;
    gap: 4px;
    background: #fff;
    border: 1px solid #dbe8f0;
    border-radius: 8px;
    padding: 3px 8px;
    font-size: clamp(11px, 1.9vw, 14px);
}

.key-branch.is-hl {
    border-color: #f08c00;
    background: #fff4dc;
    box-shadow: 0 0 0 2px rgba(240, 140, 0, .22);
}

.key-a {
    font-weight: 700;
    color: #0d5a7d;
}

.key-arrow {
    color: #7fa7bd;
    text-align: center;
}

.key-to {
    color: #12384d;
    line-height: 1.4;
}

/* 1段ずつ出すとき（段が3つ以上の検索表）。1枠ぶんの場所を使えるので大きく出す */
.visual-key.is-one {
    max-width: 480px;
}

.visual-key.is-one .key-q {
    display: block;
    text-align: center;
    font-size: clamp(14px, 2.6vw, 19px);
    padding: 6px 12px;
}

.visual-key.is-one .key-branches {
    margin-top: 8px;
    gap: 6px;
    padding-left: 0;
}

.visual-key.is-one .key-branch {
    grid-template-columns: 1fr 1.2em 1fr;
    font-size: clamp(12px, 2.2vw, 16px);
    padding: 6px 10px;
    gap: 6px;
}

/* 例の写真がある枝は、左に写真の列を足す */
.visual-key.is-one .key-branch.has-photo {
    grid-template-columns: auto 1fr 1.2em 1fr;
}

.key-photo {
    width: clamp(38px, 9vw, 54px);
    height: clamp(38px, 9vw, 54px);
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid #dbe8f0;
    background: #eef4f8;
}

/* 次の質問へ送る枝の写真（その先の例を2枚、重ねて小さく。story.js の keyStepBox） */
.key-photo--pair {
    position: relative;
    display: block;
    border: 0;
    background: none;
}

.key-photo--pair img {
    position: absolute;
    width: 72%;
    height: 72%;
    border-radius: 7px;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(10, 50, 75, .25);
}

.key-photo--pair img:first-child { left: 0; top: 0; }
.key-photo--pair img:nth-child(2) { right: 0; bottom: 0; }

/* ここまでに選んだ答え */
.key-trail {
    text-align: center;
    color: #3d7c9b;
    font-size: clamp(10px, 1.8vw, 13px);
    margin-bottom: 6px;
}

.key-progress {
    text-align: center;
    color: #5b8ba3;
    font-size: clamp(10px, 1.7vw, 12px);
    margin-top: 8px;
}

/* ------------------------------------------------------------ 図解：割合の帯（proportion） */

.visual-proportion {
    width: 100%;
    max-width: 620px;
    margin: auto;
    background: rgba(255, 255, 255, .78);
    border-radius: 12px;
    padding: 12px 14px;
}

.prop-caption {
    text-align: center;
    font-weight: 700;
    color: #0d3c55;
    font-size: clamp(12px, 2vw, 15px);
    margin-bottom: 8px;
}

.prop-bar {
    display: flex;
    height: 34px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(13, 60, 85, .2);
}

/* 帯と凡例で同じ色を使う。--seg の 0,1,2... で色を振り分ける */
.prop-seg,
.prop-swatch {
    background: #7fd3ff;
}

.prop-seg[style*="--seg: 0"],
.prop-swatch[style*="--seg: 0"] {
    background: #0d5a7d;
}

.prop-seg[style*="--seg: 1"],
.prop-swatch[style*="--seg: 1"] {
    background: #58b368;
}

.prop-seg[style*="--seg: 2"],
.prop-swatch[style*="--seg: 2"] {
    background: #f0b400;
}

.prop-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
}

.prop-seg-value {
    white-space: nowrap;
}

.prop-legend {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.prop-legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: clamp(11px, 1.9vw, 14px);
    color: #12384d;
}

.prop-swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex: 0 0 auto;
}

.prop-legend-label {
    flex: 1 1 auto;
    min-width: 0;
}

.prop-legend-value {
    font-weight: 700;
    color: #0d3c55;
}

/* ------------------------------------------------------------ ふりがな（ルビ） */

/* 語の上に、半分の大きさで出す。行間（line-height）の中に収める */
ruby {
    ruby-align: center;
}

rt {
    font-size: .5em;
    line-height: 1;
    font-weight: 400;
    opacity: .85;
    user-select: none;
    -webkit-user-select: none;
}

/* 図解の中でも小さい文字のところは、ルビを出すと元の文字まで潰れる。
   親文字はそのままに、ルビだけ伏せる（文字を小さくしないための措置） */
.phylum-feature rt,
.phylum-examples rt,
.phylum-episode rt,
.prop-legend rt,
.ladder-note rt {
    display: none;
}

/* ------------------------------------------------------------ 台詞ウィンドウ */

.story-box {
    flex: 0 0 auto;
    background: rgba(8, 40, 58, .93);
    color: #fff;
    border-top: 3px solid #7fd3ff;
    padding: 8px 14px 10px;
    cursor: pointer;
}

/* 台詞は1行30文字までの枠にして、その枠を中央に置く（文字は左寄せ）。
   横に長く流れると目が戻りにくいため */
.story-nameline,
.story-text,
.story-choices,
.story-controls {
    max-width: 30em;
    margin-left: auto;
    margin-right: auto;
}

/* 話者名（左）と音声のオン・オフ（右）を同じ行に並べる。
   台詞の枠と同じ 30em の中に入れているので、右端が本文の右端とそろう */
.story-nameline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.story-name {
    color: #ffd76a;
    font-weight: 700;
    font-size: 14px;
    min-height: 1.2em;
    flex: 1 1 auto;
    min-width: 0;
}

/* ------------------------------------------------------------ 音声のオン・オフ

   台詞ウィンドウの中なので、押しても台詞が進まないようにしてある
   （story.js の story_box のクリックは button の上では拾わない）。
   オフのときはスピーカーに×を重ね、色も落として、見ただけで分かるようにする */
.story-voicebtn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(127, 211, 255, .18);
    border: 1px solid rgba(127, 211, 255, .55);
    color: #cfefff;
    border-radius: 999px;
    padding: 2px 10px 2px 8px;
    font-size: 12px;
    line-height: 1.6;
}

.story-voicebtn:hover {
    background: rgba(127, 211, 255, .32);
}

.story-voicebtn-ico {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.story-voicebtn-ico .ico-body {
    fill: currentColor;
    stroke: none;
}

/* オンのときは×を、オフのときは音の波を隠す */
.story-voicebtn .ico-mute {
    display: none;
}

.story-voicebtn.is-off {
    background: transparent;
    border-color: rgba(255, 255, 255, .3);
    color: rgba(255, 255, 255, .55);
}

.story-voicebtn.is-off .ico-wave {
    display: none;
}

.story-voicebtn.is-off .ico-mute {
    display: inline;
}

/* 台詞は3行で固定。長さによって枠が伸び縮みすると、
   次へボタンや図解の位置が行ごとに動いて読みにくい。
   3行に収まらない台詞は、シナリオの側で短くする約束にしてある。
   行間の 2 は、ルビ（rt）が行の中に収まる高さでもある */
.story-text {
    height: 6em;
    line-height: 2;
    font-size: clamp(14px, 2.3vw, 18px);
    white-space: pre-wrap;
    text-align: left;
    overflow: hidden;
}

/* 読み物の話（episode.instant_text。ホヤ徹底編）は5行。文字送りもしない（story.js）。2026-09-29 */
body.story-reading .story-text {
    height: 10em;
}
/* 英語は日本語の2倍ほど長いので、字を少し小さく・行を詰めて7行（枠の高さは日本語と同じ） */
html[lang="en"] body.story-reading .story-text {
    font-size: calc(clamp(14px, 2.3vw, 18px) * .88);
    line-height: 1.6;
    height: calc(clamp(14px, 2.3vw, 18px) * 10);
}

.story-choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 6px 0 2px;
}

.story-choice {
    width: 100%;
    text-align: left;
    background: #fff;
    color: #12384d;
    border: 2px solid #7fd3ff;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: clamp(13px, 2.1vw, 16px);
    line-height: 1.5;
}

.story-choice:hover:not(:disabled) {
    background: #e8f6ff;
}

.story-choice:disabled {
    opacity: .6;
}

.story-choice.is-correct {
    background: #d8f5df;
    border-color: #2ea44f;
    opacity: 1;
}

.story-choice.is-correct::after {
    content: " ○";
    color: #2ea44f;
    font-weight: 700;
}

.story-choice.is-wrong {
    background: #ffe3e3;
    border-color: #d9534f;
    opacity: 1;
}

.story-choice.is-wrong::after {
    content: " ×";
    color: #d9534f;
    font-weight: 700;
}

.story-controls {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.story-btn {
    background: #7fd3ff;
    color: #06293a;
    border: none;
    border-radius: 8px;
    padding: 6px 18px;
    font-weight: 700;
}

.story-btn--ghost {
    background: transparent;
    color: #cfe8f5;
    border: 1px solid rgba(207, 232, 245, .5);
    font-weight: 400;
}

.story-btn:disabled {
    opacity: .35;
}

/* 「戻る」「次へ」の三角。文字の ▶ は端末によって絵文字になるので、形で描く */
.story-btn--prev::before,
.story-btn--next::after {
    content: "";
    display: inline-block;
    width: .6em;
    height: .7em;
    background: currentColor;
    vertical-align: -.02em;
}
.story-btn--prev::before {
    clip-path: polygon(100% 0, 0 50%, 100% 100%);
    margin-right: .4em;
}
.story-btn--next::after {
    clip-path: polygon(0 0, 100% 50%, 0 100%);
    margin-left: .4em;
}

/* 横長は横に余裕があるので、選択肢は横に並べて中央ぞろえにする。
   台詞そのものは1行30文字の枠のまま（読む向きを変えないため）。
   ※ この指定は .story-choices の定義より後ろに置くこと。
     前に置くと、あとから来る縦並びの指定に負けて効かない（一度やった） */
@media (min-aspect-ratio: 1/1) {
    .story-choices {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: stretch;
        max-width: 54em;
        gap: 8px;
    }

    .story-choices .story-choice {
        flex: 1 1 190px;
        max-width: 22em;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ------------------------------------------- クイズの選択肢を図解に重ねる（?quiz=b / c） */

/* 図解エリアの上に、半透明の帯として縦に並べる。
   直前の台詞も図解もそのまま残るので、見ながら選べる。
   ※ この指定は上の「横長では横並び」より後ろに置くこと（後ろが勝つ） */
.story-choices--stage {
    position: absolute;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    /* 絶対配置は中身なりに縮むので、幅を決めておくこと（縮むとボタンがばらばらの幅になる） */
    width: min(30em, calc(100% - 16px));
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto;
}

.story-choices--stage[hidden] {
    display: none;
}

/* b … 下寄せ。図解の下に重なるが、立ち絵の顔には掛からない */
.story-root[data-quiz="b"] .story-choices--stage {
    bottom: 31%;
}

/* c … まん中 */
.story-root[data-quiz="c"] .story-choices--stage {
    top: 50%;
    transform: translate(-50%, -50%);
}

/* d … 図解を少し縮めて、その下に置く。図解に重ならない代わりに図解が小さくなる */
.story-root[data-quiz="d"] .story-choices--stage {
    bottom: 29%;
}

.story-root[data-quiz="d"].has-choices[data-fig="f"] .story-visual,
.story-root[data-quiz="d"].has-choices[data-fig="g"] .story-visual,
.story-root[data-quiz="d"].has-choices[data-fig="h"] .story-visual { inset: 6px 8px 52% 8px; }

.story-choices--stage .story-choice {
    background: rgba(255, 255, 255, .72);
    border-color: rgba(13, 90, 125, .35);
    color: #0d3c55;
    text-align: center;
    box-shadow: 0 2px 8px rgba(8, 40, 58, .18);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.story-choices--stage .story-choice:hover:not(:disabled) {
    background: rgba(232, 246, 255, .92);
}

/* 答え合わせの色も、下の図解が透けるくらいに */
.story-choices--stage .story-choice.is-correct {
    background: rgba(216, 245, 223, .92);
    border-color: #2ea44f;
}

.story-choices--stage .story-choice.is-wrong {
    background: rgba(255, 227, 227, .92);
    border-color: #d9534f;
}

/* 横長でも、図解に重ねるときは縦に並べる（横に広げると図解を覆ってしまう） */
@media (min-aspect-ratio: 1/1) {
    .story-choices--stage {
        flex-direction: column;
        width: min(26em, 56%);
    }

    .story-choices--stage .story-choice {
        flex: 0 0 auto;
        max-width: none;
    }

    .story-root[data-quiz="b"] .story-choices--stage {
        bottom: 12px;
    }

    .story-root[data-quiz="d"] .story-choices--stage {
        bottom: 12px;
    }

    .story-root[data-quiz="d"].has-choices .story-visual {
        inset: 12px 21% 36% 21%;
    }
}

/* 系統樹のクイズ（story.js の renderChoices）。縦持ちは d と同じく木の下に並べる。
   横長で d のままだと木が小さくなりすぎるので、木を左寄せにして、選択肢は右に縦に並べる */
@media (min-aspect-ratio: 1/1) {
    /* [data-fig] まで書くこと。上の d の「[data-fig="g"]」つきの指定（縦持ち用）が横長にも効いていて、それより強くしないと負ける */
    .story-root.is-tree-quiz.has-choices[data-fig] .story-visual {
        inset: 12px 36% 12px 17%;
    }

    .story-root.is-tree-quiz .story-choices--stage {
        left: auto;
        right: 16px;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
        width: min(22em, 32%);
    }
}

/* --------------------------------------------- 読み終えたときのごほうび */

.story-reward {
    /* 確認のモーダルと同じく画面ぜんたいに重ねる（ナビバーの上にも出す） */
    position: fixed;
    inset: 0;
    z-index: 1300;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 40, 58, .55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    cursor: pointer;
    animation: story-reward-in .22s ease-out;
}

.story-reward.hidden {
    display: none;
}

@keyframes story-reward-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.story-reward-inner {
    width: min(86%, 420px);
    background: #fff;
    color: #12384d;
    border: 3px solid #7fd3ff;
    border-radius: 16px;
    padding: 18px 18px 16px;
    text-align: center;
    box-shadow: 0 12px 30px rgba(8, 40, 58, .35);
    animation: story-reward-pop .24s ease-out;
}

@keyframes story-reward-pop {
    from { transform: scale(.92); }
    to   { transform: scale(1); }
}

.story-reward-title {
    font-weight: 700;
    font-size: clamp(16px, 3vw, 21px);
    line-height: 1.8;
}

.story-reward-get {
    margin-top: 6px;
    color: #0d5a7d;
    font-size: clamp(14px, 2.5vw, 18px);
    line-height: 1.8;
}

.story-reward-chara {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.story-reward-chara[hidden] {
    display: none;
}
.story-reward-chara-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 12px;
    background: #fff8e6;
    color: #7a4b00;
    font-size: clamp(13px, 2.2vw, 16px);
    font-weight: 700;
    text-align: left;
}
.story-reward-chara-row img {
    flex: none;
    width: 48px;
    height: 64px;
    object-fit: contain;
}

.story-reward-get[hidden] {
    display: none;
}

.story-reward-img {
    display: block;
    margin: 10px auto 0;
    max-width: min(60%, 180px);
    max-height: 30vh;
    border-radius: 12px;
    border: 1px solid #dbe8f0;
}

.story-reward-img[hidden] {
    display: none;
}

.story-reward-btn {
    vertical-align: middle;
    margin-top: 14px;
    min-width: 8em;
    background: #7fd3ff;
    color: #0d3c55;
    border: none;
    border-radius: 999px;
    padding: 8px 20px;
    font-size: clamp(14px, 2.4vw, 17px);
    font-weight: 700;
    cursor: pointer;
}

.story-reward-btn:hover {
    background: #a5e1ff;
}

/* 第1話のあとの「クエストに挑戦する」（js/storyguide.js）。OK より目立たせ、OK はその横に */
.story-reward-quest { background: #f28c1e; color: #fff; margin-right: 8px; }
.story-reward-quest:hover { background: #ff9f36; }
/* 次の話へ（2026-09-29）。題名を下に小さく */
.story-reward-next { background: #2f9e6e; color: #fff; margin-right: 8px; line-height: 1.3; max-width: 100%; }
.story-reward-next:hover { background: #3cb57f; }
.story-reward-next-title { display: block; font-size: .72em; font-weight: 600; opacity: .9; max-width: 16em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-reward-btn[hidden] { display: none; }

/* ------------------------------------------------------------ ログ */

.story-logmodal {
    position: fixed;
    inset: 0;
    background: rgba(4, 22, 33, .6);
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.story-logmodal.hidden {
    display: none;
}

.story-logmodal-inner {
    background: #fff;
    border-radius: 12px;
    width: min(560px, 100%);
    max-height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.story-logmodal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #0d3c55;
    color: #fff;
    padding: 8px 12px;
    font-weight: 700;
}

.story-logmodal-body {
    overflow: auto;
    padding: 10px 14px;
}

.logrow {
    padding: 6px 0;
    border-bottom: 1px dotted #cfe0ea;
}

.logrow-name {
    font-size: 12px;
    font-weight: 700;
    color: #0d5a7d;
}

.logrow-text {
    color: #12384d;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ============================================================
   話の選択画面（stories.php）
   ============================================================ */

/* 背景は他の画面と同じ（.main-panel の青いグラデ）。ここでは敷かない */
.stories-root {
    min-height: 100%;
    padding: 18px 14px 36px;
}

/* 上の部分は紺の板に載せる。以前は背景の絵の上に半透明の白い文字が直接乗っていて、薄くて読みにくかった（2026-09-24） */
.stories-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 12px;
    max-width: 760px;
    margin: 0 auto 8px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(10, 36, 54, .92);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}

/* 青い背景の上なので、見出しは白。他の画面（クエスト・バケツ）と同じ扱い */
.stories-title {
    font-size: clamp(20px, 3.4vw, 26px);
    font-weight: 700;
    color: #fff;
    margin: 0;
    text-shadow: 0 2px 6px rgba(0, 20, 35, .45);
}

.stories-lead {
    flex: 1 1 260px;
    margin: 0;
    color: #cfe6f2;
    font-size: clamp(12px, 2vw, 14px);
    text-shadow: 0 1px 4px rgba(0, 20, 35, .45);
}

.stories-note {
    max-width: 760px;
    margin: 0 auto 12px;
    color: #5a4500;
    font-size: 12px;
    font-weight: 700;
    background: #fff5d6;
    border: 1px solid #f0d98a;
    border-radius: 10px;
    padding: 7px 12px;
}

.stories-list {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ------------------------------------------------------------ 見出し（開閉） */

/* 見出しは不透明な紺。以前は半透明の白で、背景の絵が透けて文字が読みにくかった */
.story-group {
    background: rgba(10, 36, 54, .94);
    border: 1px solid #1b4d6b;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .22);
}

/* 入れ子の見出しは、紺の中で少し明るく */
.story-group .story-group {
    background: #133d57;
    border-color: #245e80;
    border-radius: 12px;
    box-shadow: none;
}

.story-group-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    color: #fff;
    text-align: left;
}

.story-group-head:hover {
    background: rgba(255, 255, 255, .06);
}

.story-group-mark {
    flex: 0 0 auto;
    font-size: 14px;
    color: #ffd84d;
    width: 1em;
}

.story-group-label {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.story-group-title {
    font-weight: 700;
    font-size: clamp(15px, 2.6vw, 19px);
    text-shadow: 0 1px 4px rgba(0, 20, 35, .45);
}

.story-group .story-group .story-group-title {
    font-size: clamp(14px, 2.3vw, 17px);
}

.story-group-summary {
    font-size: clamp(11px, 1.9vw, 13px);
    color: #b9d7e6;
}

.story-group-count {
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 700;
    color: #3b2600;
    background: #ffd84d;
    border-radius: 999px;
    padding: 2px 10px;
    font-variant-numeric: tabular-nums;
}

/* 閉じているあいだは中身を出さない */
.story-group-body {
    display: none;
    padding: 0 10px 10px;
    flex-direction: column;
    gap: 8px;
}

.story-group.is-open > .story-group-body {
    display: flex;
}

.story-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-radius: 14px;
    border: 2px solid transparent;
    box-shadow: 0 4px 14px rgba(0, 20, 35, .28);
    padding: 12px 14px;
    color: inherit;
    text-decoration: none;
    transition: transform .12s ease, box-shadow .12s ease;
}

a.story-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(10, 50, 75, .22);
    text-decoration: none;
    color: inherit;
}

/* 準備中・未開放は、青い背景に沈ませる */
.story-card.is-locked {
    background: rgba(255, 255, 255, .58);
    box-shadow: none;
}

.story-card.is-done {
    border-color: #2ea44f;
}

.story-card-no {
    flex: 0 0 auto;
    display: flex;
    align-items: baseline;
    gap: 1px;
    color: #0d5a7d;
    background: #e8f6ff;
    border-radius: 10px;
    padding: 6px 10px;
    min-width: 62px;
    justify-content: center;
}

.story-card.is-locked .story-card-no {
    background: #e7ecef;
    color: #7d8f9a;
}

.story-card-no-label {
    font-size: 11px;
}

.story-card-no-num {
    font-size: clamp(20px, 3.6vw, 26px);
    font-weight: 700;
    line-height: 1;
}

.story-card-body {
    flex: 1 1 auto;
    min-width: 0;
}

.story-card-title {
    font-weight: 700;
    color: #0d3c55;
    font-size: clamp(15px, 2.6vw, 18px);
    line-height: 1.4;
}

.story-card-summary {
    color: #4a7089;
    font-size: clamp(12px, 2vw, 14px);
    line-height: 1.5;
    margin-top: 2px;
}

.story-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}

.story-tag {
    font-size: 11px;
    border-radius: 999px;
    padding: 1px 9px;
    line-height: 1.7;
}

.story-tag--goal {
    background: #0d5a7d;
    color: #fff;
}

.story-tag--planned {
    background: #e7ecef;
    color: #6b7d88;
}

.story-tag--locked {
    background: #fff3d6;
    color: #8a6a1f;
}

.story-tag--done {
    background: #d8f5df;
    color: #216e39;
    font-weight: 700;
}

.story-card-go {
    flex: 0 0 auto;
    color: #7fd3ff;
    font-size: 20px;
}

/* ------------------------------------------------------------ 一覧へ戻るときの確認 */

.story-confirm {
    position: fixed;
    inset: 0;
    background: rgba(4, 22, 33, .6);
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.story-confirm.hidden {
    display: none;
}

.story-confirm-inner {
    background: #fff;
    border-radius: 14px;
    padding: 20px 22px 16px;
    width: min(360px, 100%);
    box-shadow: 0 8px 24px rgba(0, 20, 35, .35);
}

.story-confirm-text {
    color: #12384d;
    font-size: clamp(14px, 2.3vw, 16px);
    line-height: 1.6;
    text-align: center;
    margin-bottom: 14px;
}

.story-confirm-btns {
    display: flex;
    gap: 8px;
}

.story-confirm-btn {
    flex: 1 1 0;
    text-align: center;
    font-weight: 700;
    background: #fff;
    color: #12384d;
    border: 2px solid #7fd3ff;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: clamp(13px, 2.1vw, 16px);
}

.story-confirm-btn:hover {
    background: #e8f6ff;
}

.story-confirm-btn.is-yes {
    background: #7fd3ff;
    border-color: #7fd3ff;
    color: #06293a;
}

/* ------------------------------------------------------------ 写真カード（2026-09-24）
   クエストの一覧と同じ「写真に斜めの帯」。表紙は episodes.json の cover（stories.js が --photo に入れる）。
   題名とあらすじは帯の上に最初から見せる。読んだ話も何度でも開ける（ボタンは「もう一度」） */
.story-group[data-arc] { --band: #0d5a7d; } /* 帯は不透明（半透明だと、下の写真の端が透けて段がついて見えた） */
.story-group[data-arc="intro"] { --band: #1a8ca0; }
.story-group[data-arc="tree"] { --band: #2e8c50; }
.story-group[data-arc="zukan"] { --band: #c9735a; }

.story-card.has-photo {
    position: relative;
    overflow: hidden;
    min-height: 118px;
    border: 0;
    border-radius: 6px;
    color: #fff;
    background: #1d1f1f;
    box-shadow: 0 4px 14px rgba(0, 20, 35, .35);
}
/* 写真はカードの右側だけに敷く（全面に敷くと、写っている生き物が左の帯の下に隠れた） */
.story-card.has-photo::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 40%;
    /* 写真は白い透かしを重ねて控えめに（写真そのままだと一覧がうるさかった。2026-09-25） */
    background: linear-gradient(rgba(255, 255, 255, .3), rgba(255, 255, 255, .3)), var(--photo) center / cover no-repeat; /* .55 は白すぎた */
    filter: saturate(.8);
    z-index: 0;
}
.story-card.has-photo::before {
    z-index: 1;
    content: "";
    position: absolute;
    inset: 0;
    background: var(--band, rgba(13, 90, 125, .86));
    clip-path: polygon(0 0, 52% 0, 70% 100%, 0 100%);
}
.story-card.has-photo > * { position: relative; z-index: 2; }
a.story-card.has-photo:hover { color: #fff; }
.story-card.has-photo .story-card-no {
    align-self: flex-start;
    min-width: 0;
    padding: 2px 8px;
    border: 1px solid rgba(255, 255, 255, .85);
    border-radius: 6px;
    background: transparent;
    color: #fff;
}
.story-card.has-photo .story-card-no-num { font-size: 18px; }
.story-card.has-photo .story-card-body { max-width: 56%; }
.story-card.has-photo .story-card-title { color: #fff; font-size: clamp(16px, 2.8vw, 20px); text-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.story-card.has-photo .story-card-summary { color: rgba(255, 255, 255, .95); text-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.story-card.has-photo .story-tag--goal { background: rgba(0, 0, 0, .28); }
.story-card.has-photo .story-tag--done { background: #ffd84d; color: #3b2600; }
.story-card.has-photo.is-done { border: 0; }
.story-card.has-photo.is-locked { filter: grayscale(.7); opacity: .7; }
/* 右の「読む／もう一度」は、写真の上に白い丸 */
.story-card.has-photo .story-card-go {
    margin-left: auto;
    align-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .92);
    color: #0d3c55;
    box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
}
.story-card-go-arrow { font-size: 16px; line-height: 1; color: #e0463a; }
.story-card-go-text { font-size: 11px; font-weight: 800; white-space: nowrap; }
@media (max-width: 480px) {
    .story-card.has-photo { flex-wrap: wrap; align-items: flex-start; }
    .story-card.has-photo .story-card-body { max-width: 66%; }
    .story-card.has-photo::before { clip-path: polygon(0 0, 62% 0, 80% 100%, 0 100%); }
    .story-card.has-photo::after { left: 45%; }
    .story-card.has-photo .story-card-go { position: absolute; right: 10px; bottom: 10px; }
}

/* 先生だけに出る「監修済み」の付け外し（js/stories.js。2026-09-27） */
.story-review { display: inline-block; margin-top: 8px; padding: 5px 12px; border-radius: 999px; border: 2px dashed #f28c1e; background: #fff8ee;
  color: #c0660a; font-size: 12.5px; font-weight: 800; cursor: pointer; }
.story-review.is-on { border-style: solid; border-color: #2f8a4f; background: #eaf7ee; color: #2f8a4f; }
.story-review:disabled { opacity: .5; }

/* ------------------------------------------------------------ 図解：模式図（ホヤ徹底編。2026-09-29） */
.visual-figure-img {
    cursor: zoom-in;
    border-width: 3px;
    min-width: min(80%, 320px);
}
.story-figzoom {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(8, 24, 36, .88);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    cursor: zoom-out;
}
.story-figzoom img {
    max-width: 100%;
    max-height: 100%;
    background: #fff;
    border-radius: 8px;
    object-fit: contain;
}

/* 2026-10-05 UI の 洗い出し: スマホ（縦持ち）で 図解の 無い 場面は、話す 人を 大きく 立たせる（以前は 右下の 小さな 丸だけで、上半分が 空いていた）。
   図解が 出ると もとの 丸に もどる。.no-visual は story.js の renderVisual が 付ける */
@media (max-aspect-ratio: 1/1) {
    .story-root.no-visual[data-fig] .story-figure.is-active:not(.is-empty) {
        right: 50%; bottom: 0; width: 78%; height: 88%; padding-bottom: 0; transform: translateX(50%);
        border: 0; border-radius: 0; box-shadow: none; background-color: transparent;
        background-size: contain; background-position: center bottom; background-repeat: no-repeat;
    }
    .story-root.no-visual[data-fig] .story-figure:not(.is-active) { opacity: 0; }
}
/* 上の ボタン（一覧へ戻る・オート・ログ・EN）を 押しやすく（高さ 25px → 34px） */
.story-topbar-right .story-iconbtn, .story-topbar-right button { min-height: 34px; padding-top: 4px; padding-bottom: 4px; }
