@font-face {
    font-family: 'Kuramubon';
    src: url('assets/fonts/kuramubon/Kuramubon.otf') format('opentype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

:root {
    /* 推しゴはPC登録済みの書体を利用。未収録文字・未導入PCはくらむぼんで補完。 */
    --game-font: 'Oshigo', '推しゴ', 'Kuramubon', 'Yu Gothic', 'Meiryo', sans-serif;
    --bg-color: #ffd1dc;
    --ui-text: #333333;
    --accent: #a855f7;
}

/* 画面全体の余白をリセットし、高さを確保 */
body,
html {
    margin: 0 !important;
    padding: 0 !important;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    font-family: var(--game-font);
    color: var(--ui-text);
    overflow: hidden;
    /* スクロールバーを出さない */
}

/* フォーム部品もゲームの基本書体を引き継ぐ */
button,
input,
select,
textarea {
    font-family: inherit;
}

/* 全要素にbox-sizingを適用してパディングによるはみ出しを防止 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* メインレイアウトコンテナ：余白を最小限に */
#main-layout {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    /* 垂直方向中央揃え */
    width: 100%;
    height: 100vh;
    /* 画面いっぱいに */
    overflow: hidden;
    /* スクロール防止 */
    padding: 10px;
    box-sizing: border-box;
    gap: 15px;
}

#ingame-wallpaper-video {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

/* The title and information pages are full-screen scenes, not game-board overlays. */
#menu-container {
    position: fixed;
    inset: 0;
    z-index: 1000;
    overflow: hidden;
    background: #100a2d url('images/bg.png') center / cover no-repeat;
}

#menu-container .game-screen {
    background: linear-gradient(135deg, rgba(14, 10, 39, .88), rgba(43, 21, 82, .72));
}

#title-screen .title-logo-heading {
    width: min(100%, 988px);
    margin: 0;
    line-height: 0;
}

#title-screen .title-logo-heading img {
    display: block;
    width: 100%;
    max-height: 39vh;
    object-fit: contain;
    transform: rotate(-2deg);
    transform-origin: center;
}

#title-bgm-toggle {
    min-width: 150px;
}

/* 中央ゲームコンテナ：可能な限り広げる */
#game-container {
    /* 画面の高さの95%を使う（上下の余白をほぼ無くす） */
    height: 95vh !important;

    /* 縦横比をスマホ画面（9:16）に維持 */
    aspect-ratio: 705 / 960 !important;

    /* 幅は高さに合わせて自動調整 */
    width: auto !important;
    max-width: 100%;

    /* 配置調整 */
    margin: 0 auto;
    /* 中央寄せ */
    position: relative;
    /* もし親要素にpaddingがある場合は無視して広げる工夫 */
    box-sizing: border-box;

    flex-grow: 0;
    display: flex;
    justify-content: center;
    align-items: center;

    /* Background Restoration */
    background-image: url('images/bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border: 3px solid #b58bd5;
    border-radius: 12px;
    overflow: hidden;
}

#puzzle-background-video,
.puzzle-background-buffer {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    pointer-events: none;
}

canvas#world {
    position: relative;
    z-index: 2;
    /* キャンバスも親に合わせて広げる */
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    /* アスペクト比を維持して収める */
    background-color: transparent !important;
    display: block;
    touch-action: none;
}

/* 左右カラムの幅固定（崩れないように） */
#left-column,
#right-panel {
    flex-basis: 280px;
    /* 幅を固定 */
    flex-shrink: 0;
    /* 縮まないようにする */
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    /* コンテンツが多い場合はスクロール */
    overflow-x: hidden;
    /* 横スクロールは禁止 */
    scrollbar-width: none;
    /* Firefox: スクロールバーを隠す */
    -ms-overflow-style: none;
    /* IE/Edge: スクロールバーを隠す */
}

#right-panel { flex-basis: 528px; }
#right-panel img#evolution-guide { max-width: 420px; align-self: center; }

/* Chrome/Safari: スクロールバーを隠す */
#left-column::-webkit-scrollbar,
#right-panel::-webkit-scrollbar {
    display: none;
}

/* --- Left Column Specifics --- */
#timer-section {
    background: rgba(255, 255, 255, 0.8);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.panel-label {
    color: var(--accent);
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0 0 10px 0;
}

#timer-display {
    background: #ffffff;
    color: #374151;
    font-size: 2.5rem;
    font-weight: 800;
    padding: 15px 0;
    border-radius: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    letter-spacing: 2px;
    margin-bottom: 15px;
    width: 100%;
    font-family: var(--game-font);
}

#timer-display.has-time-limit::before {
    content: 'あと';
    display: inline-block;
    margin-right: 12px;
    font-size: 0.65em;
    letter-spacing: 0;
    vertical-align: baseline;
}

#timer-display.countdown-active {
    color: #c02968;
    background: #fff0f6;
    box-shadow: 0 0 22px rgba(255, 115, 174, .55);
}

.mode-switch {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    position: relative;
    z-index: 200;
    /* High z-index to ensure clickability */
}

