/* ===========================================================================
   GODOT LMBAKE VIEWER — the tool's own interface.

   Same rules as bitmap-font-styling.css next door: every colour is a site
   token or derived from one, so the panel follows the reader's theme instead
   of carrying a second palette that ignores it.

   The exceptions are the two canvases. A canvas cannot read a custom property,
   so the handful of colours the probe map and the histogram need are declared
   once as --lm-* here, given a light-mode value alongside, and read back out in
   JS (readPalette() in lmbake-viewer.js) whenever the theme changes.

   The probe map's own background stays dark in both themes on purpose: it is
   showing light in a room, and a probe reading near black has to look near
   black rather than being washed out by a pale panel behind it.
   =========================================================================== */

.lm-app {
    --lm-surface: var(--color-primary-a10);
    --lm-surface-raised: var(--color-primary-a20);
    --lm-border: var(--color-card-border);
    --lm-border-strong: var(--color-primary-a20);

    --lm-map-bg: #141414;
    --lm-map-grid: rgba(255, 255, 255, 0.06);
    --lm-map-caption: #6b6b6b;
    --lm-map-marker: #70BAFA;
    --lm-hist-current: #4f9dd9;
    --lm-hist-original: #8a8a8a;
    --lm-hist-axis: #444444;
    --lm-hist-text: #777777;

    --lm-mono: "JetBrains Mono", "Fira Mono", "Consolas", ui-monospace, monospace;
    --lm-sans: "Circular Spotify", "Inter", sans-serif;

    /* A base font for the whole tool: the site sets fonts per element rather
       than on body, so anything in here that does not name one would otherwise
       come out in the browser's default serif. */
    font-family: var(--lm-sans);
    color: var(--color-text-1);

    display: flex;
    flex-direction: column;
    background: var(--lm-surface);
    border: 1px solid var(--lm-border);
    border-radius: 16px;
    overflow: hidden;
}

:root[data-theme="light"] .lm-app {
    --lm-hist-original: #6c6c6c;
    --lm-hist-axis: #b4b4b4;
    --lm-hist-text: #6b6b6b;
}

.lm-app :is(button, input, select, a):focus-visible {
    outline: 2px solid var(--color-selected-3);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   Toolbar — loading files
   --------------------------------------------------------------------------- */

.lm-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: var(--lm-surface-raised);
    border-bottom: 1px solid var(--lm-border);
}

.lm-toolbar-spacer {
    margin-left: auto;
}

.lm-file-name {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    min-width: 0;
    font-family: var(--lm-mono);
    font-size: 12px;
    color: var(--color-text-2);
}

/* A file name is the one thing here that can be arbitrarily long, so it
   truncates rather than pushing the rest of the toolbar off the edge — but
   only while there is a row to share. Below 700px it takes a line of its own,
   with the probe count and size wrapping underneath instead of squeezing in
   beside a name that has been cut down to nothing. */
.lm-file-name b {
    color: var(--color-text-1);
    font-weight: 600;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .lm-file-name {
        width: 100%;
    }
}

/* Nothing to forget until an original has actually been loaded. */
.lm-app:not(.has-baseline) #lm-base-clear {
    display: none;
}

.lm-sep {
    width: 1px;
    align-self: stretch;
    min-height: 22px;
    background: var(--lm-border-strong);
    margin: 0 2px;
}

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */

.lm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--lm-border-strong);
    background: transparent;
    color: var(--color-text-2);
    font-family: var(--lm-sans);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color var(--dur-hover) var(--ease-soft),
        border-color var(--dur-hover) var(--ease-soft),
        color var(--dur-hover) var(--ease-soft),
        transform var(--dur-hover) var(--ease-pop);
}

@media (hover: hover) {
    .lm-btn:hover:not(:disabled) {
        background: var(--color-primary-a20);
        border-color: var(--color-primary-a30);
        color: var(--color-text-1);
    }
}

.lm-btn:active:not(:disabled) {
    transform: scale(0.97);
    transition-duration: var(--dur-press);
}

.lm-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.lm-btn--primary {
    background: var(--color-selected-2);
    border-color: var(--color-selected-2);
    color: #ffffff;
    padding: 8px 18px;
    font-size: 13px;
}

