/* ===== Error Banner ===== */
.error-banner {
    text-align: center;
    padding: 10px;
    margin: 8px 0;
}
.error-banner-link {
    display: inline-block;
    padding: 8px 20px;
    background: rgba(230, 57, 70, 0.15);
    border: 1px solid rgba(230, 57, 70, 0.4);
    border-radius: 8px;
    color: #E6B422;
    font-family: 'Noto Serif JP', serif;
    font-size: 0.85rem;
    text-decoration: none;
    transition: background 0.3s ease;
}
.error-banner-link:hover {
    background: rgba(230, 57, 70, 0.25);
}

/* ===== Novel Scene Layout ===== */
.novel-scene {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 背景 */
.novel-bg, .loading-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 0;
}

/* エラー時のSD背景（背景付きSD画像をcontainで全体表示） */
.novel-bg.error-bg {
    background-size: contain !important;
    background-repeat: no-repeat;
    background-color: #0a0a1a;
}

/* キャラ立ち絵エリア */
.novel-character {
    position: absolute;
    bottom: 35%;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 400px;
    z-index: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

/* キャラ実画像（ノベル画面） */
.novel-char-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 20px rgba(0, 0, 0, 0.5));
}

/* スプライトキャンバス */
#sprite-canvas {
    display: none;
    filter: drop-shadow(0 0 30px var(--theme-color));
    animation: spriteGlow 2s ease-in-out infinite alternate;
}

@keyframes spriteGlow {
    0%   { filter: drop-shadow(0 0 20px var(--theme-color)); }
    100% { filter: drop-shadow(0 0 50px var(--theme-color)); }
}

/* ボイスON/OFFトグル（将来のアップデートで有効化予定） */
.voice-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: rgba(240, 230, 211, 0.6);
    margin-left: auto;
}

.voice-toggle input[type="checkbox"] {
    accent-color: var(--color-gold);
    width: 16px;
    height: 16px;
}

/* MVP用キャラプレースホルダー（ノベル画面） */
.novel-char-placeholder {
    width: 160px;
    height: 320px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    opacity: 0.9;
}

.novel-char-placeholder.chisa {
    background: linear-gradient(180deg, rgba(255, 248, 248, 0.8), rgba(248, 200, 220, 0.8));
    color: #d4708a;
}

.novel-char-placeholder.yogami {
    background: linear-gradient(180deg, rgba(45, 27, 78, 0.8), rgba(107, 63, 160, 0.8));
    color: #D4AF37;
}

.novel-char-placeholder.suzune {
    background: linear-gradient(180deg, rgba(230, 57, 70, 0.8), rgba(255, 107, 122, 0.8));
    color: #fff;
}

/* テキストウィンドウ */
.novel-textbox {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 35%;
    min-height: 200px;
    background: linear-gradient(180deg, rgba(10, 10, 26, 0.85) 0%, rgba(10, 10, 26, 0.95) 100%);
    border-top: 1px solid rgba(212, 175, 55, 0.3);
    padding: 20px 24px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 5;
}

.textbox-name {
    font-size: 0.9rem;
    color: var(--color-gold);
    font-weight: 700;
    letter-spacing: 0.1em;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
    display: inline-block;
    width: fit-content;
}

.textbox-text {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--color-text);
    flex: 1;
    overflow-y: auto;
}

/* タイプライターカーソル */
.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--color-gold);
    margin-left: 2px;
    animation: cursorBlink 0.8s ease-in-out infinite;
    vertical-align: text-bottom;
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ===== Fortune Choice Buttons ===== */
.fortune-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.fortune-choice-btn {
    font-family: var(--font-main);
    font-size: 0.95rem;
    padding: 12px 20px;
    background: rgba(212, 175, 55, 0.08);
    border: 1px solid rgba(212, 175, 55, 0.3);
    color: var(--color-gold);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    min-height: 44px;
}

.fortune-choice-btn:hover {
    background: rgba(212, 175, 55, 0.2);
    border-color: var(--color-gold);
    transform: translateX(4px);
}

/* ===== Input Form ===== */
.input-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.input-label {
    font-size: 0.8rem;
    color: rgba(240, 230, 211, 0.6);
}

.input-field {
    font-family: var(--font-main);
    font-size: 1rem;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(212, 175, 55, 0.3);
    color: var(--color-text);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.3s ease;
    min-height: 44px;
}

.input-field:focus {
    border-color: var(--color-gold);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.input-field::placeholder {
    color: rgba(240, 230, 211, 0.3);
}

.input-row {
    display: flex;
    gap: 8px;
}

.input-row .input-field {
    flex: 1;
    text-align: center;
}

.btn-fortune {
    font-family: var(--font-main);
    font-size: 1rem;
    padding: 12px 32px;
    border: 2px solid var(--color-gold);
    background: rgba(212, 175, 55, 0.1);
    color: var(--color-gold);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 8px;
    min-height: 44px;
}

.btn-fortune:hover {
    background: var(--color-gold);
    color: var(--color-bg);
}

.btn-fortune:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ===== Result Screen ===== */
.result-textbox {
    height: 55%;
    min-height: 300px;
}

/* 結果画面ではCGにキャラが含まれるため立ち絵エリアを非表示 */
#screen-result .novel-character {
    display: none;
}

.result-number-display {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    position: relative;
}

