:root {
    --g1: #6366f1;
    --g1-light: #c7d2fe;
    --g2: #14b8a6;
    --g2-light: #99f6e4;
    --g3: #f59e0b;
    --g3-light: #fde68a;
    --grand: #111827;
    --grand-soft: #6b7280;

    --c-within: #8b5cf6;
    --c-within-soft: #ddd6fe;
    --c-between: #f97316;
    --c-between-soft: #fed7aa;

    --bg: #f9fafb;
    --surface: #ffffff;
    --ink: #111827;
    --ink-soft: #4b5563;
    --border: #e5e7eb;
    --accent: #4f46e5;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 300;
    line-height: 1.45;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page-header {
    flex: 0 0 auto;
    padding: 14px 24px 6px;
    text-align: center;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.page-header h1 {
    font-weight: 700;
    font-size: clamp(1.05rem, 2.4vw, 1.5rem);
    margin: 0 0 2px;
    letter-spacing: -0.02em;
}

.subtitle {
    margin: 0;
    color: var(--ink-soft);
    font-size: clamp(0.78rem, 1.4vw, 0.9rem);
}

.layout {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(240px, 1fr);
    gap: 14px;
    max-width: 1280px;
    margin: 0 auto;
    padding: 6px 16px;
    width: 100%;
}

@media (max-width: 880px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1.6fr) minmax(0, 1fr);
        overflow-y: auto;
    }
}

.plot-area {
    background: var(--surface);
    border-radius: 14px;
    padding: 10px 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#anova-plot {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* ---- SVG layers ---- */
.layer {
    transition: opacity 0.4s ease;
}

.layer.hidden {
    opacity: 0;
    pointer-events: none;
}

.axis-line { stroke: #9ca3af; stroke-width: 1; }
.axis-tick { stroke: #d1d5db; stroke-width: 1; }
.axis-label { fill: var(--ink-soft); font-size: 11px; font-weight: 500; }
.axis-title { fill: var(--ink); font-size: 12px; font-weight: 500; }
.group-label { fill: var(--ink); font-size: 12px; font-weight: 500; text-anchor: middle; }

.point {
    stroke: #ffffff;
    stroke-width: 1.5;
    transition: r 0.3s ease, opacity 0.3s ease;
}
.point.g1 { fill: var(--g1); }
.point.g2 { fill: var(--g2); }
.point.g3 { fill: var(--g3); }

.group-mean {
    stroke-width: 3.5;
    stroke-linecap: round;
}
.group-mean.g1 { stroke: var(--g1); }
.group-mean.g2 { stroke: var(--g2); }
.group-mean.g3 { stroke: var(--g3); }

.group-mean-label {
    font-size: 10.5px;
    font-weight: 600;
    text-anchor: middle;
}
.group-mean-label.g1 { fill: var(--g1); }
.group-mean-label.g2 { fill: var(--g2); }
.group-mean-label.g3 { fill: var(--g3); }

.grand-line {
    stroke: var(--grand);
    stroke-width: 2.2;
    stroke-dasharray: 6 4;
}

.grand-line-label {
    fill: var(--grand);
    font-size: 11px;
    font-weight: 600;
}

.residual {
    stroke-width: 1.4;
    opacity: 0.7;
}
.residual.g1 { stroke: var(--g1); }
.residual.g2 { stroke: var(--g2); }
.residual.g3 { stroke: var(--g3); }

.residual-total { stroke-dasharray: 2 3; }

.between-arrow {
    stroke-width: 2.5;
    opacity: 0.85;
}
.between-arrow.g1 { stroke: var(--g1); }
.between-arrow.g2 { stroke: var(--g2); }
.between-arrow.g3 { stroke: var(--g3); }

/* Step 5: einheitliche Farbcodierung statt Gruppenfarben ---
   Within-Residuen lila, Between-Pfeile orange. Beide gleichzeitig sichtbar,
   bilden zusammen die Gesamtabweichung pro Punkt. */
#anova-plot.step-5 #within-residuals .residual {
    stroke: var(--c-within);
    stroke-width: 2.2;
    opacity: 0.9;
}
#anova-plot.step-5 #between-arrows .between-arrow {
    stroke: var(--c-between);
    stroke-width: 2.2;
    opacity: 0.9;
}
#anova-plot.step-5 .point {
    opacity: 0.95;
}

/* ---- Decomposition bar (Step 5) ---- */
.decomposition {
    flex: 0 0 auto;
    margin-top: 8px;
    padding: 8px 4px 2px;
    transition: opacity 0.4s ease, max-height 0.4s ease;
    overflow: hidden;
    max-height: 130px;
}

.decomposition.hidden {
    opacity: 0;
    max-height: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
}

