:root {
    --ink: #171b52;
    --muted: #627084;
    --blue: #0d74ff;
    --purple: #6345ee;
    --row: #00b8ff;
    --column: #ff5c9f;
    --answer: #ffe44d;
    --success: #23c58a;
    --danger: #ff4f68;
    --surface: rgba(255, 255, 255, 0.9);
    --line: rgba(76, 126, 199, 0.16);
    --shadow: 0 16px 34px rgba(52, 92, 150, 0.15);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "Inter", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 15%, rgba(255, 255, 255, 0.98), transparent 27%),
        radial-gradient(circle at 88% 14%, rgba(255, 228, 77, 0.34), transparent 28%),
        radial-gradient(circle at 6% 82%, rgba(0, 184, 255, 0.22), transparent 30%),
        linear-gradient(180deg, #f5fbff 0%, #e6f4ff 48%, #cfe5ff 100%);
    overflow: hidden;
}

button,
a,
input {
    font: inherit;
    -webkit-tap-highlight-color: transparent;
}

button {
    border: 0;
    cursor: pointer;
}

.pitagoras-shell {
    width: 100%;
    max-width: 430px;
    height: 100dvh;
    min-height: 680px;
    margin: 0 auto;
    padding:
        calc(env(safe-area-inset-top, 0px) + 10px)
        10px
        calc(env(safe-area-inset-bottom, 0px) + 10px);
    display: grid;
    grid-template-rows: 50px minmax(0, 1fr);
    gap: 8px;
    overflow: hidden;
}

.topbar {
    display: grid;
    grid-template-columns: 46px 1fr 46px 46px;
    align-items: center;
    gap: 8px;
}

.brand-logo {
    width: 118px;
    justify-self: center;
    filter: drop-shadow(0 8px 16px rgba(50, 130, 206, 0.14));
}

.back-button,
.sound-button,
.fullscreen-button,
.soft-button {
    min-width: 42px;
    min-height: 42px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--blue);
    box-shadow: 0 8px 18px rgba(50, 130, 206, 0.12);
    display: grid;
    place-items: center;
}

.fullscreen-button {
    min-width: 42px;
    min-height: 42px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--blue);
    box-shadow: 0 8px 18px rgba(50, 130, 206, 0.12);
    display: grid;
    place-items: center;
}

.back-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sound-button img {
    width: 26px;
    height: 26px;
    object-fit: contain;
}

.fullscreen-button svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sound-button[aria-pressed="false"] {
    filter: grayscale(0.85);
    opacity: 0.62;
}

.game {
    min-height: 0;
    display: grid;
    grid-template-rows: 82px minmax(0, 1fr) 48px;
    gap: 8px;
}

