/* Texture editor - builds on text-generators.css (.tg-* panels, chips, commands). */
.te-layout {
    display: grid;
    grid-template-columns: minmax(0, 330px) minmax(0, 1fr) minmax(0, 300px);
    gap: 18px;
    align-items: start;
}

.te-picker h2 {
    flex-wrap: wrap;
}

.te-count {
    flex-basis: 100%;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
}

.te-tabs {
    margin: 8px 0;
}

.te-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 4px;
    max-height: 420px;
    padding: 6px;
    overflow-y: auto;
    border: 1px solid var(--tg-line);
    border-radius: 12px;
    background: var(--tg-field);
}

.main .te-group {
    grid-column: 1 / -1;
    margin: 8px 0 2px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--tg-line);
    color: var(--text-primary);
    font-size: 0.78rem;
    font-weight: 600;
    text-align: left;
}

.te-group:first-child {
    margin-top: 0;
}

.te-group small {
    color: var(--text-muted);
    font-weight: 500;
}

.te-obj {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 5px 3px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.62rem;
    line-height: 1.2;
    cursor: pointer;
}

.te-obj img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    image-rendering: pixelated;
}

.te-obj span {
    max-width: 100%;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.te-obj:hover,
.te-obj.active {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.te-more {
    grid-column: 1 / -1;
    margin: 8px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

.te-texlist {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 6px;
}

.te-tex {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 4px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.64rem;
    cursor: pointer;
}

.te-tex canvas {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    border-radius: 3px;
}

.te-tex span {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.te-tex.active {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.te-tex.is-dirty::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
}

/* Editor */
.te-editor-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
}

.tg-panel .te-editor-head h2 {
    margin: 0;
}

.te-editor-head small {
    color: var(--text-muted);
    font-family: var(--mono-font);
    font-size: 0.75rem;
}

.te-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px;
}

.te-toolbar button {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 70px;
    padding: 7px 8px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.7rem;
    cursor: pointer;
}

.te-toolbar button i {
    font-size: 1rem;
}

.te-toolbar button.active {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.te-canvas-wrap {
    max-height: min(72vh, 640px);
    overflow: auto;
    border-radius: 8px;
}

/* Zoomed in: a frame to scroll in, the canvas starts at its left edge. */
.te-canvas-wrap.is-zoomed {
    border: 1px solid var(--tg-line);
    background: var(--tg-field);
}

#teCanvas {
    display: block;
    margin: 0 auto;
    width: 100%;
    max-width: 512px;
    height: auto;
    aspect-ratio: 1;
    border: 1px solid var(--tg-line);
    border-radius: 8px;
    image-rendering: pixelated;
    touch-action: none;
    cursor: crosshair;
}

#teCanvas[data-tool="picker"] {
    cursor: copy;
}

.te-pos {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-family: var(--mono-font);
    font-size: 0.75rem;
    text-align: center;
}

.te-frames {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: 8px;
}

.te-frames small {
    flex-basis: 100%;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
}

.te-frames button {
    padding: 3px 9px;
    border: 1px solid var(--tg-line);
    border-radius: 999px;
    background: var(--tg-field);
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
}

.te-frames button.active {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.te-color-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
}

.tg-panel .te-color-row input[type="color"] {
    width: 46px;
    height: 40px;
    padding: 2px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
    cursor: pointer;
}

.tg-panel .te-color-row input[type="text"] {
    width: 110px;
    padding: 8px 10px;
    font-family: var(--mono-font);
    font-size: 0.85rem;
}

.tg-panel .te-alpha {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 0.8rem;
}

.te-alpha input {
    width: 110px;
    accent-color: var(--tg-accent);
}

.te-alpha b {
    min-width: 42px;
    color: var(--tg-accent);
    font-weight: 600;
}

.te-palette {
    display: grid;
    gap: 6px;
    margin-top: 10px;
}

.te-swatches {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
}

.te-recent {
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--tg-line);
}

