@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&family=Quicksand:wght@500;600;700&display=swap');

:root {
    --bg-top: #241f3f;
    --bg-bottom: #14111f;
    --paper: #221e3a;
    --scene: #2b2650;
    --ink: #f2eefc;
    --ink-soft: #a79fc9;
    --line: #362f57;

    --mint: #cff6e0;
    --mint-ink: #1f9d5c;
    --sky: #cfe8ff;
    --sky-ink: #2178c9;
    --sun: #ffedbf;
    --sun-ink: #c9860f;
    --grape: #ece0ff;
    --grape-ink: #7c4fd1;
    --grape-bright: #b9a1ff;
    --coral: #ffdcd6;
    --coral-ink: #e1503a;

    --radius-lg: 26px;
    --radius-md: 18px;
    --cell: 42px;
}

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

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

body {
    font-family: 'Quicksand', sans-serif;
    background: radial-gradient(circle at 16% 10%, #2c2650 0%, var(--bg-top) 45%, var(--bg-bottom) 100%);
    background-attachment: fixed;
    color: var(--ink);
}

.bg-pattern {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.page {
    position: relative;
    z-index: 1;
    max-width: 560px;
    margin: 0 auto;
    padding: 56px 20px 72px;
}

.hero {
    text-align: center;
    margin-bottom: 30px;
}

.hero-title {
    font-family: 'Baloo 2', cursive;
    font-size: 32px;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.2px;
}

.hero-subtitle {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-top: 6px;
}

#menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    text-align: left;
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    padding: 13px 16px;
    cursor: pointer;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.menu-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.menu-btn:active {
    transform: translateY(0);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.menu-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 700;
    flex-shrink: 0;
}

.menu-btn-label {
    font-family: 'Baloo 2', cursive;
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
}

#start-btn .menu-btn-icon {
    background: var(--mint);
    color: var(--mint-ink);
}

#start-btn:hover {
    border-color: var(--mint-ink);
}

#infinite-btn .menu-btn-icon {
    background: var(--sky);
    color: var(--sky-ink);
}

#infinite-btn:hover {
    border-color: var(--sky-ink);
}

#htp-btn .menu-btn-icon {
    background: var(--sun);
    color: var(--sun-ink);
}

#htp-btn:hover {
    border-color: var(--sun-ink);
}

#htp {
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    padding: 22px 24px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-soft);
    line-height: 1.7;
}

#htp h2 {
    font-family: 'Baloo 2', cursive;
    color: var(--ink);
    font-size: 21px;
    margin-bottom: 14px;
}

#htp p {
    margin-bottom: 12px;
}

#back-btn {
    margin-top: 8px;
    background: var(--grape);
    color: var(--grape-ink);
    border: 1.5px solid transparent;
    border-radius: 999px;
    font-family: 'Baloo 2', cursive;
    font-weight: 700;
    font-size: 14px;
    padding: 11px 22px;
    cursor: pointer;
    transition: border-color 0.12s ease, transform 0.08s ease;
}

#back-btn:hover {
    border-color: var(--grape-ink);
    transform: translateY(-1px);
}

#puzzle {
    display: flex;
    flex-direction: column;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.toolbar-label {
    font-family: 'Baloo 2', cursive;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
}

.btn-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-group button {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1.5px solid var(--line);
    background: var(--paper);
    color: var(--ink-soft);
    cursor: pointer;
    transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.btn-group button:hover {
    border-color: var(--grape-bright);
    color: var(--ink);
}

.btn-group button.active {
    background: var(--grape);
    border-color: var(--grape-ink);
    color: var(--grape-ink);
}

.row {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 14px 16px;
    background: var(--paper);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--line);
    margin-bottom: 12px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.3);
}

.row-badge {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Baloo 2', cursive;
    font-weight: 700;
    font-size: 14px;
    background: var(--sky);
    color: var(--sky-ink);
}

.row-badge--answer {
    background: var(--grape);
    color: var(--grape-ink);
    font-size: 16px;
}

.row-body {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.answer-row {
    align-items: flex-start;
    background: linear-gradient(180deg, #2a2350, #221c3f);
    border-color: var(--grape-ink);
    margin-bottom: 0;
}

.answer-row .row-body {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
}

.answer-grids {
    display: flex;
    align-items: center;
    gap: 12px;
}

.answer-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1.5px dashed #453a72;
}

.arrow {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--sun);
    color: var(--sun-ink);
    font-size: 14px;
    font-weight: 700;
    user-select: none;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, var(--cell));
    gap: 5px;
    flex-shrink: 0;
}

.cell {
    width: var(--cell);
    height: var(--cell);
    border-radius: 10px;
    transition: transform 0.1s, box-shadow 0.1s;
}

.cell.editable {
    cursor: pointer;
    outline: 3px solid transparent;
    outline-offset: 2px;
    transition: outline-color 0.12s, transform 0.1s;
}

.cell.editable:hover {
    outline-color: var(--grape-bright);
    transform: scale(1.08);
    z-index: 1;
}

.colour-picker {
    display: flex;
    gap: 8px;
    align-items: center;
}

.swatch {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    cursor: pointer;
    border: 2.5px solid rgba(255, 255, 255, 0.08);
    transition: border-color 0.12s, transform 0.1s, box-shadow 0.12s;
}

.swatch:hover {
    transform: scale(1.1);
}

.swatch.selected {
    border-color: var(--ink);
    box-shadow: 0 0 0 3px var(--grape-ink);
}

#check-btn {
    font-family: 'Baloo 2', cursive;
    font-weight: 700;
    font-size: 15px;
    padding: 11px 26px;
    border: none;
    border-radius: 999px;
    background: var(--coral-ink);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 5px 0 #b8341f;
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.1s ease;
}

#check-btn:hover {
    filter: brightness(1.06);
}

#check-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #b8341f;
}

#result {
    font-family: 'Baloo 2', cursive;
    font-size: 14px;
    font-weight: 700;
    padding: 10px 16px;
    border-radius: 12px;
    display: none;
    align-self: center;
    margin-top: 12px;
    letter-spacing: 0.01em;
}

#result.correct {
    background: var(--mint);
    color: var(--mint-ink);
}

#result.wrong {
    background: var(--coral);
    color: var(--coral-ink);
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.001ms !important;
    }
}

button:focus-visible,
.cell.editable:focus-visible {
    outline: 3px solid var(--grape-bright);
    outline-offset: 2px;
}

@media (max-width: 500px) {
    :root {
        --cell: 32px;
    }

    .page {
        padding: 36px 16px 48px;
    }

    .hero-title {
        font-size: 25px;
    }

    .row {
        gap: 10px;
        padding: 11px 12px;
        border-radius: 14px;
    }

    .row-badge {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .answer-controls {
        margin-top: 12px;
        padding-top: 12px;
    }

    .btn-group {
        gap: 4px;
    }

    .btn-group button {
        padding: 6px 10px;
        font-size: 11px;
    }

    .swatch {
        width: 28px;
        height: 28px;
        border-radius: 8px;
    }
}

@media (max-width: 360px) {
    :root {
        --cell: 27px;
    }

    .row {
        gap: 8px;
        padding: 10px;
    }

    .row-badge {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }

    .grid {
        gap: 3px;
    }

    .cell {
        border-radius: 6px;
    }
}