.decomp-bar {
    display: flex;
    height: 32px;
    border-radius: 6px;
    overflow: hidden;
    background: #e5e7eb;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

.decomp-section {
    display: flex;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.decomp-within {
    border-right: 2px solid var(--surface);
}

.decomp-cell {
    height: 100%;
    transition: flex 0.6s ease;
    border-right: 1px solid rgba(255, 255, 255, 0.55);
}

.decomp-cell:last-child {
    border-right: none;
}

/* Within-Cells: lila-Tinte mit Gruppen-Farbakzent */
.within-cell {
    background: var(--c-within);
    opacity: 0.78;
}
.within-cell.g1 { background: linear-gradient(180deg, var(--c-within) 0%, var(--c-within) 60%, var(--g1) 60%, var(--g1) 100%); }
.within-cell.g2 { background: linear-gradient(180deg, var(--c-within) 0%, var(--c-within) 60%, var(--g2) 60%, var(--g2) 100%); }
.within-cell.g3 { background: linear-gradient(180deg, var(--c-within) 0%, var(--c-within) 60%, var(--g3) 60%, var(--g3) 100%); }

/* Between-Cells: orange-Tinte mit Gruppen-Farbakzent */
.between-cell.g1 { background: linear-gradient(180deg, var(--c-between) 0%, var(--c-between) 60%, var(--g1) 60%, var(--g1) 100%); }
.between-cell.g2 { background: linear-gradient(180deg, var(--c-between) 0%, var(--c-between) 60%, var(--g2) 60%, var(--g2) 100%); }
.between-cell.g3 { background: linear-gradient(180deg, var(--c-between) 0%, var(--c-between) 60%, var(--g3) 60%, var(--g3) 100%); }

.decomp-legend {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--ink-soft);
    gap: 8px;
}

.decomp-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-within { background: var(--c-within); }
.legend-between { background: var(--c-between); }

.decomp-numbers {
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--ink-soft);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    text-align: center;
}

/* ---- Info panel ---- */
.info-panel {
    background: var(--surface);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.info-panel h2 {
    font-weight: 700;
    font-size: clamp(0.92rem, 1.5vw, 1rem);
    margin: 0 0 6px;
    color: var(--accent);
    flex: 0 0 auto;
}

.info-panel p {
    color: var(--ink-soft);
    font-size: clamp(0.78rem, 1.2vw, 0.86rem);
    margin: 0 0 10px;
    flex: 0 0 auto;
}

.formula-box {
    background: #f3f4ff;
    border-left: 3px solid var(--accent);
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--ink);
    margin-bottom: 10px;
    font-size: clamp(0.85rem, 1.3vw, 0.95rem);
    line-height: 1.6;
    text-align: center;
    overflow-x: auto;
    flex: 0 0 auto;
    min-height: 1.6em;
}

.formula-box:empty { display: none; }

.formula-box sub, .formula-box sup {
    font-size: 0.7em;
    line-height: 0;
    position: relative;
}

.formula-box sub { vertical-align: baseline; bottom: -0.35em; }
.formula-box sup { vertical-align: baseline; top: -0.55em; }

/* Stacked sigma (Latex-Look) */
.sigma-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    line-height: 1;
    margin: 0 2px;
}

.sigma-sym {
    font-size: 1.55em;
    line-height: 0.9;
    font-weight: 500;
}

.sigma-above, .sigma-below {
    font-size: 0.55em;
    line-height: 1;
    font-weight: 400;
    color: var(--ink-soft);
    white-space: nowrap;
}

.sigma-above { margin-bottom: 1px; }
.sigma-below { margin-top: 1px; }

.sigma-above sub, .sigma-below sub {
    font-size: 0.85em;
    bottom: 0;
}

.stats-table {
    border-top: 1px solid var(--border);
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
    font-size: clamp(0.78rem, 1.1vw, 0.86rem);
    transition: background 0.3s ease;
}

.stats-row.stats-header {
    font-weight: 600;
    color: var(--ink-soft);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-row.stats-emphasis { font-weight: 600; }

.stats-row.highlight {
    background: #eef2ff;
    border-left: 3px solid var(--accent);
    padding-left: 6px;
}

/* ---- Step navigation ---- */
.step-nav {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 4px;
    flex-wrap: wrap;
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
}

.step-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.step-btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-soft);
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: clamp(0.72rem, 1.1vw, 0.82rem);
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.step-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.step-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.nav-prev, .nav-next {
    width: 36px;
    padding: 6px 0;
    font-size: 0.95rem;
}

.hint {
    flex: 0 0 auto;
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.72rem;
    padding: 0 24px 8px;
    margin: 0;
}

.key-icon {
    display: inline-block;
    padding: 0 5px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.75rem;
    margin: 0 1px;
}
