
:root {
    --background: #f7f6fb;
    --surface: #ffffff;
    --text: #29263a;
    --muted: #88849b;
    --border: #e8e5f0;
    --accent: #8b5cf6;
    --accent-dark: #7443e8;
    --accent-light: #f0eaff;
    --shadow: 0 8px 28px #30205d0a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 32px 18px;
    background: var(--background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
}

button,
select,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid #bba5ff;
    outline-offset: 3px;
}

.app {
    width: min(1120px, 100%);
    margin: 0 auto;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
}

.logo {
    display: grid;
    width: 52px;
    height: 52px;
    flex: 0 0 52px;
    place-items: center;
    border-radius: 15px;
    background: var(--accent);
    color: white;
    font-size: 29px;
    box-shadow: 0 5px 14px #8b5cf633;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 4px;
    font-size: clamp(23px, 4vw, 30px);
    letter-spacing: -1px;
}

.app-header p,
.section-heading p,
.save-actions p,
.custom-color-row p,
.modal-subtitle {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-areas: "editor tools";
    align-items: start;
    gap: 22px;
}

.editor,
.tools-panel,
.save-section {
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.canvas-column {
    grid-area: editor;
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 22px;
}

.editor {
    min-width: 0;
    padding: 24px;
}

.tools-panel {
    grid-area: tools;
    min-width: 0;
}

.save-section {
    min-width: 0;
    width: 100%;
    margin-top: 0;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

h2 {
    margin-bottom: 6px;
    font-size: 17px;
    letter-spacing: -0.3px;
}

.size-control {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

select {
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: white;
    color: var(--text);
}

.canvas-wrap {
    display: grid;
    place-items: center;
    padding: 18px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 13px;
    background-color: #fbfaff;
    background-image: radial-gradient(#e8e3f2 0.8px, transparent 0.8px);
    background-size: 14px 14px;
}

.pixel-canvas {
    display: grid;
    width: min(100%, 540px);
    aspect-ratio: 1;
    flex: 0 0 auto;
    overflow: hidden;
    border: 1px solid #d8d3e5;
    background: white;
    touch-action: none;
    user-select: none;
}

.pixel {
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: white;
    touch-action: none;
}

.pixel-canvas.show-grid .pixel {
    box-shadow: inset 0 0 0 1px #eae7f0;
}

.pixel-canvas:not(.show-grid) .pixel {
    box-shadow: none;
}

.canvas-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 15px;
    color: var(--muted);
    font-size: 12px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.tools-panel {
    padding: 21px;
}

.tool-section + .tool-section {
    margin-top: 23px;
    padding-top: 21px;
    border-top: 1px solid var(--border);
}

.tool-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.tool-button {
    display: flex;
    min-width: 0;
    min-height: 68px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: white;
    color: var(--text);
    font-size: 21px;
    transition: background 150ms ease, border-color 150ms ease;
}

.tool-button span {
    font-size: 11px;
}

.tool-button:hover {
    background: #faf8ff;
}

.tool-button.active {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent-dark);
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 9px;
    margin: 14px 0 18px;
}

.palette-color {
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px #00000012;
    transition: transform 120ms ease, outline-color 120ms ease;
}

.palette-color:hover {
    transform: scale(1.1);
}

.palette-color.active {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.custom-color-row {
    display: flex;
    align-items: center;
    gap: 11px;
}

.custom-color-wrap {
    position: relative;
    display: inline-grid;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: white;
    cursor: pointer;
}

#customColor {
    position: absolute;
    z-index: 1;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 2px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
}

#customColor::-webkit-color-swatch-wrapper {
    padding: 0;
}

#customColor::-webkit-color-swatch {
    border: 0;
    border-radius: 50%;
}

#customColor::-moz-color-swatch {
    border: 0;
    border-radius: 50%;
}

.custom-color-plus {
    position: absolute;
    z-index: 2;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 0 0 2px;
    color: white;
    font-size: 20px;
    font-weight: 500;
    line-height: 1;
    text-shadow: 0 1px 3px #0008;
    pointer-events: none;
}

.custom-color-row strong,
.current-color-row strong {
    display: block;
    font-size: 12px;
}

.custom-color-row p {
    margin-top: 3px;
    font-size: 11px;
}

.current-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 17px;
    padding: 11px;
    border-radius: 10px;
    background: #faf9fd;
}

