/* Shared styles for the /tools pages (dithering tool, Deep Fried). Moved
   here unchanged from the dithering tool's template. */
#image-editor {
    --ie-border: 1px solid black;
    --ie-panel: rgba(255, 255, 255, .85);
    --ie-accent: yellowgreen;
}

#image-editor [hidden] {
    display: none !important;
}

.ie-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 1rem;
    align-items: start;
    margin-top: 1rem;
}

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

    /* Keep the preview on screen while scrolling through the controls. */
    #image-editor.has-image .ie-stage-wrap {
        position: sticky;
        top: 0;
        z-index: 2;
        background: white;
    }
}

/* --- stage ---------------------------------------------------------- */

.ie-stage-wrap {
    border: var(--ie-border);
    background: var(--ie-panel);
    min-width: 0;
}

.ie-stage {
    position: relative;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* checkerboard so transparency is visible */
    background-color: #ddd;
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%),
        linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%);
    background-size: 16px 16px;
    background-position: 0 0, 8px 8px;
}

.ie-stage.is-actual-size {
    display: block;
    overflow: auto;
    max-height: 75vh;
}

.ie-stage canvas {
    display: block;
}

#ie-original,
.ie-stage.is-comparing #ie-result {
    display: none;
}

.ie-stage.is-comparing #ie-original {
    display: block;
}

#image-editor:not(.has-image) .ie-stage canvas,
#image-editor:not(.has-image) .ie-toolbar,
#image-editor:not(.has-image) .ie-timeline {
    display: none;
}

/* --- video ---------------------------------------------------------- */

/* The source <video> is only read from, never shown. It stays rendered
   (not display: none) because some browsers stop decoding frames for
   videos that aren't. */
.ie-source-video {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

#ie-output,
#ie-edit,
.ie-render-overlay {
    display: none;
}

#image-editor[data-mode="result"] #ie-output,
#image-editor[data-mode="result"] #ie-edit {
    display: block;
}

#image-editor[data-mode="result"] #ie-result,
#image-editor[data-mode="result"] #ie-original,
#image-editor[data-mode="result"] #ie-compare,
#image-editor[data-mode="result"] #ie-zoom,
#image-editor[data-mode="result"] .ie-timeline {
    display: none !important;
}

#image-editor[data-mode="rendering"] .ie-render-overlay {
    display: flex;
}

#image-editor[data-mode="rendering"] .ie-timeline,
#image-editor[data-mode="rendering"] #ie-compare,
#image-editor[data-mode="rendering"] #ie-zoom {
    opacity: .4;
    pointer-events: none;
}

.ie-render-overlay {
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    background: rgba(255, 255, 255, .8);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ie-render-overlay progress {
    width: min(320px, 80%);
    height: 14px;
    accent-color: black;
}

.ie-timeline {
    display: flex;
    gap: .75rem;
    align-items: center;
    padding: .5rem;
    border-top: var(--ie-border);
}

.ie-timeline input {
    flex: 1;
    min-width: 0;
    accent-color: black;
}

.ie-time {
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#ie-play {
    min-width: 4.5rem;
}

.ie-hint {
    font-size: .85rem !important;
    color: rgba(0, 0, 0, .6);
}

#image-editor.has-image .ie-drop {
    display: none;
}

.ie-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
    text-align: center;
    padding: 3rem 1.5rem;
    margin: 1.5rem;
    border: 2px dashed black;
    background: rgba(255, 255, 255, .85);
    cursor: pointer;
}

#image-editor.is-dragging .ie-stage {
    outline: 4px dashed var(--ie-accent);
    outline-offset: -8px;
}

.ie-drop strong {
    font-size: 1.4rem;
}

.ie-drop span {
    font-size: 1rem;
}

.ie-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    padding: .5rem;
    border-top: var(--ie-border);
}

.ie-status {
    margin-left: auto;
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
    color: rgba(0, 0, 0, .7);
}

/* --- controls ------------------------------------------------------- */

.ie-controls {
    border: var(--ie-border);
    background: var(--ie-panel);
    font-size: .95rem;
}

.ie-controls fieldset {
    border: 0;
    border-bottom: var(--ie-border);
    margin: 0;
    padding: .75rem .9rem;
}

.ie-controls legend {
    float: left;
    width: 100%;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-size: .8rem;
    margin-bottom: .5rem;
}

.ie-field {
    clear: both;
    margin-bottom: .65rem;
}

.ie-field:last-child {
    margin-bottom: 0;
}

.ie-controls label {
    font-weight: 600 !important;
}

.ie-field > label,
.ie-field .ie-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: .2rem;
}

.ie-field output {
    font-variant-numeric: tabular-nums;
    color: rgba(0, 0, 0, .65);
}

.ie-controls select {
    width: 100%;
    padding: .3rem;
    border: var(--ie-border);
    background: white;
    font: inherit;
}

.ie-controls input[type="range"] {
    width: 100%;
    accent-color: black;
}

.ie-check {
    display: flex !important;
    gap: .5rem;
    align-items: center;
    justify-content: flex-start !important;
    cursor: pointer;
}

.ie-check input {
    accent-color: black;
}

.ie-colors {
    display: flex;
    gap: 1rem;
}

.ie-colors label {
    display: flex;
    align-items: center;
    gap: .4rem;
}

.ie-colors input[type="color"] {
    width: 2.5rem;
    height: 1.8rem;
    border: var(--ie-border);
    padding: 0;
    background: none;
}

.ie-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-top: .4rem;
}

.ie-swatches span {
    width: 16px;
    height: 16px;
    border: 1px solid rgba(0, 0, 0, .5);
}

.ie-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .35rem .75rem;
    border: var(--ie-border);
    background: white;
    color: black;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 2px 2px 0 black;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.ie-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.ie-btn.is-primary {
    background: var(--ie-accent);
}

.ie-btn:disabled {
    opacity: .5;
    cursor: default;
}

.ie-actions {
    display: flex;
    gap: .5rem;
    padding: .75rem .9rem;
}

.ie-actions .ie-btn {
    flex: 1;
}

.ie-intro {
    font-size: 1.1rem;
    line-height: 1.6rem;
}

.ie-breadcrumb {
    font-size: .9rem;
    margin-bottom: .5rem;
}

.ie-breadcrumb a {
    color: black;
    text-decoration: underline;
}

/* --- explanatory content below the tool ----------------------------- */

.ie-about {
    margin-top: 2.5rem;
}

.ie-about h2 {
    font-size: 1.6rem;
    margin: 2rem 0 .75rem;
}

.ie-about h3 {
    font-size: 1.15rem;
    margin: 1.25rem 0 .35rem;
}

.ie-about p,
.ie-about li,
.ie-about dd {
    font-size: 1.05rem;
    line-height: 1.6rem;
    color: rgba(0, 0, 0, .8);
}

.ie-about ol,
.ie-about ul {
    padding-left: 1.5rem;
    margin: .5rem 0;
}

.ie-about ol {
    list-style: decimal;
}

.ie-about ul {
    list-style: disc;
}

.ie-about dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: .5rem 1.25rem;
}

.ie-about dt {
    font-weight: 700;
    font-size: 1.05rem;
}

.ie-about dd {
    margin: 0;
}

@media (max-width: 768px) {
    .ie-about dl {
        grid-template-columns: 1fr;
        gap: .15rem;
    }

    .ie-about dd {
        margin-bottom: .6rem;
    }
}
