/* Root CSS Custom Properties for Themed Colors and Fonts */
:root {
    --bg-color: #fbf9f4;
    --paper-grid: #ece8db;
    --text-color: #3d312a;
    --text-light: #6e5e54;
    --border-color: #3d312a;
    
    /* Boyfriend Theme (Green) */
    --primary-green: #81b29a;
    --primary-green-dark: #588b71;
    --primary-green-light: #a8d5be;
    
    /* Water Theme (Blue) */
    --water-blue: #70a1ff;
    --water-blue-dark: #1e90ff;
    --water-blue-light: #cfe2ff;
    
    /* Affection Theme (Pink/Red) */
    --heart-pink: #f28482;
    --heart-pink-dark: #e05755;
    
    /* Paper Notebook Palette */
    --notebook-red-line: #f2a6a6;
    
    /* Fonts */
    --font-handdrawn: 'Architects Daughter', cursive;
    --font-comic: 'Playpen Sans', cursive, sans-serif;
}

/* Base Resets & Layout */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-comic);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    padding: 20px 0 30px 0;
}

/* Paper Grid Background Texture */
.paper-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: -1;
    opacity: 0.7;
    background-size: 30px 30px;
    background-image: 
        linear-gradient(to right, var(--paper-grid) 1px, transparent 1px),
        linear-gradient(to bottom, var(--paper-grid) 1px, transparent 1px);
}

/* Main Game Wrapper */
.game-wrapper {
    width: 95%;
    max-width: 900px;
    height: 92vh;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px;
}

/* Handdrawn border helpers using wobbly border-radius & filter */
.handdrawn-border {
    border: 3.5px solid var(--border-color);
    /* Asymmetric border radius to look hand-sketched */
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    background-color: #ffffff;
    box-shadow: 4px 6px 0px rgba(61, 49, 42, 0.15);
    filter: url(#sketch-filter);
    transition: all 0.2s ease-in-out;
}

/* Custom Handdrawn Buttons */
.handdrawn-btn {
    border: 3px solid var(--border-color);
    border-radius: 120px 15px 100px 15px/15px 110px 15px 120px;
    background-color: #ffffff;
    color: var(--text-color);
    font-family: var(--font-handdrawn);
    font-weight: 700;
    cursor: pointer;
    font-size: 1rem;
    padding: 8px 18px;
    box-shadow: 2px 4px 0px var(--border-color);
    filter: url(#button-sketch-filter);
    position: relative;
    outline: none;
    user-select: none;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background-color 0.2s ease;
}

.handdrawn-btn:hover {
    transform: scale(1.03) rotate(-1deg);
    box-shadow: 3px 5px 0px var(--border-color);
}

.handdrawn-btn:active {
    transform: scale(0.97) rotate(1deg);
    box-shadow: 1px 2px 0px var(--border-color);
}

/* Icon Buttons specifically */
.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    padding: 0;
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
}

/* Header Design */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: #ffffff;
}

.compact-water-log {
    display: none;
}

.logo-title h1 {
    font-family: var(--font-handdrawn);
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary-green-dark);
    text-align: center;
    letter-spacing: -0.5px;
}

.stat-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-family: var(--font-handdrawn);
    font-weight: 700;
    font-size: 0.95rem;
}

.hearts-display {
    display: flex;
    gap: 2px;
    font-size: 1.1rem;
}

.heart {
    transition: transform 0.2s ease;
}

.heart.animate {
    animation: heart-pop 0.4s ease-out;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* Game Stage (Character & Tracker) */
.game-stage {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0; /* allows flex item to shrink if needed */
}

.portrait-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 30px;
    width: 100%;
    height: 100%;
    justify-content: center;
    position: relative;
    padding-bottom: 5px;
}

/* Boyfriend Avatar Card styled like a Polaroid Photo */
.avatar-card {
    width: 250px;
    height: 310px;
    padding: 12px 12px 35px 12px; /* Extra bottom padding for polaroid look */
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: float-breath 4s ease-in-out infinite alternate;
    z-index: 5;
}

