*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #f8f8fb;
    --surface:    #efeff4;
    --border:     #dcdce8;
    --text:       #1a1a2e;
    --muted:      #7a7a8e;
    --vtl:        #4444cc;
    --cone:       #1a9944;
    --opponent:   #9a7000;
    --deficiency: #cc3322;
    --combined:   #7733bb;
    --accent:     #0077aa;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Header ─────────────────────────────────────── */

header {
    padding: 1.8rem 2.5rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.header-top {
    display: flex;
    align-items: center;
    gap: 1.4rem;
}

.logo-link {
    display: block;
    flex-shrink: 0;
    opacity: 0.85;
    transition: opacity 0.15s;
}

.logo-link:hover { opacity: 1; }

.site-logo {
    height: 36px;
    width: auto;
    display: block;
}

.header-identity {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.wordmark {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.wordmark .glyph { color: var(--accent); margin-right: 0.45rem; }

.tagline {
    color: var(--muted);
    font-size: 0.78rem;
    font-style: italic;
}

.legend {
    display: flex;
    align-items: center;
    gap: 1.4rem;
    margin-top: 0.6rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--muted);
    font-size: 0.72rem;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 2px;
    flex-shrink: 0;
}

.legend-sep {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.72rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* ── Main ───────────────────────────────────────── */

main { padding: 2rem 2.5rem; }

.page-intro {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 1.6rem;
    max-width: 640px;
}

/* ── Upload zone ────────────────────────────────── */

#upload-zone {
    display: block;
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.18s, color 0.18s;
    color: var(--muted);
    margin-bottom: 2.5rem;
    user-select: none;
}

#upload-zone:hover,
#upload-zone.drag-over {
    border-color: var(--accent);
    color: var(--text);
}

#upload-zone .hint {
    font-size: 0.72rem;
    margin-top: 0.4rem;
    color: var(--muted);
}

#file-input { display: none; }

/* ── Workspace ──────────────────────────────────── */

#workspace { display: none; }

.ws-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2rem;
    margin-bottom: 2.5rem;
    align-items: start;
}

.orig-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.orig-wrap img {
    max-width: 180px;
    max-height: 180px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 4px;
    display: block;
}

.section-label {
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.scatter-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

#scatter-canvas {
    border: 1px solid var(--border);
    border-radius: 4px;
    display: block;
    width: 100%;
}

/* ── Grid ───────────────────────────────────────── */

hr.div {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0 0 2rem;
}

.grid-section-break {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    padding-top: 1.6rem;
    margin-top: 0.4rem;
    font-size: 0.68rem;
    color: var(--combined);
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.6rem;
}

.panel { display: flex; flex-direction: column; gap: 0.45rem; }

.panel-name {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.panel-name.vtl        { color: var(--vtl); }
.panel-name.cone       { color: var(--cone); }
.panel-name.opponent   { color: var(--opponent); }
.panel-name.deficiency { color: var(--deficiency); }
.panel-name.combined   { color: var(--combined); }

.panel-desc {
    font-size: 0.71rem;
    color: var(--muted);
    line-height: 1.45;
    margin: 0.25rem 0 0.5rem;
    opacity: 0.8;
}

.panel canvas {
    width: 100%;
    display: block;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.panel-metrics {
    font-size: 0.67rem;
    color: var(--muted);
    display: flex;
    gap: 0.9rem;
    flex-wrap: wrap;
}

.mk { color: var(--muted); }

/* ── Integrity score panel ──────────────────────── */

.score-panel {
    margin: 0 0 2.5rem;
    padding: 1.4rem 1.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.score-heading {
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 1.1rem;
}

.score-framing {
    font-size: 0.72rem;
    color: var(--muted);
    font-style: italic;
    line-height: 1.5;
    margin-bottom: 1.2rem;
    opacity: 0.75;
}

.score-row {
    display: grid;
    grid-template-columns: 1.4rem 9rem 3.8rem 11rem 1fr;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}

.score-row:last-child { border-bottom: none; }

.score-sym {
    font-size: 1rem;
    color: var(--accent);
    line-height: 1;
}

.score-name {
    color: var(--text);
    font-size: 0.72rem;
    letter-spacing: 0.04em;
}

.score-val {
    font-size: 0.82rem;
    color: var(--text);
    text-align: right;
}

.score-tag {
    font-size: 0.67rem;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    text-align: center;
}

.score-desc {
    font-size: 0.63rem;
    color: var(--muted);
    line-height: 1.4;
}

/* ── Kernel chart ───────────────────────────────── */

.kernel-wrap {
    margin: 0 0 2.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    display: grid;
    grid-template-columns: 62% 38%;
}

.kernel-chart {
    border-right: 1px solid var(--border);
}

.kernel-chart canvas {
    display: block;
    width: 100%;
}

.kernel-defs {
    padding: 1.2rem 1.4rem 1.2rem 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.kdef-list {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.kdef-row {
    display: grid;
    grid-template-columns: 2.2rem 1fr;
    gap: 0 0.7rem;
    align-items: baseline;
    border-top: 1px solid var(--border);
    padding: 0.28rem 0;
}

.kdef-term {
    font-size: 0.78rem;
    color: var(--accent);
    text-align: right;
    white-space: nowrap;
}

.kdef-body {
    font-size: 0.62rem;
    color: var(--muted);
    line-height: 1.45;
}

.kdef-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.60rem;
    color: var(--muted);
    flex-wrap: wrap;
    margin-top: auto;
}

.kdef-swatch {
    display: inline-block;
    width: 18px;
    height: 7px;
    border-radius: 2px;
}

.kdef-base { background: #b0b0c0; }
.kdef-conf { background: #7733bb; }

@media (max-width: 760px) {
    .kernel-wrap { grid-template-columns: 1fr; }
    .kernel-chart { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ── Processing overlay ─────────────────────────── */

#processing {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(248, 248, 251, 0.88);
    align-items: center;
    justify-content: center;
    z-index: 200;
    font-size: 0.8rem;
    color: var(--muted);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 920px) {
    .grid { grid-template-columns: repeat(2, 1fr); }
    .ws-header { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .grid { grid-template-columns: 1fr; }
    main { padding: 1.5rem; }
    header { padding: 1.4rem 1.5rem; }
}
