/* ==========================================================================
   KIDZAPS — Worksheet Engine + Canvas + SERP Preview Styles
   Loaded on worksheet pages AND admin pages (kept small — pure additions).
   Author: KidZaps Team — 2026-08
   ========================================================================== */

/* ==========================================================================
   Locked Preview (shown before "Start Activity" is clicked)
   Read-only preview of the worksheet task so parents/kids see what's inside
   and Google can still index the content.
   ========================================================================== */
.locked-preview {
    position: relative;
    background: white;
    border: 2px dashed #c7d2fe;
    border-radius: var(--radius-lg, 12px);
    padding: 1.25rem 1.5rem 1.5rem;
    margin: 0.5rem 0 1rem;
    min-height: 120px;
}

.locked-preview-badge {
    display: inline-block;
    background: #eef2ff;
    color: #4338ca;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    letter-spacing: 0.2px;
}

.locked-preview-body {
    color: #374151;
    line-height: 1.65;
    filter: grayscale(0.15);
}

/* Row-style preview for typing / tap_select / clock etc. */
.lp-row {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px dashed #e5e7eb;
    flex-wrap: wrap;
}

.lp-row:last-child {
    border-bottom: 0;
}

.lp-num {
    font-weight: 700;
    color: #6366f1;
    min-width: 1.5rem;
}

.lp-q {
    flex: 1;
    font-size: 1rem;
    color: #1f2937;
    min-width: 200px;
}

.lp-blank {
    letter-spacing: 2px;
    color: #9ca3af;
    font-weight: 700;
    min-width: 90px;
    text-align: right;
}

.lp-options {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-left: auto;
}

.lp-option {
    background: #f3f4f6;
    color: #4b5563;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid #e5e7eb;
}

/* Match-grid preview for drag_drop */
.lp-match-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.5rem 1rem;
    align-items: center;
}

.lp-match-cell {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
    color: #374151;
}

.lp-match-arrow {
    color: #9ca3af;
    font-size: 1.1rem;
    text-align: center;
}

