/* ============================================================
   Grow Together — cozy storybook UI
   ============================================================ */

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

:root {
    --font: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --text-light: #f7f0e4;
    --accent: #66bb6a;
    --accent-deep: #43a047;
    --water: #4fc3f7;
    --water-deep: #29a3e8;
    --danger: #e57373;
    --gold: #ffd54f;
    --card-bg: rgba(18, 28, 22, 0.52);
    --card-border: rgba(255, 255, 255, 0.14);
    --card-blur: 10px;
    --card-radius: 18px;
    --shadow-soft: 0 8px 28px rgba(0, 0, 0, 0.28);
    --ground-line: 15%;   /* where the tree meets the earth */
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: #16241a;
    color: var(--text-light);
    -webkit-font-smoothing: antialiased;
}

button {
    font-family: var(--font);
}

/* === Game Container === */
#game-container {
    position: fixed;
    inset: 0;
}

/* === Viewport (visual layers) === */
#viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

#viewport > div {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Background painting — pinned to the bottom so the ground
   stays put on any screen shape */
#background-layer {
    background-size: cover;
    background-position: center bottom;
    background-repeat: no-repeat;
    transition: background-image 1s ease;
}

/* Sky tint — driven by layers.js for day/night */
#sky-layer {
    transition: background 2s ease, opacity 2s ease;
    z-index: 2;
}

#weather-layer { z-index: 5; }

/* === Tree === */
#tree-layer { z-index: 10; }

#tree-anchor {
    position: absolute;
    left: 50%;
    bottom: var(--ground-line);
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    width: min(92vw, 900px);
    height: 70vh;
    pointer-events: none;
}

#tree-image {
    max-height: 100%;
    max-width: min(58vw, 620px);
    object-fit: contain;
    object-position: bottom;
    transition: opacity 0.6s ease, filter 2s ease;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
    transform-origin: 50% 100%;
}

#tree-image.grow-in {
    animation: tree-grow 0.9s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes tree-grow {
    0%   { transform: scale(0.92); }
    100% { transform: scale(1); }
}

/* Gentle sway in windy weather */
#tree-image.sway {
    animation: tree-sway 4.5s ease-in-out infinite;
}

#tree-image.sway-strong {
    animation: tree-sway-strong 2.8s ease-in-out infinite;
}

@keyframes tree-sway {
    0%, 100% { transform: rotate(-0.5deg); }
    50%      { transform: rotate(0.6deg); }
}

@keyframes tree-sway-strong {
    0%, 100% { transform: rotate(-1.1deg) skewX(0.4deg); }
    50%      { transform: rotate(1.3deg) skewX(-0.5deg); }
}

#tree-image.happy-wiggle {
    animation: happy-wiggle 0.9s ease-in-out;
}

@keyframes happy-wiggle {
    0%, 100% { transform: rotate(0deg) scale(1); }
    25%      { transform: rotate(-1.6deg) scale(1.015); }
    55%      { transform: rotate(1.4deg) scale(1.01); }
    80%      { transform: rotate(-0.6deg); }
}

/* Soft contact shadow that seats the tree into the grass */
#tree-shadow {
    position: absolute;
    bottom: -0.6vh;
    left: 50%;
    transform: translateX(-50%);
    width: clamp(150px, 26vw, 380px);
    height: clamp(14px, 4vh, 40px);
    background: radial-gradient(ellipse at center,
        rgba(15, 20, 10, 0.32) 0%,
        rgba(15, 20, 10, 0.14) 45%,
        transparent 70%);
    transition: opacity 1.5s ease;
}

/* === Animals === */
#animal-layer {
    z-index: 15;
    overflow: hidden;
}

.animal {
    position: absolute;
    pointer-events: none;
    will-change: transform;
}

.animal .gait {
    position: relative;
    display: flex;
    justify-content: center;
}

.animal img {
    height: 100%;
    display: block;
}

.animal .sprite {
    display: block;
    image-rendering: auto;
}

.animal.flip img,
.animal.flip .sprite { transform: scaleX(-1); }

.animal .critter-shadow {
    position: absolute;
    bottom: -6%;
    left: 50%;
    transform: translateX(-50%);
    width: 78%;
    height: 14%;
    background: radial-gradient(ellipse at center,
        rgba(15, 20, 10, 0.32) 0%, transparent 70%);
}

/* Gaits — applied to the inner wrapper so they never fight
   the movement transform on the outer element */
.gait-hop     { animation: gait-hop 0.55s ease-in-out infinite; }
.gait-waddle  { animation: gait-waddle 0.6s ease-in-out infinite; }
.gait-flap    { animation: gait-flap 0.38s ease-in-out infinite; }
.gait-slither { animation: gait-slither 0.9s ease-in-out infinite; }
.gait-scurry  { animation: gait-scurry 0.3s ease-in-out infinite; }

@keyframes gait-hop {
    0%, 100% { transform: translateY(0) scaleY(0.98); }
    40%      { transform: translateY(-3.4vh) scaleY(1.02); }
    70%      { transform: translateY(-0.6vh); }
}

