/* =============================================================================
   Add Text to Image - editor styles
   Everything is scoped under .tool-scope, per the project's class-prefix rule, and
   built on the template's own tokens (--bg-panel, --card-border, --accent-cyan,
   --accent-violet, --text-main, --text-muted) so the editor follows the page theme
   instead of hard-coding a second palette.
   ============================================================================= */

/* ---------------------------------------------------------------- self-hosted faces
   Paths are relative to this stylesheet, not root-absolute: the pages are opened
   straight from disk during development, where /assets means the filesystem root.
   Not preloaded: a face is only fetched when someone picks it. add-text-studio.js
   awaits document.fonts.load() before drawing, so the canvas never renders a
   fallback and then silently changes under the user. */
@font-face { font-family: 'Anton';            src: url('../../vendor/fonts/anton.woff2') format('woff2');            font-weight: 400; font-display: swap; }
@font-face { font-family: 'Bebas Neue';       src: url('../../vendor/fonts/bebas-neue.woff2') format('woff2');       font-weight: 400; font-display: swap; }
@font-face { font-family: 'Oswald';           src: url('../../vendor/fonts/oswald.woff2') format('woff2');           font-weight: 400; font-display: swap; }
@font-face { font-family: 'Playfair Display'; src: url('../../vendor/fonts/playfair-display.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Lobster';          src: url('../../vendor/fonts/lobster.woff2') format('woff2');          font-weight: 400; font-display: swap; }
@font-face { font-family: 'Pacifico';         src: url('../../vendor/fonts/pacifico.woff2') format('woff2');         font-weight: 400; font-display: swap; }
@font-face { font-family: 'Roboto Mono';      src: url('../../vendor/fonts/roboto-mono.woff2') format('woff2');      font-weight: 400; font-display: swap; }

/* ---------------------------------------------------------------- shell */
.tool-scope .ts-studio {
    --ts-gap: 1rem;
    --ts-radius: 1rem;
    --ts-field: color-mix(in srgb, var(--text-main) 5%, transparent);
    --ts-field-border: var(--card-border);
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr) 316px;
    gap: var(--ts-gap);
    align-items: start;
    margin: 0 auto;
    color: var(--text-main);
}

.tool-scope .ts-panel {
    background: var(--bg-panel);
    border: 1px solid var(--card-border);
    border-radius: var(--ts-radius);
    box-shadow: var(--shadow-glow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.tool-scope .ts-rail,
.tool-scope .ts-inspector {
    display: flex;
    flex-direction: column;
    padding: 0.9rem;
    gap: 0.75rem;
}

.tool-scope .ts-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.tool-scope .ts-title {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------- buttons */
.tool-scope .ts-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0.6rem 1rem;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-main);
    background: var(--ts-field);
    border: 1px solid var(--ts-field-border);
    border-radius: 0.7rem;
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease, transform .12s ease;
}
.tool-scope .ts-btn:hover:not(:disabled) { border-color: var(--accent-cyan); }
.tool-scope .ts-btn:active:not(:disabled) { transform: translateY(1px); }
.tool-scope .ts-btn:disabled { opacity: .45; cursor: not-allowed; }

.tool-scope .ts-btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
    border-color: transparent;
    box-shadow: 0 6px 18px -8px var(--accent-violet);
}
.tool-scope .ts-btn-primary:hover:not(:disabled) { filter: brightness(1.06); border-color: transparent; }

.tool-scope .ts-btn-block { width: 100%; }

.tool-scope .ts-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    font: inherit;
    font-size: 1rem;
    color: var(--text-muted);
    background: var(--ts-field);
    border: 1px solid var(--ts-field-border);
    border-radius: 0.7rem;
    cursor: pointer;
    transition: color .18s ease, border-color .18s ease;
}
.tool-scope .ts-icon-btn:hover:not(:disabled) { color: var(--accent-cyan); border-color: var(--accent-cyan); }
.tool-scope .ts-icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.tool-scope .ts-icon-btn svg { width: 18px; height: 18px; }

