/* Base Reset & Variables */
:root {
    --primary-red: #d32f2f;
    --primary-gold: #c5a059;
    --bg-cream: #fffaf0;
    --text-dark: #333333;
    --text-accent: #8e24aa;
    --font-main: 'Noto Serif JP', serif;
    --font-heading: 'Yuji Syuku', serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-cream);
    background-image:
        radial-gradient(#e0c3a1 1px, transparent 1px),
        radial-gradient(#e0c3a1 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    color: var(--text-dark);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 600px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border: 2px solid var(--primary-gold);
    /* overflow: hidden;  <-- Removed to allow scrolling */
    position: relative;
    padding-bottom: 20px;

}

/* ... existing code ... */

footer {
    text-align: center;
    color: #888;
    margin-top: 0;
    /* Reduced from 20px */
    padding: 5px 0;
    /* Minimal padding */
    font-size: 0.8rem;
    background: #fff;
    /* Ensure background matches if needed */
}

/* Header */
header {
    background: var(--primary-red);
    color: white;
    padding: 20px;
    text-align: center;
    border-bottom: 4px solid var(--primary-gold);
}

header h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    letter-spacing: 0.1em;
    margin-bottom: 5px;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Main Content */
main {
    padding: 20px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.screen {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: opacity 0.5s ease;
}

.hidden {
    display: none !important;
    opacity: 0;
}

.active {
    display: flex;
    opacity: 1;
}

/* Start Screen */
.image-container {
    margin-bottom: 2rem;
}

.image-container img {
    max-width: 250px;
    height: auto;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.15));
}

.bounce {
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-20px);
    }

    60% {
        transform: translateY(-10px);
    }
}

.instruction {
    font-size: 1.2rem;
    text-align: center;
    margin-bottom: 2rem;
    line-height: 1.8;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary-red), #b71c1c);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: var(--font-heading);
    box-shadow: 0 4px 15px rgba(211, 47, 47, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(211, 47, 47, 0.4);
}

.btn-secondary {
    background: transparent;
    color: var(--primary-red);
    border: 2px solid var(--primary-red);
    padding: 10px 30px;
    font-size: 1rem;
    border-radius: 50px;
    cursor: pointer;
    margin-top: 20px;
    font-family: var(--font-main);
    transition: all 0.3s;
}

.btn-secondary:hover {
    background: var(--primary-red);
    color: white;
}

/* Result Screen */
.result-card {
    text-align: center;
    width: 100%;
    animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.god-image-wrapper {
    margin-bottom: 20px;
}

.god-image {
    max-width: 280px;
    border-radius: 50%;
    border: 4px solid var(--primary-gold);
    padding: 5px;
    background: white;
}

#god-name {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    color: var(--primary-red);
    margin-bottom: 5px;
}

#god-title {
    font-size: 1rem;
    color: var(--text-accent);
    margin-bottom: 15px;
    font-weight: bold;
}

.quote-box {
    background: #fff5f5;
    border-left: 5px solid var(--primary-red);
    padding: 15px;
    margin: 20px 0;
    font-style: italic;
    font-size: 1.1rem;
    text-align: left;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.quote-box::before {
    content: '"';
    font-family: serif;
    font-size: 3rem;
    color: rgba(211, 47, 47, 0.2);
    position: absolute;
    top: -10px;
    left: 5px;
}

.luck-details {
    display: grid;
    gap: 15px;
    text-align: left;
    background: #fff;
    padding: 15px;
    border: 1px solid #eee;
    border-radius: 8px;
}

.luck-item {
    border-bottom: 1px dashed #ddd;
    padding-bottom: 10px;
}

.luck-item:last-child {
    border-bottom: none;
}

.luck-label {
    display: block;
    font-weight: bold;
    color: var(--primary-gold);
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.luck-item.highlight .luck-label {
    color: var(--primary-red);
    text-decoration: underline;
}

.luck-content {
    font-size: 1rem;
    line-height: 1.5;
}

footer {
    text-align: center;
    color: #888;
    margin-top: 0;
    padding: 5px 0;
    font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    #god-name {
        font-size: 2rem;
    }

    .god-image {
        max-width: 200px;
    }
}

/* Glowing Button Style */
.glowing-btn {
    background: linear-gradient(45deg, #FFD700, #FF8C00, #FFD700);
    background-size: 200% 200%;
    color: #fff;
    border: none;
    font-weight: bold;
    margin-top: 20px;
    animation: glowing 2s infinite, gradientMove 3s ease infinite;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

@keyframes glowing {
    0% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5), 0 0 10px rgba(255, 215, 0, 0.5);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 20px rgba(255, 140, 0, 0.8), 0 0 30px rgba(255, 140, 0, 0.6);
        transform: scale(1.03);
    }

    100% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5), 0 0 10px rgba(255, 215, 0, 0.5);
        transform: scale(1);
    }
}

