:root {
    --bg: #eef6ff;
    --card: #ffffff;
    --text: #21304a;
    --muted: #61738f;
    --primary: #4f8cff;
    --primary-soft: #d9e8ff;
    --secondary: #e2e9f4;
    --secondary-text: #314a6a;
    --accent: #ffb347;
    --accent-soft: #fff3d6;
    --warning: #ffb347;
    --warning-soft: #fff3d6;
    --success: #33a56b;
    --danger: #d94242;
    --radius: 24px;
    --shadow: 0 24px 60px rgba(33, 48, 74, 0.1);
    --border: rgba(31, 51, 71, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: radial-gradient(circle at top left, rgba(79, 140, 255, 0.18), transparent 28%), linear-gradient(180deg, #f7fbff 0%, #eaf3ff 100%);
    color: var(--text);
    display: grid;
    place-items: center;
    padding: 16px;
}

.page {
    width: min(380px, 100%);
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.title-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.help-button {
    border: none;
    background: var(--primary);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-weight: 800;
    cursor: pointer;
    position: relative;
}

.help-button[data-tooltip]:hover::after,
.help-button[data-tooltip]:focus::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-8px);
}

.help-button[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%) translateY(0);
    white-space: nowrap;
    background: rgba(33, 48, 74, 0.95);
    color: white;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.16s ease, transform 0.16s ease;
    z-index: 2;
}

.logo {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--primary);
    font-size: 0.84rem;
    margin-bottom: 4px;
}

h1 {
    font-size: clamp(1.5rem, 2vw, 2.2rem);
    margin: 0 0 6px;
    line-height: 1.05;
}

p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
    max-width: 40rem;
}

.badge {
    background: var(--primary-soft);
    color: var(--primary);
    padding: 10px 14px;
    border-radius: 18px;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: inset 0 0 0 1px rgba(79, 140, 255, 0.15);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
    margin-bottom: 0;
}

.stat-card {
    background: #f8fbff;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 12px 10px;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text);
}

.stat-label {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.92rem;
}

.section-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0 0 10px;
}

.button-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

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

.calculator {
    display: grid;
    gap: 14px;
    background: linear-gradient(180deg, #f8fbff, #eef5ff);
    border: 1px solid rgba(79, 140, 255, 0.16);
    border-radius: 28px;
    padding: 16px;
    margin-bottom: 14px;
}

.calc-display {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px;
    background: white;
    border-radius: 24px;
    box-shadow: inset 0 2px 0 rgba(79, 140, 255, 0.06);
}

.question-label {
    grid-column: 1;
    grid-row: 1;
}

.calc-question {
    grid-column: 1;
    grid-row: 2;
}

.input-label {
    grid-column: 2;
    grid-row: 1;
}

.calc-answer {
    grid-column: 2;
    grid-row: 2;
}

.question-label,
.input-label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.calc-question {
    min-height: 2.8rem;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text);
    display: grid;
    align-items: center;
    padding: 10px 12px;
    border-radius: 18px;
    background: #f5f8ff;
    text-align: center;
}

.calc-answer {
    display: grid;
    background: #eef6ff;
    border-radius: 18px;
    padding: 10px 12px;
}

#guess-input {
    border: none;
    background: transparent;
    padding: 0;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
    width: 100%;
}

#guess-input:disabled {
    background: transparent;
}

.calc-controls {
    display: grid;
    gap: 12px;
}