@media (hover: hover) {
    .lm-btn--primary:hover:not(:disabled) {
        background: var(--color-selected-3);
        border-color: var(--color-selected-3);
        color: #06121e;
    }
}

.lm-btn--accent {
    color: var(--color-accent-text);
    border-color: var(--color-selected-1);
}

@media (hover: hover) {
    .lm-btn--accent:hover:not(:disabled) {
        background: rgba(91, 148, 198, 0.14);
        border-color: var(--color-selected-2);
        color: var(--color-accent-text);
    }
}

/* Small square button, used for the per-slider reset. */
.lm-btn--icon {
    min-width: 30px;
    min-height: 30px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
}

/* ---------------------------------------------------------------------------
   Drop zone

   Shown until a bake is loaded, and it is also the drop target for the whole
   tool — dropping a file anywhere on .lm-app works, this is just where the
   invitation lives.
   --------------------------------------------------------------------------- */

.lm-drop {
    margin: 12px;
    padding: 28px 20px;
    border: 2px dashed var(--lm-border-strong);
    border-radius: 12px;
    text-align: center;
    color: var(--color-text-2);
    font-size: 13px;
    line-height: 1.6;
    transition:
        border-color var(--dur-hover) var(--ease-soft),
        background-color var(--dur-hover) var(--ease-soft);
}

.lm-app.is-dragging .lm-drop,
.lm-drop.is-dragging {
    border-color: var(--color-selected-2);
    background: rgba(91, 148, 198, 0.1);
}

.lm-drop strong {
    display: block;
    color: var(--color-text-1);
    font-size: 15px;
    margin-bottom: 6px;
}

.lm-drop-hint {
    display: block;
    margin-top: 10px;
    font-size: 12px;
    color: var(--color-primary-a30);
}

/* ---------------------------------------------------------------------------
   Layout

   Controls on the left, preview on the right, the same arrangement as the
   desktop tool this is a port of. One column below 980px, where the map would
   otherwise be squeezed down to nothing.
   --------------------------------------------------------------------------- */

.lm-body {
    display: grid;
    grid-template-columns: minmax(300px, 400px) 1fr;
    gap: 12px;
    padding: 12px;
    align-items: start;
}

@media (max-width: 980px) {
    .lm-body {
        grid-template-columns: 1fr;
    }
}

.lm-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.lm-panel {
    background: var(--color-primary-a0);
    border: 1px solid var(--lm-border);
    border-radius: 12px;
    padding: 14px;
}

.lm-panel-title {
    display: block;
    margin: 0 0 12px;
    font-family: var(--lm-sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-primary-a30);
}

.lm-panel-hint {
    margin: 10px 0 0;
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--color-primary-a30);
}

/* ---------------------------------------------------------------------------
   The bake summary

   A definition list rather than the desktop tool's block of text, so the
   labels and values line up and a long texture path can wrap on its own.
   --------------------------------------------------------------------------- */

.lm-info {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
}

.lm-info dt {
    color: var(--color-primary-a30);
    white-space: nowrap;
}

.lm-info dd {
    margin: 0;
    color: var(--color-text-2);
    font-family: var(--lm-mono);
    font-size: 11.5px;
    overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------------
   Sliders

   Four columns: name, track, typed value, reset. The number box is not just a
   readout — it accepts values past the end of the track, because a bake that
   needs a master of 6 exists and the track stops at 4.
   --------------------------------------------------------------------------- */

.lm-slider {
    display: grid;
    grid-template-columns: 106px 1fr 66px 30px;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.lm-slider:last-child {
    margin-bottom: 0;
}

.lm-slider label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-2);
    line-height: 1.25;
}

@media (max-width: 420px) {
    .lm-slider {
        grid-template-columns: 1fr 62px 30px;
    }

    .lm-slider label {
        grid-column: 1 / -1;
    }
}

.lm-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--lm-border-strong);
    cursor: pointer;
}

.lm-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-selected-2);
    border: 2px solid var(--lm-surface);
    cursor: pointer;
}

.lm-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-selected-2);
    border: 2px solid var(--lm-surface);
    cursor: pointer;
}

/* Bigger grab target on touch. A 16px thumb is sized for a mouse cursor,
   not a fingertip, and a slider is the one control on this page where a
   slightly-off tap can't just be retried like a mis-tapped button can, it
   drags to the wrong value instead. */