@keyframes gradientMove {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.chat-instruction {
    margin-top: 25px;
    font-size: 0.9rem;
    color: #555;
    font-weight: bold;
}

/* Chat Screen Styles */
.chat-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Fill parent height (which is controlled by .container) */
    min-height: 500px;
    position: relative;
    padding-bottom: 0;
}

/* Adjust main container for chat mode if needed, or make chat-screen overlay */
/* Ideally, chat-screen should probably take over more space on mobile */

.chat-header {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 2px solid var(--primary-gold);
    background: rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
    /* Header doesn't shrink */
}

.chat-god-icon img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--primary-red);
    margin-right: 15px;
    object-fit: cover;
}

.chat-title h2 {
    font-size: 1.3rem;
    color: var(--primary-red);
    margin: 0;
    line-height: 1.2;
}

.chat-title p {
    font-size: 0.8rem;
    color: #666;
    margin: 0;
}

.chat-messages {
    flex: 1;
    /* Takes remaining space */
    overflow-y: auto;
    padding: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    margin-bottom: 0;
    /* Remove margin to stick to input */
    border: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

.message.system {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message.system .bubble {
    background: white;
    border: 1px solid var(--primary-gold);
    color: var(--text-dark);
    border-top-left-radius: 4px;
}

.message.user .bubble {
    background: var(--primary-red);
    color: white;
    border-top-right-radius: 4px;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 10px 10px 5px 10px;
    /* Reduced bottom padding */
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    margin-bottom: 0;
}

#chat-input {
    flex: 1;
    padding: 12px;
    border: 2px solid #000;
    /* Black Border as requested */
    border-radius: 8px;
    resize: none;
    height: 50px;
    /* Fixed height */
    font-family: inherit;
    font-size: 1rem;
}

#chat-input:focus {
    outline: none;
    border-color: #000;
    /* Keep black on focus */
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

.btn-send {
    background: var(--primary-red);
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    height: 50px;
    /* Match input height */
}

.btn-send:hover {
    background: #b71c1c;
}

.btn-secondary.small {
    margin-top: 0;
}

/* Chat Mode: Hides header/footer to maximize space for chat on mobile */
body.chat-mode header,
body.chat-mode footer {
    display: none !important;
}

body.chat-mode {
    padding: 0 !important;
    overflow: hidden !important;
    /* Lock viewport to prevent background scrolling issues on mobile */
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

body.chat-mode .container {
    height: 100%;
    /* Fallback */
    min-height: 0;
    border: none;
    border-radius: 0;
    padding: 0;
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
}

body.chat-mode main {
    padding: 0;
    height: 100%;
    width: 100%;
}

/* Mobile specific overrides for chat mode */
@media (max-width: 480px) {
    body.chat-mode .chat-container {
        height: 100%;
        /* Fill screen on mobile */
        margin-top: 0;
        max-width: 100%;
    }

    body.chat-mode .chat-messages {
        padding-bottom: 10px;
    }
}

/* Responsive Adjustments for Chat & Mobile Layout */
@media (max-width: 480px) {

    /* Mobile Container: Allow automatic height so user can scroll content */
    .container {
        height: auto;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        padding: 0;
        border-radius: 0;
        border: none;
    }

    /* Fix header font size for mobile */
    header h1 {
        font-size: 1.4rem;
        margin-bottom: 5px;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    /* Prevent content from being pushed up into header by centering */
    main {
        flex: 1;
        width: 100%;
        padding: 20px 10px;
        min-height: auto;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        /* Start from top, don't center vertically */
        align-items: center;
    }

    /* Fix Image Size and spacing to prevent overlap */
    .god-image {
        max-width: 160px;
        /* Smaller image */
        margin-top: 10px;
    }

    .god-image-wrapper {
        margin-bottom: 15px;
    }

    /* Chat Container needs to fill screen on mobile in chat mode */
    body.chat-mode .chat-container {
        height: 100dvh;
        /* Full viewport height */
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        margin-top: 0;
        padding-bottom: env(safe-area-inset-bottom);
        /* Handle safe area for iPhone X+ */
    }

    /* Fallback/Adjustment for normal views if accessed directly or responsive resizing */


    body.chat-mode .chat-messages {
        padding-bottom: 10px;
    }

    footer {
        padding: 15px;
        background: #f9f9f9;
        margin-top: auto;
        /* Push to bottom */
    }
}