/* ---------- Theme ---------- */

:root {
    color-scheme: light;
    --bg: #f6f5f2;
    --surface: #ffffff;
    --surface-2: #f2f1ed;
    --text: #23262b;
    --text-muted: #646b74;
    --border: #e4e2dc;
    --shadow: 0 1px 2px rgba(30, 30, 20, 0.04), 0 4px 16px rgba(30, 30, 20, 0.04);

    --good: #2e9d57;
    --bad: #d64545;
    --warn: #d4a017;
    --info: #2f7fd6;

    /* Each page overrides --accent with its section color */
    --accent: #5c6370;
    --accent-text: color-mix(in srgb, var(--accent) 82%, black);
    --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));
    --accent-line: color-mix(in srgb, var(--accent) 45%, var(--surface));

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #16181b;
        --surface: #1e2125;
        --surface-2: #272b30;
        --text: #e4e4e0;
        --text-muted: #9ba2aa;
        --border: #33373d;
        --shadow: none;
        --good: #4cc27a;
        --bad: #ef6b6b;
        --warn: #e8be3f;
        --info: #5aa2ee;
        --accent-text: color-mix(in srgb, var(--accent) 60%, white);
        --accent-soft: color-mix(in srgb, var(--accent) 16%, var(--surface));
        --accent-line: color-mix(in srgb, var(--accent) 55%, var(--surface));
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #16181b;
    --surface: #1e2125;
    --surface-2: #272b30;
    --text: #e4e4e0;
    --text-muted: #9ba2aa;
    --border: #33373d;
    --shadow: none;
    --good: #4cc27a;
    --bad: #ef6b6b;
    --warn: #e8be3f;
    --info: #5aa2ee;
    --accent-text: color-mix(in srgb, var(--accent) 60%, white);
    --accent-soft: color-mix(in srgb, var(--accent) 16%, var(--surface));
    --accent-line: color-mix(in srgb, var(--accent) 55%, var(--surface));
}

/* ---------- Base ---------- */

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
}

main {
    max-width: 980px;
    margin: 0 auto;
    padding: 32px 20px 64px;
}

h1 {
    font-size: 2rem;
    line-height: 1.2;
    margin: 0 0 16px;
}

h1::after {
    content: "";
    display: block;
    width: 48px;
    height: 4px;
    margin-top: 12px;
    border-radius: 2px;
    background: var(--accent);
}

h2 {
    font-size: 1.3rem;
    margin: 0 0 8px;
}

h3 {
    font-size: 1.05rem;
    margin: 20px 0 8px;
}

p {
    margin: 0 0 12px;
}

a {
    color: var(--accent-text);
}

code {
    font-family: var(--mono);
    font-size: 0.88em;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-2);
}

/* ---------- Header ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.site-header nav {
    max-width: 1180px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.site-header a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.site-header .brand {
    font-weight: 700;
    color: var(--text);
}

.nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.nav-links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
}

.nav-links a::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dot);
}

.nav-links a:hover {
    color: var(--text);
    background: var(--surface-2);
}

.nav-links a.active {
    color: var(--text);
    background: color-mix(in srgb, var(--dot) 15%, var(--surface));
}

.theme-toggle {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    font-size: 1rem;
}

/* ---------- Page building blocks ---------- */

.lead {
    font-size: 1.05rem;
    color: var(--text-muted);
}

.flow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 24px 0 32px;
}

.flow .step {
    padding: 8px 14px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-muted);
}

.flow .step strong {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 2px;
    color: var(--text);
}

.flow .arrow {
    color: var(--accent);
    font-weight: bold;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 24px;
    margin-bottom: 28px;
    position: relative;
    overflow: hidden;
}

.panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--accent);
}

.panel > p:first-of-type {
    color: var(--text-muted);
}

details {
    margin-top: 14px;
    font-size: 0.92rem;
    color: var(--text-muted);
}

details summary {
    cursor: pointer;
    color: var(--accent-text);
    font-weight: 500;
}

details p {
    margin: 10px 0 0;
    line-height: 1.55;
}