.bg-sparkles {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 30px;
    pointer-events: none;
    overflow: hidden;
}

.sparkle-dot {
    position: absolute;
    color: var(--heart-pink);
    font-size: 14px;
    animation: sparkle-float 1.2s ease-out forwards;
}

.portrait-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background-color: #e9ecef;
    transition: opacity 0.2s ease-in-out;
}

/* Water Notebook (Pinned to the side) */
.water-notebook {
    width: 230px;
    padding: 15px;
    background-color: #fffdf5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    align-self: center;
    transform: rotate(2deg);
    border-radius: 8px 120px 10px 105px/12px 12px 110px 15px;
    border-left: 8px solid var(--notebook-red-line); /* red binder strip */
}

.notebook-title {
    font-family: var(--font-handdrawn);
    font-size: 1.05rem;
    color: var(--text-color);
    border-bottom: 2px dashed var(--border-color);
    width: 100%;
    text-align: center;
    padding-bottom: 4px;
}

.water-glasses {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 6px 0;
    width: 100%;
    justify-items: center;
}

.glass {
    font-size: 1.4rem;
    filter: grayscale(1);
    opacity: 0.3;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
}

.glass.full {
    filter: grayscale(0);
    opacity: 1;
    transform: scale(1.2);
    animation: glass-bounce 0.4s ease-out;
}

.notebook-stats {
    font-family: var(--font-handdrawn);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--water-blue-dark);
}

.log-water-btn {
    width: 100%;
    background-color: var(--water-blue-light);
    font-size: 0.95rem;
    padding: 8px 10px;
    border-color: var(--border-color);
}

.log-water-btn:hover {
    background-color: #aedbf2;
}

/* Bottom Dialogue and RPG controls */
.dialogue-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dialogue-container {
    position: relative;
    padding: 20px 24px;
    background-color: #ffffff;
    min-height: 100px;
    display: flex;
    align-items: center;
}