.te-swatch {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 5px;
    background: linear-gradient(var(--sw), var(--sw)), repeating-conic-gradient(#2a2f3a 0% 25%, #3b4250 0% 50%) 50% / 8px 8px;
    cursor: pointer;
}

.te-swatch:hover {
    outline: 2px solid var(--tg-accent);
    outline-offset: 1px;
}

.te-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.te-actions .btn[aria-pressed="true"],
.te-actions .btn.active {
    border-color: var(--tg-accent);
    color: var(--text-primary);
    background: var(--tg-accent-soft);
}

.tg-panel label.te-import {
    display: inline-flex;
    margin: 0;
    color: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* Preview */
.te-3d-wrap {
    position: relative;
}

#te3d {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid var(--tg-line);
    border-radius: 12px;
    background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--tg-accent) 10%, transparent), transparent 70%), var(--tg-field);
    cursor: grab;
    touch-action: none;
}

.te-3d-reset {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--tg-line);
    border-radius: 8px;
    background: var(--tg-panel);
    color: var(--text-secondary);
    cursor: pointer;
}

.main .te-3d-none {
    margin: 0;
    padding: 30px 12px;
    border: 1px dashed var(--tg-line);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

.te-tiled {
    display: block;
    width: 100%;
    max-width: 240px;
    height: auto;
    margin: 0 auto;
    border-radius: 8px;
    image-rendering: pixelated;
}

.te-sizes {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--tg-line);
    border-radius: 12px;
    background: #8b8b8b;
}

.te-sizes figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin: 0;
}

.te-sizes canvas {
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
}

.te-sizes figcaption {
    color: #1f1f1f;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Below: recolour + pack */
.te-below {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.te-below input[type="range"] {
    width: 100%;
    accent-color: var(--tg-accent);
}

.te-val {
    color: var(--tg-accent);
    font-weight: 600;
}

.te-pack-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
}

.te-changed {
    display: grid;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.te-changed-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
}

.te-changed-row canvas {
    flex: none;
    image-rendering: pixelated;
    border-radius: 3px;
}

.te-changed-row span {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.te-changed-row strong {
    display: block;
    font-size: 0.85rem;
}

.te-changed-row small {
    display: block;
    overflow: hidden;
    color: var(--text-muted);
    font-family: var(--mono-font);
    font-size: 0.7rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.te-zip {
    display: flex;
    width: 100%;
    justify-content: center;
    margin-top: 14px;
}

.te-howto {
    display: grid;
    gap: 8px;
    max-width: 860px;
    margin: 0 auto 10px;
    padding: 0;
    list-style: none;
}

.main .te-howto li {
    padding: 8px 12px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
    font-size: 0.86rem;
    line-height: 1.5;
    text-align: left;
}

@media (max-width: 1280px) {
    .te-layout {
        grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
    }

    .te-preview {
        grid-column: 1 / -1;
    }

    #te3d {
        max-width: 420px;
        margin: 0 auto;
    }
}

@media (max-width: 900px) {
    .te-layout,
    .te-below {
        grid-template-columns: minmax(0, 1fr);
    }

    .te-pack-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* The site makes buttons full width on phones; these are a compact row. */
.main .te-actions .btn {
    width: auto;
    flex: 0 1 auto;
    margin: 0;
}

.main .te-alpha-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--warning) 9%, transparent);
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.45;
    text-align: left;
}

.te-alpha-note i {
    margin-top: 2px;
    color: var(--warning);
}

.te-alpha-note a {
    color: var(--tg-accent);
    font-weight: 600;
}

/* ===== Editor bar: grouped, compact buttons ===== */
.te-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.te-group {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--tg-line);
    border-radius: 12px;
    background: var(--tg-field);
}

.main .te-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 58px;
    margin: 0;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.66rem;
    font-weight: 600;
    line-height: 1.1;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.te-btn i {
    font-size: 0.95rem;
}

.te-btn b {
    color: var(--tg-accent);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.main .te-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--text-primary) 8%, transparent);
    color: var(--text-primary);
}

