/* HUD editor - builds on text-generators.css (.tg-*) and texture-editor.css (.te-* toolbar, swatches, pack). */
.he-stage-panel {
    margin-bottom: 18px;
}

.he-stage {
    overflow: hidden;
    border: 1px solid var(--tg-line);
    border-radius: 12px;
    background: #0c1220;
}

#hePreview {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 300 / 104;   /* set from the script for each editor */
    image-rendering: pixelated;
    cursor: pointer;
}

.he-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px 16px;
    margin-top: 14px;
}

.tg-panel .he-range,
.tg-panel .he-view-sel label {
    display: grid;
    gap: 4px;
    margin: 0;
    font-size: 0.8rem;
    text-align: left;
}

.he-range span,
.he-view-sel label > span {
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
}

.he-range b {
    color: var(--tg-accent);
    font-variant-numeric: tabular-nums;
}

.he-range input {
    width: 100%;
    accent-color: var(--tg-accent);
}

.tg-panel .he-view-sel select {
    padding: 7px 10px;
    font-size: 0.85rem;
    text-align: left;
}

.tg-panel .he-view-sel input[type="text"] {
    padding: 7px 10px;
    font-size: 0.85rem;
    text-align: left;
}

.tg-panel .he-view-sel input[type="text"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.main .he-title-hint {
    margin: 8px 0 0;
    text-align: left;
}

.tg-panel .he-view-sel .he-check {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: end;
    padding: 8px 0;
}

.he-check input {
    accent-color: var(--tg-accent);
}

/* ===== three columns: elements | pixel editor | recolour ===== */
.he-layout {
    display: grid;
    grid-template-columns: minmax(0, 330px) minmax(0, 1fr) minmax(0, 300px);
    gap: 18px;
    align-items: start;
}

.he-groups {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.main .he-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.68rem;
    line-height: 1.15;
    cursor: pointer;
}

.he-group i {
    font-size: 1rem;
}

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

.he-sets {
    display: grid;
    gap: 8px;
    max-height: 520px;
    padding-right: 2px;
    overflow-y: auto;
}

.he-set {
    padding: 8px;
    border: 1px solid var(--tg-line);
    border-radius: 10px;
    background: var(--tg-field);
}

.he-set.active {
    border-color: color-mix(in srgb, var(--tg-accent) 55%, var(--tg-line));
}

.main .he-set-title {
    margin: 0 0 6px;
    color: var(--text-primary);
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
}

.he-set-title small {
    color: var(--text-muted);
    font-weight: 500;
}

.he-set-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
}

.main .he-spr {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 64px;
    padding: 5px 3px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.18);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.6rem;
    line-height: 1.1;
    cursor: pointer;
}

.main .he-spr.is-wide {
    width: 100%;
}

.he-spr canvas {
    max-width: 100%;
    image-rendering: pixelated;
}

.he-spr span {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main .he-spr:hover {
    border-color: var(--tg-line);
    color: var(--text-primary);
}

.main .he-spr.active {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.he-spr.is-dirty::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warning, #f5a524);
}

/* pixel editor */
.he-canvas-wrap {
    max-height: min(60vh, 520px);
    overflow: hidden;
    border-radius: 8px;
}

/* zoomed in: a slim scroll frame */
.he-canvas-wrap.is-zoomed {
    overflow: auto;
    padding-bottom: 4px;
    border: 1px solid var(--tg-line);
    background: var(--tg-field);
}

.he-canvas-wrap.is-zoomed #heCanvas {
    margin: 0;
}

#heCanvas {
    display: block;
    max-width: none;
    height: auto;
    margin: 0 auto;
    border: 1px solid var(--tg-line);
    border-radius: 6px;
    image-rendering: pixelated;
    touch-action: none;
    cursor: crosshair;
}

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

/* recolour */
.main .he-label {
    margin: 10px 0 6px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-align: center;
    text-transform: uppercase;
}

.he-scope {
    display: grid;
    gap: 4px;
}

.tg-panel .he-scope-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 7px 9px;
    border: 1px solid var(--tg-line);
    border-radius: 9px;
    background: var(--tg-field);
    font-size: 0.8rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.he-scope-opt:has(input:checked) {
    border-color: var(--tg-accent);
    background: var(--tg-accent-soft);
    color: var(--text-primary);
}

.he-scope-opt input {
    accent-color: var(--tg-accent);
}

.he-presets {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.main .he-preset {
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: var(--c);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.main .he-preset:hover,
.main .he-preset:focus-visible {
    transform: scale(1.08);
    outline: none;
}

.main .he-preset.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tg-accent) 60%, transparent);
}

.tg-panel .he-own {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0 4px;
    font-size: 0.82rem;
    text-align: left;
}

.tg-panel .he-own input[type="color"] {
    width: 42px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--tg-line);
    border-radius: 8px;
    background: var(--tg-field);
    cursor: pointer;
}

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

.he-more {
    margin-top: 8px;
}

.he-more summary {
    color: var(--text-secondary);
    font-size: 0.82rem;
    cursor: pointer;
}

