* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Yu Gothic', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 0;
    background-color: #000;
}

/* コンテナ（縦位置固定） */
#app-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 100vh;
    overflow: hidden;
}

/* 背景画像 */
.background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center 20%;
    /* Shift image upwards to balance with bottom text */
    background-color: #000;
    z-index: 1;
}

/* フェード用オーバーレイ */
.fade-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    z-index: 10;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.8s ease-in-out;
}

.fade-overlay.fade-out {
    opacity: 0;
}

.fade-overlay.fade-in {
    opacity: 1;
}

/* スタートプロンプト */
.start-prompt {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    transform: translateY(-50%);
    font-size: 28px;
    font-weight: 300;
    color: #ffffff;
    letter-spacing: 8px;
    text-indent: 8px;
    cursor: pointer;
    z-index: 20;
    padding: 20px 0;
    background-color: rgba(0, 0, 0, 0.6);
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: color 0.3s ease, opacity 0.4s ease-in-out;
}

.start-prompt span {
    position: relative;
    display: inline-block;
    transition: transform 0.3s ease;
}

.start-prompt span::before {
    content: "";
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 1px;
    background-color: #fff;
    transition: width 0.3s ease;
    opacity: 0.7;
}

.start-prompt.show {
    opacity: 1;
    pointer-events: auto;
}

.start-prompt.show span {
    animation: promptBlink 3s 1s infinite ease-in-out;
    /* 1s delay: transitionのフェードイン(0→1)が完了してからアニメーション開始 */
}

.start-prompt:hover {
    color: #ddd;
}

.start-prompt:hover span {
    transform: scale(1.05);
}

.start-prompt:hover span::before {
    width: 60%;
}

.start-prompt:active span {
    transform: scale(1.0);
}

@keyframes promptBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* テキストウィンドウ */
.text-window {
    position: absolute;
    bottom: env(safe-area-inset-bottom, 0);
    left: 0;
    width: 100%;
    height: 30%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 18;
    /* menuScreen(15)より上、sub-screen(20)より下 */
    padding: 20px 40px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
    opacity: 0;
    pointer-events: none;
}

.text-window.active {
    opacity: 1;
    pointer-events: auto;
}

.text-window.overlay-mode {
    z-index: 50 !important;
    /* tools-screen is 20, so 50 will show above it */
}

.text-window.empty {
    opacity: 0;
    pointer-events: none;
}

.text-window.empty .face-icon,
.text-window.empty .name-display,
.text-window.empty .text-content {
    display: none;
}

/* 顔アイコン */
.face-icon {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

/* テキストエリア */
.text-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* 名前表示 */
.name-display {
    display: none;
}

/* テキスト内容 */
.text-content {
    font-size: 18px;
    line-height: 1.8;
    color: #ffffff;
    padding-top: 10px;
}

/* 進行可能マーク */
.continue-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 24px;
    color: #ffffff;
    opacity: 0;
    pointer-events: none;
}

.continue-icon.show {
    opacity: 1;
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 1;
    }
}

/* メニュー画面 */
.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}

.menu-screen.show {
    opacity: 1;
    pointer-events: auto;
}

.menu-screen .menu-container,
.menu-screen .close-container {
    transition: opacity 0.3s ease-in-out;
    opacity: 1;
}

.menu-screen.sub-active .menu-container,
.menu-screen.sub-active .close-container {
    opacity: 0;
    pointer-events: none;
}

.menu-container {
    display: flex;
    flex-direction: column;
    gap: 40px;
    align-items: center;
    width: 100%;
    transform: translateY(-5vh);
    /* Shift upwards consistently based on viewport */
}

.menu-button {
    display: block;
    width: 100%;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.6);
    font-size: 28px;
    color: #fff;
    text-decoration: none;
    letter-spacing: 8px;
    text-indent: 8px;
    cursor: pointer;
    /* Slightly spread out the characters */
    padding: 20px 0;
    position: relative;
    transition: color 0.3s ease, transform 0.3s;
    font-weight: 300;
}

.menu-button span {
    position: relative;
    display: inline-block;
    transition: transform 0.3s ease;
}

.menu-button span::before {
    content: "";
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 1px;
    background-color: #fff;
    transition: width 0.3s ease;
    opacity: 0.7;
}

.menu-button:hover {
    color: #ddd;
}

.menu-button:hover span {
    transform: scale(1.05);
}

.menu-button:hover span::before {
    width: 60%;
}

.menu-button:active span {
    transform: scale(1.0);
}

/* サブ画面 (支給品・記録・名簿共通) */
.sub-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}

.sub-screen.show {
    opacity: 1;
    pointer-events: auto;
}

.close-container {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top, 0px));
    right: 20px;
}

.close-button {
    font-size: 32px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
    user-select: none;
}

.close-button:hover {
    color: #fff;
}

.sub-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
    align-items: center;
    transform: translateY(-5vh);
    /* Match main menu alignment */
}

