@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;700;900&family=Noto+Sans+TC:wght@400;700&display=swap');

:root {
    --primary-color: #ffb7c5; /* Sakura pink */
    --primary-deep: #cb3e5f;
    --text-color: #f4f4f6;
    --box-bg: rgba(18, 18, 28, 0.88);
    --name-bg: rgba(255, 183, 197, 0.95);
    --border-color: rgba(255, 255, 255, 0.22);
    --game-width: 1024px;
    --game-height: 768px; /* 4:3 for desktop / iPad */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
    touch-action: manipulation;
}

#game-container {
    width: min(100vw, calc(100vh * 4 / 3), var(--game-width));
    height: min(100vh, calc(100vw * 3 / 4), var(--game-height));
    position: relative;
    background-color: #000;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.85);
    overflow: hidden;
}

#game-container.in-game {
    cursor: pointer;
}

/* Background */
#bg-layer {
    position: absolute;
    inset: 0;
    background-color: #000;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
}

/* Characters */
#char-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    pointer-events: none;
}

#char-sprite {
    height: 88%;
    max-width: 95%;
    object-fit: contain;
    object-position: bottom center;
    transition: opacity 0.25s ease;
    will-change: opacity, transform;
}

#char-sprite.is-hiding {
    opacity: 0;
}

/* Character Animations */
.slide-in-right {
    animation: slideInRight 0.7s cubic-bezier(0.25, 0.8, 0.25, 1) both;
}

.fade-in {
    animation: fadeIn 0.45s ease both;
}

@keyframes slideInRight {
    from { transform: translateX(25%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Top Utility Controls */
#top-controls {
    position: absolute;
    top: 14px;
    right: 16px;
    z-index: 25;
    display: flex;
    gap: 10px;
}

.hud-btn {
    background: rgba(18, 18, 28, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #f0f0f0;
    padding: 6px 14px;
    font-size: 0.9rem;
    font-family: 'Noto Sans TC', sans-serif;
    border-radius: 20px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.hud-btn:hover, .hud-btn:active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #1a1a24;
}

/* UI Layer */
#ui-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 15;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 16px 32px 22px 32px;
    pointer-events: none;
}

#dialogue-box {
    width: 100%;
    min-height: 170px;
    max-height: 245px;
    background: var(--box-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: relative;
    padding: 28px 46px 26px 34px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), inset 0 0 20px rgba(255, 255, 255, 0.04);
    display: none;
    pointer-events: auto;
}

#char-name {
    position: absolute;
    top: -18px;
    left: 32px;
    background: var(--name-bg);
    color: #2a1d22;
    padding: 4px 22px;
    border-radius: 8px;
    font-family: 'Noto Serif TC', serif;
    font-size: 1.15rem;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

#char-name.visible {
    opacity: 1;
    visibility: visible;
}

#dialogue-text {
    color: var(--text-color);
    font-size: 1.3rem;
    line-height: 1.75;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.85);
    max-height: 185px;
    overflow-y: auto;
    word-break: break-word;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 183, 197, 0.45) transparent;
}

#next-indicator {
    position: absolute;
    bottom: 12px;
    right: 18px;
    color: var(--primary-color);
    font-size: 1.25rem;
    animation: bounce 0.9s infinite alternate;
    display: none;
    pointer-events: none;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(5px); }
}

/* Options Layer — positioned above dialogue box so player can still read the prompt */
#options-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 60px 20px 215px 20px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.35) 75%, rgba(0, 0, 0, 0.1) 100%);
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: default;
}

#options-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 72%;
    max-width: 620px;
}

.option-btn {
    background: rgba(24, 24, 36, 0.92);
    border: 2px solid rgba(255, 255, 255, 0.28);
    color: #fff;
    padding: 14px 26px;
    font-size: 1.15rem;
    font-family: 'Noto Sans TC', sans-serif;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.option-btn:hover:not(:disabled),
.option-btn:active:not(:disabled) {
    background: var(--primary-color);
    color: #1a1a24;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(255, 183, 197, 0.45);
}

.option-btn.special-choice {
    border-color: var(--primary-color);
    box-shadow: 0 0 18px rgba(255, 183, 197, 0.45);
}

.option-btn.locked {
    background: rgba(30, 30, 38, 0.65);
    border-color: rgba(255, 255, 255, 0.14);
    color: rgba(255, 255, 255, 0.45);
    cursor: not-allowed;
    box-shadow: none;
}

/* Ending Action Buttons */
#ending-actions {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 22;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    cursor: default;
    animation: fadeIn 0.6s ease both;
}

.ending-btn {
    min-width: 240px;
    padding: 13px 34px;
    font-size: 1.15rem;
    font-family: 'Noto Sans TC', sans-serif;
    font-weight: 700;
    border-radius: 30px;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: rgba(24, 24, 36, 0.88);
    color: #fff;
    transition: all 0.25s ease;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.ending-btn.primary {
    border-color: var(--primary-color);
    background: rgba(255, 183, 197, 0.18);
    color: var(--primary-color);
}

.ending-btn:hover, .ending-btn:active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #1a1a24;
    transform: translateY(-2px);
}

/* History Modal */
#history-modal {
    position: absolute;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    cursor: default;
}

#history-panel {
    width: 100%;
    max-width: 720px;
    height: 80%;
    background: rgba(20, 20, 30, 0.96);
    border: 1px solid rgba(255, 183, 197, 0.35);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
}

#history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--primary-color);
    font-family: 'Noto Serif TC', serif;
    font-size: 1.2rem;
    font-weight: 700;
}

#btn-close-history {
    background: transparent;
    border: none;
    color: #ddd;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
}

