:root {
    --ink: #10243c;
    --muted: #52657a;
    --paper: #f6f8fb;
    --panel: #ffffff;
    --accent: #0f8b8d;
    --accent-2: #f45d48;
    --line: #d9e0e8;
    --shadow: 0 12px 40px rgba(16, 36, 60, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 10%, rgba(15, 139, 141, 0.12), transparent 40%),
        radial-gradient(circle at 90% 20%, rgba(244, 93, 72, 0.1), transparent 35%),
        linear-gradient(180deg, #f9fbfd 0%, #edf2f7 100%);
}

.shell {
    width: min(1120px, 94vw);
    margin: 2rem auto 3rem;
    display: grid;
    gap: 1rem;
}

.hero {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1.25rem 1.4rem;
    box-shadow: var(--shadow);
    animation: rise 450ms ease both;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-size: 0.75rem;
}

h1 {
    margin: 0.35rem 0;
    font-size: clamp(1.4rem, 2.8vw, 2.2rem);
}

.sub {
    margin: 0;
    color: var(--muted);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow);
    animation: rise 520ms ease both;
}

.upload-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
}

label {
    font-weight: 600;
}

input[type="file"],
input[type="number"] {
    border: 1px solid #c7d1dd;
    border-radius: 10px;
    padding: 0.45rem 0.6rem;
    background: #fff;
    font-family: inherit;
}

button {
    border: none;
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    transition: transform 180ms ease, filter 180ms ease;
}

button:hover {
    transform: translateY(-1px);
    filter: brightness(0.95);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
    filter: none;
}

button.info-btn {
    background: var(--accent-2);
    font-size: 0.76rem;
    padding: 0.3rem 0.55rem;
}

.status {
    margin: 0.75rem 0 0;
    color: var(--muted);
}

.preview-frame {
    margin-top: 0.75rem;
    border: 1px dashed #b9c6d6;
    border-radius: 14px;
    min-height: 220px;
    max-height: 72vh;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #f8fbff;
}

#image-preview,
#match-overlay {
    grid-area: 1 / 1;
}

#image-preview {
    width: min(100%, 800px);
    height: auto;
    max-height: 72vh;
    object-fit: contain;
}

#match-overlay {
    width: min(100%, 800px);
    height: auto;
    max-height: 72vh;
    object-fit: contain;
    pointer-events: none;
}

.pixel-tools {
    margin-top: 0.95rem;
}

.palette-section {
    margin-top: 0.95rem;
    border: 1px solid #d7deea;
    border-radius: 12px;
    padding: 0.75rem;
    background: #fcfdff;
}

.palette-header-row {
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.palette-header-row h3 {
    margin: 0;
}

.palette-actions {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.palette-controls-row {
    margin-top: 0.55rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.palette-compact-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
}

.palette-paging {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

#palette-page-info {
    min-width: 110px;
    text-align: center;
}

.palette-grid {
    margin-top: 0.65rem;
    max-height: 340px;
    overflow: auto;
    display: grid;
    gap: 0.35rem;
}

.palette-row {
    display: grid;
    grid-template-columns: 56px 60px repeat(3, minmax(80px, 1fr));
    gap: 0.45rem;
    align-items: center;
}

.palette-swatch {
    width: 52px;
    height: 24px;
    border: 1px solid #000;
    border-radius: 4px;
}

.palette-row input[type="number"] {
    width: 100%;
    padding: 0.32rem 0.4rem;
}

.coords {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

.mono {
    font-family: "IBM Plex Mono", Consolas, monospace;
    font-size: 0.92rem;
}

#image-size a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 0.16em;
    font-weight: 600;
}

#pixel-result {
    margin: 0.5rem 0 0;
    display: inline-block;
    padding: 0.35rem 0.55rem;
    border: 2px solid #b9c6d6;
    border-radius: 8px;
    background: #ffffff;
}

.hint {
    margin: 0.45rem 0 0;
    color: var(--muted);
}

.chunk-list {
    display: grid;
    gap: 0.55rem;
}

details {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.45rem 0.55rem;
    background: #fbfdff;
}

summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    gap: 0.6rem;
    align-items: center;
    justify-content: space-between;
}

summary::-webkit-details-marker {
    display: none;
}

.chunk-main {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: baseline;
}

.badge {
    padding: 0.12rem 0.38rem;
    border-radius: 999px;
    background: #e8f6f6;
    color: #0b6f71;
    font-weight: 700;
}

.meta-list {
    display: grid;
    gap: 0.35rem;
}

.meta-item {
    border-bottom: 1px dashed var(--line);
    padding-bottom: 0.25rem;
}

.hidden {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 32, 0.42);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-dialog {
    width: min(980px, 96vw);
    max-height: 88vh;
    overflow: auto;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 0.85rem 1rem 1rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.modal-header h3 {
    margin: 0;
}

.modal-close {
    background: #334155;
}

.color-chart {
    margin-top: 0.8rem;
    display: grid;
    gap: 0.4rem;
}

.color-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 0.65rem;
    align-items: center;
}

.color-bar-track {
    width: 100%;
    height: 18px;
    border: 1px solid #c6d3e1;
    border-radius: 999px;
    background: #edf2f7;
    overflow: hidden;
}

.color-bar {
    height: 100%;
    border-radius: 999px;
}

.color-code {
    min-width: 270px;
    text-align: right;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 760px) {
    .shell {
        width: min(1120px, 96vw);
        margin-top: 1rem;
    }

    .panel,
    .hero {
        border-radius: 14px;
    }

    .preview-frame {
        min-height: 180px;
    }

    .color-row {
        grid-template-columns: 1fr;
    }

    .color-code {
        min-width: 0;
        text-align: left;
    }
}