.mode-label {
    color: var(--accent);
    font-weight: bold;
    font-size: 1rem;
}

#ranking-board {
    background: rgba(255, 255, 255, 0.8);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    flex-grow: 1;
    /* Extend to fill space */
}

#ranking-board h3 {
    margin-top: 0;
    border-bottom: 2px solid #ddd;
    padding-bottom: 10px;
    text-align: center;
    color: #4A3B32;
}

#ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#ranking-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;

    font-size: 1.3rem !important;
    /* 文字を大きく */
    font-weight: 800 !important;
    /* 極太に */
    color: #4b5563;
    /* 視認性の高い濃いグレー */
    margin-bottom: 8px;
    /* 行間を少し空ける */
    border-bottom: 2px dashed #e5e7eb;
    /* 下線を入れて見やすく */
}

/* 順位と上位3位の金・銀・銅メダル */
#ranking-list li .rank-number {
    display: inline-grid;
    grid-template-columns: 42px auto;
    align-items: center;
    gap: 8px;
    color: #a855f7;
    margin-right: 10px;
}

#ranking-list li {
    align-items: center;
    padding-left: 8px;
    padding-right: 8px;
}

#ranking-list .rank-medal {
    font-family: 'Segoe UI Emoji', 'Apple Color Emoji', sans-serif;
    font-size: 36px;
    line-height: 1;
    text-align: center;
    filter: drop-shadow(0 2px 2px rgba(99, 65, 18, .22));
}

#ranking-list .rank-podium {
    border-radius: 10px;
    background: linear-gradient(100deg, var(--rank-tint), transparent 85%);
}

#ranking-list .rank-podium-1 { --rank-tint: #ffe9a6; }
#ranking-list .rank-podium-2 { --rank-tint: #e3e9f5; }
#ranking-list .rank-podium-3 { --rank-tint: #f5d5ba; }
#ranking-list .rank-podium-1 .rank-number { color: #8d5c00; }
#ranking-list .rank-podium-2 .rank-number { color: #596b88; }
#ranking-list .rank-podium-3 .rank-number { color: #985324; }

/* --- Right Panel Specifics --- */
#right-panel>div,
#right-panel>img {
    /* Ensure content fills panel */
    width: 100%;
}

#next-display {
    grid-area: bubble;
    position: relative;
    z-index: 1;
    pointer-events: none;
    isolation: isolate;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    justify-self: center;
    margin-bottom: 24px;
    width: 184px;
    height: 152px;
    padding: 12px;
    border: 2px solid #c997ec;
    border-radius: 48% 52% 50% 47%;
    background: linear-gradient(155deg, #fffafd, #f4e9ff);
    box-shadow: inset 0 2px 0 #fff, 0 6px 18px rgba(93, 52, 135, .18);
    transform-origin: 42% 58%;
    animation: thought-bubble-squish 4.8s ease-in-out infinite;
}

@keyframes thought-bubble-squish {
    0%, 100% {
        border-radius: 48% 52% 50% 47%;
        transform: translateY(0) scale(1, 1);
    }
    25% {
        border-radius: 51% 47% 53% 49%;
        transform: translateY(-1px) scale(1.015, .99);
    }
    50% {
        border-radius: 47% 53% 48% 52%;
        transform: translateY(1px) scale(.99, 1.012);
    }
    75% {
        border-radius: 52% 49% 51% 46%;
        transform: translateY(-1px) scale(1.008, .996);
    }
}

@media (prefers-reduced-motion: reduce) {
    #next-display { animation: none; }
}

#next-display::before,
#next-display::after {
    content: '';
    position: absolute;
    z-index: -1;
    display: block;
    border: 2px solid #c997ec;
    border-radius: 50%;
    background: #f6edff;
}

#next-display::before { width: 22px; height: 22px; left: calc(50% - 11px); bottom: -18px; }
#next-display::after { width: 11px; height: 11px; left: calc(50% - 4px); bottom: -34px; }

/* オーディオパネル全体 */
#audio-controls {
    width: 100%;
    padding: 15px;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

#next-planet-holder .planet-preview {
    width: 72px;
    height: 72px;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}

#next-planet-holder .meteorite-preview {
    width: 43px;
    height: 43px;
}

#audio-controls .control-group {
    width: 100%;
    margin-bottom: 10px;
}

#audio-controls .control-group:last-child {
    margin-bottom: 0;
}

/* 各行のレイアウト（スライダーとMuteを横並び） */
.slider-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* 両端に配置 */
    width: 100%;
    gap: 10px;
    /* スライダーと文字の間隔 */
}

/* スライダーバーのスタイル */
#audio-controls input[type="range"] {
    flex-grow: 1;
    /* 余ったスペース一杯に伸ばす */
    width: auto !important;
    /* 固定幅を解除 */
    max-width: none;
    margin: 0;
    cursor: pointer;
}

/* Muteラベルとチェックボックス */
.mute-label {
    flex-shrink: 0;
    /* 縮まないようにする（重要） */
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
    white-space: nowrap;
    /* 勝手に改行させない */
}