@media (pointer: coarse) {
    .lm-range {
        height: 8px;
    }

    .lm-range::-webkit-slider-thumb {
        width: 26px;
        height: 26px;
    }

    .lm-range::-moz-range-thumb {
        width: 26px;
        height: 26px;
    }
}

.lm-range:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.lm-num {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 6px;
    border-radius: 6px;
    border: 1px solid var(--lm-border-strong);
    background: var(--color-primary-a0);
    color: var(--color-text-1);
    font-family: var(--lm-mono);
    font-size: 11.5px;
    text-align: right;
    transition: border-color var(--dur-hover) var(--ease-soft);
}

.lm-num:focus {
    outline: none;
    border-color: var(--color-selected-2);
}

.lm-num:disabled {
    opacity: 0.35;
}

.lm-divider {
    height: 1px;
    background: var(--lm-border-strong);
    margin: 12px 0;
}

.lm-sub-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-primary-a30);
    margin-bottom: 8px;
}

/* ---------------------------------------------------------------------------
   Canvases
   --------------------------------------------------------------------------- */

.lm-canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
    background: var(--lm-map-bg);
    touch-action: pan-y;
    max-width: 1000px;
}

.lm-map-readout {
    display: block;
    margin-top: 8px;
    min-height: 16px;
    font-family: var(--lm-mono);
    font-size: 11px;
    color: var(--color-text-2);
}

.lm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--color-primary-a30);
}

.lm-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.lm-swatch {
    width: 11px;
    height: 11px;
    border-radius: 2px;
    background: var(--lm-hist-current);
}

.lm-swatch--original {
    background: transparent;
    border: 1.5px solid var(--lm-hist-original);
}

/* The statistics table. Monospace and tabular figures so the numbers sit in
   columns and a change of grade moves the digits, not the layout. */
.lm-stats {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--lm-mono);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

.lm-stats th {
    text-align: right;
    font-weight: 600;
    color: var(--color-primary-a30);
    padding: 3px 6px;
    font-family: var(--lm-sans);
    font-size: 11px;
}

.lm-stats th:first-child {
    text-align: left;
}

.lm-stats td {
    text-align: right;
    padding: 3px 6px;
    color: var(--color-text-2);
}

.lm-stats td:first-child {
    text-align: left;
    font-family: var(--lm-sans);
    font-weight: 600;
    color: var(--color-text-1);
}

.lm-stats tr.is-change td {
    border-top: 1px solid var(--lm-border-strong);
    color: var(--color-accent-text);
    font-weight: 700;
}

/* ---------------------------------------------------------------------------
   Notes, status and warnings
   --------------------------------------------------------------------------- */

.lm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.lm-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 24px;
    font-size: 11.5px;
    font-weight: 600;
}

.lm-status:empty {
    display: none;
}

.lm-status[data-tone="ok"] {
    background: rgba(74, 222, 128, 0.14);
    color: #38b869;
}

:root:not([data-theme="light"]) .lm-status[data-tone="ok"] {
    color: #4ade80;
}

.lm-status[data-tone="error"] {
    background: rgba(231, 140, 140, 0.16);
    color: var(--color-warning-2);
}

:root:not([data-theme="light"]) .lm-status[data-tone="error"] {
    color: var(--color-warning-1);
}

.lm-status[data-tone="info"] {
    background: rgba(91, 148, 198, 0.16);
    color: var(--color-accent-text);
}

/* An inline caution inside a panel: the baked-exposure warning, and the one
   about a bake that has already been graded. */
.lm-caution {
    margin: 10px 0 0;
    padding: 9px 11px;
    border-radius: 8px;
    border-left: 3px solid var(--color-warning-2);
    background: rgba(231, 140, 140, 0.1);
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--color-text-2);
}

.lm-caution strong {
    color: var(--color-text-1);
}

.lm-caution:empty {
    display: none;
}

.lm-statusbar {
    padding: 9px 12px;
    border-top: 1px solid var(--lm-border);
    background: var(--lm-surface-raised);
    font-size: 12px;
    color: var(--color-text-2);
}

/* Anything that only makes sense once a bake is loaded. */
.lm-app:not(.is-loaded) [data-needs-bake] {
    display: none;
}

.lm-app.is-loaded .lm-drop {
    display: none;
}
