/* Raíz del sitio: /assets/css/portal-tokens.css (desde esta carpeta: 3 niveles arriba) */
@import url('../../../assets/css/portal-tokens.css');

:root {
    color-scheme: light;
    --text: var(--sp-text);
    --muted: var(--sp-muted);
    /* Superficies y “vidrio” */
    --ce-surface-1: rgba(255, 255, 255, 0.75);
    --ce-surface-2: rgba(255, 255, 255, 0.92);
    --ce-glass-border: rgba(255, 255, 255, 0.65);
    --ce-shadow-lift: 0 8px 0 rgba(0, 0, 0, 0.12), 0 20px 40px rgba(15, 23, 42, 0.2);
    --ce-shadow-press: 0 2px 0 rgba(0, 0, 0, 0.15), 0 6px 16px rgba(15, 23, 42, 0.15);
    --ce-inset: inset 0 2px 0 rgba(255, 255, 255, 0.5);
    --ce-rail-glow: 0 0 0 1px rgba(255, 255, 255, 0.35) inset, 0 4px 0 #6366f133,
        0 20px 50px rgba(67, 56, 202, 0.25);
    --card: var(--ce-surface-1);
    --card-border: rgba(99, 102, 241, 0.2);
    --focus: rgba(99, 102, 241, 0.55);
    --focus-portal: rgba(14, 165, 233, 0.45);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Outfit", "Segoe UI", system-ui, sans-serif;
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 100% 80% at 50% -10%, rgba(99, 102, 241, 0.35) 0%, transparent 55%),
        radial-gradient(ellipse 70% 50% at 0% 40%, rgba(16, 185, 129, 0.18) 0%, transparent 50%),
        radial-gradient(ellipse 60% 45% at 100% 60%, rgba(244, 114, 182, 0.14) 0%, transparent 50%),
        linear-gradient(165deg, #c4d4ff 0%, #e0e7ff 22%, #ecfdf5 55%, #dbeafe 100%);
    background-attachment: fixed;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
    padding: 20px 22px;
    border-radius: 20px;
    background: var(--ce-surface-1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--ce-glass-border);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 20px 50px rgba(67, 56, 202, 0.1);
}