img#evolution-guide {
    height: auto;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.5);
    margin-top: 20px;
    width: 100% !important;
    max-width: 100%;
    cursor: zoom-in;
    transition: transform 0.2s;
}

img#evolution-guide:hover {
    transform: scale(1.02);
}

/* Chart Modal */
#chart-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: min(1100px, 94vw);
    height: auto;
    max-height: 94vh;
    margin: auto;
    padding: 8px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
#chart-modal:not([open]) { display: none; }
#chart-modal::backdrop { background: rgba(16, 10, 45, .8); }

#chart-modal .modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 16px;
}

#chart-modal img {
    width: 100%;
    max-width: 100%;
    max-height: calc(94vh - 130px);
    object-fit: contain;
    border-radius: 12px;
    box-shadow: none;
}

#chart-modal p {
    color: white;
    margin-top: 10px;
    font-size: 18px;
    font-weight: bold;
}

#chart-close-btn {
    font-size: 45px;
    line-height: 1.3;
    padding: 12px 36px;
    margin: 0;
    min-width: 230px;
    max-width: 100%;
    flex-shrink: 0;
}

/* --- UI Layers --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

#countdown-overlay {
    position: absolute;
    top: 38%;
    left: 50%;
    width: clamp(90px, 28%, 180px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    transform: translate(-50%, -50%);
    border: 3px solid #ffe1f2;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 25%, #f9d8ff, #c45399 75%);
    color: #fff;
    font-size: clamp(3rem, 13vw, 7rem);
    font-weight: 900;
    line-height: 1;
    text-align: center;
    font-variant-numeric: tabular-nums;
    /* 行の中心より数字の見える部分が下がるため、字の大きさに比例して補正する。 */
    padding-bottom: .12em;
    text-shadow: 0 3px 12px #753c80;
    box-shadow: 0 0 0 7px rgba(255, 207, 238, .22), 0 10px 36px rgba(95, 28, 96, .55);
    z-index: 150;
}

#countdown-overlay.countdown-pop { animation: countdown-pop .55s ease-out; }
@keyframes countdown-pop {
    from { transform: translate(-50%, -50%) scale(1.22); opacity: .55; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    #countdown-overlay.countdown-pop { animation: none; }
}

#score-board {
    background: rgba(255, 255, 255, 0.8);
    padding: 20px;
    border-radius: 12px;
    font-size: 24px;
    font-weight: bold;
    color: #4A3B32;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
    margin-bottom: 20px;
}

#score-board .score-heading {
    display: block;
    font-size: 0.85em;
    line-height: 1.2;
}

#score-board #current-score {
    display: block;
    margin-top: 4px;
    font-size: 1.1em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

#score-board small {
    display: block;
    margin-top: 6px;
    font-size: 0.65em;
    color: #64546d;
}

#game-actions {
    position: fixed;
    right: calc(10px + env(safe-area-inset-right, 0px));
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    width: 420px;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#game-actions button {
    margin: 0;
    white-space: nowrap;
}

button:disabled {
    opacity: 0.48;
    cursor: not-allowed;
    transform: none;
}

.game-screen {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 28px;
    overflow-y: auto;
    text-align: center;
    color: #fff;
    background: rgba(17, 13, 42, 0.88);
    pointer-events: auto;
}

.game-screen h1 {
    margin: 0;
    font-size: clamp(2.5rem, 7vw, 4.5rem);
    line-height: 1.15;
    color: #fff0af;
    text-shadow: 0 4px 22px #271a65;
}

.game-screen h2 {
    margin: 0 0 8px;
    font-size: clamp(2rem, 5vw, 3rem);
}

.game-screen p {
    max-width: 540px;
    margin: 0;
    line-height: 1.6;
}

.game-screen .eyebrow {
    color: #ffb8e1;
    font-weight: bold;
    letter-spacing: 0.12em;
}

.game-screen ol {
    max-width: 540px;
    padding-left: 1.5em;
    text-align: left;
    line-height: 1.8;
}

.game-screen .key-hint {
    font-size: 0.9rem;
    opacity: 0.85;
}

