:root {
    color-scheme: light;
    --ink: #2b344d;
    --muted: #6f7c9e;
    --paper: #fffbf2;
    --card: #ffffff;
    --primary: #f59e0b;
    --primary-dark: #d97706;
    --accent-blue: #3b82f6;
    --accent-purple: #8b5cf6;
    --accent-pink: #ec4899;
    --accent-green: #10b981;
    --line: #ede5d8;
    --shadow: 0 16px 40px rgba(110, 80, 40, .10);
    --canvas-bg: #f8fafc;
    font-family: 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
    display: none !important;
}

body {
    font-size: 1.125rem;
    margin: 0;
    min-width: 320px;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 12%, rgba(255, 183, 3, .22) 0 65px, transparent 66px),
        radial-gradient(circle at 90% 25%, rgba(58, 134, 255, .16) 0 75px, transparent 76px),
        radial-gradient(circle at 15% 85%, rgba(236, 72, 153, .14) 0 65px, transparent 66px),
        radial-gradient(circle at 85% 85%, rgba(16, 185, 129, .15) 0 70px, transparent 71px),
        var(--paper);
}

button { font: inherit; }
.skip-link { position: fixed; z-index: 100; top: 12px; left: 12px; transform: translateY(-180%); padding: 12px 18px; border-radius: 8px; background: #2b344d; color: #fff; font-size: 1.125rem; font-weight: 700; }
.skip-link:focus { transform: translateY(0); }

.page-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding-bottom: 30px;
}

/* Header & Brand */
.topbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1.5px solid rgba(180, 150, 110, .18);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
    text-decoration: none;
    font: 800 20px/1 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
    letter-spacing: -.6px;
}

.brand-light { color: #8e7a62; font-weight: 600; }
.brand-icon {
    width: 38px;
    height: 38px;
    filter: drop-shadow(0 3px 5px rgba(130, 80, 20, .2));
    transition: transform .25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.brand:hover .brand-icon { transform: rotate(10deg) scale(1.12); }
.topbar-note { display: flex; align-items: center; gap: 8px; color: #7a6e60; font-size: 1.125rem; font-weight: 700; }
.sparkle { font-size: 1.125rem; }

/* Intro & Gallery Trigger Card */
.intro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 0 16px;
}

.eyebrow {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    color: #b45309;
    font-size: 1.125rem;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
}
.eyebrow-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffb703;
    box-shadow: 0 0 0 3px #ffe3a8;
}

h1 {
    margin: 0;
    max-width: 620px;
    font-size: clamp(30px, 4.2vw, 44px);
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1.1;
}
h1 span {
    color: #e11d48;
    text-decoration: underline;
    text-decoration-color: #f59e0b;
    text-decoration-thickness: 5px;
    text-underline-offset: 5px;
}

.intro-text {
    max-width: 500px;
    margin: 8px 0 0;
    color: #6b7280;
    font-size: 1.125rem;
    line-height: 1.5;
}

/* Gallery Trigger Card */
.gallery-trigger-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 2px solid #ecd8c0;
    border-radius: 22px;
    background: #ffffff;
    box-shadow: 0 6px 16px rgba(150, 110, 60, .09);
}

.gallery-open-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 0;
    background: transparent;
    padding: 4px 8px;
    border-radius: 14px;
    cursor: pointer;
    transition: background .18s, transform .18s;
}
.gallery-open-btn:hover {
    background: #fff8e8;
    transform: scale(1.02);
}

.gallery-btn-icon {
    font-size: 32px;
    line-height: 1;
}

.gallery-btn-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    text-align: left;
}

.gallery-btn-label {
    color: #8d7b69;
    font-size: 1.125rem;
    font-weight: 800;
    letter-spacing: 1.1px;
}

.gallery-btn-text strong {
    font: 900 1.125rem/1.1 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
    color: #1e293b;
    max-width: 170px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-badge {
    padding: 4px 9px;
    border-radius: 10px;
    background: #fef3c7;
    color: #92400e;
    font-size: 1.125rem;
    font-weight: 800;
}

.gallery-nav-arrows {
    display: flex;
    align-items: center;
    gap: 6px;
    border-left: 1.5px solid #ecd8c0;
    padding-left: 10px;
}

.nav-arrow {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 10px;
    color: #92400e;
    background: #fef3c7;
    font-size: 1.125rem;
    cursor: pointer;
    transition: background .18s, transform .18s;
}
.nav-arrow:hover:not(:disabled) {
    background: #fde68a;
    transform: scale(1.08);
}
.nav-arrow:disabled {
    opacity: .35;
    cursor: default;
}

/* Category Tabs Bar */
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 4px 0 16px;
    overflow-x: visible;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }

