/* ==========================================================================
   KIDZAPS — A4 Worksheet Shell + Interactive Component Styles
   Loaded on worksheet pages AND print pages.
   Author: KidZaps Team — 2026-08
   ========================================================================== */

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

.kz-a4-shell {
    width: 210mm;
    max-width: 100%;
    aspect-ratio: 210 / 297;
    border: 2px solid #fef3c7;
    border-radius: 16px;
    padding: 24px 28px;
    margin: 0 auto;
    overflow: hidden;
    font-family: "Fredoka", "Nunito", "Comic Sans MS", sans-serif;
}

.kz-a4-screen {
    max-width: 780px;
    margin: 24px auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
    border-radius: 16px;
    min-height: 700px;
    background: #ffffff;
    position: relative;
}

.kz-a4-print {
    border-radius: 0;
    box-shadow: none;
    width: 100%;
    min-height: 260mm;
    border: none;
}

.kz-a4-watermark {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.06;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
}

.kz-a4-watermark span {
    display: block;
    font-size: 72pt;
    font-weight: 900;
    font-family: "Fredoka", sans-serif;
    color: #6366f1;
    transform: rotate(-30deg);
    white-space: nowrap;
    letter-spacing: 12px;
    user-select: none;
    line-height: 1;
}

.kz-a4-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-bottom: 10px;
    border-bottom: 2px dashed #cbd5e1;
    margin-bottom: 16px;
    z-index: 2;
    position: relative;
}

.kz-a4-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.kz-a4-logo {
    max-height: 42px;
    width: auto;
    object-fit: contain;
}

.kz-a4-logo-emoji {
    font-size: 32px;
    line-height: 1;
}

.kz-a4-brand-name {
    font-size: 22pt;
    font-weight: 700;
    font-family: "Fredoka", sans-serif;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: #6366f1;
    /* Solid fallback (visible when print exports without gradient) */
    /* Ensure the coloured brand text is preserved when printing */
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

.kz-a4-tagline {
    font-size: 10pt;
    color: #6b7280;
    margin-top: 4px;
    font-style: italic;
    display: none;
}

.kz-a4-title {
    font-size: 24pt;
    font-weight: 700;
    text-align: center;
    color: #1f2937;
    margin: 16px 0 8px;
    font-family: "Fredoka", sans-serif;
    line-height: 1.2;
}

.kz-a4-subtitle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 11pt;
    color: #6b7280;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.kz-a4-subtitle span {
    background: #eef2ff;
    padding: 3px 10px;
    border-radius: 999px;
    color: #4338ca;
    font-weight: 500;
}

.kz-a4-fields {
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin: 12px 0 20px;
    font-size: 11pt;
    color: #374151;
    flex-wrap: wrap;
}

.kz-a4-fields label {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.kz-a4-blank {
    display: inline-block;
    border-bottom: 1.5px solid #333;
    min-width: 140px;
    height: 18px;
    padding: 0 6px;
}

.kz-a4-body {
    position: relative;
    z-index: 2;
    padding: 8px 0;
}

.kz-a4-footer {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1.5px dashed #cbd5e1;
    display: flex;
    justify-content: center;
    gap: 8px;
    font-size: 9pt;
    color: #9ca3af;
    flex-wrap: wrap;
    position: relative;
    z-index: 2;
}

.kz-a4-copy,
.kz-a4-keywords,
.kz-a4-url {
    display: inline;
}

.kz-a4-instructions {
    background: #fef9c3;
    border-left: 4px solid #fbbf24;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 11pt;
    color: #713f12;
    margin: 12px 0 16px;
    line-height: 1.5;
}

.kz-a4-h {
    font-size: 14pt;
    font-weight: 700;
    color: #4338ca;
    margin: 14px 0 8px;
    line-height: 1.3;
}

.kz-q-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 11pt;
    page-break-inside: avoid;
}

.kz-q-row.kz-q-vert {
    flex-direction: column;
    align-items: flex-start;
}

.kz-q-num {
    font-weight: 700;
    min-width: 26px;
    color: #6366f1;
    text-align: center;
    flex-shrink: 0;
}