.game-screen a { color: #a8dcff; }
#help-screen {
    justify-content: safe center;
    gap: 24px;
}
#help-screen > * { flex-shrink: 0; }
#help-screen p,
#help-screen ol {
    max-width: 960px;
    font-size: 2rem;
    line-height: 1.7;
}
#help-screen ol {
    font-size: 3rem;
    margin: 0;
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
}
#help-screen .help-line { display: block; }
#help-screen .help-phrase { display: inline-block; }
#help-screen .key-hint {
    font-size: 2.7rem;
    opacity: 1;
}
#help-back-btn {
    font-size: 1.75rem;
    padding: 12px 30px;
    max-width: 100%;
}
.menu-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.menu-row button { min-width: 140px; margin: 2px; font-size: 1rem; }
.ranking-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(100%, 600px); text-align: left; }
.ranking-columns > div { background: rgba(255,255,255,.12); padding: 10px 14px; border-radius: 12px; }
.ranking-columns h3 { margin: 0 0 8px; color: #fff0af; }
.ranking-columns ol { margin: 0; padding-left: 1.5em; line-height: 1.7; }
.mode-options { display: grid; width: min(100%, 360px); gap: 6px; }
.mode-options button { margin: 0; width: 100%; font-size: 1rem; }
#result-story { max-width: 510px; padding: 0 20px; font-size: 1.1rem !important; }
#game-over-screen.clear h1 { color: #fff0af; text-shadow: 0 0 22px #f6bdf0; }
#settings-screen #audio-controls { max-width: 420px; color: #302842; text-align: left; }
#settings-screen .control-group + .control-group { margin-top: 18px; }
#settings-screen .slider-row { display: flex; align-items: center; gap: 12px; }
#settings-screen .slider-row input[type="range"] { flex: 1; min-width: 0; }
.character-panel { display: flex; align-items: center; gap: 8px; min-height: 112px; padding: 8px; border-radius: 14px; background: rgba(255,255,255,.86); box-shadow: 0 4px 8px rgba(0,0,0,.12); }
.character-panel img { width: 92px; height: 92px; object-fit: contain; flex: none; }
.character-panel p { min-width: 0; margin: 0; font-size: .85rem; line-height: 1.35; }
.character-panel strong { display: block; color: #8840b9; margin-bottom: 4px; }
.character-panel span { display: block; }
.character-panel.speaking img { animation: character-pop .38s ease-out; }
@keyframes character-pop { 0% { transform: scale(.88) translateY(5px); } 60% { transform: scale(1.08) translateY(-3px); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .character-panel.speaking img { animation: none; } }

#geneko-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'next-heading' 'bubble' 'portrait' 'caption';
    align-items: center;
    justify-items: center;
    row-gap: 0;
    min-height: 252px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

#geneko-panel .next-heading {
    grid-area: next-heading;
    margin-bottom: 8px;
    color: #ffffff;
    font-size: .94rem;
    font-weight: 800;
    letter-spacing: .16em;
    line-height: 1;
    text-shadow: 0 2px 5px #170c38;
}

#geneko-portrait-frame {
    grid-area: portrait;
    width: 528px;
    max-width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
    align-self: end;
    position: relative;
    overflow: visible;
}

#geneko-portrait-frame img,
#geneko-portrait-frame video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
}

#geneko-panel:not(.awake):not(.sleep-video-playing) #geneko-portrait,
#geneko-panel:not(.awake):not(.worried-video-playing) #geneko-worried-portrait {
    animation: geneko-still-float 4.6s ease-in-out infinite;
}

@keyframes geneko-still-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

#geneko-worried-portrait {
    display: none;
}

#geneko-sleep-video {
    display: none;
    pointer-events: none;
}

/* Generated frames have slightly wider visible bounds than the still PNG. */
#geneko-sleep-video,
#geneko-worried-video {
    transform: scale(.976);
    transform-origin: center;
}

#geneko-panel:not(.awake).sleep-video-playing[data-dream-tension="0"] #geneko-portrait { display: none; }
#geneko-panel:not(.awake).sleep-video-playing[data-dream-tension="0"] #geneko-sleep-video { display: block; }

#geneko-worried-video {
    display: none;
    pointer-events: none;
}

#geneko-panel:not(.awake)[data-dream-tension="1"] #geneko-portrait,
#geneko-panel:not(.awake)[data-dream-tension="2"] #geneko-portrait,
#geneko-panel:not(.awake)[data-dream-tension="3"] #geneko-portrait { display: none; }
#geneko-panel:not(.awake)[data-dream-tension="1"] #geneko-worried-portrait,
#geneko-panel:not(.awake)[data-dream-tension="2"] #geneko-worried-portrait,
#geneko-panel:not(.awake)[data-dream-tension="3"] #geneko-worried-portrait { display: block; }
#geneko-panel:not(.awake).worried-video-playing[data-dream-tension="2"] #geneko-worried-portrait,
#geneko-panel:not(.awake).worried-video-playing[data-dream-tension="3"] #geneko-worried-portrait { display: none; }
#geneko-panel:not(.awake).worried-video-playing #geneko-worried-video { display: block; }
#geneko-panel.awake #geneko-portrait {
    display: block;
    width: 100%;
    height: 100%;
    bottom: 0;
    object-fit: contain;
}
#geneko-panel.awake #geneko-worried-portrait,
#geneko-panel.awake #geneko-worried-video,
#geneko-panel.awake #geneko-sleep-video { display: none; }
#geneko-panel.speaking #geneko-portrait-frame { animation: character-pop .38s ease-out; }
#geneko-panel.speaking #geneko-portrait-frame img { animation: none; }