.tool-scope .ts-studio :is(button, select, input, textarea, label, [tabindex]):focus-visible {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--border-glow);
}

/* ---------------------------------------------------------------- layer rail */
.tool-scope .ts-history { display: flex; gap: 0.4rem; }

.tool-scope .ts-layer-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 46vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tool-scope .ts-layer {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    min-height: 48px;
    padding: 0.45rem 0.55rem;
    font: inherit;
    text-align: left;
    color: var(--text-main);
    background: var(--ts-field);
    border: 1px solid transparent;
    border-radius: 0.65rem;
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease;
}
.tool-scope .ts-layer:hover { border-color: var(--card-border); }
.tool-scope .ts-layer[aria-selected="true"] {
    border-color: var(--accent-cyan);
    background: color-mix(in srgb, var(--accent-cyan) 12%, transparent);
}

/* the swatch renders in the layer's own face, so the list is scannable when
   several layers sit on top of each other on the canvas */
.tool-scope .ts-layer-swatch {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    font-size: 1.05rem;
    line-height: 1;
    color: var(--text-main);
    background: color-mix(in srgb, var(--text-main) 8%, transparent);
    border-radius: 0.5rem;
    overflow: hidden;
}

.tool-scope .ts-layer-text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-scope .ts-layer-ops {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
}

.tool-scope .ts-empty {
    margin: 0;
    padding: 0.9rem 0.6rem;
    font-size: 0.84rem;
    line-height: 1.5;
    color: var(--text-muted);
    text-align: center;
}

/* ---------------------------------------------------------------- stage */
.tool-scope .ts-stage {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 0;
}

.tool-scope .ts-viewport {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 300px;
    padding: 0.75rem;
    overflow: auto;
    overscroll-behavior: contain;
    background:
        linear-gradient(45deg, color-mix(in srgb, var(--text-main) 4%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--text-main) 4%, transparent) 75%),
        linear-gradient(45deg, color-mix(in srgb, var(--text-main) 4%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--text-main) 4%, transparent) 75%);
    background-size: 22px 22px;
    background-position: 0 0, 11px 11px;
    touch-action: none;
}

/* No max-width/max-height here: the display size is set in px by the zoom control, and a
   CSS cap would silently shrink the canvas so the zoom read-out no longer told the truth. */
.tool-scope .ts-canvas {
    display: block;
    border-radius: 0.4rem;
    box-shadow: 0 12px 30px -18px rgba(0, 0, 0, .7);
    cursor: grab;
}
.tool-scope .ts-canvas.is-dragging { cursor: grabbing; }
.tool-scope .ts-canvas[hidden] { display: none; }

.tool-scope .ts-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 2.5rem 1.25rem;
    text-align: center;
    border: 2px dashed var(--card-border);
    border-radius: 0.9rem;
    transition: border-color .18s ease, background .18s ease;
}
.tool-scope .ts-dropzone.is-over {
    border-color: var(--accent-cyan);
    background: color-mix(in srgb, var(--accent-cyan) 8%, transparent);
}
.tool-scope .ts-dropzone[hidden] { display: none; }
.tool-scope .ts-dropzone svg { width: 40px; height: 40px; color: var(--accent-cyan); }
.tool-scope .ts-drop-title { margin: 0.3rem 0 0; font-size: 1.05rem; font-weight: 700; }
.tool-scope .ts-drop-note { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--text-muted); }

.tool-scope .ts-stage-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.tool-scope .ts-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.tool-scope .ts-zoom {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.tool-scope .ts-zoom-val {
    min-width: 56px;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------- tabs */
.tool-scope .ts-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--ts-field);
    border-radius: 0.75rem;
}

