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

:root {
    --bg: #f6fbff;
    --ink: #233044;
    --muted: #66758b;
    --panel: rgba(255, 255, 255, 0.86);
    --line: rgba(45, 68, 95, 0.15);
    --green: #3dbb78;
    --orange: #f3a63a;
    --blue: #4d8fe8;
    --red: #ef5f72;
}

body {
    min-height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 18% 10%, rgba(255, 213, 122, 0.42), transparent 28%),
        radial-gradient(circle at 78% 18%, rgba(111, 197, 255, 0.42), transparent 30%),
        linear-gradient(180deg, #dff4ff 0%, #f9fcf4 56%, #e8f8d6 100%);
}

.app {
    width: 100%;
    min-height: 100vh;
    padding: clamp(16px, 2.4vw, 32px);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.topbar,
.problem-panel,
.workspace,
.summary,
.formula {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 18px 40px rgba(54, 90, 120, 0.12);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    border-radius: 18px;
    padding: 18px 22px;
}

.topbar h1 {
    font-size: clamp(1.8rem, 3vw, 3rem);
    letter-spacing: 0;
}

.topbar p,
.formula p,
.cage-header p {
    color: var(--muted);
    line-height: 1.55;
}

.back-link,
.button {
    border: 0;
    border-radius: 12px;
    padding: 11px 16px;
    background: #ecf3fa;
    color: var(--ink);
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform 160ms ease, filter 160ms ease;
}

.button:hover,
.back-link:hover,
.animal-card:hover {
    transform: translateY(-2px);
    filter: brightness(1.03);
}

.primary,
.verify {
    margin-left: auto;
    background: linear-gradient(135deg, var(--green), #1f9b64);
    color: white;
}

.problem-panel {
    border-radius: 18px;
    padding: 18px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.metric,
.summary > div {
    border-radius: 14px;
    padding: 16px;
    background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(245,250,255,0.9));
    border: 1px solid var(--line);
}

.metric span,
.summary span {
    display: block;
    color: var(--muted);
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.metric strong,
.summary strong {
    font-size: 2rem;
}

.answer-state.ok strong {
    color: var(--green);
}

.answer-state.bad strong {
    color: var(--red);
}

.workspace {
    flex: 1 1 auto;
    min-height: 430px;
    border-radius: 18px;
    padding: 18px;
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 18px;
}

.toolbox {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.animal-card {
    min-height: 145px;
    border: 2px solid transparent;
    border-radius: 16px;
    background: #fff8e8;
    color: var(--ink);
    cursor: pointer;
    display: grid;
    place-items: center;
    gap: 3px;
    font-weight: 900;
}

.animal-card.active {
    border-color: var(--orange);
    box-shadow: 0 0 0 4px rgba(243, 166, 58, 0.18);
}

.animal-card small {
    color: var(--muted);
    font-weight: 700;
}

.animal-preview {
    width: 74px;
    height: 74px;
    background-position: center bottom;
    background-size: contain;
    background-repeat: no-repeat;
}

.chicken {
    background-image: url("assets/chicken-idle.webp");
}

.rabbit {
    background-image: url("assets/rabbit-idle.webp");
}

.tool-actions {
    display: grid;
    gap: 10px;
    margin-top: auto;
}

.cage-wrap {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cage-header {
    display: flex;
    align-items: center;
    gap: 14px;
}

.cage-header h2,
.formula h2 {
    font-size: 1.35rem;
}

.cage {
    flex: 1 1 auto;
    min-height: 340px;
    border-radius: 18px;
    border: 4px solid #b88743;
    background:
        linear-gradient(90deg, rgba(120, 80, 38, 0.18) 1px, transparent 1px) 0 0 / 58px 100%,
        linear-gradient(180deg, rgba(104, 68, 29, 0.12) 1px, transparent 1px) 0 0 / 100% 72px,
        linear-gradient(180deg, #fff7d8 0%, #eac47c 100%);
    box-shadow: inset 0 0 0 10px rgba(255,255,255,0.28);
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
    align-content: end;
    gap: 10px 8px;
    overflow: auto;
}

.cage-animal {
    height: 104px;
    border: 0;
    background-color: transparent;
    background-position: center bottom;
    background-repeat: no-repeat;
    background-size: contain;
    cursor: pointer;
    filter: drop-shadow(0 7px 7px rgba(90, 58, 28, 0.24));
    animation: enter 220ms ease-out;
}

.cage-animal.chicken {
    background-image: url("assets/chicken-idle.webp");
}

.cage-animal.rabbit {
    height: 114px;
    background-image: url("assets/rabbit-idle.webp");
}

@keyframes enter {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.88);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.summary {
    border-radius: 18px;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.formula {
    border-radius: 18px;
    padding: 18px 20px;
}

.formula h2 {
    margin-bottom: 8px;
}

@media (max-width: 820px) {
    .topbar,
    .cage-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .primary,
    .verify {
        margin-left: 0;
    }

    .problem-panel,
    .summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .workspace {
        grid-template-columns: 1fr;
    }

    .toolbox {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tool-actions {
        grid-column: 1 / -1;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .problem-panel,
    .summary,
    .toolbox,
    .tool-actions {
        grid-template-columns: 1fr;
    }
}
