/* ══════════════════════════════════════════════════════════════════
   Petalcraft — Phase 1 MVP styles
   Cozy, warm palette. DOM grid + CSS-shape flowers (no art assets yet).
   ══════════════════════════════════════════════════════════════════ */

:root {
    --cream: #F7EFDD;
    --cream-warm: #FBEFDA;
    --cream-shade: #EFE4CB;
    --ink: #4A3F2E;
    --ink-soft: #6E5F45;
    --soil: #B6906A;
    --soil-dark: #8A6947;
    --grass: #A7C079;
    --grass-dark: #7A9557;
    --accent: #C7654E;   /* warm terracotta */
    --accent-soft: #E9A88F;
    --sky-day:  #DDE9E6;
    --sky-dusk: #E5C4A4;
    --sky-night: #8892A6;
    --water: #7EB0C4;

    /* Flower colors — the phenotype palette. Muted, storybook. */
    --f-white:  #F3EEE0;
    --f-yellow: #F1D65C;
    --f-red:    #C94E4E;
    --f-pink:   #E89AB2;
    --f-orange: #E9925A;
    --f-purple: #9B7BC0;
    --f-black:  #46424C;

    --radius: 14px;
    --tile-gap: 6px;
    --tap: 44px;    /* min touch target */

    color-scheme: light;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--cream);
    color: var(--ink);
    font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-weight: 500;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* Back-to-Madderverse ⌂ button — matches other games */
.madder-home {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 100;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: var(--cream-warm);
    color: var(--ink);
    border-radius: 50%;
    text-decoration: none;
    font-size: 22px;
    box-shadow: 0 2px 6px rgba(74, 63, 46, 0.15);
    border: 1px solid var(--cream-shade);
}

/* ─── App shell ─────────────────────────────────────────────────── */

.app {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    max-width: 480px;
    width: 100%;
    margin: 0 auto;
    padding: 8px 12px 12px;
    gap: 10px;
}

/* ─── Topbar ───────────────────────────────────────────────────── */

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 6px 8px 6px 52px;   /* leave room for the home ⌂ */
    min-height: var(--tap);
}

.topbar-title {
    font-family: "Fraunces", "Georgia", serif;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.5px;
    color: var(--ink);
    justify-self: start;
}

.topbar-clock {
    justify-self: center;
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: "Fraunces", "Georgia", serif;
    color: var(--ink-soft);
    background: var(--cream-warm);
    border: 1px solid var(--cream-shade);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 13px;
}

.clock-time {
    font-style: italic;
    opacity: 0.75;
}

.topbar-btn {
    justify-self: end;
    width: var(--tap);
    height: var(--tap);
    border-radius: 999px;
    border: 1px solid var(--cream-shade);
    background: var(--cream-warm);
    font-size: 20px;
    cursor: pointer;
}
.topbar-btn:active { transform: scale(0.96); }

/* ─── Garden grid ──────────────────────────────────────────────── */

.garden-wrap {
    flex: 1 1 auto;
    display: grid;
    place-items: center;
    padding: 10px 4px;
    background:
        radial-gradient(ellipse at center top, var(--cream-warm), var(--cream) 65%);
    border-radius: var(--radius);
    transition: background 800ms ease;
}