@keyframes gait-waddle {
    0%, 100% { transform: rotate(-2.5deg) translateY(0); }
    50%      { transform: rotate(2.5deg) translateY(-0.35vh); }
}

@keyframes gait-flap {
    0%, 100% { transform: translateY(0) rotate(1deg); }
    50%      { transform: translateY(-1.3vh) rotate(-1.5deg); }
}

@keyframes gait-slither {
    0%, 100% { transform: skewX(4deg) translateY(0); }
    50%      { transform: skewX(-4deg) translateY(0.3vh); }
}

@keyframes gait-scurry {
    0%, 100% { transform: translateY(0) rotate(0.6deg); }
    50%      { transform: translateY(-0.7vh) rotate(-0.6deg); }
}

/* FX layer (droplet bursts) */
#fx-layer { z-index: 18; }

.droplet {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50% 50% 50% 0;
    background: linear-gradient(135deg, #aee6ff, var(--water));
    transform: rotate(-45deg);
    opacity: 0.9;
    pointer-events: none;
}

/* === HUD cards === */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 14px 16px;
    pointer-events: none;
}

.hud-card {
    pointer-events: auto;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    backdrop-filter: blur(var(--card-blur));
    -webkit-backdrop-filter: blur(var(--card-blur));
    box-shadow: var(--shadow-soft);
    padding: 10px 16px;
}

#day-display .day-row {
    display: flex;
    align-items: baseline;
    gap: 7px;
    white-space: nowrap;
}

#day-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.75;
}

#day-number {
    font-size: 2.1rem;
    font-weight: 800;
    line-height: 1.05;
    color: #a5d6a7;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

#day-total {
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.6;
}

#day-progress {
    margin-top: 7px;
    width: 128px;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.16);
    overflow: hidden;
}

#day-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent-deep), #9ccc65);
    transition: width 1s ease;
}

#weather-display {
    display: flex;
    align-items: center;
    gap: 10px;
}

#weather-icon-display {
    display: flex;
    align-items: center;
    line-height: 0;
}

#weather-icon-display svg {
    width: 34px;
    height: 34px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

#weather-details {
    display: flex;
    flex-direction: column;
}

#weather-temp {
    font-size: 1.15rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

#weather-desc {
    font-size: 0.72rem;
    font-weight: 600;
    opacity: 0.7;
    text-transform: capitalize;
}

/* === Bottom dock === */
#dock {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0 16px calc(58px + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}

.timer-pill {
    pointer-events: auto;
    display: flex;
    align-items: baseline;
    gap: 8px;
    align-self: center;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 999px;
    backdrop-filter: blur(var(--card-blur));
    -webkit-backdrop-filter: blur(var(--card-blur));
    padding: 8px 20px;
    box-shadow: var(--shadow-soft);
}

#timer-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    opacity: 0.75;
}

#timer-value {
    font-size: 1.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

#timer-value.ready { color: var(--gold); }

/* === Water Button === */
#water-area {
    width: 100%;
    max-width: 900px;
    display: flex;
    pointer-events: none;
}

.water-button {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 30px;
    font-size: 1.15rem;
    font-weight: 800;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(160deg, var(--water), var(--water-deep));
    box-shadow: 0 6px 22px rgba(41, 163, 232, 0.45),
                inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: transform 0.25s ease, box-shadow 0.25s ease,
                filter 0.25s ease, margin 0.6s ease;
}

.water-button:not(:disabled) {
    animation: button-breathe 2.4s ease-in-out infinite;
}

@keyframes button-breathe {
    0%, 100% { box-shadow: 0 6px 22px rgba(41, 163, 232, 0.4), inset 0 1px 0 rgba(255,255,255,0.35); }
    50%      { box-shadow: 0 6px 34px rgba(79, 195, 247, 0.75), inset 0 1px 0 rgba(255,255,255,0.35); }
}

.water-button:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.03);
}

.water-button:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

.water-button:disabled {
    background: linear-gradient(160deg, #5c6b60, #46524a);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    cursor: default;
    opacity: 0.85;
    animation: none;
}

.water-button.success {
    background: linear-gradient(160deg, #81c784, var(--accent-deep));
    animation: splash 0.6s ease;
}

@keyframes splash {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.water-icon {
    display: flex;
    line-height: 0;
    color: rgba(255, 255, 255, 0.95);
}

/* The button wanders along the dock each hour — part of the game */
.water-button.pos-0 { margin-right: auto; margin-left: 2%; }
.water-button.pos-1 { margin-right: auto; margin-left: 16%; }
.water-button.pos-2 { margin-right: auto; margin-left: 30%; }
.water-button.pos-3 { margin-left: auto; margin-right: auto; }
.water-button.pos-4 { margin-left: 30%;  margin-right: auto; }
.water-button.pos-5 { margin-left: auto; margin-right: 16%; }
.water-button.pos-6 { margin-left: auto; margin-right: 2%; }
.water-button.pos-7 { margin-left: auto; margin-right: auto; }

/* === Share button === */
#share-btn {
    pointer-events: auto;
    padding: 8px 20px;
    font-size: 0.85rem;
    font-weight: 700;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    background: var(--card-bg);
    backdrop-filter: blur(var(--card-blur));
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s ease;
}

#share-btn:hover {
    border-color: var(--accent);
    color: #c8e6c9;
}

/* === Status toast === */
#status-message {
    position: absolute;
    bottom: 235px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    z-index: 30;
    max-width: min(86vw, 420px);
    text-align: center;
    padding: 11px 22px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 999px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(var(--card-blur));
    box-shadow: var(--shadow-soft);
    opacity: 0;
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

#status-message.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#status-message.success { color: #a5d6a7; border-color: rgba(102, 187, 106, 0.5); }
#status-message.error   { color: #ef9a9a; border-color: rgba(229, 115, 115, 0.5); }

/* === Overlays === */
#dead-overlay, #celebration-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
}