.app-header h1 {
    margin: 0 0 8px;
    font-size: clamp(1.55rem, 2.2vw, 2.1rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(120deg, #1e1b4b 0%, #4f46e5 40%, #059669 75%, #db2777 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.6));
}

.app-header p {
    margin: 0;
    color: var(--muted);
    max-width: 54ch;
    font-size: 14px;
}

/* Botón 3D base reutilizable */
.file-bar {
    --btn-depth: 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(238, 242, 255, 0.85) 100%);
    border: 1px solid var(--ce-glass-border);
    box-shadow: var(--ce-inset), 0 4px 0 rgba(99, 102, 241, 0.12), 0 20px 44px rgba(15, 23, 42, 0.08);
}

.file-bar-btn {
    --btn-a: #64748b;
    --btn-b: #475569;
    --btn-brim: #fff3;
    position: relative;
    top: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    min-height: 40px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 12px;
    border: 1px solid #475569;
    border-color: color-mix(in srgb, var(--btn-b) 55%, #000 10%);
    cursor: pointer;
    color: #fff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    background: linear-gradient(175deg, var(--btn-a) 0%, var(--btn-b) 100%);
    box-shadow: var(--ce-inset), 0 var(--btn-depth) 0 rgba(0, 0, 0, 0.3), 0 12px 24px rgba(15, 23, 42, 0.2);
    box-shadow: var(--ce-inset), 0 var(--btn-depth) 0 color-mix(in srgb, var(--btn-b) 75%, #000 25%),
        0 12px 24px color-mix(in srgb, var(--btn-b) 35%, transparent);
    transform: translateY(0);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease, top 0.12s ease;
}

.file-bar-btn:hover {
    filter: brightness(1.08) saturate(1.05);
    transform: translateY(-2px);
    box-shadow: var(--ce-inset), 0 calc(var(--btn-depth) + 2px) 0 rgba(0, 0, 0, 0.35), 0 16px 32px rgba(15, 23, 42, 0.2);
    box-shadow: var(--ce-inset), 0 calc(var(--btn-depth) + 2px) 0 color-mix(in srgb, var(--btn-b) 70%, #000 30%),
        0 16px 32px color-mix(in srgb, var(--btn-b) 40%, transparent);
}

.file-bar-btn:active {
    top: 2px;
    transform: translateY(0);
    box-shadow: var(--ce-inset), 0 2px 0 rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.2);
    box-shadow: var(--ce-inset), 0 2px 0 color-mix(in srgb, var(--btn-b) 80%, #000 20%),
        0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Colores por control (viveza sin tocar el HTML) */
label.file-bar-btn:has(#imageLoader) {
    --btn-a: #2dd4bf;
    --btn-b: #0d9488;
}
label.file-bar-btn:has(#guideLoader) {
    --btn-a: #67e8f9;
    --btn-b: #0891b2;
}
#btnToggleGuide[aria-pressed="false"] {
    --btn-a: #93c5fd;
    --btn-b: #2563eb;
}
#btnToggleGuide[aria-pressed="true"] {
    --btn-a: #a3e635;
    --btn-b: #4d7c0f;
}
#btnPlantilla {
    --btn-a: #fbbf24;
    --btn-b: #d97706;
    color: #1c1917;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}
.file-bar-btn-primary#btnDescargar {
    --btn-a: #3b82f6;
    --btn-b: #1d4ed8;
    border-color: #1e40af;
    font-weight: 800;
}
#btnLimpiarColor {
    --btn-a: #a78bfa;
    --btn-b: #6d28d9;
}
#btnReset {
    --btn-a: #fb7185;
    --btn-b: #e11d48;
}
#btnGuardarColoreado {
    --btn-a: #4ade80;
    --btn-b: #16a34a;
}
#btnMathMode {
    --btn-a: #22d3ee;
    --btn-b: #0891b2;
}
#btnMathMode[aria-pressed="true"] {
    --btn-a: #34d399;
    --btn-b: #059669;
}
.file-bar-btn-accent#btnMisImagenes,
#btnMisImagenes.file-bar-btn-accent {
    --btn-a: #a855f7;
    --btn-b: #7c3aed;
    border-color: #5b21b6;
    font-weight: 800;
}

.file-bar-btn-danger {
    --btn-a: #f87171;
    --btn-b: #dc2626;
}

.file-bar-btn-primary {
    /* Hereda del id: ya definido arriba; fallback por si faltase id */
    --btn-a: #3b82f6;
    --btn-b: #1d4ed8;
    font-weight: 800;
}

.file-bar-btn-accent {
    /* fallback genérico acento */
    --btn-a: #a855f7;
    --btn-b: #6d28d9;
    font-weight: 800;
}

.file-bar-status {
    font-size: 12px;
    color: var(--muted);
    flex: 1 1 140px;
    min-width: 0;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.5);
}