.garden-wrap.night {
    background:
        radial-gradient(ellipse at center top, #C2C3D4, #A9AABD 65%);
}
.garden-wrap.dusk {
    background:
        radial-gradient(ellipse at center top, #F0D4B4, #E3B896 65%);
}

.garden {
    display: grid;
    grid-template-columns: repeat(var(--gw, 6), 1fr);
    gap: var(--tile-gap);
    width: min(100%, 420px);
    aspect-ratio: var(--gw, 6) / var(--gh, 4);
}

.tile {
    aspect-ratio: 1 / 1;
    background: var(--soil);
    border-radius: 10px;
    position: relative;
    display: grid;
    place-items: center;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
    transition: transform 120ms ease;
    touch-action: manipulation;
    user-select: none;
}
.tile:active { transform: scale(0.97); }
.tile.watered {
    background: linear-gradient(180deg, var(--soil-dark), var(--soil));
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15), inset 0 0 0 2px rgba(126, 176, 196, 0.35);
}
.tile.plant-target {
    outline: 2px dashed var(--accent);
    outline-offset: -3px;
}

/* Water droplet indicator */
.tile.watered::after {
    content: "";
    position: absolute;
    top: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    background: var(--water);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    opacity: 0.85;
}

/* ─── Flower shapes (CSS-only, no images for MVP) ──────────────── */

.flower {
    width: 78%;
    height: 78%;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.flower[data-stage="0"] .fl-body {   /* seed */
    width: 22%;
    height: 22%;
    background: #6B4A2E;
    border-radius: 40% 60% 60% 40%;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.25);
}

.flower[data-stage="1"] .fl-body {   /* sprout */
    width: 12%;
    height: 60%;
    background: linear-gradient(180deg, var(--grass), var(--grass-dark));
    border-radius: 40% 40% 4px 4px;
    transform-origin: bottom center;
}
.flower[data-stage="1"] .fl-body::before {
    content: "";
    position: absolute;
    top: 12%;
    left: -80%;
    width: 60%;
    height: 30%;
    background: var(--grass);
    border-radius: 60% 10% 60% 10%;
    transform: rotate(-25deg);
}
.flower[data-stage="1"] .fl-body::after {
    content: "";
    position: absolute;
    top: 22%;
    right: -80%;
    width: 60%;
    height: 30%;
    background: var(--grass);
    border-radius: 10% 60% 10% 60%;
    transform: rotate(25deg);
}
.flower[data-stage="1"] .fl-body { position: relative; }

.flower[data-stage="2"] .fl-body {   /* bud */
    width: 40%;
    height: 60%;
    background: var(--fc, var(--f-red));
    border-radius: 50% 50% 40% 40% / 60% 60% 30% 30%;
    position: relative;
}
.flower[data-stage="2"] .fl-body::after {
    content: "";
    position: absolute;
    bottom: -25%;
    left: 30%;
    width: 40%;
    height: 40%;
    background: var(--grass-dark);
    border-radius: 40% 40% 10% 10%;
}

.flower[data-stage="3"] .fl-body {   /* bloom — 5 petal SVG-ish flower */
    position: relative;
    width: 78%;
    height: 78%;
}
.flower[data-stage="3"] .petal {
    position: absolute;
    width: 45%;
    height: 45%;
    background: var(--fc, var(--f-red));
    border-radius: 60% 20% 60% 20%;
    top: 27.5%;
    left: 27.5%;
    transform-origin: 50% 100%;
    box-shadow: inset -2px -2px 0 rgba(0,0,0,0.08);
}
.flower[data-stage="3"] .petal:nth-child(1) { transform: rotate(0deg); }
.flower[data-stage="3"] .petal:nth-child(2) { transform: rotate(72deg); }
.flower[data-stage="3"] .petal:nth-child(3) { transform: rotate(144deg); }
.flower[data-stage="3"] .petal:nth-child(4) { transform: rotate(216deg); }
.flower[data-stage="3"] .petal:nth-child(5) { transform: rotate(288deg); }
.flower[data-stage="3"] .center {
    position: absolute;
    width: 26%;
    height: 26%;
    top: 37%;
    left: 37%;
    border-radius: 50%;
    background: #F5D97E;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.15);
}
/* Tulip: single cup silhouette instead of 5-petal disc */
.flower[data-stage="3"][data-species="tulips"] .petal:nth-child(1),
.flower[data-stage="3"][data-species="tulips"] .petal:nth-child(2),
.flower[data-stage="3"][data-species="tulips"] .petal:nth-child(3),
.flower[data-stage="3"][data-species="tulips"] .petal:nth-child(4),
.flower[data-stage="3"][data-species="tulips"] .petal:nth-child(5) { display: none; }
.flower[data-stage="3"][data-species="tulips"] .center { display: none; }
.flower[data-stage="3"][data-species="tulips"] .fl-body::before {
    content: "";
    position: absolute;
    left: 30%;
    top: 8%;
    width: 40%;
    height: 55%;
    background: var(--fc, var(--f-red));
    border-radius: 50% 50% 30% 30% / 70% 70% 30% 30%;
    box-shadow: inset -3px -3px 0 rgba(0,0,0,0.10);
}
.flower[data-stage="3"][data-species="tulips"] .fl-body::after {
    content: "";
    position: absolute;
    left: 46%;
    top: 55%;
    width: 8%;
    height: 40%;
    background: var(--grass-dark);
    border-radius: 4px;
}

/* Night: all flowers pull petals in (opacity dim) */
.garden-wrap.night .flower[data-stage="3"] { opacity: 0.72; transform: scale(0.85); transition: transform 400ms ease, opacity 400ms ease; }

/* Discovery sparkle (used on new-hybrid tile briefly) */
.tile.new-hybrid {
    animation: sparkle 1200ms ease-out;
}
@keyframes sparkle {
    0%   { box-shadow: 0 0 0 0 rgba(233, 168, 143, 0.9), inset 0 -2px 0 rgba(0,0,0,0.08); }
    60%  { box-shadow: 0 0 0 12px rgba(233, 168, 143, 0), inset 0 -2px 0 rgba(0,0,0,0.08); }
    100% { box-shadow: inset 0 -2px 0 rgba(0,0,0,0.08); }
}

/* ─── Bottom tray ─────────────────────────────────────────────── */

.tray {
    background: var(--cream-warm);
    border-radius: var(--radius);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--cream-shade);
}

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

