:root {
    /* Icon size is overridable via JS */
    --icon-size: 64px;
}

/* ============================
   Base
   ============================ */

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* No page scroll; panes handle their own overflow */
    font-family: "Open Sans", system-ui, "Segoe UI", sans-serif;
}

body {
    background-color: #383668;
    font-size: 0.8rem;
    color: #fff;
}

a {
    color: #83b5ff;
}

* {
    box-sizing: border-box;
}

code {
    font-size: 1em;
    color: #83b5ff;
}

.dark-text,
.dark-text > * {
    color: #222;
}

button {
    color: #333;
}

/* Simple spacing helper */
.spaced {
    margin-right: 12px;
}

.nowrap {
    white-space: pre;
}

/* Input control styles */

input[type="number"] {
    width: 3.5em;
}

input[type="checkbox"] {
    width: 1.18em;
    height: 1.18em;
}

/* Footer icons */
.site-footer-links {
    font-size: 2.5em;
}

/* ============================
   Layout: Three panes
   ============================ */

#layout {
    display: flex;
    flex-direction: row;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Draggable bars between panes */
.drag-bar {
    width: 6px;
    background-color: #1f1e3f;
    cursor: ew-resize;
}

/* ============================
   Left Pane
   ============================ */

#left-pane {
    flex: 0 0 360px; /* initial width */
    min-width: 260px;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-right: 2px solid #222;
    overflow-y: auto;
    overflow-x: hidden;
}

#item-selections,
#item-counters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* Item selection / counter cards */
.item-selection,
.item-counter {
    font-weight: bold;
    width: 200px;
    padding: 6px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 5px;
    cursor: pointer;
    overflow-wrap: break-word;
}

.item-counter.suppressed {
    opacity: 0.35;
    border-color: rgba(128, 128, 128, 0.5);
}

.item-counter:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Icon image size (uses CSS var) */
.item-selection img,
.item-counter img {
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    image-rendering: pixelated;
}

/* Let clicks go to container */
.item-selection span,
.item-selection img {
    pointer-events: none;
}

/* Checkbox stays clickable */
.item-selection input[type="checkbox"] {
    flex-shrink: 0;
    pointer-events: auto;
}

/* ============================
   Middle Pane (Preview grid)
   ============================ */

#middle-pane {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-right: 1px solid #444;
    overflow: hidden;
}

.mp-controls {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    justify-content: center;
}

#preview-table-container {
    flex: 1 1 auto;
    overflow: auto;
    height: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#preview-table {
    /* outline: thin dashed rgb(236, 144, 38); */
    border-collapse: collapse;
}

#preview-table td {
    padding: 1px;
    margin: 0;
    width: auto;
    height: auto;
}

/* Chunk border lines */
#preview-table td.chunk-top {
    border-top: 2px solid rgba(255, 255, 255, 0.6);
}

#preview-table td.chunk-left {
    border-left: 2px solid rgba(255, 255, 255, 0.6);
}

#preview-table td.chunk-right {
    border-right: 2px solid rgba(255, 255, 255, 0.6);
}

#preview-table td.chunk-bottom {
    border-bottom: 2px solid rgba(255, 255, 255, 0.6);
}

#preview-table img.preview-cell {
    padding: 0;
    display: block;
    max-width: fit-content;
    max-height: fit-content;
    min-width: 0;
    min-height: 0;
    width: fit-content;
    height: fit-content;
    image-rendering: pixelated;
}

/* ============================
   Right Pane
   ============================ */
#right-pane {
    flex: 0 0 600px; /* initial width */
    min-width: 450px;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-left: 2px solid #222;
    overflow: hidden;
    box-sizing: border-box;
}

/* Title row */
.rp-title {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 6px;
}

.rp-title i {
    margin-left: 12px;
    font-size: 1.5rem;
}

/* Top controls */
#rp-controls {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.rp-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.rp-row-left {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 12px;
}

.rp-row-left span {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
}

.rp-row-left #image-upload {
    flex: 1 1 auto;
}

.rp-row button#btn-process {
    background-color: #6ac4ff;
    border: none;
    padding: 4px 10px;
}

/* ============================
   Right Pane — Images Section
   ============================ */

/* bottom section of right pane */
#rp-image-inputs {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    height: 90%;
    gap: 12px;
    min-height: 0;
    overflow: hidden;
}

.image-block {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.image-block.original {
    flex: 35 1 0; /* 35% */
}

.image-block.mapped {
    flex: 65 1 0; /* 65% */
}

.image-content {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-label {
    flex: 0 0 auto;
    display: flex;
    margin-top: 6px;
    justify-content: center;
}

.viewer-image {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: auto;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

#mapped-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

.contain-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#output-canvas,
#overlay-canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

#overlay-canvas {
    pointer-events: none;
    position: absolute;
    image-rendering: auto;
}

#hover-tooltip {
    position: absolute;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 12px;
    border-radius: 4px;
    pointer-events: none;
    transform: translate(10px, 10px);
    display: none;
}

/* ============================
   Cached Image Controls
   ============================ */

.image-header-row {
    display: flex;
    justify-content: center;
    align-items: flex-end; /* bottom aligned */
    gap: 10px;
    margin-bottom: 4px;
}

.clear-cache-btn {
    background-color: #ff4c4c; /* bright red */
    border: none;
    padding: 4px 10px;
    font-weight: bold;
    color: white;
    border-radius: 4px;
    cursor: pointer;
}

.clear-cache-btn:hover {
    background-color: #ff2222;
}

/* ============================
   Progress overlay
   ============================ */

#progress-overlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ============================
   Contribution page helpers
   ============================ */

.template-table {
    border-collapse: collapse;
    margin-top: 20px;
}

.template-table th,
.template-table td {
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px;
}

.template-preview {
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
    display: block;
    margin: auto;
}

/* ============================
   Update toast helpers
   ============================ */

.update-toast {
    background: #222;
    color: #fff;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    transition: opacity 0.3s;
}
.update-toast.hidden {
    opacity: 0;
    pointer-events: none;
}