.kz-q-text {
    flex: 1;
}

.kz-a4-blank-sm {
    display: inline-block;
    border-bottom: 1.5px solid #333;
    min-width: 60px;
    height: 16px;
    padding: 0 4px;
}

.kz-a4-blank-md {
    display: inline-block;
    border-bottom: 1.5px solid #333;
    min-width: 100px;
    height: 18px;
    padding: 0 6px;
}

.kz-a4-blank-lg {
    display: inline-block;
    border-bottom: 1.5px solid #333;
    min-width: 180px;
    height: 22px;
    padding: 0 6px;
}

.kz-a4-match-grid {
    display: grid;
    grid-template-columns: 1fr 50px 1fr;
    gap: 6px 10px;
    align-items: center;
    margin: 8px 0;
}

.kz-a4-match-left,
.kz-a4-match-right {
    border: 1.5px solid #555;
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    font-size: 11pt;
    background: #f9fafb;
}

.kz-a4-match-arrow {
    text-align: center;
    font-size: 14pt;
    color: #9ca3af;
}

.kz-a4-tap-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

.kz-a4-tap-option {
    border: 1.5px solid #555;
    border-radius: 999px;
    padding: 5px 14px;
    font-size: 10.5pt;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    background: white;
}

.kz-a4-card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 12px 0;
}

.kz-a4-card-item {
    border: 2px solid #555;
    border-radius: 10px;
    padding: 14px;
    text-align: center;
    font-size: 12pt;
    font-weight: 700;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.kz-a4-draw-area {
    border: 2px dashed #ccc;
    border-radius: 12px;
    min-height: 340px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 0;
    color: #bbb;
    font-size: 12pt;
    position: relative;
    overflow: hidden;
}

.kz-a4-draw-lg {
    min-height: 500px;
}

.kz-a4-writing-line {
    border-bottom: 2px solid #333;
    border-top: 1px dashed #bbb;
    height: 44px;
    margin: 14px 0;
    position: relative;
}

.kz-a4-line-num {
    position: absolute;
    left: 4px;
    top: 2px;
    font-size: 8pt;
    color: #bbb;
}

.kz-a4-grid {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}

.kz-a4-grid td {
    border: 1.5px solid #666;
    height: 50px;
    width: 25%;
    padding: 6px;
    font-size: 10pt;
    color: #9ca3af;
    vertical-align: top;
}

.kz-a4-preview-image {
    max-width: 100%;
    display: block;
    margin: 10px auto;
    border-radius: 8px;
}

.kz-a4-rich {
    line-height: 1.6;
    font-size: 11pt;
}

.kz-html-template {
    margin: 0;
    min-height: 300px;
    position: relative;
    z-index: 2;
    font-size: 11pt;
    line-height: 1.5;
}

/* ==========================================================================
   Interactive components (Phase 2)
   ========================================================================== */
.kz-practice-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 12px 0;
}

.kz-row {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
    background: #f8fafc;
}

.kz-target {
    font-size: 40pt;
    font-weight: 700;
    min-width: 60px;
    text-align: center;
    color: #4338ca;
    font-family: serif;
    line-height: 1;
}

.kz-tracing-box {
    flex: 1;
    min-height: 60px;
    border-bottom: 2px solid #333;
    border-top: 1px dashed #bbb;
    position: relative;
}

.kz-numbered {
    position: relative;
    display: inline-block;
}

.kz-hint {
    font-size: 10pt;
    color: #6b7280;
    font-style: italic;
}

.kz-flash-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    border-radius: 16px;
    background: var(--card-bg, #fef3c7);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    min-height: 140px;
    cursor: pointer;
    transition: transform 0.2s ease;
    font-family: "Fredoka", sans-serif;
}

.kz-flash-card:hover {
    transform: scale(1.05);
}

.kz-flash-card .kz-letter {
    font-size: 48pt;
    font-weight: 700;
    color: #4338ca;
    line-height: 1;
}