.tray-btn {
    flex: 1;
    min-height: var(--tap);
    border-radius: 999px;
    background: var(--cream);
    border: 1px solid var(--cream-shade);
    color: var(--ink);
    font-family: inherit;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    padding: 0 12px;
}
.tray-btn:active { transform: scale(0.97); }
.tray-btn-primary {
    background: var(--water);
    color: white;
    border-color: transparent;
}
.tray-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.tray-seeds {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 44px;
}

.seed-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--cream);
    border: 1px solid var(--cream-shade);
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    color: var(--ink);
    font-weight: 700;
    user-select: none;
    transition: transform 100ms ease;
}
.seed-chip:active { transform: scale(0.96); }
.seed-chip.armed {
    background: var(--accent);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(199, 101, 78, 0.35);
}
.seed-chip .swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--sw, #ccc);
    border: 1px solid rgba(0,0,0,0.15);
}
.seed-chip .count {
    opacity: 0.7;
    font-weight: 500;
}

.tray-hint {
    text-align: center;
    font-size: 12px;
    color: var(--ink-soft);
    font-style: italic;
    min-height: 16px;
}

/* ─── Modal (Bloombook) ────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(74, 63, 46, 0.35);
    display: grid;
    place-items: center;
    z-index: 200;
    padding: 16px;
    animation: fade-in 180ms ease;
}
.modal[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    background: var(--cream);
    border-radius: var(--radius);
    max-width: 460px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--cream-shade);
}
.modal-head h2 {
    margin: 0;
    font-family: "Fraunces", "Georgia", serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
}
.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: none;
    background: var(--cream-warm);
    font-size: 16px;
    cursor: pointer;
}

.bloombook-tabs {
    display: flex;
    gap: 6px;
    padding: 10px 14px 6px;
    overflow-x: auto;
}
.bloombook-tab {
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--cream-warm);
    border: 1px solid var(--cream-shade);
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}
.bloombook-tab.active {
    background: var(--accent);
    color: white;
    border-color: transparent;
}

.bloombook-body {
    padding: 12px 16px 18px;
    overflow-y: auto;
    flex: 1 1 auto;
}
.dex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 10px;
}
.dex-slot {
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    background: var(--cream-warm);
    border: 1px solid var(--cream-shade);
    display: grid;
    place-items: center;
    position: relative;
    font-size: 11px;
    color: var(--ink-soft);
    padding: 4px;
    text-align: center;
}
.dex-slot.filled {
    background: var(--cream);
    border-color: var(--accent-soft);
}
.dex-slot .dex-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--sw, #ccc);
    margin-bottom: 4px;
    border: 1px solid rgba(0,0,0,0.15);
}
.dex-slot.unfilled .dex-swatch {
    background: transparent;
    border: 2px dashed var(--cream-shade);
}
.dex-slot .dex-label {
    font-weight: 700;
    color: var(--ink);
    font-size: 10px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.dex-slot.unfilled .dex-label { opacity: 0.5; }

.dex-note {
    color: var(--ink-soft);
    font-size: 12px;
    margin: 0 0 10px;
    font-style: italic;
}

/* ─── Toast ───────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--cream);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    z-index: 300;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    animation: toast-in 240ms ease-out;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
    from { transform: translate(-50%, 20px); opacity: 0; }
    to   { transform: translate(-50%, 0); opacity: 1; }
}

/* ─── Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