.btn-ghost {
    --btn-a: #f1f5f9;
    --btn-b: #cbd5e1;
    position: relative;
    top: 0;
    display: inline-flex;
    align-items: center;
    padding: 10px 16px;
    min-height: 40px;
    border-radius: 12px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
    border: 1px solid #94a3b8;
    background: linear-gradient(180deg, #fff 0%, #e2e8f0 100%);
    box-shadow: inset 0 2px 0 #fff, 0 4px 0 #64748b, 0 14px 28px rgba(15, 23, 42, 0.12);
    transition: transform 0.12s ease, box-shadow 0.12s ease, top 0.12s ease;
}

.btn-ghost:hover {
    transform: translateY(-2px);
    color: #4338ca;
    box-shadow: inset 0 2px 0 #fff, 0 6px 0 #6366f1, 0 20px 36px rgba(67, 56, 202, 0.2);
}

.btn-ghost:active {
    top: 2px;
    box-shadow: inset 0 2px 0 #f8fafc, 0 2px 0 #64748b, 0 6px 12px rgba(0, 0, 0, 0.12);
}

.editor-shell {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step-pane-enter {
    transform-origin: left center;
    animation: stepPaneTurn 0.34s ease;
}

.step-pane-enter.is-reverse {
    transform-origin: right center;
    animation-name: stepPaneTurnReverse;
}

@keyframes stepPaneTurn {
    from {
        opacity: 0;
        transform: perspective(900px) rotateY(-12deg) translateX(18px);
    }
    to {
        opacity: 1;
        transform: perspective(900px) rotateY(0deg) translateX(0);
    }
}

@keyframes stepPaneTurnReverse {
    from {
        opacity: 0;
        transform: perspective(900px) rotateY(12deg) translateX(-18px);
    }
    to {
        opacity: 1;
        transform: perspective(900px) rotateY(0deg) translateX(0);
    }
}

/* Zona inmersiva: barra + herramientas + lienzo (pantalla completa / foco) */
.colorea-immersive {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Botón: modo foco (visual distinto al activo) */
#btnPantallaCompleta[aria-pressed="false"] {
    --btn-a: #0ea5e9;
    --btn-b: #0284c7;
}

#btnPantallaCompleta[aria-pressed="true"] {
    --btn-a: #fb7185;
    --btn-b: #e11d48;
    font-weight: 800;
}

body.colorea-immersive-open {
    overflow: hidden;
}

.colorea-immersive.is-active {
    position: fixed;
    z-index: 2000;
    inset: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
        max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    width: 100%;
    background:
        radial-gradient(ellipse 90% 50% at 50% 0%, rgba(99, 102, 241, 0.2) 0%, transparent 55%),
        linear-gradient(180deg, #0f172a 0%, #1e1b4b 35%, #312e81 100%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    overflow: hidden;
    animation: coloreaImmersiveIn 0.28s ease;
}

@keyframes coloreaImmersiveIn {
    from {
        opacity: 0.92;
    }
    to {
        opacity: 1;
    }
}

.colorea-immersive.is-active .file-bar {
    flex-shrink: 0;
    max-height: 42vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.85) 0%, rgba(30, 27, 75, 0.7) 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.colorea-immersive.is-active .work-bench {
    flex: 1;
    min-height: 0;
    max-height: none;
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.colorea-immersive.is-active .work-main {
    flex: 1;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 8px;
}

.colorea-immersive.is-active .work-bench-side {
    align-self: stretch;
    max-height: none;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 0 0 min(158px, 26vw);
    width: min(158px, 26vw);
}

.colorea-immersive.is-active .palette-strip--paint {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: visible;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(224, 231, 255, 0.9) 100%);
}

.colorea-immersive.is-active .palette-strip--math.palette-strip--math-dock {
    flex: 0 0 auto;
    max-height: none;
    overflow: visible;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(224, 231, 255, 0.85) 100%);
}

.colorea-immersive.is-active .canvas-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.colorea-immersive.is-active .canvas-wrap {
    flex: 1;
    min-height: 0 !important;
    height: 100% !important;
    max-height: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border: 2px solid rgba(165, 180, 252, 0.45);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* Contenedor y apilado de lienzos: escala JS según el hueco (ver app.js) */
.canvas-scale-outer {
    position: relative;
    flex: 0 0 auto;
    line-height: 0;
    margin: 0 auto;
}

.canvas-stack {
    position: relative;
    transform-origin: 0 0;
}

.math-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

.math-overlay-number {
    position: absolute;
    transform: translate(-50%, -50%);
    min-width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.5);
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
    font-size: 12px;
    font-weight: 800;
    line-height: 24px;
    text-align: center;
    box-shadow: 0 2px 0 rgba(15, 23, 42, 0.2);
}

.work-bench {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

/* Columna izquierda: herramientas + colores + reto matemático en vertical */
.work-bench-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    width: min(158px, 28vw);
    position: sticky;
    top: 16px;
    align-self: flex-start;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 3;
    scrollbar-width: thin;
}

/* Barra lateral: “dock” flotante con volumen y color */
.float-toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 14px 10px;
    flex-shrink: 0;
    position: static;
    z-index: 3;
    width: 64px;
    border-radius: 18px;
    background: linear-gradient(150deg, #312e81 0%, #4c1d95 50%, #5b21b6 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--ce-rail-glow), 0 24px 50px rgba(30, 27, 75, 0.45);
}

.float-tool {
    --t-a: #a5b4fc;
    --t-b: #6366f1;
    --t-edge: #4338ca;
    --t-ink: #eef2ff;
    width: 48px;
    height: 48px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    border: 1px solid var(--t-edge);
    cursor: pointer;
    color: var(--t-ink);
    background: linear-gradient(160deg, var(--t-a) 0%, var(--t-b) 100%);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), 0 5px 0 var(--t-edge), 0 12px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.float-tool:hover {
    transform: translateY(-3px) scale(1.03);
    filter: brightness(1.1);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), 0 7px 0 var(--t-edge), 0 20px 32px rgba(0, 0, 0, 0.35);
}