.problem-card,
.table-panel {
    border: 1px solid rgba(255, 255, 255, 0.76);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.problem-card {
    padding: 11px 13px;
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--blue);
    font-size: 0.62rem;
    font-weight: 950;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.problem-equation {
    margin: 0;
    font-family: "Archivo", sans-serif;
    font-size: 2.45rem;
    line-height: 0.9;
    letter-spacing: 0;
    display: flex;
    align-items: center;
    gap: 7px;
}

.problem-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.number-input {
    width: 58px;
    height: 48px;
    border: 0;
    border-radius: 17px;
    background:
        radial-gradient(circle at 35% 23%, rgba(255, 255, 255, 0.85), transparent 32%),
        linear-gradient(145deg, #ffffff, #e9f5ff);
    color: var(--ink);
    box-shadow:
        inset 0 -7px 10px rgba(20, 93, 168, 0.11),
        inset 0 7px 10px rgba(255, 255, 255, 0.92),
        0 8px 15px rgba(50, 130, 206, 0.14);
    font-family: "Archivo", sans-serif;
    font-size: 2rem;
    line-height: 1;
    font-weight: 800;
    text-align: center;
    outline: none;
}

.number-input::placeholder {
    color: #8b98aa;
    opacity: 0.74;
}

.number-input[readonly] {
    caret-color: transparent;
}

.number-input--row {
    color: #0879d8;
    background:
        radial-gradient(circle at 35% 23%, rgba(255, 255, 255, 0.9), transparent 32%),
        linear-gradient(145deg, #ffffff, #e6f7ff);
    box-shadow:
        inset 0 -7px 10px rgba(0, 133, 219, 0.14),
        inset 0 7px 10px rgba(255, 255, 255, 0.92),
        0 8px 15px rgba(0, 184, 255, 0.14);
}

.number-input--column {
    color: #cf2d77;
    background:
        radial-gradient(circle at 35% 23%, rgba(255, 255, 255, 0.9), transparent 32%),
        linear-gradient(145deg, #ffffff, #fff0f7);
    box-shadow:
        inset 0 -7px 10px rgba(255, 92, 159, 0.14),
        inset 0 7px 10px rgba(255, 255, 255, 0.92),
        0 8px 15px rgba(255, 92, 159, 0.14);
}

.equation-answer {
    width: 58px;
    height: 48px;
    border-radius: 17px;
    background:
        radial-gradient(circle at 35% 23%, rgba(255, 255, 255, 0.85), transparent 32%),
        linear-gradient(145deg, #ffffff, #e9f5ff);
    color: var(--purple);
    box-shadow:
        inset 0 -7px 10px rgba(20, 93, 168, 0.11),
        inset 0 7px 10px rgba(255, 255, 255, 0.92),
        0 8px 15px rgba(50, 130, 206, 0.14);
    display: grid;
    place-items: center;
    font-family: "Archivo", sans-serif;
    font-size: 1.55rem;
    font-weight: 800;
}

.equation-answer.is-visible {
    color: #725100;
    background: linear-gradient(145deg, #fff889, var(--answer) 54%, #f6a000);
}

.number-input:focus {
    box-shadow:
        inset 0 -7px 10px rgba(20, 93, 168, 0.11),
        inset 0 7px 10px rgba(255, 255, 255, 0.92),
        0 0 0 4px rgba(0, 167, 255, 0.16),
        0 8px 15px rgba(50, 130, 206, 0.14);
}

.number-input::-webkit-outer-spin-button,
.number-input::-webkit-inner-spin-button {
    margin: 0;
    appearance: none;
}

.soft-button {
    min-height: 38px;
    padding: 0 13px;
    border-radius: 15px;
    color: #1667c7;
    font-family: "Archivo", sans-serif;
    font-size: 0.78rem;
    font-weight: 800;
}

.icon-soft-button {
    width: 38px;
    min-width: 38px;
    padding: 0;
    display: grid;
    place-items: center;
}

.icon-soft-button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-soft-button:disabled {
    cursor: default;
    filter: grayscale(0.9);
    opacity: 0.48;
}

.soft-button--primary {
    color: #fff;
    background: linear-gradient(135deg, #39b7ff, var(--purple));
    box-shadow: 0 12px 24px rgba(78, 85, 229, 0.22);
}

.table-panel {
    min-height: 0;
    padding: 28px 12px 18px;
    border-radius: 28px;
    display: grid;
    place-items: start center;
}

.pitagoras-grid {
    width: 100%;
    aspect-ratio: 1;
    padding: 6px;
    border-radius: 24px;
    background:
        radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.76), transparent 28%),
        linear-gradient(135deg, rgba(0, 184, 255, 0.18), rgba(255, 92, 159, 0.14) 58%, rgba(255, 228, 77, 0.2));
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.74),
        inset 0 -14px 24px rgba(52, 92, 150, 0.08);
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(10, minmax(0, 1fr));
    gap: 3px;
}

.grid-cell {
    min-width: 0;
    min-height: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
    color: #27324a;
    box-shadow:
        inset 0 -5px 8px rgba(57, 91, 142, 0.08),
        inset 0 4px 8px rgba(255, 255, 255, 0.86),
        0 5px 9px rgba(35, 74, 126, 0.07);
    display: grid;
    place-items: center;
    font-family: "Archivo", sans-serif;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    transition: transform 130ms ease, background 130ms ease, color 130ms ease, box-shadow 130ms ease;
}

.grid-cell--corner {
    background: rgba(255, 255, 255, 0.36);
    box-shadow: none;
}

.grid-cell--head {
    color: #fff;
    background: linear-gradient(145deg, #39b7ff, #4c64ef);
}

.grid-cell--side {
    color: #fff;
    background: linear-gradient(145deg, #ff9a4d, #ff4e91);
}

.grid-cell--row {
    background: rgba(0, 184, 255, 0.18);
    color: #085f9b;
}

.grid-cell--column {
    background: rgba(255, 92, 159, 0.18);
    color: #9a245b;
}

.grid-cell--selected {
    color: #725100;
    background: linear-gradient(145deg, #fff889, var(--answer) 56%, #f6a000);
    box-shadow:
        inset 0 7px 9px rgba(255, 255, 255, 0.45),
        inset 0 -9px 12px rgba(185, 123, 10, 0.24),
        0 10px 18px rgba(214, 144, 16, 0.18);
    transform: scale(1.04);
}

.grid-cell--correct {
    color: #fff;
    background: linear-gradient(145deg, #74f4c7, var(--success));
}

.grid-cell--wrong {
    color: #fff;
    background: linear-gradient(145deg, #ff8d68, var(--danger));
    animation: wrongTap 210ms ease;
}

.game-actions {
    min-height: 0;
    display: grid;
    grid-template-columns: 76px 90px minmax(0, 1fr);
    align-items: center;
    gap: 7px;
}

.result-text {
    min-width: 0;
    margin: 0;
    min-height: 38px;
    padding: 0 8px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.62);
    color: #536070;
    font-size: 0.69rem;
    line-height: 1.15;
    font-weight: 800;
    text-align: center;
    display: grid;
    place-items: center;
    overflow-wrap: anywhere;
}

.result-text.is-success {
    color: #117a59;
}

.animated-result {
    grid-column: 1 / -1;
    min-height: 0;
    padding: 18px;
    border: 1px solid rgba(76, 126, 199, 0.12);
    border-radius: 22px;
    background:
        radial-gradient(circle at 86% 18%, rgba(255, 228, 77, 0.26), transparent 32%),
        linear-gradient(145deg, rgba(229, 249, 255, 0.95), rgba(241, 238, 255, 0.95));
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.animated-result__equation {
    color: #536070;
    font: 800 clamp(1.35rem, 2.2vw, 2rem)/1.1 "Archivo", sans-serif;
}

.animated-result__value {
    display: block;
    margin: 10px 0;
    color: #79849a;
    font: 800 clamp(3.4rem, 7vw, 6.4rem)/0.9 "Archivo", sans-serif;
    transform-origin: center;
}

.animated-result.is-revealed .animated-result__value {
    color: #6242e9;
    animation: answerPop 520ms cubic-bezier(.2, .9, .25, 1.25) both;
    text-shadow: 0 12px 28px rgba(98, 66, 233, 0.18);
}

.animated-result .result-text {
    min-height: 44px;
    margin-top: auto;
}

.next-button {
    grid-column: 1 / -1;
}

.next-button:disabled {
    opacity: 0.42;
    filter: grayscale(0.25);
    cursor: not-allowed;
    box-shadow: none;
}

@keyframes answerPop {
    0% { opacity: 0; transform: scale(.55) rotate(-5deg); }
    58% { opacity: 1; transform: scale(1.12) rotate(2deg); }
    100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes wrongTap {
    0%,
    100% {
        transform: translateX(0);
    }

    35% {
        transform: translateX(-3px);
    }

    70% {
        transform: translateX(3px);
    }
}

@media (max-height: 740px) {
    .pitagoras-shell {
        min-height: 620px;
        padding-top: calc(env(safe-area-inset-top, 0px) + 7px);
        gap: 6px;
    }

    .topbar {
        height: 46px;
    }

    .game {
        grid-template-rows: 72px minmax(0, 1fr) 44px;
        gap: 7px;
    }

    .problem-equation {
        font-size: 2.06rem;
    }

    .number-input {
        width: 52px;
        height: 43px;
        font-size: 1.74rem;
    }

    .equation-answer {
        width: 52px;
        height: 43px;
        font-size: 1.36rem;
    }

    .table-panel {
        padding: 22px 10px 14px;
    }

    .pitagoras-grid {
        gap: 3px;
        padding: 6px;
        border-radius: 22px;
    }

    .grid-cell {
        border-radius: 9px;
        font-size: 0.7rem;
    }

}

@media (max-width: 480px) {
    .pitagoras-shell {
        padding-left: 8px;
        padding-right: 8px;
    }

    .topbar {
        grid-template-columns: 42px 1fr 42px 42px;
        gap: 6px;
    }

    .brand-logo {
        width: 106px;
    }

    .back-button,
    .sound-button,
    .fullscreen-button,
    .soft-button {
        min-width: 40px;
        min-height: 40px;
        border-radius: 14px;
    }

    .game {
        grid-template-rows: auto minmax(0, 1fr) 42px;
        gap: 6px;
    }

    .problem-card {
        padding: 10px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .problem-card > div:first-child {
        min-width: 0;
    }

    .problem-equation {
        font-size: 1.9rem;
        gap: 6px;
        flex-wrap: nowrap;
    }

    .number-input,
    .equation-answer {
        width: 50px;
        height: 42px;
        border-radius: 15px;
        font-size: 1.55rem;
        flex: 0 0 auto;
    }

    .equation-answer {
        font-size: 1.3rem;
    }

    .problem-actions {
        width: 100%;
        justify-content: flex-end;
        gap: 6px;
    }

    .soft-button {
        padding: 0 10px;
        font-size: 0.72rem;
    }

    .icon-soft-button {
        width: 40px;
        min-width: 40px;
        padding: 0;
    }

    .table-panel {
        padding: 12px 8px 10px;
        border-radius: 24px;
    }

    .pitagoras-grid {
        width: min(100%, 316px);
        gap: 2px;
        padding: 5px;
        border-radius: 18px;
    }

    .grid-cell {
        border-radius: 7px;
        font-size: 0.62rem;
    }

    .game-actions {
        grid-template-columns: 1fr 1fr 1.15fr;
        gap: 6px;
    }

    .result-text {
        min-height: 34px;
        font-size: 0.63rem;
        border-radius: 13px;
        padding: 0 6px;
    }
}

@media (max-width: 370px) {
    .pitagoras-shell {
        padding-left: 8px;
        padding-right: 8px;
    }

    .soft-button {
        padding: 0 10px;
        font-size: 0.7rem;
    }

    .pitagoras-grid {
        gap: 2px;
        padding: 5px;
    }

    .grid-cell {
        border-radius: 8px;
        font-size: 0.66rem;
    }

    .problem-equation {
        font-size: 1.72rem;
    }

    .number-input,
    .equation-answer {
        width: 46px;
        height: 40px;
        font-size: 1.38rem;
    }

    .equation-answer {
        font-size: 1.18rem;
    }
}

@media (min-width: 900px) {
    body {
        overflow: hidden;
    }

    .pitagoras-shell {
        width: min(100vw, 1280px);
        max-width: 1280px;
        height: 100dvh;
        min-height: 0;
        padding: 84px clamp(18px, 3vw, 44px) 18px;
        position: relative;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        grid-template-rows: repeat(5, minmax(0, 1fr));
        gap: 5px;
        overflow: hidden;
    }

    .topbar {
        position: absolute;
        top: 18px;
        left: clamp(18px, 3vw, 44px);
        right: clamp(18px, 3vw, 44px);
        z-index: 8;
        height: 52px;
        display: grid;
        grid-template-columns: 48px 150px minmax(0, 1fr) 48px 48px;
        align-items: center;
        gap: 8px;
        pointer-events: none;
    }

    .brand-logo {
        width: 142px;
        grid-column: 2;
        justify-self: start;
    }

    .back-button,
    .sound-button,
    .fullscreen-button,
    .soft-button {
        min-width: 48px;
        min-height: 48px;
        border-radius: 18px;
    }

    .sound-button,
    .fullscreen-button {
        justify-self: end;
    }

    .back-button,
    .brand-logo,
    .sound-button,
    .fullscreen-button {
        pointer-events: auto;
    }

    .back-button {
        grid-column: 1;
        grid-row: 1;
    }

    .sound-button {
        grid-column: 4;
        grid-row: 1;
    }

    .fullscreen-button {
        grid-column: 5;
        grid-row: 1;
    }

    .game {
        display: contents;
    }

    .problem-card {
        min-height: 0;
        padding: 14px 16px;
        border-radius: 28px;
        align-self: stretch;
    }

    .eyebrow {
        font-size: 0.68rem;
    }

    .problem-equation {
        font-size: clamp(1.7rem, 3.2vw, 2.5rem);
        gap: 8px;
    }

    .number-input,
    .equation-answer {
        width: clamp(48px, 4.8vw, 68px);
        height: clamp(44px, 4.8vw, 58px);
        border-radius: 20px;
        font-size: clamp(1.5rem, 2.4vw, 2rem);
    }

    .equation-answer {
        font-size: clamp(1.25rem, 2.1vw, 1.7rem);
    }

    .table-panel {
        min-height: 0;
        padding: clamp(8px, 1vw, 12px);
        border-radius: 34px;
        place-items: center;
        align-self: stretch;
        overflow: hidden;
    }

    .pitagoras-grid {
        width: min(100%, 560px);
        height: auto;
        max-height: 100%;
        aspect-ratio: 1;
        gap: clamp(3px, 0.55vw, 6px);
        padding: clamp(7px, 1vw, 12px);
        border-radius: 30px;
    }

    .grid-cell {
        border-radius: 13px;
        font-size: clamp(0.72rem, 1.1vw, 1rem);
    }

    .game-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 52px minmax(0, 1fr) 52px;
        align-content: stretch;
        gap: 10px;
        min-height: 0;
        padding: 14px;
        border-radius: 30px;
        background: var(--surface);
        box-shadow: var(--shadow);
        border: 1px solid rgba(255, 255, 255, 0.76);
    }

    .result-text { border-radius: 16px; font-size: 0.86rem; }

    .layout-main {
        grid-column: span 2 / span 2;
        grid-row: span 5 / span 5;
        grid-column-start: 2;
        grid-row-start: 1;
    }

    .layout-operation {
        grid-column: span 2 / span 2;
        grid-column-start: 4;
        grid-row-start: 1;
    }

    .layout-count {
        grid-column: span 2 / span 2;
        grid-column-start: 4;
        grid-row-start: 2;
        grid-row-end: 6;
        align-self: stretch;
    }

    .layout-logo {
        grid-column: auto;
        grid-row: auto;
    }
}

@media (max-width: 899px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
    }

    .pitagoras-shell {
        height: auto;
        min-height: 100svh;
        overflow: visible;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    }

    .game {
        grid-template-rows: auto auto auto;
    }

    .table-panel {
        min-height: auto;
        padding-bottom: 14px;
    }

    .game-actions {
        min-height: 286px;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 46px minmax(190px, auto) 46px;
        padding: 10px;
        border-radius: 24px;
        background: var(--surface);
        box-shadow: var(--shadow);
    }

    .animated-result {
        min-height: 190px;
        padding: 16px;
    }

    .next-button {
        min-height: 42px;
    }
}