#dead-overlay {
    background: radial-gradient(ellipse at center,
        rgba(30, 12, 8, 0.55) 0%, rgba(12, 5, 3, 0.88) 100%);
    backdrop-filter: blur(3px);
}

#celebration-overlay {
    background: radial-gradient(ellipse at center,
        rgba(20, 30, 8, 0.45) 0%, rgba(8, 14, 4, 0.85) 100%);
    backdrop-filter: blur(3px);
}

.overlay-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    backdrop-filter: blur(var(--card-blur));
    box-shadow: var(--shadow-soft);
    padding: 38px 44px;
    max-width: 480px;
}

.overlay-emoji {
    font-size: 3.2rem;
    margin-bottom: 10px;
}

#dead-overlay h2 {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--danger);
    margin-bottom: 12px;
}

#celebration-overlay h2 {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--gold);
    margin-bottom: 12px;
}

.overlay-card p {
    font-size: 1.05rem;
    margin-bottom: 10px;
    opacity: 0.85;
}

#dead-countdown {
    font-size: 1.5rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--danger);
}

#rebirth-btn {
    margin-top: 20px;
    padding: 15px 38px;
    font-size: 1.2rem;
    font-weight: 800;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    background: linear-gradient(160deg, #81c784, var(--accent-deep));
    color: white;
    box-shadow: 0 6px 22px rgba(76, 175, 80, 0.4);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#rebirth-btn:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 8px 30px rgba(76, 175, 80, 0.55);
}

/* Confetti */
#confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -10px;
    animation: confetti-fall 3s linear infinite;
}

@keyframes confetti-fall {
    to { transform: translateY(110vh) rotate(720deg); }
}

/* === Sound toggle === */
.music-btn {
    position: fixed;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    right: 14px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    backdrop-filter: blur(var(--card-blur));
    cursor: pointer;
    font-size: 1.15rem;
    z-index: 50;
    transition: transform 0.2s ease, background 0.3s;
}

.music-btn:hover {
    transform: scale(1.08);
    background: rgba(18, 28, 22, 0.75);
}

/* === Navigation === */
#main-nav {
    position: fixed;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    left: 14px;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 14px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 999px;
    backdrop-filter: blur(var(--card-blur));
}

#main-nav a {
    color: var(--text-light);
    text-decoration: none;
    opacity: 0.75;
    transition: opacity 0.3s;
    font-size: 0.82rem;
    font-weight: 700;
}

#main-nav a:hover { opacity: 1; }

#donate-button-container {
    display: flex;
    align-items: center;
    opacity: 0.75;
    transition: opacity 0.3s;
}

#donate-button-container:hover { opacity: 1; }

/* === Footer === */
footer {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 68px;
    z-index: 20;
    opacity: 0.45;
    font-size: 0.72rem;
}

footer a {
    color: #a5d6a7;
    text-decoration: none;
}

footer a:hover { text-decoration: underline; }

/* === Utility === */
.hidden { display: none !important; }

/* === Responsive === */
@media (max-width: 640px) {
    :root { --ground-line: 17%; }

    #hud { padding: 10px; flex-wrap: wrap; }

    .timer-pill { order: 3; width: 100%; justify-content: center; margin-top: 6px; }

    .hud-card { padding: 8px 12px; border-radius: 14px; }

    #day-number { font-size: 1.6rem; }
    #day-progress { width: 92px; }

    #weather-icon-display svg { width: 28px; height: 28px; }
    #weather-temp { font-size: 1rem; }

    #tree-image { max-width: 80vw; }
    #tree-anchor { height: 62vh; }

    #dock { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

    .water-button { padding: 14px 24px; font-size: 1.02rem; }

    /* On small screens the wander stays reachable */
    .water-button.pos-1, .water-button.pos-2 { margin-left: 8%; }
    .water-button.pos-4, .water-button.pos-5 { margin-right: 8%; }

    .overlay-card { padding: 28px 24px; }
    #dead-overlay h2, #celebration-overlay h2 { font-size: 1.7rem; }

    footer { display: none; }
}