/* Iconos: acento en color por herramienta (llamativo) */
.float-tool[data-tool="brush"] {
    --t-a: #7dd3fc;
    --t-b: #0284c7;
    --t-edge: #075985;
    --t-ink: #f0f9ff;
}
.float-tool[data-tool="marker"] {
    --t-a: #fde68a;
    --t-b: #ea580c;
    --t-edge: #9a3412;
    --t-ink: #fffbeb;
}
.float-tool[data-tool="eraser"] {
    --t-a: #e2e8f0;
    --t-b: #94a3b8;
    --t-edge: #64748b;
    --t-ink: #1e293b;
}
.float-tool[data-tool="fill"] {
    --t-a: #86efac;
    --t-b: #16a34a;
    --t-edge: #14532d;
    --t-ink: #f0fdf4;
}
.float-tool[data-tool="rect-fill"] {
    --t-a: #c4b5fd;
    --t-b: #6d28d9;
    --t-edge: #4c1d95;
    --t-ink: #faf5ff;
}
.float-tool[data-tool="circle-fill"] {
    --t-a: #fbcfe8;
    --t-b: #db2777;
    --t-edge: #9d174d;
    --t-ink: #fff1f2;
}

.float-tool-icon {
    display: block;
    filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.25));
}

/* Herramienta activa: “hundida” 3D */
.float-tool.active {
    transform: translateY(1px) scale(0.98);
    box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.35), inset 0 -1px 0 rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    filter: saturate(1.15) brightness(0.92);
    color: #fff;
}

.float-tool.active .float-tool-icon {
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.4));
}

.work-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
    z-index: 2;
}

.math-top-bank {
    border: 1px solid var(--ce-glass-border);
    border-radius: 14px;
    padding: 10px 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(224, 231, 255, 0.72) 100%);
}

#imageBankTopList.image-bank-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.math-steps-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.math-step-chip {
    font-size: 11px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(99, 102, 241, 0.35);
    background: rgba(255, 255, 255, 0.9);
    color: #334155;
}

.math-step-chip.is-active {
    color: #1e1b4b;
    background: linear-gradient(90deg, #c7d2fe, #a5f3fc);
    border-color: rgba(79, 70, 229, 0.5);
}

.math-flow-status {
    font-size: 12px;
    font-weight: 800;
    color: #1e3a8a;
}

.math-start-big {
    width: 100%;
    justify-content: center;
    min-height: 44px;
    font-size: 14px;
    font-weight: 800;
}

.palette-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px 22px;
    padding: 14px 16px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(224, 231, 255, 0.6) 100%);
    border: 1px solid var(--ce-glass-border);
    box-shadow: var(--ce-inset), 0 20px 44px rgba(79, 70, 229, 0.1);
    backdrop-filter: blur(8px);
}