@media (prefers-reduced-motion: reduce) {
    #geneko-panel:not(.awake):not(.sleep-video-playing) #geneko-portrait,
    #geneko-panel:not(.awake):not(.worried-video-playing) #geneko-worried-portrait { animation: none; }
    #geneko-panel:not(.awake).worried-video-playing #geneko-worried-video { display: none; }
    #geneko-panel:not(.awake).worried-video-playing[data-dream-tension="2"] #geneko-worried-portrait,
    #geneko-panel:not(.awake).worried-video-playing[data-dream-tension="3"] #geneko-worried-portrait { display: block; }
    #geneko-panel:not(.awake).sleep-video-playing[data-dream-tension="0"] #geneko-sleep-video { display: none; }
    #geneko-panel:not(.awake).sleep-video-playing[data-dream-tension="0"] #geneko-portrait { display: block; }
    #geneko-panel.speaking #geneko-portrait-frame { animation: none; }
}

#geneko-panel p { grid-area: caption; align-self: start; text-align: center; }
#geneko-panel p { color: #fff3fc; text-shadow: 0 2px 5px #170c38; }
#geneko-panel strong { color: #f2cfff; }

.game-screen button,
#game-over-screen button {
    min-width: 190px;
}

button.secondary-btn {
    background: #50466f;
}

button.secondary-btn:hover {
    background: #695b92;
}

#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 200;
}

.hidden {
    display: none !important;
}

/* Buttons */
button {
    padding: 12px 24px;
    margin: 10px;
    font-size: 18px;
    cursor: pointer;
    border: none;
    border-radius: 50px;
    background: #4488ff;
    color: white;
    transition: transform 0.1s, background 0.2s;
}

button:hover {
    transform: scale(1.05);
    background: #5599ff;
}

#game-over-screen h1 {
    color: #ff4444;
    font-size: 48px;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

#game-over-screen p {
    color: white;
    font-size: 24px;
    text-align: center;
    line-height: 1.5;
}

#game-over-screen strong {
    color: #fff0af;
}

@media (max-width: 1320px) {
    #game-actions {
        right: 0;
        width: 100%;
    }

    html, body {
        height: auto;
        min-height: 100%;
        overflow: auto;
    }

    #main-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "score timer"
            "geneko geneko"
            "game game"
            "guide guide"
            "ranking ranking";
        align-items: stretch;
        height: auto;
        min-height: 100vh;
        max-width: 735px;
        margin: 0 auto;
        gap: 8px;
        padding: 8px;
        overflow: visible;
    }

    #left-column {
        display: contents;
    }

    #score-board { grid-area: score; margin: 0; }
    #timer-section { grid-area: timer; }
    #ranking-board { grid-area: ranking; }
    #right-panel { display: contents; }
    #geneko-panel { grid-area: geneko; }
    #evolution-guide { grid-area: guide; }

    #game-container {
        grid-area: game;
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 705 / 960 !important;
        max-width: 705px;
    }

    #score-board,
    #timer-section,
    #ranking-board { padding: 12px; }

    #timer-display {
        font-size: clamp(1.15rem, 5vw, 2rem);
        padding: 8px 0;
    }

    #right-panel img#evolution-guide {
        width: min(100%, 420px) !important;
        justify-self: center;
        margin-top: 0;
    }
}

@media (min-width: 1181px) {
    #right-panel { align-self: stretch; }
    #geneko-panel { margin-top: clamp(48px, 8vh, 96px); }
    #game-container {
        width: min(69.77vh, calc(100vw - 750px)) !important;
        height: auto !important;
    }
}

@media (max-width: 700px) {
    #main-layout {
        grid-template-areas:
            "score timer"
            "geneko geneko"
            "game game"
            "guide guide"
            "ranking ranking";
    }
}

@media (max-width: 520px) {
    #main-layout { gap: 6px; padding: 5px; }
    #game-actions {
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
    }
    #game-actions button { padding: 10px 12px; font-size: .85rem; }
    #score-board { font-size: 18px; }
    .panel-label { font-size: 0.9rem; }
    .mode-label { font-size: 0.8rem; }
    #timer-section { padding: 7px; }
    #timer-display { margin-bottom: 5px; }
    .game-screen { padding: 14px; gap: 8px; justify-content: flex-start; }
    .game-screen ol { margin: 0; font-size: 0.87rem; }
    .game-screen p { font-size: 0.88rem; }
    #game-over-screen h1 { font-size: 2rem; }
    #game-over-screen p { font-size: 1rem; }
    .character-panel { min-height: 74px; gap: 2px; padding: 4px; }
    .character-panel img { width: 58px; height: 58px; }
    .character-panel p { font-size: .7rem; }
    #geneko-panel {
        min-height: 0;
        padding: 0;
    }
    #geneko-portrait-frame { width: 528px; max-width: 100%; height: auto; }
    #geneko-panel.awake #geneko-portrait { width: 100%; height: 100%; }
    #next-display { width: 138px; height: 124px; padding: 12px; }
    #next-display::before { width: 14px; height: 14px; left: calc(50% - 7px); bottom: -13px; }
    #next-display::after { width: 8px; height: 8px; left: calc(50% - 3px); bottom: -25px; }
    #geneko-panel .next-heading { font-size: .8rem; }
    #next-planet-holder .planet-preview { width: 58px; height: 58px; }
    #next-planet-holder .meteorite-preview { width: 35px; height: 35px; }
    .menu-row button { min-width: 0; padding: 8px 10px; font-size: .85rem; }
    .ranking-columns { grid-template-columns: 1fr; gap: 6px; font-size: .78rem; }
    .ranking-columns > div { padding: 6px; }
}