/* List items initial hidden state for animation */
.sub-container>* {
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity 0.4s ease-out, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Trigger animation when screen is shown */
.sub-screen.show .sub-container>* {
    opacity: 1;
    transform: translateX(0);
}

/* Staggering delays for up to 10 items */
.sub-screen.show .sub-container>*:nth-child(1) {
    transition-delay: 0.1s;
}

.sub-screen.show .sub-container>*:nth-child(2) {
    transition-delay: 0.2s;
}

.sub-screen.show .sub-container>*:nth-child(3) {
    transition-delay: 0.3s;
}

.sub-screen.show .sub-container>*:nth-child(4) {
    transition-delay: 0.4s;
}

.sub-screen.show .sub-container>*:nth-child(5) {
    transition-delay: 0.5s;
}

.sub-screen.show .sub-container>*:nth-child(6) {
    transition-delay: 0.6s;
}

.sub-screen.show .sub-container>*:nth-child(7) {
    transition-delay: 0.7s;
}

.sub-screen.show .sub-container>*:nth-child(8) {
    transition-delay: 0.8s;
}

.sub-screen.show .sub-container>*:nth-child(9) {
    transition-delay: 0.9s;
}

.sub-screen.show .sub-container>*:nth-child(10) {
    transition-delay: 1.0s;
}

.list-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-info-btn {
    position: absolute;
    left: calc(100% + 15px);
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    font-weight: bold;
}

.tool-info-btn:hover {
    color: #fff;
    border-color: #fff;
    transform: scale(1.1);
}

.list-button {
    font-size: 20px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    letter-spacing: 6px;
    cursor: pointer;
    padding: 12px 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    width: 360px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    transition: all 0.3s ease;
    font-weight: 300;
    background-color: rgba(0, 0, 0, 0.6);
}

.list-button::after {
    content: "→";
    font-size: 16px;
    color: rgba(255, 255, 255, 0.4);
    transition: all 0.3s ease;
    transform: translateX(-5px);
}

.list-button:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.8);
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

.list-button:hover::after {
    color: #fff;
    transform: translateX(3px);
}

.list-button:active {
    background-color: rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

.characters-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Ensures content aligns to top */
    padding-top: 10vh;
    /* Fixed offset from top */
    gap: 30px;
    width: 90%;
    max-width: 500px;
    height: 100%;
    /* Take full height so flex-start works correctly */
}

.character-icons {
    display: flex;
    gap: 15px;
    justify-content: center;
    width: 100%;
    /* Ensure full width */
    height: 70px;
    /* Fixed height to match icon, prevents layout jump */
    flex-shrink: 0;
}

.character-icon {
    width: 70px;
    height: 70px;
    border-radius: 0;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.3s, border-color 0.3s, filter 0.3s, opacity 0.3s;
    background: none;
    overflow: hidden;
    filter: grayscale(100%);
    opacity: 0.6;
}

.character-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-icon:hover {
    transform: scale(1.1);
    filter: grayscale(0%);
    opacity: 1;
    z-index: 10;
}

.character-icon.active {
    border-color: rgba(255, 255, 255, 0.8);
    filter: grayscale(0%);
    opacity: 1;
}

.sub-screen.show .character-icon {
    animation: cascadeReveal 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.sub-screen.show .character-icon:nth-child(1) {
    animation-delay: 0.10s;
}

.sub-screen.show .character-icon:nth-child(2) {
    animation-delay: 0.15s;
}

.sub-screen.show .character-icon:nth-child(3) {
    animation-delay: 0.20s;
}

.sub-screen.show .character-icon:nth-child(4) {
    animation-delay: 0.25s;
}

.sub-screen.show .character-icon:nth-child(5) {
    animation-delay: 0.30s;
}

@keyframes cascadeReveal {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.8);
        filter: blur(4px) grayscale(100%);
    }
}

.character-display {
    background-color: transparent;
    padding: 0px;
    text-align: center;
    width: 100%;
    height: 300px;
    /* Align height with old card */
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.character-display.animating::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 2px;
    background-color: #fff;
    transform: translate(-50%, -50%);
    animation: drawLine 0.15s ease-out forwards;
    z-index: 5;
}

.character-display.animating .character-image {
    animation: revealImage 0.3s 0.1s ease-out forwards;
    opacity: 0;
}

@keyframes drawLine {
    0% {
        width: 0;
    }

    100% {
        width: 100%;
        opacity: 0;
    }
}

@keyframes revealImage {
    0% {
        opacity: 0;
        transform: scaleY(0);
        filter: brightness(2) contrast(2);
    }

    100% {
        opacity: 1;
        transform: scaleY(1);
        filter: brightness(1) contrast(1);
    }
}

.character-display .character-image {
    max-width: 250px;
    max-height: 250px;
    object-fit: contain;
}

/* フッター */
.footer {
    position: fixed;
    bottom: 10px;
    left: 0;
    width: 100%;
    font-size: 10px;
    text-align: center;
    color: #666666;
    /* 控えめなグレー */
    z-index: 100;
    /* オーバーレイに影響されず常に一番上に表示 */
    pointer-events: none;
    letter-spacing: 1px;
}

.footer a {
    color: inherit;
    text-decoration: underline;
    pointer-events: auto;
    transition: color 0.3s ease;
}

.footer a:hover {
    color: #999999;
}

/* グローバルミュートボタン */
#globalMuteBtn {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top, 0px));
    left: 20px;
    z-index: 100;
    background: transparent;
    border: none;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

#globalMuteBtn svg {
    fill: rgba(255, 255, 255, 0.5);
    width: 28px;
    height: 28px;
    transition: fill 0.2s ease, transform 0.3s ease;
    display: block;
}

#globalMuteBtn:hover svg {
    fill: #ffffff;
}

/* レスポンシブ対応 */

/* モバイル */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding-top: 10vh;
    }

    #app-container {
        height: 90vh;
    }

    .text-window {
        height: 35%;
        padding: 15px 20px;
        padding-bottom: max(15px, env(safe-area-inset-bottom, 15px));
        gap: 15px;
    }

    .face-icon {
        width: 70px;
        height: 70px;
        border-width: 2px;
    }

    .name-display {
        font-size: 16px;
    }

    .text-content {
        font-size: 14px;
    }

    .continue-icon {
        font-size: 20px;
        right: 15px;
    }

    .menu-button {
        font-size: 24px;
        letter-spacing: 6px;
    }

    .list-button {
        width: 80vw;
    }
}