/* Paleta de pintura debajo de las herramientas, columna estrecha */
.palette-strip--paint.palette-strip--vertical {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 12px;
    padding: 10px 8px 12px;
    width: 100%;
    box-sizing: border-box;
}

.palette-strip--vertical .palette-block {
    align-items: stretch;
}

.palette-strip--vertical .palette-row {
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.palette-strip--vertical .palette-size {
    flex: 0 0 auto;
}

.palette-strip--vertical .dock-swatch-grid {
    grid-template-columns: repeat(4, 15px);
    gap: 3px;
    justify-content: center;
}

.palette-strip--vertical .dock-swatch {
    width: 15px;
    height: 15px;
}

.palette-strip--vertical .dock-color-input {
    width: 34px;
    height: 34px;
}

.palette-strip--vertical .dock-size-comb {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
}

.palette-strip--vertical .dock-size-tooth {
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    padding: 2px 4px;
}

.palette-strip--vertical .palette-tol input[type="range"] {
    width: 100%;
    max-width: none;
}

.palette-strip--vertical .palette-value {
    align-self: center;
}

/* Reto matemático en columna izquierda (misma orientación que herramientas/colores) */
.palette-strip--math.palette-strip--math-dock {
    align-items: stretch;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 10px 8px 12px;
    width: 100%;
    box-sizing: border-box;
}

.palette-strip--math-dock .palette-math {
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
}

.palette-strip--math-dock .palette-row--math-tools {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.palette-strip--math-dock .palette-row--math-tools .palette-label {
    text-align: center;
}

.palette-strip--math-dock .file-bar-btn {
    width: 100%;
    justify-content: center;
    font-size: 11px;
    padding: 8px 6px;
    min-height: 38px;
    line-height: 1.2;
}

.palette-strip--math-dock .math-start-big {
    min-height: 40px;
    font-size: 12px;
}

.palette-strip--math-dock .math-challenge {
    padding: 8px;
    gap: 6px;
}

.palette-strip--math-dock .math-flow-status {
    font-size: 11px;
    line-height: 1.35;
}

.palette-strip--math-dock .math-hint {
    font-size: 10px;
    line-height: 1.35;
}

.palette-strip--math-dock .math-target {
    font-size: 11px;
    flex-wrap: wrap;
    align-items: flex-start;
    word-break: break-word;
}

.palette-strip--math-dock .math-scoreboard {
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
}

.palette-strip--math-dock .math-score-pill {
    font-size: 10px;
    justify-content: center;
    text-align: center;
    padding: 5px 8px;
}

.palette-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.palette-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.palette-label {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #4f46e5;
}

.palette-value {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 800;
    color: #0f172a;
    background: linear-gradient(120deg, #e0e7ff, #fce7f3);
    border-radius: 999px;
    border: 1px solid rgba(99, 102, 241, 0.3);
    box-shadow: 0 2px 0 #c4b5fd;
}

.palette-size {
    flex: 1 1 200px;
}

.palette-tol input[type="range"] {
    width: 130px;
    max-width: 38vw;
    accent-color: #6366f1;
    height: 6px;
    border-radius: 4px;
}

.palette-math {
    flex: 1 1 320px;
    min-width: min(100%, 320px);
}

.math-challenge {
    border: 1px solid rgba(8, 145, 178, 0.3);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(236, 254, 255, 0.9) 0%, rgba(224, 242, 254, 0.9) 100%);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-question {
    font-weight: 800;
    color: #164e63;
}

.math-answer-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.math-grade-label {
    font-size: 12px;
    font-weight: 700;
    color: #164e63;
}

#mathGrade {
    border: 1px solid rgba(8, 145, 178, 0.35);
    border-radius: 10px;
    padding: 6px 8px;
    font-weight: 700;
    color: #0f172a;
    background: #fff;
}

.math-timer {
    margin-left: auto;
    font-size: 12px;
    font-weight: 800;
    color: #0f172a;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(8, 145, 178, 0.3);
}

#mathAnswer,
.math-answer-input {
    width: 120px;
    max-width: 100%;
    border: 1px solid rgba(8, 145, 178, 0.35);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 1.15rem;
    font-weight: 800;
    text-align: center;
    color: #0f172a;
    background: #fff;
}

#mathAnswer:focus {
    outline: 3px solid rgba(99, 102, 241, 0.45);
    outline-offset: 2px;
}

.math-keypad-hint {
    margin: 2px 0 0;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
}

.math-keypad {
    display: grid;
    grid-template-columns: repeat(3, minmax(48px, 1fr));
    gap: 8px;
    max-width: 260px;
    margin-top: 6px;
}

.math-keypad-btn {
    min-height: 48px;
    margin: 0;
    padding: 8px;
    font-family: inherit;
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
    border-radius: 12px;
    border: 1px solid rgba(8, 145, 178, 0.35);
    background: linear-gradient(180deg, #fff 0%, #ecfeff 100%);
    box-shadow: 0 3px 0 rgba(8, 145, 178, 0.25);
    cursor: pointer;
    transition: transform 0.08s ease, filter 0.08s ease;
}

.math-keypad-btn:hover {
    filter: brightness(1.03);
}

.math-keypad-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(8, 145, 178, 0.25);
}

.math-keypad-btn--action {
    font-size: 1.35rem;
}

.math-keypad-btn--ok {
    background: linear-gradient(180deg, #34d399 0%, #059669 100%);
    border-color: #047857;
    color: #fff;
    box-shadow: 0 3px 0 #065f46;
}

.math-keypad-btn--ok:active {
    box-shadow: 0 1px 0 #065f46;
}

.math-keypad--inactive {
    opacity: 0.45;
    pointer-events: none;
    filter: grayscale(0.25);
}

.math-hint {
    font-size: 12px;
    color: #334155;
}

.math-target {
    min-height: 28px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
}

.math-target-color {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 1px solid rgba(15, 23, 42, 0.4);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.math-scoreboard {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.math-score-pill {
    font-size: 11px;
    font-weight: 800;
    color: #0f172a;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(8, 145, 178, 0.28);
    border-radius: 999px;
    padding: 4px 8px;
}

.math-counting-aid {
    border: 1px dashed rgba(14, 116, 144, 0.45);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-counting-aid.is-visible {
    display: flex;
}

.math-step-dialog .math-step-body {
    padding: 14px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.math-aid-title {
    font-size: 12px;
    font-weight: 800;
    color: #155e75;
}

.math-leaf-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.math-leaf {
    width: 20px;
    height: 20px;
    border-radius: 60% 40% 60% 40%;
    border: 1px solid rgba(15, 23, 42, 0.2);
    box-shadow: 0 2px 0 rgba(15, 23, 42, 0.2);
    cursor: grab;
}

.math-cups {
    display: grid;
    grid-template-columns: repeat(5, minmax(48px, 1fr));
    gap: 6px;
}

.math-cup {
    min-height: 66px;
    border-radius: 10px 10px 14px 14px;
    border: 2px solid rgba(14, 116, 144, 0.35);
    background: linear-gradient(180deg, rgba(224, 242, 254, 0.8) 0%, rgba(186, 230, 253, 0.9) 100%);
    padding: 6px 4px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-content: flex-start;
    justify-content: center;
    position: relative;
}

.math-cup-label {
    width: 100%;
    text-align: left;
    font-size: 10px;
    font-weight: 800;
    color: #0f172a;
}

.math-cup-counter {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 10px;
    font-weight: 800;
    color: #0f172a;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(14, 116, 144, 0.35);
    border-radius: 999px;
    min-width: 18px;
    line-height: 16px;
    text-align: center;
    padding: 0 4px;
}

.math-cup-leaves {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: center;
    align-content: flex-start;
}

.dock-swatch-grid {
    display: grid;
    grid-template-columns: repeat(16, 16px);
    gap: 4px;
}

@media (max-width: 700px) {
    .dock-swatch-grid {
        grid-template-columns: repeat(8, 16px);
    }
}

.dock-swatch {
    width: 16px;
    height: 16px;
    padding: 0;
    border: 1px solid rgba(15, 23, 42, 0.4);
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.dock-swatch:hover {
    transform: scale(1.1);
    z-index: 1;
}

.dock-swatch.selected {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #fff, 0 4px 0 #4338ca;
}

.dock-color-input {
    width: 38px;
    height: 32px;
    padding: 2px;
    border: 2px solid #a5b4fc;
    border-radius: 10px;
    cursor: pointer;
    background: #fff;
    box-shadow: 0 3px 0 #6366f1, 0 8px 16px rgba(99, 102, 241, 0.25);
}

.dock-size-comb {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 4px 8px;
}

.dock-size-tooth {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 3px 2px 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.12s ease, transform 0.12s ease;
}

.dock-size-tooth:hover {
    background: rgba(99, 102, 241, 0.12);
    transform: scale(1.05);
}

.dock-size-tooth.selected .dock-size-dot {
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px #6366f1, 0 3px 0 #4338ca;
}

.dock-size-dot {
    display: block;
    border-radius: 50%;
    background: #1e293b;
    border: 1px solid #0f172a;
}

.dock-size-tooth-label {
    font-size: 8px;
    font-weight: 800;
    color: var(--muted);
}

.canvas-panel {
    position: relative;
    border-radius: 20px;
    padding: 16px;
    background: var(--ce-surface-1);
    border: 1px solid var(--ce-glass-border);
    box-shadow: var(--ce-inset), 0 4px 0 rgba(15, 23, 42, 0.06), 0 30px 60px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(6px);
}

.canvas-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, rgba(16, 185, 129, 0.05) 100%);
    pointer-events: none;
    z-index: 0;
}

.canvas-wrap {
    position: relative;
    z-index: 1;
    border: 2px solid rgba(99, 102, 241, 0.35);
    border-radius: 14px;
    overflow: auto;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.06);
    background-image: linear-gradient(45deg, #e0e7ff 25%, transparent 25%),
        linear-gradient(-45deg, #e0e7ff 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e0e7ff 75%),
        linear-gradient(-45deg, transparent 75%, #e0e7ff 75%);
    background-color: #f5f3ff;
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    min-height: min(64vh, 500px);
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    image-rendering: auto;
}

#baseCanvas,
#guideCanvas,
#previewCanvas {
    pointer-events: none !important;
}

#guideCanvas {
    z-index: 1;
    opacity: 0.45;
}

#drawCanvas {
    pointer-events: auto !important;
    touch-action: none;
    cursor: crosshair;
    z-index: 2;
}

#previewCanvas {
    z-index: 4;
}

.paint-bank {
    margin-top: 4px;
    padding: 20px 18px 22px;
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.88) 0%, rgba(237, 233, 254, 0.5) 100%);
    border: 1px solid var(--ce-glass-border);
    box-shadow: 0 18px 44px rgba(76, 29, 149, 0.1);
}

.paint-bank-title {
    margin: 0 0 8px;
    font-size: 1.15rem;
    font-weight: 800;
    color: #312e81;
    letter-spacing: -0.02em;
}

.paint-bank-hint {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--muted);
}

