:root {
    color-scheme: light;
    --background: #f7f7f5;
    --surface: #ffffff;
    --surface-muted: #f1f3f4;
    --border: #d9dde2;
    --text: #1f2933;
    --text-muted: #64707d;
    --accent: #285b8f;
    --accent-dark: #1f466e;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

.container {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.intro {
    padding: 32px 0 20px;
}

.intro h1 {
    margin: 0 0 8px;
    font-size: 2rem;
}

.intro p {
    max-width: 760px;
    margin: 0;
    color: var(--text-muted);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
    gap: 24px;
    padding-bottom: 40px;
}

.input-panel,
.results-panel,
.submitted-code {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}

.input-panel,
.results-panel {
    padding: 24px;
}

h2,
h3 {
    margin-top: 0;
}

h2 {
    margin-bottom: 16px;
    font-size: 1.25rem;
}

h3 {
    margin-bottom: 8px;
    font-size: 1rem;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

textarea {
    width: 100%;
    min-height: 420px;
    padding: 12px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fcfcfc;
    color: var(--text);
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.95rem;
    line-height: 1.45;
}

textarea:focus {
    outline: 3px solid rgba(40, 91, 143, 0.18);
    border-color: var(--accent);
}

button {
    margin-top: 14px;
    padding: 10px 18px;
    border: 0;
    border-radius: 4px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

button:hover {
    background: var(--accent-dark);
}

.secondary-button {
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.secondary-button:hover {
    background: var(--surface-muted);
}

.status-message {
    margin: 0 0 16px;
    padding: 10px 12px;
    border-left: 4px solid var(--accent);
    background: var(--surface-muted);
}

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

.submitted-code {
    margin-bottom: 18px;
    padding: 16px;
}

.submitted-code pre {
    max-height: 260px;
    margin: 0;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 0;
}

.metric-box {
    padding: 14px;
    border-left: 4px solid var(--accent);
    background: var(--surface-muted);
}

.metric-box p {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
}

.collapsible-section {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}

.collapsible-section:first-of-type {
    margin-top: 0;
}

.collapsible-section summary {
    padding: 13px 16px;
    background: var(--surface-muted);
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
}

.collapsible-section summary:hover {
    background: #e8ecef;
}

.collapsible-section[open] summary {
    border-bottom: 1px solid var(--border);
}

.collapsible-content {
    position: relative;
    padding: 16px;
}

.warning-block {
    margin-top: 18px;
}

.table-wrapper {
    overflow-x: auto;
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th,
td {
    padding: 9px 10px;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--surface-muted);
    font-weight: 700;
}

td code {
    white-space: pre-wrap;
    word-break: break-word;
}

.matrix-table th,
.matrix-table td {
    text-align: center;
}

.warning-list {
    margin: 0;
    padding-left: 20px;
}

.graph-container {
    min-height: 500px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fbfbfa;
}

.graph-actions {
    display: flex;
    justify-content: flex-end;
}

.graph-fallback {
    margin: 0;
    padding: 16px;
    color: var(--text-muted);
}

.graph-legend {
    margin: 12px 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.graph-node-popover {
    position: absolute;
    z-index: 20;
    width: min(340px, calc(100% - 32px));
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 10px 24px rgba(31, 41, 51, 0.16);
}

.graph-node-popover h3 {
    margin: 0 28px 10px 0;
}

.graph-node-popover dl {
    display: grid;
    gap: 6px;
    margin: 0 0 10px;
}

.graph-node-popover dl div {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 8px;
}

.graph-node-popover dt {
    color: var(--text-muted);
    font-weight: 700;
}

.graph-node-popover dd {
    margin: 0;
}

.graph-node-popover pre {
    max-height: 220px;
    margin: 0;
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #f8fafc;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
}

.graph-popover-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #ffffff;
    color: var(--text);
    line-height: 1;
}

.graph-popover-close:hover {
    background: var(--surface-muted);
}

@media (max-width: 860px) {
    .workspace,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    textarea {
        min-height: 320px;
    }
}