.tool-scope .ts-tab {
    min-height: 44px;
    padding: 0.45rem 0.3rem;
    font: inherit;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: 0;
    border-radius: 0.55rem;
    cursor: pointer;
    transition: color .18s ease, background .18s ease;
}
.tool-scope .ts-tab[aria-selected="true"] {
    color: var(--text-main);
    background: var(--bg-panel);
    box-shadow: 0 1px 6px -2px rgba(0, 0, 0, .25);
}

.tool-scope .ts-tabpanel { display: flex; flex-direction: column; gap: 0.65rem; }
.tool-scope .ts-tabpanel[hidden] { display: none !important; }

/* ---------------------------------------------------------------- fields */
/* `:not([hidden])` is load-bearing: a bare `display: flex` silently overrides the
   hidden attribute, which is how the JPG quality slider stayed on screen in PNG mode. */
.tool-scope .ts-field:not([hidden]) { display: flex; flex-direction: column; gap: 0.3rem; }

.tool-scope .ts-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}
.tool-scope .ts-value {
    font-size: 0.78rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}

.tool-scope .ts-input,
.tool-scope .ts-select,
.tool-scope .ts-textarea {
    width: 100%;
    min-height: 44px;
    padding: 0.55rem 0.7rem;
    font: inherit;
    font-size: 0.92rem;
    color: var(--text-main);
    background: var(--ts-field);
    border: 1px solid var(--ts-field-border);
    border-radius: 0.65rem;
    transition: border-color .18s ease;
}
.tool-scope .ts-textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.tool-scope .ts-select { appearance: none; padding-right: 2rem; cursor: pointer; }

.tool-scope .ts-select-wrap { position: relative; }
.tool-scope .ts-select-wrap::after {
    content: '';
    position: absolute;
    right: 0.85rem; top: 50%;
    width: 7px; height: 7px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

/* A colour input renders as a bare hairline in several browsers, which is what the
   old panel showed for "Text Fill Color". Give it a real swatch box. */
.tool-scope .ts-color {
    width: 100%;
    height: 44px;
    padding: 3px;
    background: var(--ts-field);
    border: 1px solid var(--ts-field-border);
    border-radius: 0.65rem;
    cursor: pointer;
}
.tool-scope .ts-color::-webkit-color-swatch-wrapper { padding: 0; }
.tool-scope .ts-color::-webkit-color-swatch { border: 0; border-radius: 0.45rem; }
.tool-scope .ts-color::-moz-color-swatch { border: 0; border-radius: 0.45rem; }

.tool-scope .ts-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px;
    gap: 0.5rem;
    align-items: center;
}

.tool-scope input[type="range"].ts-range {
    width: 100%;
    height: 24px;
    padding: 0;
    background: none;
    border: 0;
    appearance: none;
    cursor: pointer;
}
.tool-scope .ts-range::-webkit-slider-runnable-track {
    height: 5px;
    background: color-mix(in srgb, var(--text-main) 16%, transparent);
    border-radius: 999px;
}
.tool-scope .ts-range::-webkit-slider-thumb {
    appearance: none;
    width: 18px; height: 18px;
    margin-top: -6.5px;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-panel);
    border-radius: 50%;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .3);
}
.tool-scope .ts-range::-moz-range-track {
    height: 5px;
    background: color-mix(in srgb, var(--text-main) 16%, transparent);
    border-radius: 999px;
}
.tool-scope .ts-range::-moz-range-thumb {
    width: 16px; height: 16px;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-panel);
    border-radius: 50%;
}

/* ---------------------------------------------------------------- segmented */
.tool-scope .ts-seg {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--ts-field);
    border: 1px solid var(--ts-field-border);
    border-radius: 0.65rem;
}
.tool-scope .ts-seg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: none;
    border: 0;
    border-radius: 0.45rem;
    cursor: pointer;
}
.tool-scope .ts-seg-btn[aria-pressed="true"] {
    color: var(--text-main);
    background: var(--bg-panel);
    box-shadow: 0 1px 5px -1px rgba(0, 0, 0, .22);
}
.tool-scope .ts-seg-btn svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- presets */
.tool-scope .ts-presets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
}