.kz-flash-card .kz-picture {
    font-size: 40pt;
    line-height: 1;
}

.kz-flash-card .kz-word {
    font-size: 14pt;
    font-weight: 600;
}

.kz-train-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 20px 0;
    align-items: flex-end;
}

.kz-train-locomotive {
    font-size: 40pt;
    line-height: 1;
    margin-right: 8px;
}

.kz-train-wagon {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin: 0 4px 20px;
}

.kz-train-wagon .kz-number-box {
    width: 56px;
    height: 56px;
    border: 3px solid #1f2937;
    border-radius: 12px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22pt;
    font-weight: 700;
    font-family: "Fredoka", sans-serif;
}

.kz-train-wagon.kz-empty .kz-number-box {
    background: #f3f4f6;
    cursor: pointer;
    transition: all 0.2s ease;
}

.kz-train-wagon.kz-empty .kz-number-box:hover {
    background: #e5e7eb;
    border-color: #6366f1;
}

.kz-train-wagon .kz-wheel-row {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.kz-train-wagon .kz-wheel {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #dc2626;
    border: 2px solid #7f1d1d;
}

.kz-train-wagon.kz-correct .kz-number-box {
    background: #dcfce7;
    border-color: #16a34a;
    color: #14532d;
    animation: kzTrainPop 0.4s ease;
}

.kz-train-wagon.kz-wrong .kz-number-box {
    background: #fee2e2;
    border-color: #dc2626;
    color: #7f1d1d;
}

.kz-cursive-line {
    position: relative;
    height: 90px;
    margin: 12px 0;
    border-bottom: 2px solid #333;
    border-top: 2px solid #333;
}

.kz-cursive-line::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: 1px dashed #94a3b8;
    transform: translateY(-50%);
}

.kz-cursive-word {
    font-size: 44pt;
    font-family: "Kalam", "Homemade Apple", cursive;
    color: transparent;
    -webkit-text-stroke: 1.5px #6b7280;
    letter-spacing: 4px;
    line-height: 1;
}

/* ==========================================================================
   SVG tracing overlay
   ========================================================================== */
.kz-trace-svg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: all;
    touch-action: none;
}

.kz-trace-path {
    fill: none;
    stroke: rgba(200, 200, 200, 0.5);
    stroke-width: 6;
    stroke-dasharray: 6, 4;
}

.kz-trace-ink {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 6;
    stroke: #4f46e5;
}

/* ==========================================================================
   On-screen number pad (mobile-friendly)
   ========================================================================== */
.kz-numpad {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    padding: 12px;
    display: none;
    grid-template-columns: repeat(3, 60px);
    gap: 8px;
    z-index: 500;
}

.kz-numpad.kz-open {
    display: grid;
}