.category-tab {
    flex: 0 0 auto;
    padding: 8px 16px;
    border: 1.5px solid #ebd9c2;
    border-radius: 14px;
    background: #ffffff;
    color: #64748b;
    font-size: 1.125rem;
    font-weight: 800;
    cursor: pointer;
    transition: background .18s, color .18s, border-color .18s, transform .18s;
    white-space: nowrap;
}
.category-tab:hover {
    color: #1e293b;
    border-color: #d1be9e;
    transform: translateY(-1px);
}
.category-tab.active {
    background: #f59e0b;
    color: #422006;
    border-color: #d97706;
    box-shadow: 0 3px 8px rgba(245, 158, 11, .3);
}

/* Game Card */
.game-card {
    overflow: hidden;
    border: 2px solid rgba(220, 195, 160, .35);
    border-radius: 28px;
    background: var(--card);
    box-shadow: var(--shadow);
}

/* Toolbar */
.game-toolbar {
    min-height: 76px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    border-bottom: 1.5px solid #f1e9dd;
    background: linear-gradient(110deg, #fffbeb, #fff8f1 50%, #fef2f8);
}

.stats, .stat, .actions { display: flex; align-items: center; }
.stats { gap: 12px; min-width: 0; }
.stat { gap: 10px; flex-shrink: 0; }
.stat-icon {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #fef3c7;
    font-size: 18px;
}
.palette-icon { background: #e0e7ff; }
.stat small { display: block; margin-bottom: 2px; color: #857564; font-size: 1.125rem; font-weight: 800; letter-spacing: 1px; }
.stat strong { display: block; font: 800 1.125rem/1.1 'Trebuchet MS', 'Segoe UI', Arial, sans-serif; color: #1e293b; }
.parent-trigger {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    font: 800 1.125rem/1.1 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
    color: #1e293b;
    text-align: left;
    white-space: nowrap;
    cursor: default;
    user-select: none;
}
#parent-status { color: #64748b; font-size: 1.125rem; }
#parent-complete-button:disabled { opacity: .5; cursor: default; transform: none; }
.stat-divider { height: 26px; border-left: 1.5px solid #ebd9c2; }

.actions { gap: 8px; justify-self: end; }
.actions > button { flex-shrink: 0; }
.icon-button {
    width: 40px;
    height: 40px;
    border: 1.5px solid #e7ded0;
    border-radius: 13px;
    background: #ffffff;
    color: #574b3f;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .18s, border-color .18s, transform .18s;
}
.icon-button:hover:not(:disabled) { background: #fffcf4; border-color: #d8c3a5; transform: translateY(-2px); }
.icon-button:disabled { color: #d1c8bd; background: #faf8f5; border-color: #eee9e0; cursor: default; }

.gallery-shortcut-btn, .next-level-button, .dialog-done, .action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 12px;
    color: #ffffff;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    font-size: 1.125rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(217, 119, 6, .28);
    transition: transform .18s, box-shadow .18s, filter .18s;
}
.gallery-shortcut-btn:hover, .next-level-button:hover, .dialog-done:hover, .action-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 14px rgba(217, 119, 6, .35);
    filter: brightness(1.05);
}

/* Board Wrap */
.board-wrap {
    padding: 20px 24px 28px;
    background: radial-gradient(ellipse at 50% 50%, #fffbf2 0%, #ffffff 80%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.board-heading {
    width: 100%;
    max-width: 640px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #786b59;
    font-size: 1.125rem;
    flex-wrap: wrap;
}

#board-instruction {
    font-weight: 800;
    color: #4b3e2e;
    flex: 1 1 220px;
}

.board-heading-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border: 1.5px solid #e8decb;
    border-radius: 12px;
    background: #faf4e8;
    color: #716250;
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .18s, color .18s, border-color .18s, box-shadow .18s;
    white-space: nowrap;
}
.tool-toggle:hover { color: #3d3121; border-color: #d1be9e; }
.tool-toggle.active {
    background: #ffffff;
    color: #b45309;
    border-color: #f59e0b;
    font-weight: 800;
    box-shadow: 0 2px 7px rgba(245, 158, 11, .2);
}

/* All persistent tools use the same visible on/off treatment. */
.toggle-state { padding: 2px 5px; border-radius: 5px; background: #e2e8f0; color: #475569; font-size: 1.125rem; font-weight: 800; line-height: 1.3; }
.tool-toggle[aria-pressed="true"], .state-toggle[aria-pressed="true"] { background: #fff1c5; color: #92400e; border-color: #f59e0b; box-shadow: 0 2px 7px #f59e0b33; }
[aria-pressed="true"] > .toggle-state { background: #92400e; color: #fff; }
.state-toggle { display: flex; align-items: center; justify-content: center; width: auto; min-width: 48px; flex-direction: column; gap: 2px; padding: 5px 7px; }
.help-now-button { display: flex; align-items: center; justify-content: center; width: auto; min-width: 80px; gap: 7px; padding: 5px 12px; }
.actions > .icon-button { height: 48px; }
.help-now-button > span:last-child { font-size: 1.125rem; font-weight: 800; }
#hint-button { background: #e0f2fe; color: #075985; border-color: #0ea5e9; box-shadow: 0 2px 8px #0284c733; }
#hint-button:hover:not(:disabled) { background: #bae6fd; border-color: #0284c7; }
.eye-icon { width: 22px; height: 22px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#preview-toggle[aria-pressed="true"] .eye-slash { display: none; }
.icon-button:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

.helper-dot-sample {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ef4444, #eab308 50%, #3b82f6);
    display: inline-block;
}

/* Art Board Canvas Area */
.art-board-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 6px auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.art-board-frame {
    --board-inset: 10px;
    position: relative;
    width: 100%;
    max-width: 640px;
    aspect-ratio: var(--board-aspect, 1 / 1);
    padding: var(--board-inset);
    background: #fff8eb;
    border: 3.5px solid #d4b886;
    border-radius: 24px;
    box-shadow: 0 10px 28px rgba(100, 70, 30, .14), inset 0 2px 6px rgba(255, 255, 255, .8);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    overflow: hidden;
}

.finished-art-reveal {
    position: absolute;
    inset: var(--board-inset);
    width: calc(100% - var(--board-inset) - var(--board-inset));
    height: calc(100% - var(--board-inset) - var(--board-inset));
    object-fit: fill;
    background: #fff;
    border-radius: 14px;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity .8s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, .15);
}

.finished-art-reveal[hidden] {
    display: none !important;
}

.finished-art-reveal.visible {
    display: block !important;
    opacity: 1;
    pointer-events: auto;
}

.art-board {
    user-select: none;
    -webkit-user-select: none;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(var(--board-cols, 10), 1fr);
    grid-template-rows: repeat(var(--board-rows, 10), 1fr);
    background: var(--canvas-bg);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: inset 0 0 12px rgba(0, 0, 0, .05);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.art-board, .finished-art-reveal { transform-origin: 0 0; transform: translate(var(--zoom-x, 0px), var(--zoom-y, 0px)) scale(var(--zoom-scale, 1)); }
.zoom-controls { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.art-board-frame.pan-mode, .art-board-frame.pan-mode .vector-region, .art-board-frame.pan-mode .art-cell { cursor: grab; }
.art-board-frame.pan-mode:active, .art-board-frame.pan-mode:active .vector-region, .art-board-frame.pan-mode:active .art-cell { cursor: grabbing; }
.zoom-controls output { min-width: 60px; text-align: center; font-size: 1.125rem; font-weight: 800; }
.zoom-tip { font-size: 1.125rem; color: #786b59; margin: 8px 0 0; text-align: center; }
.generation-loading { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; background: #fffdf3ed; text-align: center; border-radius: 20px; }
.generation-loading[hidden] { display: none; }
.generation-loading strong { font-size: 1.125rem; }
.generation-loading small { max-width: 270px; font-size: 1.125rem; color: #786b59; }
.generation-loading progress { width: min(100%, 280px); height: 14px; accent-color: #f59e0b; }

/* A quiet painting-only fullscreen, using the same board and palette nodes. */
body.painting-fullscreen-open { overflow: hidden; }
.board-wrap.is-fullscreen { position: fixed; inset: 0; z-index: 90; width: 100%; height: 100dvh; max-width: none; padding: 48px 12px 12px; gap: 10px; background: #fffaf0; overflow: hidden; }
.is-fullscreen .art-board-container { flex: 1; min-height: 0; width: 100%; max-width: none; margin: 0; justify-content: center; }
.is-fullscreen .art-board-frame { flex-shrink: 0; max-width: none; border-width: 2px; border-radius: 16px; box-shadow: 0 3px 15px #64461e14; --board-inset: 5px; }
.is-fullscreen .board-heading { position: absolute; top: 14px; left: 16px; width: calc(100% - 128px); max-width: none; font-size: 1.125rem; }
.is-fullscreen .board-heading-controls, .is-fullscreen .settings-availability, .is-fullscreen .zoom-tip, .is-fullscreen #win-message { display: none; }
.fullscreen-hud { position: absolute; top: 8px; right: 10px; z-index: 25; display: flex; gap: 6px; }
.fullscreen-small-button { width: 36px; height: 36px; border: 1px solid #d6cfc1; border-radius: 10px; background: #ffffffcc; color: #586375; font-size: 1.125rem; cursor: pointer; opacity: .8; }
.fullscreen-small-button:hover, .fullscreen-small-button:focus-visible { opacity: 1; background: #fff; }
.fullscreen-panel { width: min(780px, 100%); max-height: 45dvh; overflow-y: auto; flex-shrink: 0; padding: 8px 10px; border: 1px solid #e6dccb; border-radius: 14px; background: #ffffffbf; box-shadow: 0 2px 8px #64461e0a; }
.fullscreen-tools { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.fullscreen-tools .zoom-controls { margin: 0; gap: 6px; }
.fullscreen-tools .icon-button { width: 44px; height: 44px; border-radius: 9px; font-size: 18px; }
.fullscreen-tools .help-now-button { width: auto; min-width: 72px; padding: 4px 8px; }
.fullscreen-tools .help-now-button { background: #e0f2fe; color: #075985; border-color: #0ea5e9; }
.fullscreen-tools .state-toggle { width: 42px; min-width: 42px; height: 40px; padding: 2px 5px; gap: 0; }
.fullscreen-tools .eye-icon { width: 19px; height: 19px; }
.fullscreen-tools .tool-toggle, .fullscreen-tools .text-button { font-size: 1.125rem; }
.fullscreen-tools .toggle-state { font-size: 1.125rem; }
.fullscreen-panel .palette-container { width: 100%; margin: 6px 0 0; }
.fullscreen-panel .palette-title { display: none; }
.fullscreen-panel .palette-scroll { padding: 2px 0; gap: 6px; }
.fullscreen-panel .palette-pot { min-width: 42px; padding: 4px; border-radius: 10px; }
.fullscreen-panel .pot-color-disc { width: 27px; height: 27px; }
.fullscreen-panel .pot-number { font-size: 1.125rem; }
.fullscreen-panel .pot-name { display: none; }
.fullscreen-panel .pot-count { min-width: 18px; font-size: 1.125rem; }
.state-toggle[aria-pressed="true"] .eye-slash { display: none; }

/* Vector Mode: Escape CSS Grid so SVG fills 100% of the frame without shrinking */
.art-board.vector-mode {
    display: block !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    background: #ffffff;
}

/* Vector Painting Board (Smooth True SVG Outlines & Regions) */
.vector-board {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1 / 1;
    border-radius: 14px;
    background: #ffffff;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    display: block !important;
    outline: none;
}

.vector-guide {
    opacity: .3;
    pointer-events: none;
}

.vector-region {
    fill: #ffffff;
    stroke: #64748b;
    stroke-width: 2.2;
    stroke-linejoin: round;
    stroke-linecap: round;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    transition: fill .2s ease, stroke .15s ease;
}

/* Generated regions share fitted curves; no blur is needed to hide pixel steps. */
.vector-region.soft-region {
    fill: rgba(255, 255, 255, .3);
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke: rgba(71, 85, 105, .62);
    stroke-width: .9;
}

.soft-vector-mode .vector-label,
.soft-vector-mode .vector-label.active-color {
    font-size: max(1.125rem, var(--label-font-size, 16px)) !important;
    stroke-width: 2px !important;
    filter: none;
}

.soft-vector-mode .soft-region.highlighted:not(.painted) {
    fill: rgba(254, 240, 138, .45) !important;
    stroke-width: 1.4 !important;
    animation: none;
}

.soft-vector-mode .soft-region:hover:not(.painted) {
    fill: rgba(254, 252, 232, .5);
    stroke-width: 1.2;
}

.soft-vector-mode .soft-region:focus-visible:not(.painted) {
    stroke-width: 1.8;
}

.art-board[aria-busy="true"] { pointer-events: none; opacity: .65; }

.difficulty-label { display: block; font-weight: 700; margin: 1.25rem 0 .5rem; }
.difficulty-select { width: 100%; padding: .75rem; border: 1px solid #d8c3a5; border-radius: 12px; background: #fffdf5; color: #334155; font: inherit; }
.difficulty-current { padding: .75rem; border-radius: 12px; background: #fff8eb; }
.difficulty-warning { padding: .75rem; border-radius: 12px; background: #fff1d6; color: #92400e; font-weight: 700; }
.difficulty-note { font-size: 1.125rem; color: #64748b; }
.image-import-divider { text-align: center; margin: 1.5rem 0 0; color: #786b59; font-size: 1.125rem; }
.image-url-status { min-height: 1.6em; color: #475569; font-size: 1.125rem; }
.image-url-status.is-error { color: #b91c1c; }
#image-url-input { min-width: 0; box-sizing: border-box; }
.settings-fields { border: 0; padding: 0; margin: 0; min-width: 0; }
.settings-availability { width: 100%; max-width: 640px; margin: 0; color: #786b59; font-size: 1.125rem; }
.settings-checkbox { display: flex; gap: .6rem; align-items: flex-start; margin-top: 1rem; font-size: 1.125rem; }
.settings-checkbox input { margin-top: .15rem; flex-shrink: 0; accent-color: #f59e0b; }
.color-count-range { width: 100%; accent-color: #f59e0b; cursor: pointer; }

.confetti-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; overflow: hidden; }
.confetti { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: confetti-fall 2.4s ease-in forwards; }
@keyframes confetti-fall { to { transform: translate(var(--drift), 110vh) rotate(720deg); } }

#art-board .vector-region.idle-nudge:not(.painted) { stroke: #f59e0b !important; stroke-width: 3 !important; transition: none; animation: idle-nudge 1.1s ease-in-out infinite !important; }
#art-board .vector-label.idle-nudge:not(.hidden) { stroke: #fbbf24 !important; animation: idle-nudge 1.1s ease-in-out infinite !important; }
#art-board .art-cell.idle-nudge:not(.painted) { outline: 3px solid #f59e0b; outline-offset: -3px; animation: idle-nudge 1.1s ease-in-out infinite !important; }
@keyframes idle-nudge { 50% { filter: drop-shadow(0 0 4px #f59e0b); } }
.hint-marker { position: absolute; z-index: 15; width: 38px; height: 38px; border: 3px solid #0284c7; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; box-shadow: 0 0 0 3px #fff, 0 0 0 6px #0284c755; animation: hint-beacon 1s ease-in-out infinite; }
.hint-marker span { position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); padding: 4px 9px; border-radius: 8px; background: #0369a1; color: #fff; font-size: 1.125rem; font-weight: 800; box-shadow: 0 1px 5px #0003; }
@keyframes hint-beacon { 50% { box-shadow: 0 0 0 3px #fff, 0 0 0 12px #0284c733; } }
@keyframes manual-hint-pulse { 50% { filter: drop-shadow(0 0 5px #0284c7) brightness(.88); } }
#art-board .vector-region.hint-focus:not(.painted) { fill: #e0f2fe !important; stroke: #0284c7 !important; stroke-width: 3 !important; vector-effect: non-scaling-stroke; transition: none; animation: manual-hint-pulse 1s ease-in-out infinite !important; }
#art-board .art-cell.hint-focus:not(.painted) { outline: 3px solid #0284c7; outline-offset: -3px; z-index: 10; box-shadow: 0 0 12px #0284c780; animation: manual-hint-pulse 1s ease-in-out infinite !important; }
@media (prefers-reduced-motion: reduce) {
    #art-board .vector-region.idle-nudge:not(.painted),
    #art-board .vector-label.idle-nudge:not(.hidden),
    #art-board .art-cell.idle-nudge:not(.painted),
    #art-board .vector-region.hint-focus:not(.painted),
    #art-board .art-cell.hint-focus:not(.painted) { animation: none !important; filter: none; }
    .hint-marker { animation: none; }
    .confetti { display: none; }
}

/* Keyboard users still get a visible (but shape-following) focus marker */
.vector-region:focus-visible:not(.painted) {
    stroke: #7c3aed;
    stroke-width: 4;
}

.vector-region:hover:not(.painted) {
    fill: #fefce8;
    stroke: #0f172a;
    stroke-width: 3;
}

.vector-region.highlighted:not(.painted) {
    fill: #fef08a !important;
    stroke: #ca8a04 !important;
    stroke-width: 3.5 !important;
    animation: region-pulse 1.4s infinite alternate ease-in-out;
}

@keyframes region-pulse {
    0% { fill: #fef08a; }
    100% { fill: #fde047; }
}


/* Painted areas: stroke takes the fill colour (set inline) so the picture looks seamless */
.vector-region.painted {
    stroke-width: 1;
    cursor: default;
}

/* One full-resolution source under opaque masks. Painting reveals original
   colours, gradients and fine details without separate bitmap copies. */
.original-art-mode .vector-guide {
    opacity: 1;
}

.original-art-mode .vector-region:not(.painted) {
    fill: rgba(255, 255, 255, .79);
}

.original-art-mode .vector-region.highlighted:not(.painted) {
    fill: rgba(254, 240, 138, .82) !important;
}

.original-art-mode .vector-region:hover:not(.painted) {
    fill: rgba(254, 252, 232, .75);
}

.original-art-mode .vector-region.painted {
    transition: none;
}

.original-art-mode .vector-label.hidden {
    display: none;
}

.vector-labels-group {
    pointer-events: none;
}

.vector-label {
    font-family: 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
    font-size: 19px;
    font-weight: 900;
    fill: #0f172a;
    paint-order: stroke fill;
    stroke: #ffffff;
    stroke-width: 5px;
    stroke-linejoin: round;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    transition: opacity .2s ease, font-size .15s ease;
}

.vector-label.small {
    font-size: 1.125rem;
    stroke-width: 3.5px;
}

.vector-label.small.active-color {
    font-size: 1.125rem !important;
    stroke-width: 5px !important;
}

.vector-label.active-color {
    font-size: 24px !important;
    fill: #000000 !important;
    stroke: #facc15 !important;
    stroke-width: 7px !important;
    filter: drop-shadow(0 2px 5px rgba(202, 138, 4, 0.75));
    animation: label-glow 1.2s infinite alternate ease-in-out;
}

@keyframes label-glow {
    0% { stroke: #facc15; }
    100% { stroke: #fbbf24; }
}

.vector-label.hidden {
    opacity: 0;
}

/* Seamless finished vector view */
.vector-board.grid-hidden .vector-region {
    stroke: transparent !important;
}

/* Tiles / Cells - Fluid Scaling Font Size */
.art-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: max(1.125rem, calc(min(480px, 86vw) / var(--board-cols, 10) * 0.46));
    color: #334155;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, transform .12s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Background cell (outside the motif shape) */
.art-cell.canvas-bg {
    background: #f1f5f9 !important;
    border-color: #e2e8f0 !important;
    cursor: default;
}

/* Unpainted motif cell */
.art-cell:not(.painted):not(.canvas-bg) {
    background: #ffffff;
    border-color: #94a3b8;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .05);
}

.art-cell:hover:not(.painted):not(.canvas-bg) {
    background: #fefce8;
    color: #0f172a;
    z-index: 1;
}

/* Number display inside cell */
.cell-number {
    pointer-events: none;
    line-height: 1;
    transition: opacity .15s ease, transform .15s ease;
}

/* Highlighted: Active Color Helper */
.art-cell.highlighted:not(.painted) {
    background: #fef08a !important;
    color: #854d0e !important;
    font-weight: 900 !important;
    border-color: #eab308 !important;
    box-shadow: 0 0 8px rgba(234, 179, 8, .45), inset 0 0 0 1.5px #ca8a04 !important;
    z-index: 2;
    animation: cell-pulse 1.6s infinite alternate ease-in-out;
}

@keyframes cell-pulse {
    0% { background: #fef08a; }
    100% { background: #fde047; }
}


/* Painted State */
.art-cell.painted {
    border-color: rgba(0, 0, 0, .08);
    color: transparent;
    cursor: default;
}
.art-cell.painted .cell-number {
    opacity: 0;
    transform: scale(0.5);
}

/* Pop Animation on Paint */
.art-cell.pop-paint {
    animation: paint-pop .25s ease-out;
    z-index: 5;
}

@keyframes paint-pop {
    0% { transform: scale(0.85); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Wrong Click Wobble */
.art-cell.wrong-shake {
    animation: wrong-wobble .4s ease-in-out;
    background: #fee2e2 !important;
    border-color: #f87171 !important;
}

@keyframes wrong-wobble {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px) rotate(-3deg); }
    40% { transform: translateX(4px) rotate(3deg); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* Grid lines disabled (seamless finished artwork) */
.art-board.grid-hidden .art-cell {
    border-color: transparent !important;
}

/* Win Celebration Banner (Placed BELOW the artwork, never covering it!) */
.win-banner {
    width: 100%;
    max-width: 520px;
    margin: 10px auto 4px;
    padding: 16px 20px;
    border-radius: 20px;
    background: linear-gradient(135deg, #fefce8, #fef9c3);
    border: 2px solid #facc15;
    box-shadow: 0 8px 24px rgba(234, 179, 8, .2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    animation: banner-slide-in .4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.win-banner[hidden] {
    display: none !important;
}

@keyframes banner-slide-in {
    from { opacity: 0; transform: translateY(-10px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.win-banner-badge {
    font-size: 38px;
    line-height: 1;
    animation: bounce-trophy 1.2s infinite alternate ease-in-out;
}
@keyframes bounce-trophy {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-6px) scale(1.1); }
}

.win-banner-title {
    margin: 0;
    font-size: 22px;
    font-weight: 900;
    color: #854d0e;
}

.win-banner-text {
    margin: 4px 0 0;
    font-size: 1.125rem;
    color: #713f12;
}

.win-banner-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 4px;
}

.download-button {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    box-shadow: 0 3px 8px rgba(37, 99, 235, .28);
}
.download-button:hover {
    box-shadow: 0 5px 14px rgba(37, 99, 235, .35);
}

.gallery-btn {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    box-shadow: 0 3px 8px rgba(124, 58, 237, .28);
}
.gallery-btn:hover {
    box-shadow: 0 5px 14px rgba(124, 58, 237, .35);
}

/* Palette Container & Buttons */
.palette-container {
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.palette-title {
    font-size: 1.125rem;
    font-weight: 800;
    color: #8c7b68;
    text-transform: uppercase;
    letter-spacing: 1.1px;
}

.palette-scroll {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 6px 4px 10px;
    overflow-x: visible;
    scrollbar-width: thin;
    scrollbar-color: #d8c3a5 transparent;
    -webkit-overflow-scrolling: touch;
}

.palette-pot {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 68px;
    padding: 8px 6px;
    border: 2px solid #e8decb;
    border-radius: 18px;
    background: #ffffff;
    cursor: pointer;
    transition: transform .18s, border-color .18s, box-shadow .18s;
    outline: none;
}

.palette-pot:hover {
    transform: translateY(-2px);
    border-color: #d1be9e;
}

.palette-pot.active {
    border-color: #f59e0b;
    background: #fffdf5;
    box-shadow: 0 5px 14px rgba(245, 158, 11, .28);
    transform: translateY(-4px) scale(1.05);
}

.pot-color-disc {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    box-shadow: 0 3px 6px rgba(0, 0, 0, .14), inset 0 2px 4px rgba(255, 255, 255, .4);
    border: 2px solid rgba(255, 255, 255, .8);
}

.pot-number {
    font-size: 1.125rem;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

.pot-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: #64748b;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pot-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    font-size: 1.125rem;
    font-weight: 800;
    background: #f1f5f9;
    color: #475569;
}

/* Palette pot completed */
.palette-pot.completed {
    opacity: .85;
    border-color: #a7f3d0;
    background: #f0fdf4;
}
.palette-pot.completed .pot-count {
    background: #047857;
    color: #ffffff;
}

/* Game Footer */
.game-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    border-top: 1.5px solid #f1e9dd;
    background: #faf6ed;
    color: #786b59;
    font-size: 1.125rem;
    flex-wrap: wrap;
}

.game-footer p { margin: 0; display: flex; align-items: center; gap: 8px; }
.hint-icon { font-size: 1.125rem; }

.text-button {
    border: 0;
    background: transparent;
    color: #b45309;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.text-button:hover { text-decoration: underline; }

/* Bottom Note */
.bottom-note {
    margin-top: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 24px;
    border-radius: 20px;
    background: #ffffff;
    border: 1.5px solid #ebe2d3;
    box-shadow: 0 4px 14px rgba(100, 70, 30, .05);
    flex-wrap: wrap;
}

.note-art { font-size: 24px; }
.bottom-note p { margin: 0; color: #64748b; font-size: 1.125rem; flex: 1 1 240px; }

.data-actions { display: flex; align-items: center; gap: 10px; }
.data-button {
    padding: 6px 14px;
    border: 1.5px solid #d4c5b0;
    border-radius: 10px;
    background: #fdfbf7;
    color: #635341;
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .18s, border-color .18s;
}
.data-button:hover { background: #f7f1e4; border-color: #bfae95; }

.no-ads {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: 12px;
    background: #dcfce7;
    color: #15803d;
    font-size: 1.125rem;
    font-weight: 800;
}

/* Footer */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 8px 10px;
    color: #94a3b8;
    font-size: 1.125rem;
    font-weight: 600;
}

/* Dialogs */
.help-dialog {
    border: 0;
    border-radius: 26px;
    background: #ffffff;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25);
    padding: 28px;
    max-width: 540px;
    width: calc(100% - 32px);
    color: var(--ink);
}

.help-dialog::backdrop {
    background: rgba(30, 41, 59, .5);
    backdrop-filter: blur(4px);
}

.dialog-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 0;
    background: #f1f5f9;
    color: #64748b;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
}
.dialog-close:hover { background: #e2e8f0; color: #1e293b; }

.help-dialog h2 { margin: 4px 0 16px; font-size: 26px; font-weight: 800; }

.help-steps {
    list-style: none;
    padding: 0;
    margin: 0 0 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.help-steps li {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.step-num {
    flex: 0 0 32px;
    height: 32px;
    border-radius: 50%;
    background: #fef3c7;
    color: #92400e;
    font-weight: 900;
    font-size: 1.125rem;
    display: grid;
    place-items: center;
}

.help-steps strong { display: block; font-size: 1.125rem; color: #1e293b; margin-bottom: 2px; }
.help-steps p { margin: 0; font-size: 1.125rem; color: #64748b; line-height: 1.4; }

/* Gallery Dialog */
.gallery-dialog { max-width: 720px; }
.gallery-dialog-desc { margin: 0 0 14px; font-size: 1.125rem; color: #64748b; }

.modal-category-filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.modal-filter-btn {
    padding: 6px 13px;
    border-radius: 12px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.modal-filter-btn:hover { background: #ffffff; border-color: #cbd5e1; }
.modal-filter-btn.active {
    background: #f59e0b;
    color: #422006;
    border-color: #d97706;
}
.modal-filter-btn.diff-btn {
    border-color: #c084fc;
    color: #7e22ce;
}
.modal-filter-btn.diff-btn.active {
    background: #9333ea;
    color: #ffffff;
    border-color: #7e22ce;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    gap: 12px;
    max-height: 380px;
    overflow-y: auto;
    padding: 4px 4px 14px;
    margin-bottom: 20px;
    scrollbar-width: thin;
}

.gallery-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    border-radius: 18px;
    border: 2px solid #e2e8f0;
    background: #ffffff;
    cursor: pointer;
    text-align: center;
    transition: transform .18s, border-color .18s, box-shadow .18s;
}

.gallery-card:hover {
    transform: translateY(-3px);
    border-color: #f59e0b;
    box-shadow: 0 6px 14px rgba(245, 158, 11, .2);
}

.gallery-card.active {
    border-color: #f59e0b;
    background: #fffdf5;
    box-shadow: 0 4px 12px rgba(245, 158, 11, .25);
}

.gallery-card-icon {
    font-size: 34px;
    line-height: 1;
}

.gallery-card-preview { width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: contain; border-radius: 10px; background: #fff8eb; }
.image-credit { margin: 0; font-size: 1.125rem; color: #786b59; text-align: center; line-height: 1.5; }
.image-credit a, .footer a { color: inherit; text-underline-offset: 2px; }
.is-fullscreen .image-credit { display: none; }

.gallery-card-title {
    font-size: 1.125rem;
    font-weight: 800;
    color: #1e293b;
    line-height: 1.2;
}

.gallery-diff-tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 1.125rem;
    font-weight: 800;
    letter-spacing: .4px;
}
.diff-easy { background: #dcfce7; color: #15803d; }
.diff-medium { background: #fef3c7; color: #92400e; }
.diff-hard { background: #f3e8ff; color: #7e22ce; }

.gallery-card-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 1.125rem;
    font-weight: 700;
    color: #64748b;
}

.gallery-card-star {
    color: #f59e0b;
    font-size: 1.125rem;
}

/* Responsive adjustments */
@media (max-width: 1023px) {
    .game-toolbar { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 680px) {
    .category-tabs { flex-wrap: wrap; overflow-x: visible; }
    .category-tab { flex: 1 1 140px; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
    .palette-scroll { flex-wrap: wrap; overflow-x: visible; }
    .actions > .icon-button { min-height: 54px; }
    .fullscreen-small-button { width: 44px; height: 44px; }
    .board-wrap.is-fullscreen { padding: 58px 8px 8px; }
    .fullscreen-panel { padding: 6px; }
    .topbar { flex-wrap: wrap; gap: 8px; padding: 12px 0; }
    .intro { flex-direction: column; align-items: flex-start; gap: 14px; }
    .gallery-trigger-card { width: 100%; justify-content: space-between; }
    .gallery-open-btn { flex: 1; min-width: 0; gap: 8px; padding: 4px; }
    .gallery-btn-text { min-width: 0; }
    .gallery-btn-text strong { max-width: 100%; font-size: 1.125rem; }
    .gallery-badge { display: none; }
    .gallery-nav-arrows { flex-shrink: 0; }
    .game-toolbar { padding: 12px 14px; }
    .stats { flex-wrap: wrap; }
    .actions { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); width: 100%; }
    .actions > .icon-button { width: 100%; min-width: 0; padding-left: 3px; padding-right: 3px; }
    .actions > .help-now-button { flex-direction: column; gap: 1px; }
    .actions > .help-now-button > span:last-child { font-size: 1.125rem; }
    .actions > .upload-btn, .actions > .gallery-shortcut-btn { grid-column: span 3; min-height: 44px; padding: 0 8px; }
    .board-wrap { padding: 14px 12px; }
    .art-board-frame { --board-inset: 6px; }
    .palette-pot { min-width: 58px; padding: 6px 4px; }
    .pot-color-disc { width: 32px; height: 32px; }
    .pot-number { font-size: 1.125rem; }
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

.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;
}

/* Keep secondary labels readable while preserving the compact drawing controls. */
.section-label, .gallery-btn-label, .stat small, .toggle-state, .zoom-tip,
.generation-loading small, .board-heading, .fullscreen-tools .tool-toggle,
.fullscreen-tools .text-button, .fullscreen-tools .toggle-state, .settings-availability,
.image-credit, .gallery-diff-tag, .gallery-card-meta, .actions > .help-now-button > span:last-child {
    font-size: 1.125rem;
}
.gallery-btn-label { color: #705c48; }

/* Keep secondary text and native form controls readable when zoomed. */
:where(small, sub, sup) { font-size: 1.125rem; }
:where(input, select, textarea) { font: inherit; }