.control-group {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.num-button,
#clear-answer {
    border: none;
    background: #ffffff;
    border-radius: 18px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    padding: 14px 0;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(31, 51, 71, 0.08);
    transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.num-button:hover,
#clear-answer:hover,
.action-button:hover {
    transform: translateY(-1px);
}

.num-button:active,
#clear-answer:active,
.action-button:active {
    transform: translateY(0);
}

.calc-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.op-button,
.action-button,
.answer-box {
    border: none;
    border-radius: 18px;
    font-size: 1rem;
    font-weight: 700;
    padding: 14px 16px;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease, color 0.16s ease;
    min-height: 54px;
}

.op-button {
    background: #f5f8ff;
    color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(31, 51, 71, 0.08);
    text-align: center;
}

.op-button:hover,
.action-button:hover,
.answer-box:hover {
    transform: translateY(-1px);
}

.op-button.active {
    color: white;
    box-shadow: 0 14px 22px rgba(79, 140, 255, 0.18);
}

.op-add.active {
    background: var(--primary);
}

.op-sub.active {
    background: #ff6961;
}

.op-mul.active {
    background: #7f6fdf;
}

.op-div.active {
    background: #33a56b;
}

.op-add {
    background: #eef6ff;
    color: #2f5bc8;
}

.op-sub {
    background: #fff0f1;
    color: #bf3635;
}

.op-mul {
    background: #f0edff;
    color: #5c4ad1;
}

.op-div {
    background: #e8fff0;
    color: #1f7b4a;
}

.difficulty-button {
    background: #f4f7fb;
    color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(31, 51, 71, 0.08);
}

.difficulty-button.active {
    color: white;
}

.difficulty-button[data-difficulty="easy"].active {
    background: #b9f2c0;
    color: #1d5b2a;
}

.difficulty-button[data-difficulty="medium"].active {
    background: #94cfff;
    color: #164c77;
}

.difficulty-button[data-difficulty="hard"].active {
    background: #ffbf7a;
    color: #7a4a00;
}

.difficulty-button[data-difficulty="expert"].active {
    background: #ff9393;
    color: #7f1b1b;
}

.action-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 0;
    align-items: stretch;
}

.action-row .answer-box {
    flex: 1;
    width: auto;
    min-height: 54px;
}

.action-button {
    flex: 1;
    background: var(--secondary);
    color: var(--secondary-text);
    box-shadow: 0 14px 28px rgba(49, 73, 110, 0.12);
}

.action-button.primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 14px 28px rgba(79, 140, 255, 0.24);
}

.action-button.secondary {
    background: var(--secondary);
    color: var(--secondary-text);
}

.action-button.warning {
    background: var(--warning);
    color: #4d3200;
    box-shadow: 0 14px 28px rgba(255, 179, 71, 0.24);
}

.action-button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    box-shadow: none;
}

.question-box {
    min-height: 5.5rem;
    background: linear-gradient(180deg, #fff, #eef6ff);
    border-radius: 22px;
    display: grid;
    place-items: center;
    padding: 24px;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 18px;
    text-align: center;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.answer-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--text);
    width: 100%;
    text-align: center;
    min-height: 54px;
    position: relative;
    overflow: hidden;
}

.answer-box.reward {
    background: linear-gradient(135deg, #fff7d7 0%, #d7fef3 100%);
    color: #0f3d25;
    border: 1px solid rgba(56, 174, 108, 0.22);
    box-shadow: 0 14px 30px rgba(79, 140, 255, 0.12);
    animation: rewardPulse 0.85s ease-out;
}

.answer-box.reward::before {
    content: "🎉";
    position: absolute;
    left: 16px;
    top: 12px;
    font-size: 1.4rem;
}

.answer-box.reward::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 40%);
    pointer-events: none;
}

@keyframes rewardPulse {
    0% { transform: scale(0.98); opacity: 0.96; }
    50% { transform: scale(1.02); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.answer-box.hidden {
    display: none;
}

.feedback {
    margin-top: 10px;
    font-size: 0.95rem;
    color: var(--muted);
    min-height: 1.4rem;
}

@media (max-width: 520px) {
    .page {
        padding: 20px;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .action-row {
        flex-direction: column;
    }

    .button-group {
        grid-template-columns: 1fr;
    }

    .difficulty-group {
        grid-template-columns: 1fr;
    }
}