.main .te-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.main .te-btn[aria-pressed="true"],
.main .te-btn.active {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.te-file .te-btn {
    border-color: var(--tg-line);
    background: var(--tg-field);
}

.main .te-btn.te-btn-primary {
    border-color: transparent;
    background: var(--primary-gradient, var(--primary));
    color: #fff;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 30%, transparent);
}

.main .te-btn.te-btn-primary:hover {
    filter: brightness(1.08);
    background: var(--primary-gradient, var(--primary));
    color: #fff;
}

.tg-panel label.te-btn {
    margin: 0;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: center;
}

@media (max-width: 480px) {
    .main .te-btn {
        min-width: 50px;
        padding: 6px 6px;
    }
}

/* links in the how-to read on the dark panel (were browser blue) */
.te-howto a {
    color: var(--tg-accent);
    font-weight: 600;
}

/* button labels wrap instead of being cut ("Spiegeln …" on phones) */
.main .te-btn span {
    white-space: normal;
    text-align: center;
}

/* RGB brush: painted pixels run through the rainbow in the game */
.te-rgb-btn {
    min-width: 64px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000) 0 0 / 200% 100%;
    color: #fff;
    font: inherit;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    cursor: pointer;
}

.te-rgb-btn.active {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
    animation: te-rgb-run 2.4s linear infinite;
}

.te-rgb-btn.is-off {
    opacity: 0.45;
    filter: grayscale(1);
}

@keyframes te-rgb-run {
    to {
        background-position: 200% 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .te-rgb-btn.active {
        animation: none;
    }
}

/* full screen: the editor panel over the whole page, canvas left, controls right */
html.te-full-open,
html.te-full-open body {
    overflow: hidden;
}

html.te-full-open .toast-container {
    z-index: 1600;
}

.tg-panel.te-full {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    grid-template-rows: repeat(29, auto) 1fr;
    grid-auto-flow: row dense;
    column-gap: 20px;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 16px;
    border-radius: 0;
    background: var(--bg-primary, #0f1117);
    overflow: auto;
}

.tg-panel.te-full > * {
    grid-column: 2;
}

.tg-panel.te-full > .te-canvas-wrap,
.tg-panel.te-full > .he-canvas-wrap {
    grid-column: 1;
    grid-row: 1 / span 30;
    align-self: start;
    max-height: calc(100vh - 32px);
    overflow: auto;
}

.tg-panel.te-full > .te-alpha-note {
    display: none;
}

@media (max-width: 760px) {
    .tg-panel.te-full {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: none;
    }

    .tg-panel.te-full > *,
    .tg-panel.te-full > .te-canvas-wrap,
    .tg-panel.te-full > .he-canvas-wrap {
        grid-column: 1;
        grid-row: auto;
    }

    .tg-panel.te-full > .te-canvas-wrap,
    .tg-panel.te-full > .he-canvas-wrap {
        max-height: 70vh;
    }
}

/* brush size */
.tg-panel .te-size {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 10px;
    font-size: 0.8rem;
}

.tg-panel .te-size input[type="range"] {
    width: min(200px, 45vw);
    margin: 0;
}

.tg-panel .te-size b {
    min-width: 3.2em;
    color: var(--tg-accent);
    font-family: var(--mono-font);
}

/* the 3D preview sticks while the page scrolls, like the preview of the text generators -
   only side by side; never taller than the screen */
@media (min-width: 1281px) {
    .te-picker,
    .te-preview {
        position: sticky;
        top: 96px;
        max-height: calc(100vh - 112px);
        overflow-y: auto;
    }
}

/* "only this block" switch for blocks that borrow a texture (stairs, fences, buttons ...) */
.tg-panel .te-own.toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 10px;
    padding: 8px 10px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
    text-align: left;
}

.te-own[hidden] {
    display: none;
}

.te-own input {
    margin-top: 3px;
    accent-color: var(--tg-accent);
}

.te-own span {
    display: grid;
    gap: 2px;
}

.te-own strong {
    color: var(--text-primary);
    font-size: 0.82rem;
}

.te-own small {
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.35;
}

.te-tex.is-own canvas {
    outline: 2px solid var(--tg-accent);
    outline-offset: 1px;
}