/* Card preview for flip_card */
.lp-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.lp-card {
    background: linear-gradient(135deg, #eef2ff, white);
    border: 1px solid #c7d2fe;
    border-radius: 10px;
    padding: 1.25rem 0.5rem;
    text-align: center;
    font-weight: 700;
    color: #4338ca;
    font-size: 1rem;
}

.lp-card-more {
    background: #f3f4f6;
    color: #6b7280;
    font-style: italic;
    font-weight: 500;
    border-color: #e5e7eb;
}

.lp-instructions,
.lp-fallback {
    color: #4b5563;
    font-size: 1rem;
    line-height: 1.6;
    text-align: center;
    padding: 0.5rem 0;
}

.lp-fallback strong {
    color: #4338ca;
}

/* ==========================================================================
   Worksheet Engine — per-question interactive UI (.wks-*)
   ========================================================================== */
.wks-typing-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.wks-heading {
    text-align: center;
    color: var(--color-primary, #4f46e5);
    margin-bottom: 1.5rem;
    font-size: 1.15rem;
}

.wks-heading kbd {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.85em;
    font-family: monospace;
}

.wks-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background: var(--color-gray-50, #f8f9ff);
    border-radius: var(--radius-lg, 12px);
    border: 2px solid transparent;
    transition: border-color 0.3s, background 0.3s, transform 0.2s;
}

.wks-row.wks-correct {
    border-color: var(--color-success, #22c55e);
    background: #ecfdf5;
}

.wks-row.wks-wrong {
    border-color: var(--color-danger, #ef4444);
    background: #fef2f2;
}

.wks-num {
    font-weight: 700;
    color: var(--color-primary, #4f46e5);
    min-width: 2rem;
    font-size: 1.1rem;
}

.wks-q-text {
    flex: 1;
    font-size: 1.1rem;
}

.wks-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    flex-shrink: 0;
}

.wks-input {
    max-width: 140px;
    min-width: 90px;
    min-height: 48px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 0.5rem 0.75rem;
    border: 2px solid #dadce0;
    border-radius: 8px;
    background: white;
}

.wks-input:focus {
    outline: none;
    border-color: var(--color-primary, #4f46e5);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.wks-input.completed {
    background: #ecfdf5;
    border-color: var(--color-success, #22c55e);
    color: #065f46;
}

.wks-feedback {
    font-size: 1.4rem;
    min-width: 1.8rem;
    text-align: center;
    line-height: 1;
}

.wks-check {
    color: var(--color-success, #22c55e);
}

.wks-cross {
    color: var(--color-danger, #ef4444);
}

.wks-hint-btn,
.wks-retry-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.3rem;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    padding: 0;
    line-height: 1;
}

.wks-hint-btn:hover,
.wks-hint-btn:focus-visible {
    background: #fef3c7;
    transform: scale(1.1);
    outline: none;
}

.wks-retry-btn:hover,
.wks-retry-btn:focus-visible {
    background: #e0e7ff;
    transform: rotate(-90deg);
    outline: none;
}

.wks-hidden {
    display: none !important;
}

.wks-hint-tip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: #1f2937;
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.wks-hint-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1f2937;
}

.wks-hint-tip.wks-visible {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

.wks-actions {
    text-align: center;
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Animations */
@keyframes wksBounce {

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

    50% {
        transform: scale(1.03);
    }
}

@keyframes wksShake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    75% {
        transform: translateX(6px);
    }
}

/* Responsive */
@media (max-width: 640px) {
    .wks-row {
        flex-wrap: wrap;
    }

    .wks-q-text {
        flex-basis: 100%;
        margin-bottom: 0.5rem;
    }

    .wks-input-wrap {
        margin-left: auto;
    }
}

/* ==========================================================================
   Canvas Overlay (opens over the typing form when "Draw on Canvas" is clicked)
   ========================================================================== */
.wks-canvas-overlay {
    background: white;
    border: 2px solid var(--color-primary, #4f46e5);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 1rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.wks-canvas-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.wks-canvas-topbar strong {
    color: var(--color-primary, #4f46e5);
    font-size: 1.05rem;
}

.wks-canvas-help {
    flex: 1;
    color: #6b7280;
    font-size: 0.85rem;
}

.wks-canvas-close {
    padding: 0.4rem 0.9rem !important;
    font-size: 0.85rem !important;
}

.wks-canvas-shell {
    padding: 1rem 0;
}

/* ==========================================================================
   Canvas Engine (kz-canvas-*)
   ========================================================================== */
.kz-canvas-engine {
    background: #fafafa;
    border-radius: 12px;
    padding: 12px;
}

.kz-canvas-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    margin-bottom: 12px;
}

.kz-canvas-palette {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.kz-color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.kz-color-swatch:hover,
.kz-color-swatch:focus-visible {
    transform: scale(1.15);
    outline: none;
}

.kz-color-swatch.active {
    border-color: #1f2937;
    box-shadow: 0 0 0 3px rgba(31, 41, 55, 0.15);
    transform: scale(1.15);
}

.kz-canvas-brush {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #374151;
}

.kz-canvas-brush input[type=range] {
    width: 120px;
}

.kz-brush-preview {
    display: inline-block;
    background: #4f46e5;
    border-radius: 50%;
    transition: width 0.15s, height 0.15s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.kz-canvas-btn {
    min-height: 40px;
    padding: 8px 14px;
    background: #f3f4f6;
    color: #1f2937;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.kz-canvas-btn:hover,
.kz-canvas-btn:focus-visible {
    background: #e5e7eb;
    outline: none;
}

.kz-canvas-btn-primary {
    background: #4f46e5;
    color: white;
    border-color: #4f46e5;
}

.kz-canvas-btn-primary:hover,
.kz-canvas-btn-primary:focus-visible {
    background: #4338ca;
    border-color: #4338ca;
}

.kz-canvas-wrap {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px;
    overflow: hidden;
    text-align: center;
}

.kz-canvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    background: white;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    cursor: crosshair;
    touch-action: none;
    /* critical for mobile drawing */
}

@media (max-width: 640px) {
    .kz-canvas-toolbar {
        gap: 8px;
    }

    .kz-canvas-brush input[type=range] {
        width: 90px;
    }
}

/* ==========================================================================
   Admin — SERP Preview Widget (Google-style live preview)
   ========================================================================== */
.serp-preview-widget {
    font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    max-width: 640px;
    margin: 16px 0 24px;
    padding: 20px;
    background: white;
    border: 1px solid #dfe1e5;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.serp-widget-title {
    font-size: 14px;
    color: #202124;
    margin: 0 0 4px 0;
    letter-spacing: 0.2px;
}

.serp-note {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: #70757a;
    margin-top: 2px;
}

.serp-card {
    padding: 14px 0 18px;
    border-bottom: 1px solid #f3f4f6;
    margin-bottom: 16px;
}

.serp-site-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.serp-favicon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.serp-site-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.serp-site-name {
    font-size: 14px;
    color: #202124;
    line-height: 1.2;
}

.serp-url {
    font-size: 12px;
    color: #4d5156;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.serp-menu-dots {
    color: #70757a;
    font-size: 18px;
    padding: 0 4px;
}

.serp-title {
    font-size: 20px;
    color: #1a0dab;
    line-height: 1.3;
    margin: 4px 0 6px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    font-weight: 400;
}

.serp-title:hover {
    text-decoration: underline;
}

.serp-description {
    font-size: 14px;
    color: #4d5156;
    line-height: 1.58;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.serp-description .serp-bold {
    font-weight: 700;
    color: #202124;
}

.serp-inputs {
    margin-top: 4px;
}

.serp-field {
    margin-bottom: 16px;
}

.serp-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
}

.serp-field label small {
    font-weight: 400;
    color: #9ca3af;
    margin-left: 6px;
}

.serp-field input,
.serp-field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #dadce0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.serp-field input:focus,
.serp-field textarea:focus {
    outline: none;
    border-color: #4285f4;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.15);
}

.serp-field textarea {
    resize: vertical;
    min-height: 60px;
    line-height: 1.5;
}

.serp-char-counter {
    font-size: 12px;
    margin-top: 4px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    transition: color 0.2s;
}

.serp-char-counter.green {
    color: #0d652d;
}

.serp-char-counter.yellow {
    color: #b06000;
}

.serp-char-counter.red {
    color: #c5221f;
    font-weight: 600;
}

.serp-rating {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
}

.serp-rating.good {
    background: #e6f4ea;
    color: #137333;
}

.serp-rating.warning {
    background: #fef7e0;
    color: #b06000;
}

.serp-rating.bad {
    background: #fce8e6;
    color: #c5221f;
}