.current-color-preview {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border: 1px solid #00000012;
    border-radius: 8px;
    background: var(--accent);
}

.muted-label {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 10px;
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
}

.option-row strong,
.option-row small {
    display: block;
}

.option-row strong {
    font-size: 12px;
}

.option-row small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.actions-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
}

.actions-section h2 {
    margin-bottom: 2px;
}

.action-button,
.secondary-button,
.primary-button {
    display: inline-flex;
    min-height: 39px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    transition: background 150ms ease, transform 150ms ease;
}

.action-button:hover,
.secondary-button:hover {
    background: #f6f3ff;
}

.primary-button {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

.primary-button:hover {
    border-color: var(--accent-dark);
    background: var(--accent-dark);
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.save-section {
    margin-top: 22px;
    padding: 22px;
}

.save-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.save-actions h2 {
    margin-bottom: 5px;
}

.save-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 9px;
}

.gallery-panel {
    margin-top: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fafafd;
    transform-origin: top;
    animation: gallery-drop 220ms ease;
}

.gallery-panel[hidden] {
    display: none !important;
}

.gallery-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.gallery-panel-header h2 {
    margin: 0;
}

.close-button {
    display: grid;
    width: 34px;
    height: 34px;
    min-height: 34px;
    flex: 0 0 34px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: white;
    color: var(--muted);
}

.close-button:hover {
    background: #f0edff;
    color: var(--text);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 15px;
}

.gallery-card {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
}

.gallery-preview {
    display: grid;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--border);
    background: white;
    image-rendering: pixelated;
}

.gallery-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.gallery-card-title {
    margin: 10px 0 8px;
    overflow-wrap: anywhere;
    font-size: 12px;
    font-weight: 600;
}

.gallery-card-actions {
    display: flex;
    gap: 6px;
}

.gallery-card-actions button {
    flex: 1;
    min-width: 0;
    padding: 7px 5px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: white;
    color: var(--text);
    font-size: 11px;
}

.gallery-card-actions button:hover {
    background: var(--accent-light);
}

.gallery-card-actions .delete-artwork:hover {
    border-color: #f1b8c1;
    background: #fff0f2;
    color: #b4233c;
}