.kz-numpad-key {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 22pt;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.kz-numpad-key:hover {
    transform: scale(1.08);
    background: #c7d2fe;
}

.kz-numpad-key:active {
    transform: scale(0.95);
}

.kz-numpad-key.kz-numpad-clear {
    background: #fee2e2;
    color: #b91c1c;
    grid-column: 1 / 2;
}

.kz-numpad-key.kz-numpad-enter {
    background: #dcfce7;
    color: #166534;
    grid-column: 3 / 4;
}

/* ==========================================================================
   Color picker (kid-friendly, floating)
   ========================================================================== */
.kz-colorpicker {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 6px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.kz-color-dot {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.15s ease;
    padding: 0;
}

.kz-color-dot:hover {
    transform: scale(1.15);
}

.kz-color-dot.active {
    box-shadow: 0 0 0 3px #1f2937;
    transform: scale(1.2);
}

/* ==========================================================================
   Waving hand hint animation
   ========================================================================== */
.kz-hint-hand {
    position: absolute;
    font-size: 42px;
    pointer-events: none;
    z-index: 200;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    animation: kzHandWave 1.2s ease-in-out infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.kz-hint-hand.kz-visible {
    opacity: 1;
}

@keyframes kzHandWave {
    0% {
        transform: rotate(0deg) scale(1);
    }

    15% {
        transform: rotate(15deg) scale(1.1);
    }

    30% {
        transform: rotate(-15deg) scale(1);
    }

    45% {
        transform: rotate(15deg) scale(1.1);
    }

    60% {
        transform: rotate(-15deg) scale(1);
    }

    75% {
        transform: rotate(10deg) scale(1.05);
    }

    100% {
        transform: rotate(0deg) scale(1);
    }
}

@keyframes kzTrainPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* ==========================================================================
   Admin — Collapsible HTML editor
   ========================================================================== */
.admin-collapse {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    margin: 16px 0;
    background: #fafbff;
    overflow: hidden;
}

.admin-collapse-html {
    border-color: #a5b4fc;
    background: linear-gradient(to right, #f5f3ff, #ffffff);
}

.admin-collapse-summary {
    cursor: pointer;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    background: #f9fafb;
    transition: all 0.15s ease;
    list-style: none;
}

.admin-collapse-summary::-webkit-details-marker {
    display: none;
}

.admin-collapse-summary:hover {
    background: #f3f4f6;
}

.admin-collapse[open] .admin-collapse-summary {
    border-bottom: 1px solid #e5e7eb;
    background: #eef2ff;
}

.admin-collapse-caret {
    transition: transform 0.2s ease;
    color: #6366f1;
    display: inline-block;
}

.admin-collapse[open] .admin-collapse-caret {
    transform: rotate(90deg);
}

.admin-collapse-body {
    padding: 16px;
}

.code-textarea {
    font-family: Consolas, "Courier New", monospace;
    font-size: 12.5px;
    line-height: 1.5;
    tab-size: 2;
    -moz-tab-size: 2;
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #334155;
    width: 100%;
    min-height: 200px;
    resize: vertical;
}

.code-textarea:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

/* ==========================================================================
   Print overrides
   ========================================================================== */
@media print {

    .kz-numpad,
    .kz-colorpicker,
    .kz-hint-hand,
    .btn,
    button:not(.kz-a4-tap-option) {
        display: none !important;
    }

    .kz-a4-shell {
        width: 100% !important;
        max-width: 100% !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        border: none !important;
        margin: 0 !important;
        padding: 12mm 15mm !important;
    }

    .kz-a4-tagline {
        display: block !important;
    }

    .kz-q-row,
    .kz-train-row,
    .kz-flash-card,
    .kz-cursive-line {
        page-break-inside: avoid !important;
    }

    .kz-a4-watermark {
        opacity: 0.04;
    }

    .kz-flash-card:hover {
        transform: none;
    }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media screen and (max-width: 768px) {
    .kz-a4-shell.kz-a4-screen {
        width: 100%;
        max-width: 100%;
        padding: 16px;
        border-radius: 0;
        margin: 0;
        box-shadow: none;
        min-height: auto;
        aspect-ratio: auto;
    }

    .kz-a4-title {
        font-size: 20pt;
    }

    .kz-a4-brand-name {
        font-size: 18pt;
    }

    .kz-a4-fields {
        gap: 10px;
        font-size: 10pt;
    }

    .kz-a4-blank {
        min-width: 90px;
    }

    .kz-numpad {
        grid-template-columns: repeat(3, 52px);
    }

    .kz-numpad-key {
        width: 52px;
        height: 52px;
        font-size: 18pt;
    }

    .kz-a4-card-grid {
        grid-template-columns: 1fr;
    }

    .kz-a4-match-grid {
        grid-template-columns: 1fr 40px 1fr;
    }

    .kz-target {
        font-size: 30pt;
        min-width: 48px;
    }

    .kz-flash-card .kz-letter {
        font-size: 36pt;
    }

    .kz-flash-card .kz-picture {
        font-size: 32pt;
    }

    .kz-train-wagon .kz-number-box {
        width: 46px;
        height: 46px;
        font-size: 18pt;
    }

    .kz-colorpicker {
        top: 8px;
        right: 8px;
        padding: 6px;
        gap: 4px;
    }

    .kz-color-dot {
        width: 22px;
        height: 22px;
    }
}