.image-bank-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

.bank-card {
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 0 6px 0 #c4b5fd, 0 16px 32px rgba(15, 23, 42, 0.1);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.bank-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #a5b4fc, 0 24px 48px rgba(99, 102, 241, 0.2);
}

.bank-card--locked {
    border-color: rgba(100, 116, 139, 0.45);
    box-shadow: 0 6px 0 #cbd5e1, 0 14px 28px rgba(15, 23, 42, 0.08);
}

.bank-card--locked:hover {
    box-shadow: 0 8px 0 #94a3b8, 0 20px 36px rgba(15, 23, 42, 0.1);
}

.bank-card-thumb-wrap {
    aspect-ratio: 4 / 3;
    background: linear-gradient(180deg, #f1f5f9, #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--card-border);
}

.bank-card-thumb {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.bank-card-body {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.bank-card-name {
    font-size: 12px;
    font-weight: 800;
    word-break: break-word;
    line-height: 1.25;
    min-height: 2.4em;
    color: #1e1b4b;
}

.bank-card-meta {
    font-size: 10px;
    color: var(--muted);
}

.bank-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
}

.bank-card-actions .file-bar-btn {
    padding: 6px 10px;
    font-size: 10px;
    min-height: 32px;
    --btn-a: #818cf8;
    --btn-b: #4f46e5;
    border-radius: 8px;
}

#imageBankTopList .bank-card {
    box-shadow: 0 3px 0 #c4b5fd, 0 10px 18px rgba(15, 23, 42, 0.08);
}

#imageBankTopList .bank-card-actions .file-bar-btn {
    font-size: 9px;
    min-height: 28px;
    padding: 4px 8px;
}

