body {
    min-height: 100vh;
    margin: 0;
    font-family: Arial, sans-serif;
    color: #1f2937;
    background:
        radial-gradient(circle at 12% 16%, rgba(255, 214, 102, 0.26), transparent 25%),
        radial-gradient(circle at 88% 10%, rgba(80, 200, 180, 0.2), transparent 25%),
        linear-gradient(135deg, #f8fbff 0%, #eef6f0 48%, #fff7e8 100%);
}

.hierarchy-app {
    width: min(1080px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 48px;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(96px, 150px) 1fr minmax(96px, 150px);
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

h1 {
    margin: 0;
    text-align: center;
    font-size: clamp(28px, 5vw, 52px);
    color: #17324d;
}

button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(31, 41, 55, 0.12);
    transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 11px 22px rgba(31, 41, 55, 0.16);
}

.back-button {
    background: #dbeafe;
    color: #164e8b;
}

.new-button {
    background: #b8f2c6;
    color: #14532d;
}

.task-area,
.progress-wrap,
.finished {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(23, 50, 77, 0.12);
    border-radius: 8px;
    box-shadow: 0 16px 34px rgba(31, 41, 55, 0.12);
}

.exercise-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 210px;
    align-items: start;
    gap: 18px;
}

.task-area {
    padding: 28px;
    text-align: center;
}

.eyebrow {
    margin: 0 0 18px;
    font-size: 16px;
    font-weight: 700;
    color: #52616f;
}

.interactive-expression {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 130px;
    margin: 0 auto;
    overflow-x: auto;
    font-size: clamp(30px, 6vw, 62px);
    line-height: 1.45;
    white-space: nowrap;
}

.interactive-expression sup {
    position: relative;
    top: -0.38em;
    font-size: 0.48em;
    line-height: 0;
}

.number,
.plain-group {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.op-button,
.solved-op {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0.48em;
    min-height: 0.78em;
    margin: 0 0.08em;
    border: 0;
    border-radius: 4px;
    padding: 0 0.08em;
    font: inherit;
    font-weight: 900;
    color: inherit;
    background: transparent;
    box-shadow: none;
    text-decoration: none;
}

.op-button {
    position: relative;
    cursor: pointer;
}

.pending-op {
    opacity: 0.78;
}

.op-button.done,
.solved-op {
    background: #eafff0;
    color: #166534;
}

.op-parentheses {
    color: #d69200;
    background: #fff3c4;
}

.op-power {
    color: #9b3bc7;
    background: #f2ddff;
}

.op-multiply {
    color: #146eb4;
    background: #dcefff;
}

.op-plusminus {
    color: #148356;
    background: transparent;
}

.op-symbol {
    display: inline-block;
    margin: 0 0.16em;
    font-weight: 900;
}

.interactive-expression sup .op-button {
    min-width: 0.45em;
    min-height: 0.55em;
    margin: 0;
    border-radius: 6px;
    padding: 0 0.06em;
    box-shadow: none;
}

.paren-symbol {
    color: #d69200;
    font-weight: 900;
}

.message {
    min-height: 28px;
    margin-top: 18px;
    font-size: 18px;
    font-weight: 700;
    color: #334155;
}

.message.good {
    color: #15803d;
}

.message.bad {
    color: #b91c1c;
}

.legend {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 0;
}

.legend-item {
    min-height: 42px;
    border-radius: 8px;
    padding: 10px 12px;
    font-weight: 800;
    text-align: center;
}

.legend-parentheses {
    background: #fff3c4;
    color: #8a5b00;
}

.legend-powers {
    background: #f2ddff;
    color: #78319a;
}

.legend-multiply {
    background: #dcefff;
    color: #12598f;
}

.legend-plusminus {
    background: #ddfaeb;
    color: #146c49;
}

.progress-wrap {
    min-height: 96px;
    padding: 18px;
}

.steps {
    display: grid;
    gap: 10px;
    color: #334155;
    font-size: 18px;
}

.step-line {
    padding: 10px 12px;
    border-left: 5px solid #78c2ad;
    border-radius: 8px;
    background: #f8fafc;
}

.finished {
    margin-top: 18px;
    padding: 22px;
    text-align: center;
}

.finished h2 {
    margin: 0 0 8px;
    color: #14532d;
}

.finished p {
    margin: 0 0 16px;
    font-size: 20px;
    font-weight: 700;
}

.effects {
    pointer-events: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 20;
}

.sparkle,
.fog,
.confetti {
    position: absolute;
    border-radius: 999px;
}

.sparkle {
    width: 9px;
    height: 9px;
    background: #ffd166;
    animation: sparkle 780ms ease-out forwards;
}

.fog {
    width: 42px;
    height: 42px;
    background: rgba(110, 120, 130, 0.22);
    filter: blur(4px);
    animation: fog 820ms ease-out forwards;
}

.confetti {
    width: 11px;
    height: 18px;
    animation: confetti 1100ms ease-out forwards;
}

@keyframes sparkle {
    from {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(var(--x), var(--y)) scale(0.2);
    }
}

@keyframes fog {
    from {
        opacity: 0.75;
        transform: translate(-50%, -50%) scale(0.4);
    }
    to {
        opacity: 0;
        transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1.5);
    }
}

@keyframes confetti {
    from {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }
    to {
        opacity: 0;
        transform: translateY(130px) rotate(420deg);
    }
}

@media (max-width: 720px) {
    .topbar {
        grid-template-columns: 1fr 1fr;
    }

    .topbar h1 {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .back-button,
    #newExerciseTop {
        grid-row: 2;
    }

    .task-area {
        padding: 20px 12px;
    }

    .exercise-layout {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 440px) {
    .legend {
        grid-template-columns: 1fr;
    }
}