/* Each card previews itself: the glyphs are drawn with the preset's own face,
   fill, stroke and shadow, so the row is a set of samples rather than a word list. */
.tool-scope .ts-preset {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-height: 62px;
    padding: 0.5rem 0.35rem;
    font: inherit;
    background: var(--ts-field);
    border: 1px solid var(--ts-field-border);
    border-radius: 0.6rem;
    cursor: pointer;
    transition: border-color .18s ease, transform .12s ease;
}
.tool-scope .ts-preset:hover { border-color: var(--accent-cyan); }
.tool-scope .ts-preset:active { transform: translateY(1px); }
.tool-scope .ts-preset-sample {
    font-size: 1.35rem;
    line-height: 1.1;
    white-space: nowrap;
}
.tool-scope .ts-preset-name {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------- actions */
.tool-scope .ts-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 0.75rem;
    margin-top: auto;
    border-top: 1px solid var(--card-border);
}
.tool-scope .ts-export-row {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 0.5rem;
}

.tool-scope .ts-note {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-muted);
}
.tool-scope .ts-note[hidden] { display: none; }
.tool-scope .ts-note.is-warn { color: var(--accent-violet); font-weight: 600; }

/* The boot check swaps this in if the module never registers, so a missing asset
   reads as a message rather than a dead canvas. */
.tool-scope .ts-boot-error {
    padding: 2rem 1.25rem;
    text-align: center;
    border: 1px solid var(--card-border);
    border-radius: var(--ts-radius);
    background: var(--bg-panel);
}

/* ---------------------------------------------------------------- responsive */

/* An editor earns more width than a converter's list of options. The template caps
   .tool-outer at 1100px, which leaves the canvas about 340px wide between two panels. */
@media (min-width: 1180px) {
    .tool-outer:has(.ts-studio) { max-width: 1400px; }
}

@media (max-width: 1100px) {
    .tool-scope .ts-studio { grid-template-columns: 200px minmax(0, 1fr) 280px; }
}

/* Tablet and phone: the image comes first. It is the thing being edited, so it should not
   sit below a list of layers you have not made yet. */
@media (max-width: 900px) {
    .tool-scope .ts-studio {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: 'stage' 'rail' 'inspector';
    }
    .tool-scope .ts-rail { grid-area: rail; }
    .tool-scope .ts-stage { grid-area: stage; }
    .tool-scope .ts-inspector { grid-area: inspector; }

    .tool-scope .ts-layer-list {
        flex-direction: row;
        max-height: none;
        overflow-x: auto;
        scrollbar-width: none;
        padding-bottom: 0.25rem;
    }
    .tool-scope .ts-layer-list::-webkit-scrollbar { display: none; }
    .tool-scope .ts-layer { flex: 0 0 auto; width: 190px; }
    .tool-scope .ts-layer-ops { grid-template-columns: repeat(4, 44px); justify-content: start; }
}

/* Phone: the stage stays on screen while any control is being changed, so you can
   see what a slider is doing without scrolling back up. */
@media (max-width: 640px) {
    .tool-scope .ts-studio { --ts-gap: 0.7rem; }
    .tool-scope .ts-stage {
        position: sticky;
        top: 0.4rem;
        z-index: 6;
        padding: 0.4rem;
        background: var(--bg-panel);
        border: 1px solid var(--card-border);
        border-radius: var(--ts-radius);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
    .tool-scope .ts-viewport { min-height: 0; padding: 0.35rem; }
    .tool-scope .ts-canvas { max-height: 34vh; }
    .tool-scope .ts-dropzone { padding: 1.6rem 1rem; }
    .tool-scope .ts-hint { display: none; }
    .tool-scope .ts-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tool-scope .ts-row { grid-template-columns: minmax(0, 1fr) 84px; }
}

@media (prefers-reduced-motion: reduce) {
    .tool-scope .ts-studio * { transition: none !important; }
}