.tips {
    margin-top: 4px;
    font-size: 13px;
    color: #4338ca;
    font-weight: 600;
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 14px;
    padding: 12px 16px;
    background: linear-gradient(100deg, rgba(224, 231, 255, 0.8) 0%, rgba(252, 231, 243, 0.5) 100%);
    box-shadow: 0 3px 0 #c7d2fe;
}

.tips strong {
    color: #0f172a;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.file-bar-btn:focus-visible,
.btn-ghost:focus-visible,
.float-tool:focus-visible,
.dock-swatch:focus-visible,
.dock-size-tooth:focus-visible,
input:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.mis-img-dialog {
    max-width: min(96vw, 760px);
    width: 100%;
    border: 1px solid var(--ce-glass-border);
    border-radius: 20px;
    padding: 0;
    background: linear-gradient(180deg, #faf5ff 0%, #e0e7ff 100%);
    color: var(--text);
    box-shadow: 0 4px 0 #6366f1, 0 40px 80px rgba(15, 23, 42, 0.35);
}

.mis-img-dialog::backdrop {
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
}

.mis-img-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--card-border);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(238, 242, 255, 0.9) 100%);
    border-radius: 20px 20px 0 0;
}

.mis-img-dialog-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
    color: #312e81;
}

.mis-img-dialog-intro {
    margin: 0;
    padding: 12px 18px 0;
}

#imageBankListDialog {
    padding: 14px 18px 22px;
    max-height: min(60vh, 480px);
    overflow: auto;
}

@media (max-width: 780px) {
    .work-bench-side {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: flex-start;
        align-content: flex-start;
        position: static;
        max-height: none;
        overflow: visible;
    }

    .palette-strip--paint.palette-strip--vertical {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
        flex: 1 1 280px;
        max-width: none;
        padding: 12px 14px;
    }

    .palette-strip--vertical .dock-swatch-grid {
        grid-template-columns: repeat(8, 14px);
    }

    .palette-strip--vertical .dock-size-comb {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-end;
        justify-content: center;
    }

    .palette-strip--math.palette-strip--math-dock {
        flex: 1 1 100%;
        width: 100%;
        max-width: none;
    }
}

@media (max-width: 520px) {
    .work-bench {
        flex-direction: column;
        align-items: stretch;
    }

    .work-bench-side {
        flex-direction: column;
        align-items: center;
    }

    .float-toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        padding: 12px;
    }

    .float-tool {
        width: 46px;
        height: 46px;
    }
}