/* Title scene: a soft, star-lit menu distinct from the game controls. */
#menu-container #title-screen {
    justify-content: safe center;
    gap: clamp(8px, 1.5vh, 17px);
    padding: clamp(18px, 3vh, 36px) 18px;
    padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
    background: transparent;
    scrollbar-width: thin;
    scrollbar-color: #b9a0da transparent;
}

#title-background-video {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

#menu-container #title-screen::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 1;
    background: linear-gradient(180deg, rgba(22, 12, 56, .35), rgba(23, 12, 58, .62));
    pointer-events: none;
}

#menu-container #title-screen > :not(video):not(#title-planet-field) {
    position: relative;
    z-index: 3;
}

#title-planet-field {
    position: fixed;
    inset: 0;
    z-index: 2;
    overflow: hidden;
    perspective: 1100px;
    pointer-events: none;
}

.title-drifting-planet {
    position: absolute;
    left: var(--planet-x);
    top: var(--planet-y);
    width: var(--planet-size);
    translate: -50% -50%;
    opacity: var(--planet-opacity);
    filter: blur(var(--planet-blur));
    animation: title-planet-drift var(--drift-duration) ease-in-out infinite;
    animation-delay: var(--drift-delay);
}

.title-drifting-planet img {
    display: block;
    width: 100%;
    height: auto;
    animation: title-planet-spin var(--spin-duration) linear infinite;
    animation-delay: var(--spin-delay);
}

@keyframes title-planet-drift {
    0%, 100% { transform: translate3d(0, 0, var(--depth-start)); }
    33% { transform: translate3d(var(--drift-x1), var(--drift-y1), var(--depth-middle)); }
    66% { transform: translate3d(var(--drift-x2), var(--drift-y2), var(--depth-end)); }
}

@keyframes title-planet-spin {
    from { transform: rotate(var(--spin-start)); }
    to { transform: rotate(calc(var(--spin-start) + var(--spin-turn))); }
}

.title-drifting-planet.title-crossing-planet {
    left: 0;
    animation-name: title-planet-cross;
    animation-timing-function: linear;
}

@keyframes title-planet-cross {
    from { transform: translate3d(var(--cross-start-x), 0, var(--depth-start)); }
    to { transform: translate3d(var(--cross-end-x), 0, var(--depth-start)); }
}

.title-crossing-comet img {
    animation: none;
    transform: rotate(var(--spin-start));
}

#title-planet-field[data-paused="true"] .title-drifting-planet,
#title-planet-field[data-paused="true"] img {
    animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
    .title-drifting-planet,
    .title-drifting-planet img { animation: none; }
    .title-drifting-planet.title-crossing-planet {
        animation: none;
        left: var(--planet-x);
        transform: translateZ(var(--depth-start));
    }
    .title-drifting-planet { transform: translateZ(var(--depth-start)); }
    .title-drifting-planet img { transform: rotate(var(--spin-start)); }
}

#title-screen .eyebrow {
    color: #ffe1f3;
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: .3em;
    text-shadow: 0 0 16px rgba(255, 172, 228, .75);
}

#title-screen .title-logo-heading {
    flex: 0 0 auto;
    filter: drop-shadow(0 12px 32px rgba(21, 9, 58, .48));
    animation: title-logo-float 4.8s ease-in-out infinite;
}

@keyframes title-logo-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

#title-screen .title-story {
    max-width: 1000px;
    color: #f8eafb;
    font-size: clamp(1.54rem, 2.7125vw, 1.82rem);
    letter-spacing: .045em;
    text-shadow: 0 2px 10px rgba(18, 7, 50, .85);
}

#title-screen .mode-options {
    width: min(100%, 560px);
    gap: 10px;
    margin-top: 4px;
}

#title-screen button {
    position: relative;
    min-width: 0;
    margin: 0;
    color: #fff7ff;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: .06em;
    border: 1px solid rgba(255, 228, 250, .37);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .17), 0 8px 24px rgba(11, 6, 37, .24);
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

#title-screen button:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 242, 255, .8);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 12px 28px rgba(11, 6, 37, .34);
}

#title-screen button:active { transform: translateY(0); }
#title-screen button:focus-visible { outline: 3px solid #ffe39d; outline-offset: 3px; }

#title-screen .mode-options button {
    min-height: 48px;
    padding: 8px 24px;
    font-size: clamp(1.6rem, 4.2vw, 1.8rem);
    line-height: 1.4;
    white-space: normal;
    overflow-wrap: anywhere;
}

#title-screen #start-btn {
    min-height: 56px;
    color: #392550;
    font-size: 2rem;
    letter-spacing: .16em;
    border-color: rgba(255, 255, 255, .82);
    background: linear-gradient(115deg, #ffe0f2 0%, #ffc6e3 43%, #d7c2ff 100%);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, .75), 0 8px 28px rgba(244, 137, 224, .27);
}

