:root {
    --bg-top: #1a3a45;
    --bg-bottom: #0d2229;
    --panel: rgba(255, 247, 236, 0.95);
    --ink: #1f2a2e;
    --muted: #5c6b71;
    --accent: #f08a4b;
    --accent-2: #3cb8a9;
    --danger: #e25c5c;
    --warn: #e4a01a;
    --bar-bg: #e7ddd2;
    --cat: #f2a65a;
    --cat-dark: #d4843a;
    --cat-light: #ffe0b8;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --radius: 22px;
    --font-display: "Fredoka", system-ui, sans-serif;
    --font-body: "Nunito", system-ui, sans-serif;
}

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

body {
    min-height: 100vh;
    font-family: var(--font-body);
    color: var(--ink);
    background:
        radial-gradient(ellipse 80% 50% at 20% 10%, rgba(240, 138, 75, 0.22), transparent 50%),
        radial-gradient(ellipse 70% 45% at 90% 80%, rgba(60, 184, 169, 0.18), transparent 45%),
        linear-gradient(165deg, var(--bg-top), var(--bg-bottom));
    display: grid;
    place-items: center;
    padding: 0.75rem;
}

.app {
    width: min(440px, 100%);
    max-height: calc(100vh - 1.5rem);
    overflow: auto;
    background: var(--panel);
    border-radius: 28px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem 1.15rem 0.5rem;
    gap: 0.75rem;
}

.eyebrow {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}

h1 {
    font-family: var(--font-display);
    font-size: 1.7rem;
    line-height: 1;
}

.meta {
    text-align: right;
    display: grid;
    gap: 0.2rem;
    font-weight: 800;
    font-size: 0.78rem;
    justify-items: end;
}

.coins {
    background: #fff4e4;
    border: 1px solid #f0d7b0;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    color: var(--accent);
}

.stage-pill {
    background: rgba(60, 184, 169, 0.15);
    color: #1f7a70;
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.3rem;
    padding: 0 0.85rem 0.65rem;
}

.tab {
    border: none;
    background: #efe6da;
    color: var(--muted);
    font: inherit;
    font-weight: 800;
    font-size: 0.75rem;
    padding: 0.5rem 0.2rem;
    border-radius: 12px;
    cursor: pointer;
}

.tab.active {
    background: var(--accent-2);
    color: #fff;
}

.panel { display: none; padding: 0 0.85rem 0.75rem; }
.panel.active { display: block; }
.panel-hint {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 0.65rem;
}