.hint {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin: 6px 0 0;
}

.row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin: 12px 0;
}

.empty {
    color: var(--text-muted);
    font-style: italic;
}

/* ---------- Form controls ---------- */

input[type="text"],
input[type="number"],
textarea,
select {
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 9px;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--accent-line);
    outline-offset: 0;
    border-color: var(--accent);
}

input[type="checkbox"],
input[type="radio"],
input[type="range"] {
    accent-color: var(--accent);
}

textarea {
    resize: vertical;
}

button {
    font: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 12px;
    cursor: pointer;
}

button:hover {
    background: var(--surface-2);
}

label {
    cursor: pointer;
}

.wide {
    width: 420px;
    max-width: 100%;
}

.doc-input {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 8px 0;
}

.doc-label {
    flex: 0 0 52px;
    padding-top: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

.doc-input input,
.doc-input textarea {
    flex: 1;
    max-width: 560px;
}

/* Settings grid made of small fieldsets */
.settings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px 12px;
    margin: 0;
}

legend {
    font-weight: 600;
    padding: 0 6px;
}

fieldset label {
    margin-right: 12px;
    white-space: nowrap;
}

fieldset textarea {
    display: block;
    width: 100%;
    margin-top: 8px;
}

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
}

table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
    font-size: 0.92rem;
}

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

th {
    background: var(--accent-soft);
    color: var(--accent-text);
    font-weight: 600;
    border-bottom: 2px solid var(--accent-line);
}

tr.muted td {
    color: var(--text-muted);
    opacity: 0.6;
}

tr.highlight td {
    background: var(--accent-soft);
}

/* ---------- Token chips ---------- */

.token {
    display: inline-block;
    margin: 2px 3px;
    padding: 1px 7px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    font-family: var(--mono);
    font-size: 0.85rem;
}

.token.changed {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    border-color: var(--accent-line);
}

.token.removed {
    text-decoration: line-through;
    color: var(--text-muted);
    border-style: dashed;
    opacity: 0.7;
}

.token.added {
    background: color-mix(in srgb, var(--info) 14%, var(--surface));
    border-color: var(--info);
    border-style: dashed;
}

.token.match,
.token.result {
    background: color-mix(in srgb, var(--good) 16%, var(--surface));
    border-color: var(--good);
}

.token.miss {
    background: color-mix(in srgb, var(--bad) 14%, var(--surface));
    border-color: var(--bad);
}

.token .sub {
    color: var(--text-muted);
    font-size: 0.85em;
}

.legend {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* ---------- Stat cards ---------- */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.stat {
    padding: 12px 16px;
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.stat .label {
    font-weight: 600;
    color: var(--text);
}

.stat .value {
    display: block;
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--accent-text);
    line-height: 1.3;
}

/* ---------- Ranked lists ---------- */

.rankings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.ranking {
    background: var(--surface-2);
    border-radius: 8px;
    padding: 4px 16px 8px;
}

.ranking.featured {
    background: var(--accent-soft);
    outline: 1px solid var(--accent-line);
}

.ranking h3 {
    margin: 12px 0 6px;
}

.ranking ol {
    padding-left: 20px;
    margin: 0;
}

.ranking li {
    margin: 6px 0;
    font-size: 0.9rem;
}

.score {
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 0.85em;
}

/* ---------- Home ---------- */

.hero {
    padding: 24px 0 8px;
}

.hero h1 {
    font-size: 2.4rem;
}

.group {
    margin-top: 36px;
}

.group-title {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
}

.card {
    display: block;
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--card-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    transition: transform 0.15s, border-color 0.15s;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--card-color);
}

.card h3 {
    margin: 0 0 4px;
    color: color-mix(in srgb, var(--card-color) 80%, var(--text));
}

.card p {
    margin: 0;
    font-size: 0.92rem;
    color: var(--text-muted);
}

.card .step-number {
    float: right;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
    main {
        padding: 20px 16px 48px;
    }
    .panel {
        padding: 18px 16px;
    }
    .doc-label {
        flex-basis: 44px;
    }
}
