/* ============================================================
   Kids Kingdom - Capital Letters Tracing (v9)
   Breakpoints (exact, as specified):
     >1280px            - large desktop, row layout, 8 letters
     1024px - 1280px    - desktop, row layout, 8 letters
     768px  - 1023px    - tablet, row layout, 6 letters
     581px  - 767px     - small tablet/large phone, row layout, 5 letters
     421px  - 580px     - mobile, STACKED layout, 2x3 = 6 letters
     <=420px            - small mobile, STACKED layout, 2x3 = 6 letters
   Only at 580px and below does the tracing area drop to its own
   line - everything above that stays one horizontal row.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Devanagari:wght@100;300;400&display=swap');

.trace-wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 0px 50px;
}

/* ---------------- Toolbar (pen size + clear all) ---------------- */
.trace-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    background: var(--color-bg);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 24px;
}

.trace-toolbar label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--color-dark);
    font-weight: 600;
}

.trace-toolbar input[type="range"] {
    width: 120px;
}

.trace-btn-ghost {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.85rem;
    background: #fff;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    padding: 9px 18px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
    margin-left: auto;
}

.trace-btn-ghost:hover {
    background: var(--color-primary);
    color: #fff;
}

.trace-letter-section {
    margin-bottom: 22px;
}

.trace-letter-label {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--color-dark);
    margin-bottom: 10px;
}

/* ---------------- Row: image + reference + tracing + clear ---------------- */
/* Base = default = anything above 1280px (large desktop) AND the
   1024-1280 tier too, since both use identical sizing. */
.trace-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.trace-box {
    border-radius: 12px;
    background: #fff;
    border: 0px solid var(--color-bg);
    position: relative;
    overflow: hidden;
    flex: 0 0 110px;
    aspect-ratio: 1 / 1;
}

.trace-box.is-image {
    /* background: var(--color-bg); */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0px;
}

.trace-box.is-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.trace-box.is-reference {
    /* background: var(--color-bg); */
    display: flex;
    align-items: center;
    justify-content: center;
}

.trace-box.is-reference span {
    font-family: 'Noto Sans Devanagari', var(--font-heading), sans-serif;
    font-weight: 500;
    font-size: 3.2rem;
    line-height: 1;
    color: var(--color-primary);
}

.trace-canvas-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
    background: #fff;
    border-radius: 12px;
    border: 0px solid var(--color-bg);
    display: flex;
    align-items: center;
}

.trace-canvas {
    display: block;
    width: 100%;
    height: 110px;
    touch-action: none;
    cursor: crosshair;
    -webkit-user-select: none;
    user-select: none;
}

.trace-row-actions {
    flex: 0 0 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.trace-clear-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--color-bg);
    font-size: 1rem;
    color: #999;
    cursor: pointer;
}

.trace-clear-btn:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

/* ================= 1024px - 1280px ================= */
@media (min-width: 1024px) and (max-width: 1280px) {
    .trace-box {
        flex-basis: 110px;
    }
    .trace-box.is-reference span {
        font-size: 3.4rem;
    }
    .trace-canvas {
        height: 110px;
    }
}

/* ================= 768px - 1023px (tablet) =================
   Still one horizontal row - 6 letters instead of 8. */
@media (max-width: 1023px) and (min-width: 768px) {
    .trace-box {
        flex-basis: 92px;
    }
    .trace-box.is-reference span {
        font-size: 2.9rem;
    }
    .trace-canvas {
        height: 102px;
    }
}

/* ================= 581px - 767px =================
   Still one horizontal row (tracing stays beside the boxes) -
   5 letters to keep them readable at this width. */
@media (max-width: 767px) and (min-width: 581px) {
    .trace-row {
        gap: 8px;
    }
    .trace-box {
        flex-basis: 78px;
    }
    .trace-box.is-reference span {
        font-size: 2.4rem;
    }
    .trace-canvas {
        height: 92px;
    }
    .trace-row-actions {
        flex-basis: 40px;
    }
    .trace-clear-btn {
        width: 32px;
        height: 32px;
    }
}

/* ================= 421px - 580px =================
   STACKED layout begins here: [image][reference][clear] on the
   first line, the wide tracing canvas drops to its own full-width
   line below - 3 letters x 2 lines = 6 total, drawn inside one
   taller canvas. Image/letter sized up per feedback. */
@media (max-width: 580px) and (min-width: 421px) {
    .trace-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .trace-box {
        flex-basis: 100px;
        order: 1;
    }
    .trace-box.is-reference {
        order: 2;
    }
    .trace-box.is-reference span {
        font-size: 3.3rem;
    }
    .trace-row-actions {
        order: 3;
        flex: 0 0 42px;
    }
    .trace-clear-btn {
        width: 34px;
        height: 34px;
    }
    .trace-canvas-wrap {
        order: 4;
        flex: 1 1 100%;
        margin-top: 8px;
    }
    .trace-canvas {
        height: 190px;
    }
    .trace-toolbar {
        width: 100%;
    }
    .trace-toolbar label {
        width: 100%;
    }
    .trace-toolbar input[type="range"] {
        flex: 1;
    }
}

/* ================= <=420px (small mobile) =================
   Also stacked - kept roomy (not shrunk further) per feedback
   that things were looking too small. */
@media (max-width: 420px) {
    .trace-row {
        flex-wrap: wrap;
        gap: 6px;
    }
    .trace-box {
        flex-basis: 92px;
        order: 1;
    }
    .trace-box.is-reference {
        order: 2;
    }
    .trace-box.is-reference span {
        font-size: 3rem;
    }
    .trace-row-actions {
        order: 3;
        flex: 0 0 38px;
    }
    .trace-clear-btn {
        width: 32px;
        height: 32px;
    }
    .trace-canvas-wrap {
        order: 4;
        flex: 1 1 100%;
        margin-top: 6px;
    }
    .trace-canvas {
        height: 180px;
    }
    .trace-toolbar {
        width: 100%;
    }
    .trace-toolbar label {
        width: 100%;
    }
    .trace-toolbar input[type="range"] {
        flex: 1;
    }
}