.stage {
    position: relative;
    height: 240px;
    border-radius: var(--radius);
    overflow: hidden;
    background: linear-gradient(180deg, #87c5c0 0%, #f7e7c8 55%, #efd7b0 100%);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
    margin-bottom: 0.75rem;
}

.window { position: absolute; inset: 0; pointer-events: none; }

.sky {
    position: absolute;
    inset: 0 0 35% 0;
    background:
        radial-gradient(circle at 78% 28%, rgba(255, 255, 220, 0.95) 0 10%, transparent 11%),
        linear-gradient(180deg, #6eb8d6, #b8e0d8 60%, transparent);
    transition: 0.5s ease;
}

.stage.night .sky {
    background:
        radial-gradient(circle at 72% 30%, #fff8d6 0 4%, transparent 5%),
        radial-gradient(circle at 20% 40%, rgba(255,255,255,0.7) 0 1px, transparent 2px),
        linear-gradient(180deg, #1b2d4a, #3d4f6b 70%, transparent);
}

.stage.night {
    background: linear-gradient(180deg, #243449 0%, #3a4658 50%, #4a3f38 100%);
}

.sill {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 38%;
    background:
        linear-gradient(180deg, transparent, rgba(0,0,0,0.05) 20%),
        repeating-linear-gradient(90deg, #d9b48a 0 28px, #cda578 28px 30px);
}

.status-chips {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.chip {
    font-size: 0.68rem;
    font-weight: 800;
    background: rgba(255,255,255,0.9);
    border-radius: 999px;
    padding: 0.2rem 0.45rem;
}

.chip.danger { background: #ffe1e1; color: var(--danger); }
.chip.warn { background: #fff0d0; color: #9a6400; }

.pet-wrap {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    place-content: center;
    gap: 0.15rem;
    z-index: 2;
}

.speech {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 0.35rem 0.65rem;
    border-radius: 14px;
    font-size: 0.78rem;
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
    white-space: nowrap;
    animation: pop 0.35s ease;
    z-index: 5;
}

.speech::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #fff;
}

.pet-name {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
}

.xp-line {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
}

.stage.night .pet-name,
.stage.night .xp-line { color: #f6efe6; }

.cat {
    --coat: var(--cat);
    --coat-dark: var(--cat-dark);
    --coat-light: var(--cat-light);
    position: relative;
    width: 140px;
    height: 150px;
    animation: breathe 2.8s ease-in-out infinite;
    transition: transform 0.3s ease, filter 0.3s ease;
}

.cat[data-stage="kitten"] { --stage-scale: 0.78; }
.cat[data-stage="teen"] { --stage-scale: 0.92; }
.cat[data-stage="adult"] { --stage-scale: 1; }
.cat[data-stage="senior"] { --stage-scale: 1.05; filter: saturate(0.85); }

.cat[data-coat="orange"] { --coat: #f2a65a; --coat-dark: #d4843a; --coat-light: #ffe0b8; }
.cat[data-coat="gray"] { --coat: #9aa3ad; --coat-dark: #6f7883; --coat-light: #e5e9ed; }
.cat[data-coat="black"] { --coat: #3d3a3a; --coat-dark: #231f1f; --coat-light: #8a8484; }
.cat[data-coat="calico"] { --coat: #e8b07a; --coat-dark: #c46b4a; --coat-light: #fff0dc; }
.cat[data-coat="white"] { --coat: #f4f1ea; --coat-dark: #d5cfc4; --coat-light: #ffffff; }

.cat.eating { animation: bounce 0.45s ease 2; }
.cat.playing { animation: wiggle 0.5s ease 3; }
.cat.sleeping { animation: none; filter: brightness(0.85); }
.cat.washing { animation: shake 0.4s ease 2; }
.cat.petting { animation: bounce 0.35s ease 2; }
.cat.sad { filter: grayscale(0.2) brightness(0.95); }
.cat.sick { filter: hue-rotate(-25deg) saturate(0.65); animation: limp 1.6s ease-in-out infinite; }

.ear {
    position: absolute;
    top: 8px;
    width: 0; height: 0;
    border-left: 18px solid transparent;
    border-right: 18px solid transparent;
    border-bottom: 32px solid var(--coat);
    z-index: 1;
}
.ear::after {
    content: "";
    position: absolute;
    left: -10px; top: 10px;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 18px solid #f7b7a0;
}
.ear.left { left: 18px; transform: rotate(-12deg); }
.ear.right { right: 18px; transform: rotate(12deg); }

.head {
    position: absolute;
    top: 28px; left: 50%;
    transform: translateX(-50%);
    width: 96px; height: 78px;
    background: var(--coat);
    border-radius: 48% 48% 42% 42%;
    z-index: 2;
    box-shadow: inset 0 -8px 0 rgba(0,0,0,0.05);
}

.eye {
    position: absolute;
    top: 30px;
    width: 16px; height: 16px;
    background: #1f2a2e;
    border-radius: 50%;
    overflow: hidden;
}
.eye span {
    display: block;
    width: 6px; height: 6px;
    background: #fff;
    border-radius: 50%;
    margin: 3px 0 0 3px;
}
.eye.left { left: 22px; }
.eye.right { right: 22px; }

.cat.sleeping .eye,
.cat[data-mood="sleep"] .eye {
    height: 3px; top: 36px; border-radius: 2px;
}
.cat.sleeping .eye span,
.cat[data-mood="sleep"] .eye span { display: none; }

.blush {
    position: absolute;
    top: 42px;
    width: 12px; height: 7px;
    background: rgba(255, 120, 140, 0.35);
    border-radius: 50%;
}
.blush.left { left: 12px; }
.blush.right { right: 12px; }

.nose {
    position: absolute;
    left: 50%; top: 46px;
    transform: translateX(-50%);
    width: 12px; height: 9px;
    background: #e57a8a;
    border-radius: 40% 40% 55% 55%;
}

.mouth {
    position: absolute;
    left: 50%; top: 54px;
    width: 18px; height: 8px;
    margin-left: -9px;
    border-bottom: 2px solid #b45a3a;
    border-radius: 0 0 10px 10px;
}

.cat[data-mood="sad"] .mouth,
.cat[data-mood="sick"] .mouth {
    border-bottom: none;
    border-top: 2px solid #b45a3a;
    top: 58px;
    border-radius: 10px 10px 0 0;
}

.whisker {
    position: absolute;
    top: 50px;
    width: 28px; height: 2px;
    background: rgba(80, 50, 30, 0.45);
    border-radius: 2px;
}
.w1 { left: 4px; transform: rotate(12deg); }
.w2 { left: 4px; top: 56px; transform: rotate(-8deg); }
.w3 { right: 4px; transform: rotate(-12deg); }
.w4 { right: 4px; top: 56px; transform: rotate(8deg); }

.body {
    position: absolute;
    bottom: 8px; left: 50%;
    transform: translateX(-50%);
    width: 110px; height: 72px;
    background: var(--coat);
    border-radius: 48% 48% 40% 40%;
    z-index: 1;
}

.belly {
    position: absolute;
    left: 50%; bottom: 10px;
    transform: translateX(-50%);
    width: 58px; height: 42px;
    background: var(--coat-light);
    border-radius: 50%;
}

.paw {
    position: absolute;
    bottom: -4px;
    width: 28px; height: 18px;
    background: var(--coat-dark);
    border-radius: 40% 40% 45% 45%;
}
.paw.left { left: 18px; }
.paw.right { right: 18px; }

.collar {
    position: absolute;
    left: 50%; top: 8px;
    transform: translateX(-50%);
    width: 54px; height: 10px;
    border-radius: 999px;
    background: #3cb8a9;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}
.collar.gold { background: linear-gradient(90deg, #f0c35a, #e0892f); }
.collar.pink { background: #ef7aa8; }
.collar.blue { background: #5b8def; }

.tail {
    position: absolute;
    right: -6px; bottom: 40px;
    width: 44px; height: 14px;
    background: var(--coat);
    border-radius: 20px;
    transform-origin: left center;
    animation: tail 2.2s ease-in-out infinite;
    z-index: 0;
}
.cat.sleeping .tail { animation: none; }

.poops {
    position: absolute;
    bottom: 42px;
    left: 18px;
    display: flex;
    gap: 0.2rem;
    font-size: 1rem;
    z-index: 3;
}

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.fx span {
    position: absolute;
    font-size: 1.35rem;
    animation: float-up 0.9s ease forwards;
}

.stats {
    display: grid;
    gap: 0.4rem;
    margin-bottom: 0.7rem;
}

.stat-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 800;
    margin-bottom: 0.12rem;
    color: var(--muted);
}
.stat-head b { color: var(--ink); }

.bar {
    height: 8px;
    background: var(--bar-bg);
    border-radius: 999px;
    overflow: hidden;
}
.bar i {
    display: block;
    height: 100%;
    width: 80%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-2), #62d4a8);
    transition: width 0.35s ease, background 0.35s ease;
}
.stat[data-warn="1"] .bar i { background: linear-gradient(90deg, #f0b429, var(--accent)); }
.stat[data-warn="2"] .bar i { background: linear-gradient(90deg, var(--accent), var(--danger)); }
.stat[data-stat="health"] .bar i { background: linear-gradient(90deg, #ef7aa8, #e25c5c); }

.actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.action {
    border: none;
    background: #fff;
    border-radius: 16px;
    padding: 0.55rem 0.2rem;
    display: grid;
    gap: 0.15rem;
    place-items: center;
    cursor: pointer;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.68rem;
    color: var(--ink);
    box-shadow: 0 5px 0 #e5d8c8;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.action:hover { transform: translateY(-2px); }
.action:active { transform: translateY(3px); box-shadow: 0 2px 0 #e5d8c8; }
.action:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.action .icon { font-size: 1.2rem; line-height: 1; }

.log-box {
    background: #fff;
    border-radius: 16px;
    padding: 0.65rem 0.75rem;
    border: 1px solid #eadfce;
    max-height: 110px;
    overflow: auto;
}
.log-title {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    margin-bottom: 0.35rem;
}
#log-list {
    list-style: none;
    display: grid;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 700;
}
#log-list li { color: var(--ink); opacity: 0.85; }

.item-grid {
    display: grid;
    gap: 0.5rem;
}

.item-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.65rem;
    align-items: center;
    background: #fff;
    border: 1px solid #eadfce;
    border-radius: 16px;
    padding: 0.65rem 0.75rem;
    text-align: left;
}

.item-card .ico { font-size: 1.5rem; }
.item-card h3 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
}
.item-card p {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 700;
}
.item-card .qty {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--accent-2);
}

.item-card button,
.shop-buy {
    border: none;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 800;
    font-size: 0.72rem;
    padding: 0.45rem 0.65rem;
    border-radius: 10px;
    cursor: pointer;
    white-space: nowrap;
}
.item-card button:disabled,
.shop-buy:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ach-list { display: grid; gap: 0.45rem; }
.ach-card {
    background: #fff;
    border: 1px solid #eadfce;
    border-radius: 14px;
    padding: 0.65rem 0.75rem;
    display: flex;
    gap: 0.6rem;
    align-items: center;
    opacity: 0.45;
}
.ach-card.done {
    opacity: 1;
    border-color: var(--accent-2);
    background: #f2fffc;
}
.ach-card .ico { font-size: 1.4rem; }
.ach-card h3 {
    font-size: 0.88rem;
    font-family: var(--font-display);
}
.ach-card p {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 700;
}

.bottom {
    display: flex;
    justify-content: space-between;
    padding: 0 0.85rem 1rem;
    gap: 0.45rem;
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, transparent, var(--panel) 30%);
}

.ghost, .primary {
    border: none;
    border-radius: 14px;
    padding: 0.6rem 0.85rem;
    font-family: inherit;
    font-weight: 800;
    cursor: pointer;
}
.ghost {
    background: transparent;
    color: var(--muted);
    border: 1.5px solid #d9cfc3;
}
.ghost:hover { color: var(--ink); border-color: var(--accent); }
.primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 0 #c56d35;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 20, 24, 0.55);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 30;
}
.modal[hidden] { display: none; }

.modal-card {
    width: min(360px, 100%);
    background: #fffaf3;
    border-radius: 22px;
    padding: 1.2rem;
    box-shadow: var(--shadow);
    display: grid;
    gap: 0.75rem;
}
.modal-card h2 { font-family: var(--font-display); font-size: 1.3rem; }
.modal-card p { color: var(--muted); line-height: 1.45; font-weight: 700; }
.over-stats { font-size: 0.85rem !important; color: var(--ink) !important; }
.modal-card input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    border: 1.5px solid #dccfbf;
    font: inherit;
    font-weight: 700;
}
.modal-card input:focus { outline: none; border-color: var(--accent-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

.minigame-card { width: min(380px, 100%); }
.mg-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.mg-score { font-weight: 800; }
.mg-arena {
    position: relative;
    height: 220px;
    border-radius: 18px;
    background:
        radial-gradient(circle at 30% 20%, rgba(240,138,75,0.2), transparent 40%),
        linear-gradient(180deg, #dff3ef, #f8e9d4);
    overflow: hidden;
    border: 2px solid #e4d5c0;
}
.mg-ball {
    position: absolute;
    width: 56px; height: 56px;
    border: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 6px 0 #e5d8c8;
    font-size: 1.7rem;
    cursor: pointer;
    left: 40%; top: 40%;
    transition: transform 0.08s ease;
}
.mg-ball:active { transform: scale(0.9); }

@keyframes breathe {
    0%, 100% { transform: translateY(0) scale(var(--stage-scale, 1)); }
    50% { transform: translateY(-4px) scale(var(--stage-scale, 1)); }
}

@keyframes tail {
    0%, 100% { transform: rotate(18deg); }
    50% { transform: rotate(42deg); }
}
@keyframes bounce {
    0%, 100% { transform: translateY(0) scale(var(--stage-scale, 1)); }
    50% { transform: translateY(-12px) scale(var(--stage-scale, 1)); }
}
@keyframes wiggle {
    0%, 100% { transform: rotate(0) scale(var(--stage-scale, 1)); }
    25% { transform: rotate(-8deg) scale(var(--stage-scale, 1)); }
    75% { transform: rotate(8deg) scale(var(--stage-scale, 1)); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0) scale(var(--stage-scale, 1)); }
    25% { transform: translateX(-6px) scale(var(--stage-scale, 1)); }
    75% { transform: translateX(6px) scale(var(--stage-scale, 1)); }
}
@keyframes limp {
    0%, 100% { transform: translateY(0) rotate(-2deg) scale(var(--stage-scale, 1)); }
    50% { transform: translateY(3px) rotate(2deg) scale(var(--stage-scale, 1)); }
}
@keyframes float-up {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(1.3); }
}
@keyframes pop {
    from { opacity: 0; transform: translateX(-50%) translateY(6px) scale(0.9); }
    to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@media (max-width: 420px) {
    .stage { height: 220px; }
    .actions { gap: 0.35rem; }
    .action { font-size: 0.64rem; }
}