#btn-close-history:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

#history-list {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    user-select: text;
    -webkit-user-select: text;
}

.history-item {
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.history-speaker {
    color: var(--primary-color);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.history-text {
    color: #eaeaea;
    font-size: 1.02rem;
    line-height: 1.65;
}

.history-empty {
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    margin-top: 40px;
}

/* Overlay Layer for transitions */
#overlay-layer {
    position: absolute;
    inset: 0;
    background: #000;
    z-index: 30;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.9s ease;
}

#overlay-layer.black-screen {
    opacity: 1;
    pointer-events: auto;
}

/* Start Screen specific styling */
#start-screen {
    position: absolute;
    inset: 0;
    background: url('assets/images/bg.webp?v=20261203b') no-repeat center center;
    background-size: cover;
    z-index: 40;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 24px;
    cursor: default;
}

#start-card {
    position: relative;
    z-index: 45;
    background: rgba(255, 255, 255, 0.48);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 22px;
    padding: 40px 56px 32px 56px;
    box-shadow: 0 12px 36px rgba(45, 28, 38, 0.14);
    max-width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#start-title {
    color: #9e2a47;
    font-family: 'Noto Serif TC', serif;
    font-size: 3.1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.25;
    margin: 0;
    text-shadow: 0 1px 4px rgba(255, 255, 255, 0.65);
}

#start-divider {
    width: 64px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #d47a92, transparent);
    margin: 16px 0 14px 0;
}

#start-subtitle {
    font-size: 1.15rem;
    color: #42343a;
    font-family: 'Noto Sans TC', sans-serif;
    font-weight: 500;
    letter-spacing: 0.06em;
    margin-bottom: 28px;
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.65);
}

#start-btn {
    padding: 13px 52px;
    font-size: 1.25rem;
    font-family: 'Noto Sans TC', sans-serif;
    background: #b53453;
    border: 2px solid #b53453;
    color: #ffffff;
    font-weight: 700;
    letter-spacing: 0.1em;
    cursor: pointer;
    border-radius: 999px;
    box-shadow: 0 6px 18px rgba(181, 52, 83, 0.28);
    transition: background-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

#start-btn:hover:not(:disabled) {
    background: #962642;
    border-color: #962642;
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(150, 38, 66, 0.35);
}

#start-btn:disabled {
    opacity: 0.65;
    cursor: default;
}

#start-footer {
    margin-top: 26px;
    padding-top: 18px;
    border-top: 1px solid rgba(158, 42, 71, 0.14);
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#start-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#logo-salesian {
    height: 44px;
    width: auto;
    object-fit: contain;
    display: block;
}

#logo-ss75 {
    height: 29px;
    width: auto;
    object-fit: contain;
    display: block;
}

/* Cherry Blossom Petals */
#petals-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 41;
}

.petal {
    position: absolute;
    top: -10%;
    background-color: #ffb7c5;
    border-radius: 12px 0px 12px 0px;
    opacity: 0;
    box-shadow: 0 0 4px rgba(255, 183, 197, 0.6);
    animation: fall linear infinite;
    animation-fill-mode: backwards;
    z-index: 41;
}

@keyframes fall {
    0% { transform: translateY(0) rotate(0deg) translateX(0); opacity: 0; }
    12% { opacity: 0.65; }
    80% { opacity: 0.5; }
    100% { transform: translateY(115vh) rotate(720deg) translateX(150px); opacity: 0; }
}

#start-credits {
    color: #3d3036;
    font-size: 0.95rem;
    text-align: center;
    font-family: 'Noto Sans TC', sans-serif;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.65);
}

/* Screen shake effect */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-0.6deg); }
    20% { transform: translate(-3px, 0px) rotate(0.6deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(0.6deg); }
    50% { transform: translate(-1px, 2px) rotate(-0.6deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-0.6deg); }
    80% { transform: translate(-1px, -1px) rotate(0.6deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-0.6deg); }
}

.shake-effect {
    animation: shake 0.45s linear infinite;
}

/* Mobile Responsive Adjustments */
@media screen and (max-width: 768px) {
    #game-container {
        width: 100vw;
        height: 100dvh;
        max-width: none;
        max-height: none;
        box-shadow: none;
    }

    #char-sprite {
        height: 68vh;
        max-width: 100%;
    }

    #top-controls {
        top: 12px;
        right: 12px;
        gap: 8px;
    }

    .hud-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    #ui-layer {
        padding: 0 14px max(22px, env(safe-area-inset-bottom)) 14px;
    }

    #dialogue-box {
        min-height: 150px;
        max-height: 36dvh;
        padding: 26px 34px 22px 20px;
    }

    #char-name {
        top: -15px;
        left: 18px;
        font-size: 1.05rem;
        padding: 3px 14px;
    }

    #dialogue-text {
        font-size: 1.08rem;
        line-height: 1.65;
        max-height: calc(36dvh - 52px);
    }

    #options-layer {
        padding: 64px 16px 210px 16px;
    }

    #options-container {
        width: 94%;
        gap: 12px;
    }

    .option-btn {
        padding: 13px 18px;
        font-size: 1.02rem;
    }

    #start-card {
        padding: 30px 24px 24px 24px;
        width: 92%;
    }

    #start-title {
        font-size: 2.05rem;
    }

    #start-subtitle {
        font-size: 0.98rem;
        margin-bottom: 22px;
    }

    #start-btn {
        padding: 12px 42px;
        font-size: 1.12rem;
    }

    #logo-salesian {
        height: 38px;
    }

    #logo-ss75 {
        height: 25px;
    }

    #start-credits {
        font-size: 0.88rem;
    }
}
