:root {
    --bg: #fff8ee;
    --surface: #ffffff;
    --ink: #2b2140;
    --ink-soft: #6b6280;
    --line: #efe4d4;

    --red: #ff6b6b;
    --orange: #ff9f43;
    --yellow: #ffc94d;
    --green: #3ecf8e;
    --blue: #4d96ff;
    --purple: #9b5de5;
    --pink: #ff6fb5;

    --radius: 22px;
    --shadow: 0 2px 0 rgba(43, 33, 64, .06), 0 10px 24px -12px rgba(43, 33, 64, .25);
    --shadow-lift: 0 4px 0 rgba(43, 33, 64, .08), 0 22px 36px -16px rgba(43, 33, 64, .35);

    --font-display: "Fredoka", "Comic Sans MS", system-ui, sans-serif;
    --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background:
        radial-gradient(circle at 12% 8%, rgba(255, 201, 77, .22) 0 120px, transparent 121px),
        radial-gradient(circle at 92% 18%, rgba(62, 207, 142, .14) 0 160px, transparent 161px),
        var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

img, svg { display: block; max-width: 100%; }

button { font: inherit; color: inherit; cursor: pointer; }

.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 16px;
}

main.container { flex: 1; padding-bottom: 56px; }

/* ---------- Header ---------- */

.site-header { padding: 24px 0 20px; text-align: center; }

.header-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.logo { margin: 0; line-height: 0; }
.logo a { display: inline-block; border-radius: 24px; transition: transform .2s; }
.logo a:hover { transform: rotate(-2deg) scale(1.03); }
.logo img { width: clamp(220px, 42vw, 340px); height: auto; }

.tagline {
    margin: 0;
    max-width: 560px;
    color: var(--ink-soft);
    font-size: 1.08rem;
}

/* ---------- Age groups ---------- */

[data-age="all"]       { --age-color: var(--ink); }
[data-age="ages-2-4"]  { --age-color: var(--green); }
[data-age="ages-5-7"]  { --age-color: var(--blue); }
[data-age="ages-8-12"] { --age-color: var(--purple); }

.ages-section { margin: 12px 0 8px; }

.ages-section h2 {
    margin: 0 0 12px;
    text-align: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.35rem;
}

.ages {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
}

.age {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 18px;
    text-align: left;
    background: var(--surface);
    border: 3px solid var(--line);
    border-radius: 20px;
    transition: transform .15s, border-color .15s, background-color .15s, box-shadow .15s;
}
.age:hover { transform: translateY(-2px); border-color: var(--age-color); }
.age.is-active {
    border-color: var(--age-color);
    background: color-mix(in srgb, var(--age-color) 12%, white);
    box-shadow: 0 4px 0 var(--age-color);
}

.age-label {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.3rem;
    line-height: 1.2;
}
.age-label::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--age-color);
    vertical-align: 2px;
}
.age-hint { font-size: .92rem; color: var(--ink-soft); }

/* ---------- Toolbar ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 18px 0 26px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    border: 2px solid var(--line);
    background: var(--surface);
    border-radius: 999px;
    padding: 8px 18px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    transition: transform .15s, background-color .15s, border-color .15s, color .15s;
}
.chip:hover { transform: translateY(-2px); border-color: var(--yellow); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

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

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 2px solid var(--line);
    border-radius: 999px;
    padding: 0 16px;
    transition: border-color .15s;
}
.search:focus-within { border-color: var(--blue); }
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--ink-soft); stroke-width: 2.4; stroke-linecap: round; }
.search input {
    border: 0;
    outline: 0;
    background: transparent;
    font: inherit;
    color: var(--ink);
    padding: 9px 0;
    width: 180px;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: 999px;
    padding: 12px 24px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.1rem;
    color: #fff;
    box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
    transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.btn-surprise { background: var(--purple); padding: 10px 20px; font-size: 1rem; }
.btn-print { background: var(--blue); }
.btn-download { background: var(--green); }
.btn[disabled] { opacity: .65; cursor: progress; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ---------- Grid ---------- */

.grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 22px;
}

.card { --accent: var(--blue); }
.card[data-category="animals"]  { --accent: var(--orange); }
.card[data-category="nature"]   { --accent: var(--green); }
.card[data-category="vehicles"] { --accent: var(--red); }
.card[data-category="space"]    { --accent: var(--purple); }
.card[data-category="food"]     { --accent: var(--yellow); }
.card[data-category="fantasy"]  { --accent: var(--pink); }
.card[data-category="toys"]     { --accent: var(--purple); }
.card[data-category="people"]   { --accent: var(--orange); }
.card[data-category="sports"]   { --accent: var(--green); }

