:root {
    color-scheme: dark;
    font-family: Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--page);
    --page: #101820;
    --surface: #18242e;
    --surface-subtle: #1e2e3a;
    --panel: #131f28;
    --border: #607889;
    --accent: #72bdff;
    --accent-fill: #0968b5;
    --focus: #d1a7ff;
    --muted: #b7c7d2;
    --text: #eef5f8;
    --header: #0a293e;
    --status-background: #19384c;
    --status-text: #e4f3fc;
    --error-background: #4a2024;
    --error-text: #ffd9dc;
    --control-background: #22333f;
    --control-text: #f3f8fa;
    --graph-background: #142b3a;
    --card-border: #607889;
    --completed: #83dfa0;
}

:root[data-theme="light"] {
    color-scheme: light;
    --page: #eef5fa;
    --surface: #fff;
    --surface-subtle: #eef5fa;
    --panel: #f7fafc;
    --border: #a7b8c5;
    --accent: #075ca8;
    --accent-fill: #075ca8;
    --focus: #8a3ffc;
    --muted: #526270;
    --text: #17212b;
    --header: #173a54;
    --status-background: #d8e9f5;
    --status-text: #20313e;
    --error-background: #fde7e7;
    --error-text: #791a1a;
    --control-background: #fff;
    --control-text: #17212b;
    --graph-background: #d3e7f5;
    --card-border: #c1ced8;
    --completed: #176329;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; color: var(--text); background: var(--page); }
a { color: var(--accent); }
button, input, select { font: inherit; }
button { padding: .55rem .75rem; color: var(--control-text); background: var(--control-background); border: 1px solid var(--border); border-radius: .3rem; cursor: pointer; }
button:hover { border-color: var(--accent); }
button, [role="button"], input, select { min-height: 44px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 9999; padding: .75rem 1rem; color: #fff; background: #111; }
.skip-link:focus { top: 1rem; }

.app-header { display: flex; justify-content: space-between; gap: 2rem; align-items: center; padding: 1rem 1.25rem; color: #fff; background: var(--header); }
.app-header h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
.app-header p { margin: .25rem 0 0; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 1rem; }
.header-help { max-width: 38rem; line-height: 1.4; }
.theme-toggle { display: inline-grid; flex: 0 0 auto; place-items: center; width: 44px; padding: .55rem; color: #fff; background: rgb(255 255 255 / 10%); border-color: rgb(255 255 255 / 55%); }
.theme-toggle:hover { background: rgb(255 255 255 / 18%); border-color: #fff; }
.theme-icon { display: none; width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="light"] .theme-icon-moon { display: block; }
.status { padding: .55rem 1.25rem; color: var(--status-text); background: var(--status-background); border-bottom: 1px solid var(--border); }
.status.error { color: var(--error-text); background: var(--error-background); }

.app-shell { display: grid; grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr); min-height: calc(100vh - 8rem); align-items: start; }
.controls-panel { grid-column: 1; grid-row: 1; min-height: 100%; padding: 1rem; background: var(--panel); border-right: 1px solid var(--border); }
#main-content { grid-column: 2; grid-row: 1; min-width: 0; padding: 1rem; }
#main-content h2 { margin-top: 0; }

#searchBox { padding: 1rem; color: var(--text); background: var(--surface); }
.MuiPaper-root, .MuiAutocomplete-paper { color: var(--text) !important; background-color: var(--surface) !important; }
.MuiInputBase-root, .MuiInputLabel-root, .MuiFormControlLabel-label { color: var(--text) !important; }
.MuiOutlinedInput-notchedOutline { border-color: var(--border) !important; }
.MuiInputLabel-root.Mui-focused { color: var(--accent) !important; }
.MuiAutocomplete-option[aria-selected="true"], .MuiAutocomplete-option.Mui-focused { background-color: var(--surface-subtle) !important; }
.MuiButton-outlined { color: var(--accent) !important; border-color: var(--border) !important; }
.MuiButton-outlinedError { color: var(--error-text) !important; }
.MuiSwitch-switchBase:not(.Mui-checked) { color: var(--muted) !important; }
.MuiSwitch-track { background-color: var(--muted) !important; }
.control-group { margin-top: 1.1rem; }
.control-group legend, .control-label { display: block; margin-bottom: .45rem; font-weight: 600; }
.view-switcher { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.view-switcher button[aria-pressed="true"] { color: #fff; background: var(--accent-fill); }
.native-select { width: 100%; padding: .5rem; color: var(--control-text); border: 1px solid var(--border); border-radius: 4px; background: var(--control-background); }
.secondary-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.help-text { color: var(--muted); font-size: .9rem; line-height: 1.4; }
.faction-help { margin: .35rem 0 0; }

.explorer-summary { margin: 0 0 1rem; color: var(--muted); }
.explorer-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(19rem, 100%), 1fr)); gap: .75rem; padding: 0; margin: 0; list-style: none; }
.explorer-card { height: 100%; padding: .85rem; text-align: left; color: inherit; background: var(--surface); border: 2px solid var(--card-border); border-left: .55rem solid var(--category-color, #7890a0); border-radius: .45rem; cursor: pointer; }
.explorer-card:hover { border-color: var(--accent); }
.explorer-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.explorer-card strong, .explorer-card span { display: block; }
.explorer-card .meta { margin-top: .35rem; color: var(--muted); font-size: .9rem; }
.explorer-card.completed strong { text-decoration: line-through; }
.completed-label { font-weight: 600; color: var(--completed) !important; }
.campaign-start-label { font-weight: 600; color: var(--completed) !important; }
.explorer-card.campaign-start-completed strong { text-decoration-style: double; }
.campaign-start-note { padding: .7rem .85rem; border-left: .3rem solid var(--completed); background: color-mix(in srgb, var(--completed) 12%, transparent); }
.load-more { display: block; margin: 1.25rem auto; }

#graph-view { min-height: 42rem; }
.graph-heading-row { display: flex; justify-content: space-between; gap: 1rem; }
.graph-heading-row p { max-width: 55rem; }
.graph-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-content: flex-start; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin: .5rem 0; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend-swatch { width: 1rem; height: 1rem; border: 3px solid #075ca8; border-radius: 50%; }
.legend-swatch.project { border-color: #237a3b; }
.legend-swatch.completed { display: inline-grid; place-items: center; color: var(--completed); border-width: 4px; border-color: var(--completed); font-size: .75rem; font-style: normal; font-weight: 800; line-height: 1; box-shadow: 0 0 .4rem var(--completed); }
.legend-line { width: 1.5rem; border-top: 2px solid #526270; }
#mynetwork { width: 100%; height: calc(100vh - 16rem); min-height: 34rem; border: 1px solid var(--border); background: var(--graph-background); }

.details-panel { grid-column: 2; grid-row: 1; position: sticky; z-index: 20; top: .75rem; justify-self: end; align-self: start; width: min(26rem, 45vw); max-height: var(--details-max-height, calc(100vh - 9rem)); overflow: auto; margin: .75rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: .5rem; box-shadow: 0 8px 30px rgb(0 0 0 / 25%); }
.details-panel[hidden] { display: none; }
#sidebar-react { min-width: 0; word-break: break-word; }
.details-sticky { position: sticky; z-index: 2; top: -1rem; margin: -1rem -1rem 1rem; padding: 1rem 1rem .75rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.details-header { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.details-header h2 { margin: 0; }
.details-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.prereqButton { margin: 0 .5rem .5rem 0 !important; text-transform: none !important; }
.researchDone { text-decoration: line-through !important; }
.hideButton { display: none !important; }
.hideBullets { list-style: none; padding: 0; margin: 0; }
pre { max-width: 100%; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.module-icon { width: 100px; height: 100px; object-fit: contain; }
.module-summary { margin: .75rem 0 1rem; padding: .75rem; background: var(--surface-subtle); border: 1px solid var(--border); border-radius: .4rem; }
.module-summary h4 { margin: 0 0 .6rem; }
.module-stats { display: grid; grid-template-columns: minmax(9rem, 1fr) minmax(10rem, 2fr); gap: .35rem 1rem; margin: 0; }
.module-stats dt { font-weight: 600; }
.module-stats dd { margin: 0; }
.stat-note { display: block; color: var(--muted); font-size: .85rem; }
.raw-data { margin: .75rem 0 1.25rem; }
.raw-data summary { min-height: 44px; padding: .65rem 0; font-weight: 600; cursor: pointer; }
.long-form-details { margin: .75rem 0 1.25rem; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.long-form-details summary { min-height: 44px; padding: .75rem 0; font-weight: 600; cursor: pointer; }
.long-form-details p { margin-top: 0; }

@media (min-width: 1280px) {
    .app-shell.details-open { grid-template-columns: minmax(17rem, 20rem) minmax(0, 1fr) minmax(26rem, 30rem); }
    .app-shell.details-open .details-panel { grid-column: 3; width: auto; justify-self: stretch; margin-left: 0; }
}

@media (max-width: 760px) {
    .app-header { display: block; }
    .header-actions { align-items: flex-start; justify-content: space-between; margin-top: .75rem; }
    .header-help { margin-top: 0 !important; }
    .app-shell { display: block; }
    .controls-panel { border-right: 0; border-bottom: 1px solid var(--border); }
    #main-content { padding: .75rem; }
    .graph-heading-row { display: block; }
    #mynetwork { height: 65vh; min-height: 28rem; }
    .details-panel { position: fixed; inset: 0; width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0; }
    .module-stats { grid-template-columns: 1fr; }
    .module-stats dd { margin-bottom: .45rem; }
}

@media (max-width: 480px) {
    .header-actions { display: block; }
    .theme-toggle { margin-top: .75rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
    .explorer-card, .legend-swatch { border-color: ButtonText; }
}