.empty-gallery {
    margin: 18px 0 4px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.empty-gallery[hidden] {
    display: none;
}

footer {
    padding: 24px 0 6px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

@keyframes gallery-drop {
    from {
        opacity: 0;
        transform: translateY(-8px) scaleY(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scaleY(1);
    }
}

@media (max-width: 820px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "editor"
            "tools"
            "save";
    }

    .canvas-column {
        display: contents;
    }

    .editor { grid-area: editor; }
    .tools-panel { grid-area: tools; }
    .save-section { grid-area: save; width: 100%; }

    .tools-panel {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }

    .tool-section + .tool-section {
        margin-top: 0;
        padding-top: 0;
        border-top: 0;
    }

    .save-actions {
        align-items: flex-start;
        flex-direction: column;
    }

    .save-buttons {
        justify-content: flex-start;
    }
}

@media (max-width: 520px) {
    body {
        padding: 20px 11px;
    }

    .app-header {
        gap: 10px;
        margin-bottom: 20px;
    }

    .logo {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
    }

    .editor,
    .tools-panel,
    .save-section {
        padding: 15px;
        border-radius: 14px;
    }

    .section-heading {
        align-items: flex-start;
    }

    .size-control {
        align-items: flex-end;
        flex-direction: column;
        gap: 5px;
    }

    .canvas-wrap {
        padding: 8px;
    }

    .tools-panel {
        gap: 22px 15px;
    }

    .tool-button {
        min-height: 62px;
    }

    .save-buttons {
        width: 100%;
    }

    .save-buttons button {
        flex: 1 1 auto;
    }

    .gallery-panel {
        padding: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* Guides page navigation and layout additions */
.app-header {
    flex-wrap: wrap;
}

.header-copy {
    min-width: 0;
    flex: 1;
}

.guides-link {
    display: inline-flex;
    min-height: 39px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: background 150ms ease, transform 150ms ease;
}

.guides-link:hover {
    background: var(--accent-light);
}

.guides-intro {
    margin-bottom: 22px;
    padding: 25px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.guides-intro p {
    max-width: 720px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.7;
}

.guides-back-link {
    display: inline-flex;
    margin-bottom: 16px;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.guides-back-link:hover {
    text-decoration: underline;
}

.guides-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.guide-card {
    min-width: 0;
    padding: 21px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.guide-number {
    display: inline-grid;
    width: 34px;
    height: 34px;
    margin-bottom: 12px;
    place-items: center;
    border-radius: 10px;
    background: var(--accent-light);
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 700;
}

.guide-card h2 {
    margin-bottom: 9px;
}

.guide-card p,
.guide-card li {
    color: #625d73;
    font-size: 13px;
    line-height: 1.7;
}

.guide-card p {
    margin-bottom: 0;
}

.guide-card ul,
.guide-card ol {
    margin: 8px 0 0;
    padding-left: 20px;
}

.guide-card li + li {
    margin-top: 4px;
}

.guide-tip {
    margin-top: 12px !important;
    padding: 10px 12px;
    border-radius: 9px;
    background: #faf8ff;
}

.guides-footer-actions {
    display: flex;
    justify-content: center;
    margin-top: 22px;
}

@media (max-width: 650px) {
    .guides-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .guides-intro,
    .guide-card {
        padding: 17px;
    }

    .app-header {
        align-items: flex-start;
    }

    .guides-link {
        margin-left: auto;
    }
}


/* Guide buttons and the on-canvas hologram demonstration */
.guide-card { display: flex; flex-direction: column; align-items: flex-start; }
.guide-card-actions { margin-top: auto; padding-top: 15px; }
.guide-show-button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 8px 12px; border: 1px solid #8b5cf6; border-radius: 9px; background: #f0eaff; color: #7443e8; font-size: 12px; font-weight: 700; text-decoration: none; transition: background 150ms ease, transform 150ms ease; }
.guide-show-button:hover { background: #e5d9ff; }
.canvas-wrap { position: relative; }
.hologram-overlay { position: absolute; z-index: 5; top: 50%; left: 50%; width: min(100%, 540px); aspect-ratio: 1; transform: translate(-50%, -50%); display: grid; place-items: center; overflow: hidden; border: 1px solid #55f5ff88; border-radius: 4px; background: #072f4b20; box-shadow: inset 0 0 35px #31e9ff20, 0 0 24px #31e9ff22; pointer-events: none; }
.hologram-overlay::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, transparent 0 5px, #70f7ff13 6px 7px); pointer-events: none; }
.hologram-sprite { width: 72%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(16, 1fr); grid-template-rows: repeat(16, 1fr); opacity: .62; filter: drop-shadow(0 0 5px #31e9ff); }
.hologram-pixel { background: #4df5ff; box-shadow: inset 0 0 1px #e5ffff; }
.hologram-pixel.soft { background: #3b9dff; }
.hologram-caption { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 11px; border: 1px solid #6ef6ff66; border-radius: 9px; background: #071b35e8; color: #b8fbff; font-size: 11px; box-shadow: 0 0 15px #31e9ff22; pointer-events: auto; }
.hologram-caption strong { display: block; margin-bottom: 2px; color: #e0feff; font-size: 12px; }
.hologram-close { flex: 0 0 auto; padding: 7px 9px; border: 1px solid #6ef6ff88; border-radius: 7px; background: #123c59; color: white; font-size: 11px; cursor: pointer; }
.hologram-close:hover { background: #1c5874; }
@media (prefers-reduced-motion: no-preference) { .hologram-overlay { animation: hologram-flicker 3s ease-in-out infinite; } }
@keyframes hologram-flicker { 0%, 100% { opacity: .94; } 50% { opacity: .78; } }

/* True guide overlay: coloured sample pixels align one-to-one with canvas cells. */
.pixel-canvas { position: relative; }
.guide-art-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: grid;
    pointer-events: none;
    overflow: hidden;
}
.guide-art-pixel {
    min-width: 0;
    min-height: 0;
    background: transparent;
}
.guide-art-pixel.is-art {
    opacity: 0.48;
    outline: 1px solid rgba(255, 255, 255, 0.18);
    outline-offset: -1px;
}
.guide-art-close {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 6;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid rgba(60, 50, 75, 0.25);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.88);
    color: #342a45;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    pointer-events: auto;
}
.guide-art-close:hover { background: #fff; }
/* Disable the previous blue glow / caption hologram styles. */
.hologram-overlay, .hologram-sprite, .hologram-caption { display: none !important; }


/* Let the artwork/gallery bar use the full workspace width when the tools
   sidebar fits beside the canvas. If the sidebar is taller, JS adds
   .sidebar-taller so the bar stays within the canvas column instead. */
.save-section {
    width: calc(100% + 302px);
    margin-top: 0;
    padding: 22px;
}

body.sidebar-taller .save-section,
body.guide-mode.sidebar-taller .save-section {
    width: 100%;
}

/* Guide mode: keep the gallery compact so the extra guide palette fits. */
body.guide-mode .gallery-panel {
    max-height: 260px;
    overflow: auto;
    padding: 12px;
}
body.guide-mode .gallery-panel-header { margin-bottom: 10px; }
body.guide-mode .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 8px;
}
body.guide-mode .gallery-card { padding: 6px; border-radius: 9px; }
body.guide-mode .gallery-preview { max-height: 86px; }
body.guide-mode .gallery-card-title { margin: 6px 0; font-size: 10px; }
body.guide-mode .gallery-card-actions { flex-wrap: wrap; }
body.guide-mode .gallery-card-actions button { padding: 5px 3px; font-size: 9px; }

.guide-color-section {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.guide-color-section h3 { margin: 0 0 5px; font-size: 13px; }
.guide-color-section p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
#guideColorPalette { margin-top: 10px; }

/* A painted pixel that does not match the guide blinks red. */
.guide-art-pixel.is-wrong {
    background: #ff1f3d !important;
    opacity: 1 !important;
    outline: 1px solid #8f0015;
    outline-offset: -1px;
    box-shadow: inset 0 0 0 1px #ffffff70;
    animation: guide-wrong-blink 700ms steps(2, end) infinite;
    z-index: 2;
}

@keyframes guide-wrong-blink {
    0%, 100% {
        background: #ff1f3d !important;
        box-shadow: inset 0 0 0 2px #ffffff90, 0 0 7px #ff1f3d;
    }
    50% {
        background: #8f0015 !important;
        box-shadow: inset 0 0 0 1px #ffffff35;
    }
}

@media (prefers-reduced-motion: reduce) {
    .guide-art-pixel.is-wrong {
        animation: none;
        background: #ff1f3d !important;
    }
}

/* Guide thumbnails on the guides page */
.guide-preview-image {
    display: block;
    width: 100%;
    max-width: 170px;
    aspect-ratio: 1;
    height: auto;
    margin: 0 0 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fffdf8;
    image-rendering: pixelated;
}


/* Controls shown only while a guide is active. */
.guide-resolution-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}
.guide-resolution-control select {
    width: 100%;
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    color: var(--text);
    font-size: 12px;
}
.guide-auto-complete {
    width: 100%;
    margin-top: 10px;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 750;
    transition: background 150ms ease, transform 150ms ease;
}
.guide-auto-complete:hover { background: var(--accent-dark); }
.guide-auto-complete:active { transform: translateY(1px); }
#guideColorSection h4 {
    margin: 16px 0 0;
    font-size: 12px;
}

/* Dark theme: keep gallery and guide cards dark instead of leaving hard-coded white surfaces. */
body.dark-mode {
    --background: #15151d;
    --surface: #22222e;
    --text: #eeeaf8;
    --muted: #aaa5bd;
    --border: #3b394b;
    --accent: #9b7aff;
    --accent-dark: #8060e8;
    --accent-light: #342b4d;
    --shadow: 0 8px 28px #00000030;
    color-scheme: dark;
}

body.dark-mode .gallery-panel,
body.dark-mode .gallery-card,
body.dark-mode .gallery-preview,
body.dark-mode .gallery-card-actions button,
body.dark-mode .close-button,
body.dark-mode .guide-resolution-control select {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
body.dark-mode .gallery-panel { background-color: #1c1c27; }
body.dark-mode .gallery-preview { background-color: #171720; }
body.dark-mode .gallery-card-actions button:hover,
body.dark-mode .close-button:hover {
    background-color: var(--accent-light);
    color: var(--text);
}
body.dark-mode .gallery-card-actions .delete-artwork:hover {
    background: #492630;
    border-color: #854052;
    color: #ffb8c5;
}
body.dark-mode .guide-card {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
body.dark-mode .guide-show-button {
    background: var(--accent-light);
    border-color: var(--accent);
    color: #d9cbff;
}
body.dark-mode .guide-show-button:hover { background: #433661; }
body.dark-mode .guide-preview-image { background: #1a1a24; border-color: var(--border); }
body.dark-mode .guide-resolution-control select { background-color: #292735; }
body.dark-mode input,
body.dark-mode select { color-scheme: dark; }

/* Dark-mode fixes for the selected-colour area and custom colour picker. */
body.dark-mode .current-color-row {
    background-color: #292735;
    color: var(--text);
}
body.dark-mode .custom-color-wrap {
    background-color: #292735;
    border-color: var(--border);
}
body.dark-mode .current-color-preview {
    border-color: #ffffff30;
}
body.dark-mode .color-palette .palette-color {
    border-color: #ffffff16;
}

/* Canvas cells must never shift while pressed; keep drawing exactly under the pointer. */
#pixelCanvas .pixel,
#pixelCanvas .pixel:active {
    transform: none !important;
    transition: none !important;
}

/* Comprehensive dark-mode surfaces and controls (studio + guides). */
.theme-toggle-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 39px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.theme-toggle-button:hover {
    background: var(--accent-light);
    border-color: var(--accent);
}

body.dark-mode .theme-toggle-button,
body.dark-mode .tool-button,
body.dark-mode .action-button,
body.dark-mode .secondary-button,
body.dark-mode .guides-link,
body.dark-mode .gallery-card-actions button,
body.dark-mode .close-button,
body.dark-mode .guide-resolution-control select,
body.dark-mode select {
    background-color: #292936;
    border-color: var(--border);
    color: var(--text);
}
body.dark-mode .primary-button,
body.dark-mode .guide-auto-complete {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
body.dark-mode .primary-button:hover,
body.dark-mode .guide-auto-complete:hover {
    background-color: var(--accent-dark);
    border-color: var(--accent-dark);
}
body.dark-mode .tool-button:hover,
body.dark-mode .action-button:hover,
body.dark-mode .secondary-button:hover,
body.dark-mode .guides-link:hover,
body.dark-mode .theme-toggle-button:hover {
    background-color: #393449;
    border-color: #76619e;
    color: var(--text);
}
body.dark-mode .tool-button.active {
    background-color: #39304f;
    border-color: var(--accent);
    color: #e3d8ff;
}

/* The dotted area surrounding the drawing canvas was hard-coded light. */
body.dark-mode .canvas-wrap {
    background-color: #191922;
    background-image: radial-gradient(#454252 0.8px, transparent 0.8px);
    border-color: var(--border);
}
body.dark-mode .pixel-canvas {
    border-color: #555064;
}
body.dark-mode .pixel-canvas.show-grid .pixel {
    box-shadow: inset 0 0 0 1px #343341;
}
body.dark-mode .canvas-footer,
body.dark-mode .guide-card p,
body.dark-mode .guide-card li {
    color: var(--muted);
}
body.dark-mode .guide-tip {
    background: #292735;
    color: var(--text);
}
body.dark-mode .guides-intro {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
body.dark-mode .guides-back-link {
    color: #c8b7ff;
}
body.dark-mode .current-color-row,
body.dark-mode .custom-color-wrap {
    background-color: #292735;
    border-color: var(--border);
    color: var(--text);
}
body.dark-mode .gallery-panel {
    background-color: #1b1b25;
    border-color: var(--border);
}
body.dark-mode .gallery-card {
    background-color: #242430;
    border-color: var(--border);
    color: var(--text);
}
body.dark-mode .gallery-preview,
body.dark-mode .guide-preview-image {
    background-color: #171720;
    border-color: var(--border);
}
body.dark-mode .empty-gallery {
    color: var(--muted);
}
body.dark-mode .guide-card {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
body.dark-mode .guide-show-button {
    background-color: #39304f;
    border-color: var(--accent);
    color: #e3d8ff;
}
body.dark-mode .guide-show-button:hover {
    background-color: #494064;
}
body.dark-mode .guide-art-close {
    background: #292936;
    border-color: var(--border);
    color: var(--text);
}

/* Classroom preview */
.classroom-app { max-width: 1120px; }
.classroom-notice { margin: 18px 0; padding: 16px 18px; border: 1px solid #e6b65c; border-radius: 14px; background: #fff8e8; color: #6c4b13; }
.classroom-notice p { margin: 6px 0 0; line-height: 1.55; }
.classroom-hero { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: clamp(22px, 4vw, 38px); margin: 22px 0; border-radius: 22px; background: linear-gradient(120deg, #eee8ff, #e6f5ff); color: #292143; }
.classroom-hero h2 { margin: 5px 0 8px; font-size: clamp(1.6rem, 4vw, 2.5rem); }
.classroom-hero p { margin: 0; line-height: 1.55; }
.classroom-hero .eyebrow { font-size: .75rem; font-weight: 800; letter-spacing: .12em; color: #6950a6; }
.classroom-hero-icon { font-size: clamp(3rem, 8vw, 5.5rem); }
.classroom-panel { background: var(--surface, #fff); border: 1px solid var(--border, #e3e0eb); border-radius: 20px; padding: clamp(16px, 3vw, 28px); }
.classroom-panel-heading { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 18px; }
.classroom-panel-heading h2, .classroom-panel-heading h3 { margin: 0 0 5px; }
.classroom-panel-heading p { margin: 0; color: var(--muted, #6e6a79); }
.classroom-role-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 24px; }
.role-tab, .classroom-primary, .classroom-secondary, .text-button { cursor: pointer; border-radius: 11px; padding: 11px 15px; border: 1px solid var(--border, #ddd); font: inherit; font-weight: 700; }
.role-tab { background: var(--surface, white); color: var(--text, #252333); }
.role-tab.active { background: #eee7ff; border-color: #8b6bd6; color: #4d328e; }
.classroom-two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.classroom-form { display: flex; flex-direction: column; align-items: stretch; gap: 9px; padding: 20px; border: 1px solid var(--border, #e3e0eb); border-radius: 16px; background: var(--surface, #fff); }
.classroom-form h3 { margin: 0; }
.classroom-form p { margin: 0 0 8px; color: var(--muted, #6e6a79); line-height: 1.45; }
.classroom-form label { font-size: .9rem; font-weight: 700; margin-top: 3px; }
.classroom-form input, .classroom-form textarea, .classroom-form select { width: 100%; min-width: 0; border: 1px solid var(--border, #d8d4e1); border-radius: 10px; padding: 11px 12px; font: inherit; color: var(--text, #252333); background: var(--surface, white); }
.classroom-primary { margin-top: 7px; border-color: #7450c8; background: #7450c8; color: white; }
.classroom-primary:disabled, .classroom-secondary:disabled { opacity: .55; cursor: not-allowed; }
.class-list-heading { margin-top: 30px; }
.classroom-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.classroom-card, .classroom-task { border: 1px solid var(--border, #e3e0eb); background: var(--surface, #fff); border-radius: 15px; padding: 17px; min-width: 0; }
.classroom-card-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.classroom-class-icon { font-size: 1.6rem; }
.classroom-code { font: 800 .8rem ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; padding: 6px 8px; background: var(--soft-surface, #f2eff9); border-radius: 7px; }
.classroom-card h4, .classroom-task h4 { font-size: 1.1rem; margin: 13px 0 6px; overflow-wrap: anywhere; }
.classroom-card p, .classroom-task p { margin: 0; color: var(--muted, #6e6a79); line-height: 1.5; overflow-wrap: anywhere; }
.classroom-card-meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-top: 17px; padding-top: 12px; border-top: 1px solid var(--border, #e3e0eb); font-size: .85rem; }
.text-button { padding: 6px 9px; font-size: .82rem; background: transparent; color: var(--text, #252333); }
.classroom-task-list { display: grid; gap: 12px; }
.classroom-task { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.classroom-task-main { flex: 1; min-width: 0; }
.classroom-task h4 { margin-top: 9px; }
.classroom-task-tags, .classroom-task-meta, .classroom-task-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.task-tag { font-size: .75rem; padding: 5px 8px; border-radius: 100px; background: #eee8ff; color: #5a4094; font-weight: 700; }
.task-tag-done { background: #dcf6e7; color: #176b3c; }
.classroom-task-meta { margin-top: 13px; color: var(--muted, #6e6a79); font-size: .82rem; }
.classroom-task-actions { justify-content: flex-end; }
.classroom-secondary { background: transparent; color: var(--text, #252333); }
.classroom-empty { text-align: center; padding: 28px 15px; border: 1px dashed var(--border, #d8d4e1); border-radius: 14px; grid-column: 1 / -1; }
.classroom-empty > span { font-size: 2rem; }
.classroom-empty h4 { margin: 8px 0 5px; }
.classroom-empty p { margin: 0; color: var(--muted, #6e6a79); }
.classroom-status { min-height: 1.4em; margin: 16px 0 0; color: var(--muted, #6e6a79); }
.join-class-form { max-width: 520px; margin-bottom: 28px; }
[hidden] { display: none !important; }
body.dark-mode .classroom-notice { background: #3a3020; color: #ffe3a5; border-color: #8a6b2f; }
body.dark-mode .classroom-hero { background: linear-gradient(120deg, #2c2540, #202e3b); color: #f4efff; }
body.dark-mode .classroom-hero .eyebrow { color: #c9b4ff; }
body.dark-mode .role-tab.active { background: #39304f; border-color: #9c82e3; color: #e3d8ff; }
body.dark-mode .classroom-code { background: #302b3c; }
body.dark-mode .task-tag { background: #39304f; color: #e3d8ff; }
body.dark-mode .task-tag-done { background: #203c2c; color: #a9f0c5; }
@media (max-width: 720px) { .classroom-two-col { grid-template-columns: 1fr; } .classroom-task { flex-direction: column; } .classroom-task-actions { justify-content: flex-start; } .classroom-hero-icon { display: none; } }

/* Connected classroom account and submission UI */
.api-settings-panel { margin: 18px 0; padding: 16px 20px; }
.api-settings-panel summary { cursor: pointer; }
.api-settings-panel summary span, .form-help { color: var(--muted, #6e6a79); }
.api-settings-form { margin-top: 14px; padding: 14px; }
.classroom-auth-switch { display: flex; gap: 10px; margin: 16px 0; }
.classroom-auth-form { max-width: 560px; }
.classroom-auth-form [hidden] { display: none !important; }
.classroom-auth-form input, .classroom-auth-form select { box-sizing: border-box; width: 100%; border: 1px solid var(--border, #d8d4e1); border-radius: 10px; padding: 11px 12px; font: inherit; color: var(--text, #252333); background: var(--surface, white); }
.classroom-account-bar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 22px; padding: 14px 16px; border-radius: 14px; background: var(--soft-surface, #f2eff9); }
.classroom-account-bar p { margin: 4px 0 0; color: var(--muted, #6e6a79); }
.classroom-status.error { color: #b42318; }
.classroom-form-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.submission-details { margin-top: 14px; padding: 12px; border: 1px solid var(--border, #ddd); border-radius: 10px; }
.submission-details summary { cursor: pointer; font-weight: 700; }
.submission-item { margin-top: 12px; padding: 12px; border-radius: 9px; background: var(--soft-surface, #f7f5fb); overflow-wrap: anywhere; }
.submission-item p { margin: 6px 0; }
.submission-item a { color: var(--accent, #7450c8); }
.submission-count { margin-top: 12px !important; font-size: .88rem; }
.submission-dialog { margin-top: 18px; }
.submission-dialog h2 { margin-top: 0; }
.submission-dialog > p { color: var(--muted, #6e6a79); }
.submission-dialog input[type="file"] { max-width: 100%; }
@media (max-width: 700px) { .classroom-account-bar, .classroom-task { flex-direction: column; align-items: stretch; } .classroom-task-actions { justify-content: flex-start; } }


/* The studio stays hidden until the session and selected class are verified. */
html.studio-access-check body { visibility: hidden; }
.active-class-banner { margin: 0 auto 12px; padding: 11px 15px; border: 1px solid var(--border, #ded9e8); border-radius: 12px; background: var(--soft-surface, #f4f0fb); color: var(--text, #252333); }
.active-class-banner a { margin-left: 10px; font-weight: 700; color: var(--accent, #7450c8); }


/* Class-first sign-in directory */
.directory-class-card { display: block; width: 100%; text-align: left; color: var(--text, #252333); cursor: pointer; font: inherit; transition: transform .15s ease, border-color .15s ease; }
.directory-class-card:hover, .directory-class-card:focus-visible { transform: translateY(-2px); border-color: #8b6bd6; outline: none; }
.directory-class-card h4 { margin: 10px 0 5px; font-size: 1.15rem; }
.directory-class-card p { margin: 0 0 12px; color: var(--muted, #6e6a79); }
.directory-member-count { display: block; color: var(--muted, #6e6a79); font-size: .9rem; font-weight: 700; }
.directory-roster-heading { margin-top: 24px; }
.directory-user-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.directory-user-button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 1px solid var(--border, #e3e0eb); border-radius: 13px; background: var(--surface, #fff); color: var(--text, #252333); text-align: left; cursor: pointer; font: inherit; }
.directory-user-button:hover, .directory-user-button:focus-visible { border-color: #8b6bd6; background: var(--surface-hover, #f8f5ff); outline: none; }
.directory-user-button > span:nth-child(2) { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.directory-user-button small { color: var(--muted, #6e6a79); overflow-wrap: anywhere; }
.directory-avatar { display: grid; place-items: center; flex: 0 0 40px; height: 40px; border-radius: 12px; background: #eee7ff; color: #4d328e; font-weight: 800; }
.directory-user-arrow { margin-left: auto; font-size: 1.2rem; color: var(--muted, #6e6a79); }
#authPanel[hidden], #directoryRosterPanel[hidden] { display: none !important; }


/* Focused sign-in landing screen: keep the classroom dashboard out of sight until login. */
body.signed-out { min-height: 100vh; background: radial-gradient(ellipse at 15% 0%, rgba(133, 99, 220, .14), transparent 42%), var(--page-bg, #f7f6fb); }
body.signed-out .app-header,
body.signed-out .classroom-notice,
body.signed-out .classroom-hero { display: none !important; }
body.signed-out .classroom-app { max-width: 760px; padding-top: clamp(28px, 7vh, 72px); }
body.signed-out .api-settings-panel { max-width: 620px; margin: 0 auto 12px; padding: 0; border: 0; background: transparent; box-shadow: none; }
body.signed-out #apiSettingsDetails { font-size: .82rem; color: var(--muted, #777); }
body.signed-out #apiSettingsDetails summary { text-align: center; cursor: pointer; }
body.signed-out .login-card { border: 1px solid var(--border, #e5e1ef); border-radius: 24px; padding: clamp(20px, 4vw, 38px); box-shadow: 0 24px 70px rgba(42, 30, 75, .10); background: var(--panel, #fff); }
.login-brand { display: flex; align-items: center; gap: 17px; margin: 0 0 30px; padding-bottom: 24px; border-bottom: 1px solid var(--border, #e8e4f0); }
.login-mark { display: grid; place-items: center; flex: 0 0 58px; height: 58px; border-radius: 17px; background: linear-gradient(135deg, #8e6be8, #5c45b4); color: white; font-size: 2.1rem; box-shadow: 0 8px 22px rgba(105, 76, 190, .24); }
.login-brand .eyebrow { margin: 0 0 5px; font-size: .72rem; letter-spacing: .16em; font-weight: 800; color: #8464ce; }
.login-brand h1 { margin: 0 0 5px; font-size: clamp(1.5rem, 4vw, 2rem); letter-spacing: -.035em; }
.login-brand p:last-child { margin: 0; color: var(--muted, #777); }
body.signed-out .classroom-panel-heading { align-items: center; gap: 14px; }
body.signed-out .classroom-panel-heading h2 { font-size: 1.2rem; }
body.signed-out .classroom-panel-heading p { font-size: .92rem; }
body.signed-out .directory-class-card { border-radius: 16px; padding: 19px; background: var(--card, #fff); border: 1px solid var(--border, #e8e4f0); }
body.signed-out .directory-class-card h4 { font-size: 1.12rem; }
body.signed-out .directory-class-card .classroom-class-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: rgba(132, 100, 206, .12); }
body.signed-out .directory-member-count { font-size: .83rem; }
body.signed-out .classroom-auth-form { max-width: 460px; margin: 0 auto; }
body.signed-out .classroom-auth-form input, body.signed-out .classroom-auth-form select { border-radius: 12px; min-height: 46px; }
body.signed-out #authSubmit { width: 100%; min-height: 47px; margin-top: 8px; border-radius: 12px; }
body.signed-out .classroom-secondary, body.signed-out .classroom-primary { border-radius: 12px; }
body.signed-out .login-footer { margin-top: 18px; color: var(--muted, #888); text-align: center; font-size: .85rem; }
body.signed-out .classroom-status { text-align: center; }
body.signed-out .classroom-account-bar, body.signed-out .role-view { display: none; }
@media (max-width: 560px) { body.signed-out .classroom-app { padding: 20px 12px; } body.signed-out .login-card { padding: 20px 16px; border-radius: 19px; } .login-brand { align-items: flex-start; gap: 12px; } .login-mark { flex-basis: 48px; height: 48px; border-radius: 14px; font-size: 1.7rem; } body.signed-out .classroom-panel-heading { align-items: flex-start; flex-direction: column; } }