#title-screen #start-btn::before {
    content: '✦';
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    color: #9c65ba;
    font-size: 1.1rem;
}

#title-screen #start-btn:hover {
    background: linear-gradient(115deg, #fff0f8, #ffdbed 43%, #e8d9ff);
    box-shadow: inset 0 2px 0 #fff, 0 12px 34px rgba(244, 137, 224, .42);
}

#title-screen .mode-options .secondary-btn {
    background: linear-gradient(110deg, rgba(93, 63, 143, .79), rgba(73, 51, 121, .82));
    backdrop-filter: blur(10px);
}

#title-screen .mode-options .secondary-btn:hover {
    background: linear-gradient(110deg, rgba(125, 80, 163, .9), rgba(97, 67, 148, .92));
}

#title-screen #help-btn,
#title-screen .menu-row button,
#title-screen #title-bgm-toggle {
    background: rgba(53, 36, 101, .48);
    backdrop-filter: blur(8px);
    border-color: rgba(231, 208, 255, .27);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}

#title-screen #help-btn:hover,
#title-screen .menu-row button:hover,
#title-screen #title-bgm-toggle:hover {
    background: rgba(117, 74, 156, .65);
}

#title-screen #help-btn {
    min-width: 126px;
    padding: 5.6px 12.6px;
    font-size: 1.155rem;
}

#title-screen .menu-row {
    gap: 8px;
    width: min(100%, 1000px);
    flex-wrap: nowrap;
    align-items: center;
    justify-content: safe center;
    overflow-x: auto;
    padding: 6px 4px;
}

#title-screen .menu-row button {
    flex: 0 0 auto;
    white-space: nowrap;
    min-width: 77px;
    padding: 5.6px 9.8px;
    font-size: 1.12rem;
}

#title-screen #title-bgm-toggle {
    min-width: 0;
    padding: 4.9px 11.2px;
    color: #eacff5;
    font-size: .98rem;
    border-radius: 999px;
}

@media (max-width: 520px) {
    #menu-container #title-screen {
        justify-content: flex-start;
        gap: 9px;
        padding: 24px 14px calc(48px + env(safe-area-inset-bottom, 0px));
    }

    #title-screen .title-story { font-size: 1.47rem; }
    #title-screen .mode-options { gap: 8px; }
    #title-screen .mode-options button { min-height: 48px; padding: 8px 16px; }
    #title-screen #start-btn { min-height: 56px; }
    #title-screen .menu-row { width: 100%; gap: 10px; }
    #title-screen .menu-row button { flex: 0 0 auto; min-width: 0; padding: 5.6px 7px; font-size: .98rem; }
}

/* 大きな文字のまま、低い画面でも全メニューへスクロールできる。 */
#menu-container #title-screen > :not(video):not(#title-planet-field) {
    flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
    #title-screen .title-logo-heading { animation: none; }
    #title-screen button { transition: none; }
}
/* NEXTの玉だけを画面上の座標で飛ばす。吹き出しやジェネコは動かさない。 */
.next-planet-transfer {
    position: fixed;
    z-index: 900;
    pointer-events: none;
    object-fit: contain;
    transform-origin: center;
    will-change: transform;
}

/* インゲームは固定の一枚の配置。既存の画面幅別配置より優先する。 */
html, body { height: 100%; overflow: hidden; }
#main-layout.fixed-game-layout {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 1849px;
    height: 1000px;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 20px;
    display: grid;
    grid-template-columns: 528px 705px 528px;
    grid-template-rows: 960px;
    grid-template-areas: 'left game right';
    justify-content: center;
    align-items: center;
    gap: 24px;
    overflow: hidden;
    transform: translate(-50%, -50%) scale(var(--game-layout-scale, 1));
    transform-origin: center;
}
.fixed-game-layout #left-column {
    grid-area: left;
    display: flex;
    width: 528px;
    align-items: center;
    gap: 16px;
    overflow: hidden;
}
.fixed-game-layout #left-column > div { width: 480px; }
.fixed-game-layout #ingame-title-logo { width: 320px; height: 180px; object-fit: contain; flex-shrink: 0; cursor: pointer; }
#ingame-title-logo:focus-visible { outline: 3px solid #a855f7; outline-offset: 4px; border-radius: 12px; }
#leave-confirm h2 { font-size: 38px; }
#leave-confirm p { font-size: 26px; }
#leave-confirm button { font-size: 30px; min-width: 300px; }
.fixed-game-layout #ranking-board { flex-grow: 0; }
.fixed-game-layout #score-board { grid-area: auto; margin: 0; padding: 8px 20px; font-size: 34px; }
.fixed-game-layout #timer-section { grid-area: auto; padding: 20px; }
.fixed-game-layout #ranking-board { grid-area: auto; padding: 20px; }
.fixed-game-layout #timer-display { font-size: 40px; padding: 15px 0; margin-bottom: 15px; }
.fixed-game-layout .panel-label { font-size: 28px; }
.fixed-game-layout #ranking-board h3 { font-size: 28px; line-height: 1.35; }
.fixed-game-layout #ranking-list li { font-size: 28px !important; line-height: 1.4; }
.fixed-game-layout .mode-label { font-size: 14px; }
.fixed-game-layout #puzzle-frame {
    grid-area: game;
    position: relative;
    width: 705px;
    height: 960px;
    isolation: isolate;
}