.speaker-name-tag {
    position: absolute;
    top: -18px;
    left: 20px;
    background-color: var(--primary-green);
    color: #ffffff;
    font-family: var(--font-handdrawn);
    font-size: 1.05rem;
    font-weight: bold;
    padding: 4px 14px;
    border-radius: 20px 10px 20px 10px/10px 20px 10px 20px;
    box-shadow: 2px 3px 0px var(--border-color);
    letter-spacing: 0.5px;
    filter: url(#button-sketch-filter);
    z-index: 10;
}

.dialogue-content {
    width: 100%;
    position: relative;
}

.dialogue-text {
    font-family: var(--font-comic);
    font-size: 0.98rem;
    color: var(--text-color);
    white-space: pre-line; /* respects line breaks */
    padding-right: 15px;
}

.typing-arrow {
    position: absolute;
    bottom: -10px;
    right: 0;
    font-size: 0.75rem;
    color: var(--text-light);
    animation: arrow-blink 0.8s steps(2) infinite;
    cursor: pointer;
    user-select: none;
}

/* Choice Buttons Container */
.choices-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.choice-btn {
    width: 100%;
    text-align: left;
    padding: 10px 15px;
    font-size: 0.95rem;
    font-family: var(--font-comic);
    background-color: #ffffff;
    box-shadow: 2px 3px 0px var(--border-color);
    font-weight: 500;
    opacity: 0;
    animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.choice-btn:hover {
    background-color: #fffbf0;
}

/* Modal Overlay for Stats & Endings */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(61, 49, 42, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    width: 90%;
    max-width: 480px;
    background-color: #faf9f5;
    padding: 24px;
    position: relative;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-content h2 {
    font-family: var(--font-handdrawn);
    font-size: 1.4rem;
    text-align: center;
    color: var(--text-color);
    border-bottom: 3px dashed var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 16px;
}

.close-modal-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    border: none;
    background: none;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-light);
}

.close-modal-btn:hover {
    color: var(--text-color);
}

.modal-body {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 4px;
}

.modal-body h3 {
    font-family: var(--font-handdrawn);
    font-size: 1.15rem;
    margin-bottom: 8px;
}

.endings-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ending-card {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    background-color: #ffffff;
    transition: transform 0.2s ease;
}

.ending-card:hover {
    transform: translateY(-2px);
}

.ending-card.locked {
    background-color: #e9ecef;
    opacity: 0.6;
}

.ending-card.locked .ending-emoji {
    filter: blur(2px) grayscale(1);
}

.ending-card.locked p {
    font-style: italic;
    color: var(--text-light);
}

.ending-emoji {
    font-size: 1.6rem;
    background: #f1f3f5;
    padding: 6px;
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
    border: 1.5px solid var(--border-color);
}

.ending-card h4 {
    font-size: 0.95rem;
    font-weight: 700;
}

.ending-card p {
    font-size: 0.8rem;
    color: var(--text-light);
}

.stats-summary {
    background-color: #fffef0;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 12px;
}

.stats-summary p {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

/* Animations */
@keyframes pop-in {
    0% {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes float-breath {
    0% {
        transform: translateY(0px) rotate(-1deg);
    }
    100% {
        transform: translateY(-8px) rotate(1deg);
    }
}

@keyframes heart-pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.5);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes glass-bounce {
    0% {
        transform: scale(0.6);
    }
    70% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1.2);
    }
}

@keyframes arrow-blink {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes sparkle-float {
    0% {
        transform: translateY(0) scale(0) rotate(0deg);
        opacity: 0;
    }
    30% {
        opacity: 1;
    }
    100% {
        transform: translateY(-40px) scale(1) rotate(45deg);
        opacity: 0;
    }
}

/* Site Footer */
.site-footer {
    margin-top: 14px;
    font-family: var(--font-handdrawn);
    font-size: 0.85rem;
    color: var(--text-light);
    text-align: center;
    z-index: 10;
}

.site-footer a {
    color: var(--primary-green-dark);
    text-decoration: none;
    font-weight: bold;
    border-bottom: 1.5px dashed var(--primary-green-dark);
    padding-bottom: 1px;
}

.site-footer a:hover {
    color: var(--primary-green);
    border-bottom-style: solid;
}

/* Responsive Overrides */
@media (max-width: 650px) {
    .game-wrapper {
        height: 94vh;
        max-height: 720px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        gap: 8px;
        padding: 6px;
    }

    .game-header {
        padding: 8px 12px;
        gap: 8px;
    }

    #affection-label {
        display: none;
    }

    .logo-title {
        display: none;
    }

    .compact-water-log {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .compact-log-btn {
        padding: 4px 10px;
        font-size: 0.85rem;
        font-family: var(--font-handdrawn);
        background-color: var(--water-blue-light);
        border: 2px solid var(--border-color);
        box-shadow: 1px 2px 0px var(--border-color);
    }

    .compact-hydration-count {
        font-family: var(--font-handdrawn);
        font-weight: 700;
        font-size: 0.95rem;
        color: var(--water-blue-dark);
    }

    .portrait-wrapper {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding-bottom: 0;
        margin-top: 0;
    }

    .water-notebook {
        display: none;
    }

    .choices-container {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .avatar-card {
        width: 140px;
        height: 180px;
        padding: 8px 8px 24px 8px;
    }

    .dialogue-container {
        padding: 12px 16px;
        min-height: 80px;
    }

    .speaker-name-tag {
        font-size: 0.9rem;
        padding: 2px 10px;
        top: -14px;
    }

    .choice-btn {
        padding: 6px 10px;
        font-size: 0.85rem;
        text-align: center;
    }

    .site-footer {
        margin-top: 6px;
    }
}
