:root {
    --ink: #10223a;
    --muted: #5b6b80;
    --line: #d8e0ea;
    --paper: #f4f6f9;
    --card: #ffffff;
    --accent: #0e7c86;
    --accent-dark: #0a5f67;
    --ok: #13795b;
    --ok-bg: #e5f5ee;
    --fail: #b42318;
    --fail-bg: #fdecea;
    --mono: "Cascadia Code", Consolas, "SFMono-Regular", monospace;
    --page: 1320px;
    --gutter: 24px;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--paper);
}

* { box-sizing: border-box; }

body { margin: 0; }

.top {
    background: linear-gradient(120deg, #0b1b2e, #12385a 60%, #0e5d68);
    color: #fff;
    padding: 28px 0;
}
.top > div { max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); }

.top h1 { margin: 0 0 6px; font-size: 1.7rem; letter-spacing: .01em; }
.top h1 span { color: #6fe0d6; }
.top p { margin: 0; color: #c7d6e6; }

main { max-width: var(--page); margin: 24px auto 48px; padding: 0 var(--gutter); }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 6px 24px rgba(16, 34, 58, .06);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 22px;
}

.source, .actions, .alert, .result { grid-column: 1 / -1; }
.source { grid-column: 1; display: flex; flex-direction: column; }

.source-head, .source-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.source-tools { justify-content: flex-start; flex-wrap: wrap; margin: 0 0 8px; }
.source-tabs { display: flex; gap: 4px; }
.source-tab {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px 12px;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
}
.source-tab[aria-selected="true"] { background: #fff; border-color: var(--line); color: var(--accent-dark); }
#panel-source { display: flex; flex-direction: column; flex: 1; min-height: 460px; }
#panel-syntax { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#panel-syntax[hidden], #panel-source[hidden] { display: none; }
#panel-source[hidden] ~ #mermaid-dir-status { display: none; }
.preview-stage { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.preview-stage.is-full,
.preview-stage:fullscreen {
    position: fixed;
    inset: 0;
    z-index: 40;
    padding: 14px 16px 16px;
    gap: 10px;
    background:
        radial-gradient(circle at 8% 0%, rgba(111, 224, 214, .45), transparent 26%),
        linear-gradient(145deg, #0b1b2e, #12385a 55%, #0e5d68);
}
.stage-help { display: none; margin: 0; color: #d7e6f2; font-size: .92rem; align-items: center; gap: 10px; }
.stage-mark { width: 64px; height: 40px; flex: none; }
.preview-stage.is-full .stage-help,
.preview-stage:fullscreen .stage-help { display: flex; }
.preview-stage.is-full .source-tools,
.preview-stage:fullscreen .source-tools {
    margin: 0;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 10px 28px rgba(6, 20, 36, .28);
}
.preview-stage.is-full .source-tools label,
.preview-stage:fullscreen .source-tools label { color: var(--accent-dark); font-weight: 700; font-size: .85rem; }
.preview-stage.is-full #mermaid-cdn-status,
.preview-stage:fullscreen #mermaid-cdn-status { color: #e7f2f8; }
.preview.mermaid-cdn { flex: 1; height: auto; min-height: 420px; margin-top: 0; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.preview-stage.is-full .preview.mermaid-cdn,
.preview-stage:fullscreen .preview.mermaid-cdn {
    min-height: 0;
    height: 100%;
    border: 0;
    border-radius: 16px;
    cursor: grab;
    box-shadow: 0 16px 40px rgba(6, 20, 36, .35);
}
.view-tools { display: none; align-items: center; gap: 8px; }
.preview-stage.is-full .view-tools,
.preview-stage:fullscreen .view-tools { display: inline-flex; }
.zoom { color: var(--muted); font-size: .85rem; font-weight: 600; }
.preview-stage.is-full .zoom,
.preview-stage:fullscreen .zoom { color: var(--accent-dark); }
#mermaid-zoom { width: 140px; accent-color: var(--accent); }
.preview-stage.is-full [data-preview-dir][aria-pressed="true"],
.preview-stage:fullscreen [data-preview-dir][aria-pressed="true"] { background: #e5f6f4; border-color: var(--accent); color: var(--accent-dark); }

.codebox { position: relative; flex: 1; min-height: 460px; }
.codebox pre, .codebox textarea {
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font: 13px/1.5 var(--mono);
    tab-size: 4;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
.codebox pre {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    background: #0f1c2c;
    color: #e3edf7;
}
.codebox textarea {
    position: relative;
    min-height: 460px;
    height: 100%;
    resize: vertical;
    background: transparent;
    color: transparent;
    caret-color: #e3edf7;
}
.codebox textarea::selection,
.codebox textarea::-moz-selection {
    background: #3d5a80;
    color: #fff;
}
.tok-c { color: #8aa0b8; font-style: italic; }
.tok-s { color: #e6c07b; }
.tok-k { color: #7ec8e3; }
.tok-a { color: #f0a070; }

.options { grid-column: 2; display: flex; flex-direction: column; gap: 14px; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; color: var(--accent-dark); }

.field { display: grid; gap: 4px; margin-top: 10px; font-size: .9rem; }
.field span { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.field small { color: var(--muted); }

select, input[type="text"] {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}

select:focus, input:focus, textarea:focus, button:focus-visible, .button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; font-size: .92rem; }
.check input { margin-top: 3px; }

code { font-family: var(--mono); font-size: .88em; background: #eef2f7; padding: 1px 5px; border-radius: 4px; }

.actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

button, .button {
    font: inherit;
    cursor: pointer;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    padding: 8px 14px;
    text-decoration: none;
    display: inline-block;
}

button:hover, .button:hover { border-color: var(--accent); color: var(--accent-dark); }

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
    padding: 11px 22px;
}

button.primary:hover { background: var(--accent-dark); color: #fff; }

button.mini { padding: 2px 8px; font-size: 12px; line-height: 1.4; border-radius: 6px; }
.dir { display: inline-flex; gap: 4px; }
button.mini[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
button[aria-disabled="true"] { opacity: .6; pointer-events: none; }

.busy { color: var(--muted); }
.busy::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    border: 2px solid var(--accent);
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -1px;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.alert { border-radius: 10px; padding: 12px 16px; margin: 0; }
.alert.error { background: var(--fail-bg); color: #7a1b13; border: 1px solid #f5c2bc; }
.alert ul { margin: 8px 0; padding-left: 20px; }
.alert li { margin: 4px 0; word-break: break-word; }

.retry { display: flex; flex-wrap: wrap; gap: 8px; }

.result { border-top: 1px solid var(--line); padding-top: 20px; display: grid; gap: 14px; }
.result-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.result h2 { margin: 8px 0 4px; }
.meta { margin: 0; color: var(--muted); }

.badge { display: inline-block; font-size: .8rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }

.downloads { display: flex; flex-wrap: wrap; gap: 8px; }

.gates { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }
.gates li { font-size: .85rem; padding: 4px 10px; border-radius: 6px; font-family: var(--mono); }
.gates li.ok { background: var(--ok-bg); color: var(--ok); }
.gates li.fail { background: var(--fail-bg); color: var(--fail); }

.note { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: #fafbfd; }
.note summary { cursor: pointer; font-weight: 600; }
.note ul { margin: 10px 0 2px; padding-left: 20px; font-size: .9rem; }
.note li { margin: 4px 0; word-break: break-word; }

.preview {
    width: 100%;
    height: 82vh;
    min-height: 620px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs[hidden] { display: none; }
.tabs [role="tab"] {
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    margin-bottom: -1px;
    padding: 10px 18px;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
}
.tabs [role="tab"][aria-selected="true"] {
    background: var(--card);
    border-color: var(--line);
    color: var(--accent-dark);
    box-shadow: inset 0 3px 0 var(--accent);
}
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: 1px; }
.dot.ok { background: var(--ok); }
.dot.fail { background: var(--fail); }

.panel { display: grid; gap: 14px; }
.panel[hidden] { display: none; }
.hint { margin: 0; color: var(--muted); font-size: .9rem; }
.preview.graph { background: #0f0f1a; }

.report { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.report-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: #fafbfd; }
.report-card.wide { grid-column: 1 / -1; }
.report-card h3 { margin: 0 0 10px; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-dark); }
.report-card ul, .report-card ol { margin: 0; padding-left: 20px; font-size: .92rem; }
.report-card li { margin: 6px 0; word-break: break-word; }
.report-card small { display: block; color: var(--muted); margin-top: 2px; }
.report-card .empty { margin: 0; color: var(--muted); font-size: .9rem; }

.communities { list-style: none; padding: 0 !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.communities li { margin: 0; }
.communities .focus-row { height: 100%; background: #fff; border-color: var(--line); padding: 10px 12px; }
.communities .members { display: block; margin-top: 6px; color: var(--muted); font-size: .88rem; }
.community-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }

.focus-row {
    display: block;
    width: 100%;
    text-align: left;
    font-size: inherit;
    line-height: inherit;
    padding: 4px 8px;
    margin-left: -8px;
    border-color: transparent;
    background: transparent;
    border-radius: 8px;
}
.communities .focus-row { margin-left: 0; }
.focus-row:not([data-focus]) { cursor: default; }
.focus-row:not([data-focus]):hover { border-color: transparent; color: inherit; }
.communities .focus-row:not([data-focus]):hover { border-color: var(--line); }
.focus-row[data-focus]:hover { background: #eef7f7; color: inherit; }
.focus-row[aria-pressed="true"] { background: #dff1f1; border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.honesty { font-size: .85rem; }
.groups, .gaps { list-style: none; padding-left: 0 !important; }
.groups .focus-row, .gaps .focus-row { margin-left: 0; }
.cohesion { white-space: nowrap; font-size: .78rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.bar { display: inline-block; width: 54px; height: 6px; background: #e3e9f1; border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }

.graph-image { display: block; width: 100%; max-height: 640px; object-fit: contain; background: #1a1a2e; border-radius: 10px; }
.formats { margin-top: 12px !important; }

.gods .count { float: right; margin-left: 10px; color: var(--muted); font-size: .82rem; white-space: nowrap; }

/* Breakpoints follow Bootstrap (sm 576, lg 992, xl 1200, xxl 1400) plus wider monitor steps. */
@media (max-width: 1199.98px) {
    .report { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 991.98px) {
    .report { grid-template-columns: 1fr; }
    .card { grid-template-columns: 1fr; }
    .source, .options { grid-column: 1; }
    textarea { min-height: 320px; }
}

@media (max-width: 575.98px) {
    :root { --gutter: 12px; }
    main { margin-top: 14px; }
    .top { padding: 20px 0; }
    .top h1 { font-size: 1.35rem; }
    .card { padding: 14px; gap: 16px; border-radius: 10px; }
    .tabs [role="tab"] { padding: 8px 12px; }
    .preview { min-height: 460px; }
}

@media (min-width: 1600px) {
    :root { --page: 1520px; --gutter: 32px; }
    .card { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
}

@media (min-width: 1920px) {
    :root { --page: 1800px; }
    .card { padding: 28px; gap: 28px; }
    textarea { min-height: 560px; }
}

@media (min-width: 2560px) {
    :root { --page: 2400px; --gutter: 40px; font-size: 112.5%; }
    textarea { font-size: 14px; min-height: 680px; }
}