/* 盤面は変えず、淡い斜めストライプの縁とクローバーで飾る。 */
#puzzle-frame::before,
#puzzle-frame::after {
    content: '';
    position: absolute;
    pointer-events: none;
    z-index: 4;
}
#puzzle-frame::before {
    inset: -14px;
    border: 12px solid transparent;
    border-radius: 24px;
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .85) 0 6px, transparent 6px 17px),
        linear-gradient(135deg, #eadbfa 0%, #fbdcec 32%, #fffafd 55%, #efdffb 78%, #f9ddec 100%);
    -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
}
#puzzle-frame::after {
    inset: -14px;
    border: 2px solid rgba(255, 250, 253, .95);
    border-radius: 24px;
    box-shadow: 0 4px 12px rgba(145, 111, 170, .2);
}
.frame-clover {
    position: absolute;
    top: -14px;
    z-index: 5;
    width: 44px;
    height: 44px;
    filter: drop-shadow(0 2px 3px #b99bc866);
    pointer-events: none;
}
.frame-clover-left { left: -14px; transform: rotate(-15deg); }
.frame-clover-right { right: -14px; transform: rotate(15deg); }
.frame-clover i {
    position: absolute;
    width: 25px;
    height: 25px;
    border: 2px solid #fffafd;
    border-radius: 60% 60% 8% 60%;
    background: linear-gradient(135deg, #fff5fc, #ebcff5 55%, #f3bbdb);
}
.frame-clover i:nth-child(1) { top: 0; left: 0; }
.frame-clover i:nth-child(2) { top: 0; right: 0; transform: rotate(90deg); }
.frame-clover i:nth-child(3) { bottom: 0; right: 0; transform: rotate(180deg); }
.frame-clover i:nth-child(4) { bottom: 0; left: 0; transform: rotate(270deg); }

.fixed-game-layout #game-container {
    grid-area: game;
    width: 705px !important;
    height: 960px !important;
    max-width: none;
    margin: 0;
}
.fixed-game-layout #right-panel {
    grid-area: right;
    display: flex;
    position: relative;
    align-self: stretch;
    align-items: center;
    width: 528px;
    gap: 20px;
    overflow: hidden;
}
.fixed-game-layout #geneko-panel {
    grid-area: auto;
    flex: 0 0 580px;
    height: 580px;
    min-height: 0;
    margin: 0;
    padding: 0;
    grid-template-rows: 64px 152px 310px 54px;
}
.fixed-game-layout #geneko-portrait-frame { width: 528px; height: 330px; }
.fixed-game-layout #geneko-panel p { font-size: 14px; margin: 12px 0 0; }
.fixed-game-layout #geneko-panel .next-heading { font-size: 56px; }
.fixed-game-layout #next-display { width: 184px; height: 152px; padding: 20px; margin-bottom: 0; }
.fixed-game-layout #next-display::before { width: 22px; height: 22px; left: calc(50% - 11px); bottom: -20px; }
.fixed-game-layout #next-display::after { width: 12px; height: 12px; left: calc(50% - 6px); bottom: -39px; }
.fixed-game-layout #next-planet-holder .planet-preview { width: 72px; height: 72px; }
.fixed-game-layout #next-planet-holder .meteorite-preview { width: 43px; height: 43px; }
.fixed-game-layout #right-panel img#evolution-guide {
    grid-area: auto;
    width: 480px !important;
    max-width: 480px;
    height: 270px;
    flex: 0 0 270px;
    object-fit: contain;
    margin: 0;
}
.fixed-game-layout #game-actions {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 528px;
    gap: 8px;
}
.fixed-game-layout #game-actions button {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    min-width: 64px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .65);
    background: rgba(255, 255, 255, .5);
    color: #655278;
    box-shadow: 0 2px 6px rgba(88, 62, 108, .1);
}
#game-actions .game-icon-button svg { width: 28px; height: 28px; fill: currentColor; }
#game-actions .bgm-off-mark { display: none; }
#game-actions .is-muted .bgm-off-mark { display: block; }
#game-actions .game-icon-button:hover { background: rgba(255, 255, 255, .8); }
#game-actions .game-icon-button:focus-visible { outline: 3px solid #a855f7; outline-offset: 3px; }
.fixed-game-layout #countdown-overlay { width: 180px; font-size: 112px; }

/* 一時停止の説明・選択肢を、縮小された盤面でも読みやすくする。 */
#pause-screen { gap: 20px; }
#pause-screen p {
    font-size: 30px;
    line-height: 1.65;
    max-width: 100%;
}
#pause-screen button {
    font-size: 32px;
    line-height: 1.4;
    min-width: 320px;
    max-width: 100%;
    min-height: 76px;
    padding: 14px 30px;
    margin: 6px 0;
}