.tg-panel .he-tint-bar {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.he-tint-bar .btn {
    flex: 1;
    justify-content: center;
    min-width: 0;
    padding: 10px 8px;
}

.he-tint-bar .btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
    box-shadow: none;
}

.main .he-preset-rgb {
    grid-column: 1 / -1;
    aspect-ratio: auto;
    height: 34px;
    background: linear-gradient(90deg, #ff4d4d, #ffb84d, #f5ff4d, #4dff88, #4dd2ff, #6b6bff, #d24dff, #ff4d4d);
    background-size: 200% 100%;
    color: #fff;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    animation: heRainbow 4s linear infinite;
}

@keyframes heRainbow {
    to { background-position: 200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .main .he-preset-rgb { animation: none; }
}

.he-rgb-row {
    margin-top: 8px;
}

.he-spr.is-rgb canvas {
    animation: heHue 2.4s linear infinite;
}

@keyframes heHue {
    to { filter: hue-rotate(360deg); }
}

.he-rgb-tag {
    padding: 1px 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, #ff4d4d, #f5ff4d, #4dff88, #4dd2ff, #d24dff);
    color: #111;
    font-size: 0.62rem;
    font-weight: 800;
}

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

    .he-editor {
        grid-column: 1 / -1;
        order: 3;
    }
}

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

    .he-groups {
        grid-template-columns: repeat(4, 1fr);
    }

    .he-view {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Inventar-Editor: a taller view (300 x 240), so it does not grow over the whole screen */
[data-he-mode="gui"] .he-stage {
    max-width: 720px;
    margin: 0 auto;
}

/* selection: painting and recolouring stay inside it */
.he-sel-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.he-sel-bar[hidden],
.main .he-sel-note[hidden] {
    display: none;
}

.he-sel-bar > span {
    flex-basis: 100%;
    text-align: center;
    color: var(--text-muted);
    font-family: var(--mono-font);
    font-size: 0.75rem;
}

.he-sel-bar.is-on > span {
    color: var(--tg-accent);
}

.he-scope.is-off {
    opacity: 0.4;
    pointer-events: none;
}

.main .he-sel-note {
    margin: 8px 0 0;
    padding: 8px 10px;
    border: 1px solid var(--tg-accent);
    border-radius: 8px;
    background: var(--tg-accent-soft);
    color: var(--text-primary);
    font-size: 0.78rem;
    line-height: 1.45;
}

/* colour: the current one big and clear, dye swatches, RGB brush, recent */
.he-colors {
    margin-top: 12px;
}

.he-current {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.he-current-swatch {
    position: relative;
    width: 58px;
    height: 58px;
    border: 2px solid var(--tg-line);
    border-radius: 12px;
    background: linear-gradient(var(--cur, #3d9be9), var(--cur, #3d9be9)), repeating-conic-gradient(#2a2f3a 0% 25%, #3b4250 0% 50%) 50% / 10px 10px;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.he-current-swatch:hover {
    border-color: var(--tg-accent);
}

.tg-panel .he-current-swatch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
}

.he-current-swatch.is-rgb,
.he-colors .te-swatch.he-sw-rgb {
    background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000) 0 0 / 200% 100%;
    animation: he-rgb-run 2.4s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .he-current-swatch.is-rgb,
    .he-colors .te-swatch.he-sw-rgb {
        animation: none;
    }
}

.he-current-info {
    display: grid;
    gap: 4px;
}

.he-current-info small {
    color: var(--text-muted);
    font-size: 0.72rem;
}

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

.main .he-colors .he-label {
    text-align: center;
}

.he-colors .te-swatch {
    width: 24px;
    height: 24px;
}

.he-colors .te-swatch.active {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

.he-colors .he-label[hidden] {
    display: none;
}

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

/* RGB swatch on a picture that cannot animate (container screens) */
.he-colors .te-swatch.he-sw-rgb.is-off {
    opacity: 0.35;
    filter: grayscale(1);
    animation: none;
}

/* picture as the window's background (Inventar-Editor) */
.he-bgimg {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--tg-line);
}

.tg-panel .he-bg-upload {
    width: 100%;
    justify-content: center;
    cursor: pointer;
}

.he-bg-name {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.he-bg-opts {
    display: grid;
    gap: 2px;
    margin-top: 10px;
}

.he-bg-opts[hidden] {
    display: none;
}

/* fit buttons of "Bild als Hintergrund" (the same look as the Gemälde-Generator's) */
.he-bgimg .pg-seg {
    display: flex;
    margin: 4px 0 6px;
    padding: 3px;
    border: 1px solid var(--tg-line);
    border-radius: 11px;
    background: var(--tg-field);
}

.main .he-bgimg .pg-seg button {
    flex: 1;
    padding: 7px 4px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}

.main .he-bgimg .pg-seg button.active {
    background: var(--tg-accent-soft);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px var(--tg-accent);
}

.he-bgimg .pg-range {
    display: grid;
    gap: 4px;
    margin: 8px 0 0;
    font-size: 0.78rem;
}

.he-bgimg .pg-range b {
    color: var(--tg-accent);
}

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

/* in full screen the block sits in the tools column */
.tg-panel.te-full > .he-bgimg {
    margin-top: 10px;
}