.result-number-card {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 8px;
    filter: drop-shadow(0 0 10px rgba(212, 175, 55, 0.4));
    animation: cardReveal 0.6s ease-out;
}

@keyframes cardReveal {
    0%   { transform: scale(0.5) rotateY(90deg); opacity: 0; }
    100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}

.result-master-badge {
    width: 80px;
    height: 48px;
    object-fit: contain;
    filter: drop-shadow(0 0 15px rgba(212, 175, 55, 0.6));
    animation: masterGlow 2s ease-in-out infinite alternate;
}

@keyframes masterGlow {
    0%   { filter: drop-shadow(0 0 10px rgba(212, 175, 55, 0.4)); }
    100% { filter: drop-shadow(0 0 25px rgba(212, 175, 55, 0.8)); }
}

.result-label {
    font-size: 0.85rem;
    color: rgba(240, 230, 211, 0.6);
}

.result-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-gold);
    text-shadow: 0 0 20px rgba(212, 175, 55, 0.6);
}

.result-text-scroll {
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(212, 175, 55, 0.3) transparent;
}

.result-text-scroll::-webkit-scrollbar {
    width: 4px;
}

.result-text-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.result-text-scroll::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.3);
    border-radius: 2px;
}

.result-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 10px;
    border-top: 1px solid rgba(212, 175, 55, 0.15);
}

/* ===== Loading Screen ===== */
.loading-scene {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.loading-sprite {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
}

.loading-number-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    text-align: center;
}

#loading-number {
    font-size: 72px;
    font-family: var(--font-main);
    font-weight: 700;
    color: var(--color-gold);
    text-shadow: 0 0 20px rgba(212, 175, 55, 0.8);
    transition: transform 0.2s ease;
}

.loading-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.loading-label {
    font-size: 0.85rem;
    color: rgba(240, 230, 211, 0.5);
    letter-spacing: 0.2em;
}

.loading-bar-container {
    width: 60%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

#loading-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-gold), var(--color-gold-light), var(--color-gold));
    transition: width 0.3s ease;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .novel-textbox {
        height: 40%;
        padding: 16px 18px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .novel-character {
        bottom: 40%;
    }

    .result-textbox {
        height: 60%;
    }

    .result-buttons {
        flex-wrap: wrap;
    }

    /* エラーSD背景: モバイルではcoverで表示 */
    .novel-bg.error-bg {
        background-size: cover !important;
        background-position: top center;
    }
}

@media (max-width: 480px) {
    .novel-textbox {
        height: 45%;
        padding: 14px 14px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .novel-character {
        bottom: 45%;
        width: 140px;
        height: 280px;
    }

    .novel-char-placeholder {
        width: 120px;
        height: 240px;
        font-size: 36px;
    }

    #loading-number {
        font-size: clamp(40px, 12vw, 56px);
    }

    .textbox-name {
        font-size: 0.8rem;
    }
    .textbox-text {
        font-size: 0.9rem;
    }

    /* 結果画面: 16:9 CG + 不透明結果エリアのスタックレイアウト */
    #screen-result .novel-scene {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    #screen-result .novel-bg {
        position: relative;
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
        flex-shrink: 0;
    }

    .result-textbox {
        position: relative;
        flex: 1;
        min-height: 0;
        height: auto;
        max-height: none;
        background: #0a0a1a;
        border-top: 1px solid rgba(212, 175, 55, 0.3);
        padding: 12px 14px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        display: flex;
        flex-direction: column;
    }

    .result-number-display {
        gap: 8px;
        padding: 4px 0;
        flex-shrink: 0;
    }

    .result-number-card {
        width: 44px;
        height: 44px;
    }

    .result-number {
        font-size: 1.5rem;
    }

    .result-master-badge {
        width: 56px;
        height: 34px;
    }

    /* スクロールフェードインジケーター */
    .result-text-scroll {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        font-size: 0.9rem;
        line-height: 1.6;
        max-height: none;
        -webkit-mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
        mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
    }

    /* 2×2グリッドボタン */
    .result-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding-top: 8px;
        flex-shrink: 0;
    }

    .result-buttons .btn-result {
        width: 100%;
        padding: 10px 8px;
        font-size: 0.8rem;
    }

    .result-buttons .voice-toggle {
        grid-column: 1 / -1;
        justify-content: center;
    }

    /* テキストウィンドウも行間縮小 */
    .textbox-text {
        line-height: 1.6;
    }
}

/* 横向き・低い画面高さ */
@media (max-height: 500px) {
    .novel-textbox {
        height: 55%;
        min-height: 140px;
        padding: 10px 14px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
    }
    .novel-character {
        bottom: 55%;
        width: 100px;
        height: 200px;
    }
    .novel-char-placeholder {
        width: 80px;
        height: 160px;
        font-size: 28px;
    }
    #loading-number {
        font-size: clamp(36px, 10vw, 48px);
    }
    .loading-number-container {
        top: 35%;
    }
    .textbox-name {
        font-size: 0.75rem;
        padding-bottom: 2px;
    }
    .textbox-text {
        font-size: 0.85rem;
        line-height: 1.5;
    }
    .result-textbox {
        position: relative;
        height: auto;
        min-height: unset;
    }
    .result-text-scroll {
        max-height: 35vh;
        font-size: 0.85rem;
        line-height: 1.5;
    }
}