.card-button {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px 12px 16px;
    text-align: left;
    background: var(--surface);
    border: 3px solid transparent;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform .2s, box-shadow .2s, border-color .2s;
}
.card-button:hover,
.card-button:focus-visible {
    transform: translateY(-5px) rotate(-1deg);
    box-shadow: var(--shadow-lift);
    border-color: var(--accent);
}
.card:nth-child(even) .card-button:hover { transform: translateY(-5px) rotate(1deg); }

.card-image {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 14px;
    background: #fff;
    border: 2px dashed var(--line);
    display: block;
    padding: 10px;
    margin-bottom: 8px;
    overflow: hidden;
}
/* Square and tall (A4) pages both fit whole inside the square box */
.card-image img { width: 100%; height: 100%; object-fit: contain; }

.card-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.2rem;
    line-height: 1.2;
    padding: 0 4px;
}

.card-tag {
    margin-left: 4px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-soft);
}
.card-tag::before {
    content: "";
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--accent);
    vertical-align: 1px;
}

.card-age {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 3px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--age-color) 22%, white);
    color: var(--ink);
    font-size: .78rem;
    font-weight: 700;
}

.no-results, .empty {
    text-align: center;
    color: var(--ink-soft);
    padding: 48px 16px;
}
.empty h2 { font-family: var(--font-display); color: var(--ink); }
.empty code { background: var(--surface); padding: 2px 8px; border-radius: 6px; }

/* ---------- Viewer (dialog) ---------- */

.viewer {
    width: min(760px, calc(100% - 32px));
    max-height: calc(100% - 32px);
    border: 0;
    border-radius: 28px;
    padding: 20px 22px 22px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 30px 80px -20px rgba(43, 33, 64, .5);
    overflow: auto;
}
.viewer::backdrop { background: rgba(43, 33, 64, .55); backdrop-filter: blur(3px); }
.viewer[open] { animation: pop .22s ease-out; }

@keyframes pop {
    from { transform: scale(.94); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.viewer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.viewer-head h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; line-height: 1.15; }
.viewer-tag { font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }

.icon-btn {
    flex: none;
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 2px solid var(--line);
    background: var(--surface);
    transition: background-color .15s, transform .15s;
}
.icon-btn:hover { background: var(--bg); transform: scale(1.06); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

.viewer-body { display: flex; align-items: center; gap: 10px; }

.viewer-image {
    flex: 1;
    min-width: 0;
    border: 2px dashed var(--line);
    border-radius: 18px;
    padding: 12px;
    background: #fff;
}
.viewer-image img { width: 100%; height: min(60vh, 560px); object-fit: contain; }

.viewer-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; margin-top: 18px; }
.viewer-actions .btn { min-width: 170px; padding: 14px 28px; font-size: 1.2rem; }

.viewer-alt { text-align: center; margin: 12px 0 0; font-size: .9rem; color: var(--ink-soft); }
.viewer-alt a { color: var(--blue); font-weight: 700; }

/* ---------- Footer ---------- */

.site-footer { padding: 24px 0 32px; text-align: center; color: var(--ink-soft); font-size: .92rem; }
.site-footer p { margin: 0; }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
    body { font-size: 16px; }
    .site-header { padding-top: 24px; }
    .ages { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .age { padding: 12px 14px; }
    .age-label { font-size: 1.1rem; }
    .age-hint { font-size: .82rem; }
    .card-age { top: 16px; right: 16px; font-size: .72rem; padding: 2px 8px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .chips { justify-content: center; }
    .toolbar-right { justify-content: center; }
    .search { flex: 1; }
    .search input { width: 100%; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
    .card-title { font-size: 1.05rem; }

    .viewer { padding: 16px; border-radius: 22px; }
    .viewer-head h2 { font-size: 1.4rem; }
    .viewer-body { position: relative; }
    .nav { position: absolute; z-index: 1; width: 40px; height: 40px; }
    .nav.prev { left: 6px; }
    .nav.next { right: 6px; }
    .viewer-image img { height: 52vh; }
    .viewer-actions .btn { flex: 1; min-width: 0; padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Printing: only the chosen picture ---------- */

#print-area { display: none; }

/* No page margin leaves the browser no room for its date/URL header and footer */
@page { margin: 0; }

@media print {
    body { background: #fff; display: block; min-height: 0; padding: 12mm; }

    body.has-picture { padding: 0; }
    body.has-picture > *:not(#print-area) { display: none !important; }
    body.has-picture #print-area {
        display: block;
        height: 100vh;
        padding: 12mm;
        overflow: hidden;
    }
    #print-area img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
}
