/*
 * The Hundredth Flame - Designsystem v0.1.0
 * Embers over Greylock
 * Default: Ash & Dawn (light). Dark: Ember Night.
 */

:root,
html[data-thf-theme="light"] {
    color-scheme: light;

    --thf-bg: #f3efe7;
    --thf-bg-deep: #e9e2d7;
    --thf-surface: #fffaf2;
    --thf-surface-raised: #fffdf8;
    --thf-surface-muted: #ece8e1;
    --thf-stone: #d4d0c7;
    --thf-stone-strong: #aaa79f;
    --thf-smoke-blue: #7e8fa6;

    --thf-text: #25282d;
    --thf-text-soft: #686a6e;
    --thf-text-faint: #85878a;
    --thf-link: #5f6f84;
    --thf-link-hover: #39495f;

    --thf-gold: #c89b4d;
    --thf-gold-soft: #d8b66f;
    --thf-gold-pale: #ead8ad;
    --thf-copper: #a67c52;
    --thf-amber: #c98237;
    --thf-ember: #b95832;

    --thf-info: #5f8fa8;
    --thf-success: #6f8d70;
    --thf-warning: #b88739;
    --thf-error: #9f5148;
    --thf-secret: #7f6c8d;

    --thf-border: rgba(89, 79, 63, .22);
    --thf-border-strong: rgba(166, 124, 82, .58);
    --thf-shadow: 0 10px 28px rgba(50, 43, 33, .08);
    --thf-overlay: rgba(24, 25, 29, .58);

    --thf-accent: var(--thf-gold);
    --thf-accent-soft: var(--thf-gold-soft);

    --thf-font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    --thf-font-display: Georgia, "Times New Roman", serif;

    --thf-radius-xs: 2px;
    --thf-radius-sm: 3px;
    --thf-radius-md: 5px;

    --thf-space-1: 4px;
    --thf-space-2: 8px;
    --thf-space-3: 12px;
    --thf-space-4: 16px;
    --thf-space-5: 24px;
    --thf-space-6: 32px;
    --thf-space-7: 48px;

    --thf-content-max: 1500px;
    --thf-content-reading: 860px;
}

html[data-thf-theme="dark"] {
    color-scheme: dark;

    --thf-bg: #111722;
    --thf-bg-deep: #0b1018;
    --thf-surface: #171e29;
    --thf-surface-raised: #1d2633;
    --thf-surface-muted: #232d39;
    --thf-stone: #34404c;
    --thf-stone-strong: #65717d;
    --thf-smoke-blue: #7e8fa6;

    --thf-text: #ece8df;
    --thf-text-soft: #b9b5ad;
    --thf-text-faint: #8f9398;
    --thf-link: #aeb9c9;
    --thf-link-hover: #f1ddb2;

    --thf-gold: #c89b4d;
    --thf-gold-soft: #d8b66f;
    --thf-gold-pale: #8c7449;
    --thf-copper: #a67c52;
    --thf-amber: #d18a39;
    --thf-ember: #d0643c;

    --thf-info: #75a5bd;
    --thf-success: #86a586;
    --thf-warning: #d1a453;
    --thf-error: #c96c61;
    --thf-secret: #a08ab1;

    --thf-border: rgba(216, 182, 111, .16);
    --thf-border-strong: rgba(200, 155, 77, .55);
    --thf-shadow: 0 16px 38px rgba(0, 0, 0, .24);
    --thf-overlay: rgba(4, 7, 12, .76);
}

html[data-thf-theme="auto"] {
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    html[data-thf-theme="auto"] {
        --thf-bg: #111722;
        --thf-bg-deep: #0b1018;
        --thf-surface: #171e29;
        --thf-surface-raised: #1d2633;
        --thf-surface-muted: #232d39;
        --thf-stone: #34404c;
        --thf-stone-strong: #65717d;
        --thf-text: #ece8df;
        --thf-text-soft: #b9b5ad;
        --thf-text-faint: #8f9398;
        --thf-link: #aeb9c9;
        --thf-link-hover: #f1ddb2;
        --thf-border: rgba(216, 182, 111, .16);
        --thf-border-strong: rgba(200, 155, 77, .55);
        --thf-shadow: 0 16px 38px rgba(0, 0, 0, .24);
        --thf-overlay: rgba(4, 7, 12, .76);
    }
}

/* ---------- Layout + typography ---------- */
.thf-ui,
.thf-panel,
.thf-card,
.thf-modal,
.thf-alert,
.thf-empty {
    box-sizing: border-box;
    font-family: var(--thf-font-body);
    color: var(--thf-text);
}

.thf-shell {
    width: min(calc(100% - 32px), var(--thf-content-max));
    margin-inline: auto;
}

.thf-reading {
    max-width: var(--thf-content-reading);
}

.thf-title,
.thf-heading,
.thf-ember-heading {
    margin: 0;
    color: var(--thf-text);
    font-family: var(--thf-font-display);
    font-weight: 600;
    letter-spacing: .015em;
}

.thf-title { font-size: clamp(1.65rem, 2vw, 2.35rem); }
.thf-heading { font-size: clamp(1.2rem, 1.5vw, 1.55rem); }

.thf-ember-heading {
    position: relative;
    padding-bottom: 10px;
}

.thf-ember-heading::after,
.thf-ember-line::after {
    content: "";
    display: block;
    width: min(180px, 42%);
    height: 1px;
    margin-top: 9px;
    background: linear-gradient(90deg, var(--thf-ember), var(--thf-gold), transparent);
}

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

/* ---------- Panels + cards ---------- */
.thf-panel,
.thf-card {
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-sm);
    background: var(--thf-surface);
    box-shadow: var(--thf-shadow);
}

.thf-panel { padding: var(--thf-space-5); }
.thf-card { overflow: hidden; }

.thf-card__header,
.thf-card__body,
.thf-card__footer {
    padding: var(--thf-space-4) var(--thf-space-5);
}

.thf-card__header {
    border-bottom: 1px solid var(--thf-border);
    background: linear-gradient(90deg, color-mix(in srgb, var(--thf-surface-muted) 72%, transparent), var(--thf-surface));
}

.thf-card__footer {
    border-top: 1px solid var(--thf-border);
    background: color-mix(in srgb, var(--thf-surface-muted) 62%, transparent);
}

/* ---------- Buttons ---------- */
.thf-button {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    box-sizing: border-box;
    padding: 7px 12px;
    border: 1px solid var(--thf-border-strong);
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-raised);
    color: var(--thf-text);
    font: 600 12px/1.25 var(--thf-font-body);
    letter-spacing: .025em;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .16s ease, background .16s ease, color .16s ease, transform .16s ease;
}

.thf-button:hover,
.thf-button:focus-visible {
    border-color: var(--thf-gold);
    outline: none;
}

.thf-button:active { transform: translateY(1px); }

.thf-button--primary {
    border-color: var(--thf-gold);
    background: color-mix(in srgb, var(--thf-gold) 18%, var(--thf-surface));
    color: var(--thf-text);
}

.thf-button--secondary {
    border-color: color-mix(in srgb, var(--thf-copper) 68%, var(--thf-border));
}

.thf-button--ghost {
    border-color: transparent;
    background: transparent;
}

.thf-button--danger {
    border-color: color-mix(in srgb, var(--thf-error) 70%, var(--thf-border));
    background: color-mix(in srgb, var(--thf-error) 11%, var(--thf-surface));
}

.thf-button:disabled,
.thf-button[aria-disabled="true"] {
    opacity: .48;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Tabs ---------- */
.thf-tabs {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    border-bottom: 1px solid var(--thf-border);
    scrollbar-width: thin;
}

.thf-tab {
    position: relative;
    flex: 0 0 auto;
    padding: 9px 12px;
    border: 0;
    background: transparent;
    color: var(--thf-text-soft);
    font: 600 12px/1.2 var(--thf-font-body);
    text-decoration: none;
    cursor: pointer;
}

.thf-tab:hover,
.thf-tab:focus-visible,
.thf-tab.is-active {
    color: var(--thf-text);
    outline: none;
}

.thf-tab.is-active::after {
    content: "";
    position: absolute;
    right: 8px;
    bottom: -1px;
    left: 8px;
    height: 2px;
    background: linear-gradient(90deg, var(--thf-ember), var(--thf-gold));
}

/* ---------- Status chips ---------- */
.thf-chip {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 7px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-muted);
    color: var(--thf-text-soft);
    font: 700 10px/1.2 var(--thf-font-body);
    letter-spacing: .06em;
    text-transform: uppercase;
}

.thf-chip--info { border-color: color-mix(in srgb, var(--thf-info) 60%, transparent); color: var(--thf-info); }
.thf-chip--success { border-color: color-mix(in srgb, var(--thf-success) 60%, transparent); color: var(--thf-success); }
.thf-chip--warning { border-color: color-mix(in srgb, var(--thf-warning) 65%, transparent); color: var(--thf-warning); }
.thf-chip--error { border-color: color-mix(in srgb, var(--thf-error) 65%, transparent); color: var(--thf-error); }
.thf-chip--secret { border-color: color-mix(in srgb, var(--thf-secret) 65%, transparent); color: var(--thf-secret); }

/* ---------- Alerts ---------- */
.thf-alert {
    position: relative;
    padding: 12px 14px 12px 17px;
    border: 1px solid var(--thf-border);
    border-left: 3px solid var(--thf-info);
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-raised);
}

.thf-alert--success { border-left-color: var(--thf-success); }
.thf-alert--warning { border-left-color: var(--thf-warning); }
.thf-alert--error { border-left-color: var(--thf-error); }
.thf-alert__title { display: block; margin-bottom: 3px; }
.thf-alert__content { color: var(--thf-text-soft); }

/* ---------- Forms ---------- */
.thf-field {
    display: grid;
    gap: 6px;
}

.thf-label {
    color: var(--thf-text);
    font: 650 11px/1.25 var(--thf-font-body);
    letter-spacing: .055em;
    text-transform: uppercase;
}

.thf-help,
.thf-field__message {
    color: var(--thf-text-soft);
    font-size: 11px;
}

.thf-input,
.thf-select,
.thf-textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-raised);
    color: var(--thf-text);
    font: 13px/1.4 var(--thf-font-body);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.thf-input,
.thf-select { min-height: 36px; padding: 7px 9px; }
.thf-textarea { min-height: 110px; padding: 9px; resize: vertical; }

.thf-input:focus,
.thf-select:focus,
.thf-textarea:focus,
.thf-field.is-focus .thf-input,
.thf-field.is-focus .thf-select,
.thf-field.is-focus .thf-textarea {
    border-color: var(--thf-gold);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--thf-gold) 15%, transparent);
    outline: none;
}

.thf-field.is-error .thf-input,
.thf-field.is-error .thf-select,
.thf-field.is-error .thf-textarea {
    border-color: var(--thf-error);
}

.thf-field.is-error .thf-field__message { color: var(--thf-error); }

.thf-field.is-success .thf-input,
.thf-field.is-success .thf-select,
.thf-field.is-success .thf-textarea {
    border-color: var(--thf-success);
}

.thf-field.is-success .thf-field__message { color: var(--thf-success); }

.thf-input:disabled,
.thf-select:disabled,
.thf-textarea:disabled,
.thf-field.is-disabled {
    opacity: .58;
    cursor: not-allowed;
}

/* ---------- Empty + loading ---------- */
.thf-empty {
    padding: 34px 24px;
    border: 1px dashed var(--thf-border-strong);
    border-radius: var(--thf-radius-sm);
    background: color-mix(in srgb, var(--thf-surface) 92%, transparent);
    text-align: center;
}

.thf-empty__mark {
    margin-bottom: 8px;
    color: var(--thf-gold);
    font-size: 20px;
}

.thf-empty__title {
    display: block;
    font-family: var(--thf-font-display);
    font-size: 18px;
}

.thf-empty__text { margin-top: 6px; color: var(--thf-text-soft); }
.thf-empty__action { margin-top: 14px; }

.thf-loading {
    position: relative;
    min-height: 70px;
    overflow: hidden;
    border: 1px solid var(--thf-border);
    background: var(--thf-surface);
}

.thf-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--thf-gold) 8%, transparent), transparent);
    animation: thf-loading-sweep 1.3s infinite;
}

@keyframes thf-loading-sweep { to { transform: translateX(100%); } }

/* ---------- Modal ---------- */
.thf-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    place-items: center;
    padding: 24px;
    background: var(--thf-overlay);
}

.thf-modal.is-open { display: grid; }

.thf-modal__dialog {
    width: min(680px, 100%);
    max-height: min(82vh, 760px);
    overflow: auto;
    border: 1px solid var(--thf-border-strong);
    border-radius: var(--thf-radius-sm);
    background: var(--thf-surface-raised);
    box-shadow: var(--thf-shadow);
}

.thf-modal__header,
.thf-modal__body,
.thf-modal__footer { padding: 16px 18px; }
.thf-modal__header { border-bottom: 1px solid var(--thf-border); }
.thf-modal__footer { border-top: 1px solid var(--thf-border); }

/* ---------- Fixed media contracts ---------- */
.thf-media-avatar,
.thf-media-icon,
.thf-media-signature {
    display: block;
    max-width: 100%;
    overflow: hidden;
    border: 1px solid var(--thf-border);
    background: var(--thf-surface-muted);
}

.thf-media-avatar { width: 250px; aspect-ratio: 250 / 280; }
.thf-media-icon { width: 250px; aspect-ratio: 250 / 120; }
.thf-media-signature { width: 500px; aspect-ratio: 500 / 250; }

.thf-media-avatar img,
.thf-media-icon img,
.thf-media-signature img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ---------- Utility ---------- */
.thf-stack { display: grid; gap: var(--thf-space-4); }
.thf-inline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--thf-space-2); }
.thf-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: var(--thf-space-4); }
.thf-divider { height: 1px; border: 0; background: var(--thf-border); }

/* ---------- Responsive foundations ---------- */
@media (max-width: 1180px) {
    .thf-shell { width: min(calc(100% - 24px), var(--thf-content-max)); }
}

@media (max-width: 820px) {
    .thf-panel { padding: var(--thf-space-4); }
    .thf-card__header,
    .thf-card__body,
    .thf-card__footer { padding: 13px 14px; }
    .thf-modal { padding: 14px; }
}

@media (max-width: 560px) {
    .thf-shell { width: calc(100% - 16px); }
    .thf-button { min-height: 36px; }
    .thf-tabs { margin-inline: -8px; padding-inline: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .thf-button,
    .thf-input,
    .thf-select,
    .thf-textarea { transition: none; }
    .thf-loading::after { animation: none; display: none; }
}

/* ============================================================
   v0.2 - SCHOOL / AREA ACCENTS
   School colours are intentionally restrained affiliation accents.
   ============================================================ */

.thf-accent,
[data-thf-school],
[data-thf-area] {
    --thf-context-accent: var(--thf-accent);
    --thf-context-accent-soft: color-mix(in srgb, var(--thf-context-accent) 18%, transparent);
}

[data-thf-school="hogwarts"] { --thf-context-accent: #8b3438; }
[data-thf-school="beauxbatons"] { --thf-context-accent: #78a9bd; }
[data-thf-school="durmstrang"] { --thf-context-accent: #6f2838; }
[data-thf-school="ilvermorny"] { --thf-context-accent: #344e72; }
[data-thf-school="castelobruxo"] { --thf-context-accent: #3f7654; }
[data-thf-school="uagadou"] { --thf-context-accent: #52508a; }
[data-thf-school="mahoutokoro"] { --thf-context-accent: #4f846f; }
[data-thf-school="koldovstoretz"] { --thf-context-accent: #91b7c7; }
[data-thf-school="nordhalla"] { --thf-context-accent: #527890; }
[data-thf-school="sturmhoehe"] { --thf-context-accent: #4e9ba2; }
[data-thf-school="kororaora"] { --thf-context-accent: #3d8194; }
[data-thf-school="academie-des-marais"] { --thf-context-accent: #2f6668; }
[data-thf-school="northern-circle-academy"],
[data-thf-school="northern-winds"] { --thf-context-accent: #56547f; }

[data-thf-area="neutral"] { --thf-context-accent: #7e8fa6; }
[data-thf-area="greywick"] { --thf-context-accent: #a67c52; }
[data-thf-area="wondergrounds"] { --thf-context-accent: #9b7e9b; }
[data-thf-area="starfall-circus"] { --thf-context-accent: #b98c8c; }
[data-thf-area="tournament"] { --thf-context-accent: #c89b4d; }
[data-thf-area="owlery"] { --thf-context-accent: #a67c52; }
[data-thf-area="whispers"] { --thf-context-accent: #7f6c8d; }
[data-thf-area="hundredth-wire"] { --thf-context-accent: #7e8fa6; }
[data-thf-area="ministry"] { --thf-context-accent: #6f747a; }
[data-thf-area="adult"] { --thf-context-accent: #8a7f73; }

.thf-accent-line {
    position: relative;
}

.thf-accent-line::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 2px;
    background: var(--thf-context-accent);
}

.thf-accent-text { color: var(--thf-context-accent); }
.thf-accent-border { border-color: color-mix(in srgb, var(--thf-context-accent) 62%, var(--thf-border)); }
.thf-accent-surface { background: color-mix(in srgb, var(--thf-context-accent) 9%, var(--thf-surface)); }

.thf-school-mark,
.thf-area-mark {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 26px;
    padding: 4px 8px;
    border: 1px solid color-mix(in srgb, var(--thf-context-accent) 42%, var(--thf-border));
    border-radius: var(--thf-radius-xs);
    background: color-mix(in srgb, var(--thf-context-accent) 7%, var(--thf-surface));
    color: var(--thf-text);
    font: 650 11px/1.2 var(--thf-font-body);
}

.thf-school-mark::before,
.thf-area-mark::before {
    content: "";
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border: 1px solid color-mix(in srgb, var(--thf-context-accent) 70%, var(--thf-border));
    background: var(--thf-context-accent);
    transform: rotate(45deg);
}

/* ---------- v0.2 icon system ---------- */
.thf-icon {
    width: 1.05em;
    height: 1.05em;
    flex: 0 0 auto;
    overflow: visible;
    vertical-align: -0.15em;
    color: currentColor;
}

.thf-icon--sm { width: .9em; height: .9em; }
.thf-icon--lg { width: 1.3em; height: 1.3em; }
.thf-icon--accent { color: var(--thf-context-accent, var(--thf-gold)); }

/* ---------- v0.2 responsive navigation ---------- */
.thf-nav {
    --thf-nav-height: 40px;
    position: relative;
    z-index: 110;
    font-family: var(--thf-font-body);
}

.thf-nav__toggle {
    display: none;
    min-height: var(--thf-nav-height);
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
    border: 1px solid var(--thf-border-strong);
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-raised);
    color: var(--thf-text);
    font: 650 12px/1 var(--thf-font-body);
    cursor: pointer;
}

.thf-nav__backdrop { display: none; }

.thf-nav__drawer {
    display: flex;
    align-items: center;
}

.thf-nav__drawer-head { display: none; }

.thf-nav__items {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
}

.thf-nav__item {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: var(--thf-nav-height);
    padding: 8px 10px;
    color: var(--thf-text-soft);
    font: 620 12px/1.2 var(--thf-font-body);
    text-decoration: none;
    white-space: nowrap;
}

.thf-nav__item:hover,
.thf-nav__item:focus-visible,
.thf-nav__item.is-active {
    color: var(--thf-text);
    outline: none;
}

.thf-nav__item.is-active::after {
    content: "";
    position: absolute;
    right: 9px;
    bottom: 3px;
    left: 9px;
    height: 1px;
    background: linear-gradient(90deg, var(--thf-ember), var(--thf-gold));
}

.thf-nav__close {
    display: inline-grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-xs);
    background: transparent;
    color: var(--thf-text);
    cursor: pointer;
}

html.thf-nav-open,
body.thf-nav-open { overflow: hidden; }

@media (max-width: 820px) {
    .thf-nav__toggle { display: inline-flex; }

    .thf-nav__backdrop {
        position: fixed;
        inset: 0;
        z-index: 998;
        background: var(--thf-overlay);
    }

    .thf-nav__drawer {
        position: fixed;
        z-index: 999;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(360px, calc(100vw - 44px));
        display: block;
        overflow-y: auto;
        border-left: 1px solid var(--thf-border-strong);
        background: var(--thf-surface-raised);
        box-shadow: -14px 0 34px rgba(0,0,0,.18);
        transform: translateX(104%);
        transition: transform .2s ease;
    }

    .thf-nav.is-open .thf-nav__backdrop { display: block; }
    .thf-nav.is-open .thf-nav__drawer { transform: translateX(0); }

    .thf-nav__drawer-head {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        min-height: 58px;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 10px 12px 10px 16px;
        border-bottom: 1px solid var(--thf-border);
        background: color-mix(in srgb, var(--thf-surface-raised) 96%, transparent);
        backdrop-filter: blur(8px);
    }

    .thf-nav__drawer-head strong {
        font-family: var(--thf-font-display);
        font-size: 17px;
        font-weight: 600;
    }

    .thf-nav__items {
        display: grid;
        gap: 0;
        padding: 8px 0 18px;
    }

    .thf-nav__item {
        min-height: 44px;
        padding: 10px 16px;
        border-bottom: 1px solid color-mix(in srgb, var(--thf-border) 70%, transparent);
    }

    .thf-nav__item.is-active::after {
        top: 9px;
        right: auto;
        bottom: 9px;
        left: 0;
        width: 2px;
        height: auto;
        background: var(--thf-gold);
    }
}

@media (prefers-reduced-motion: reduce) {
    .thf-nav__drawer { transition: none; }
}


/* ============================================================
 * v0.3 Theme switcher + design preview
 * ============================================================ */
.thf-theme-switcher {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-sm);
    background: var(--thf-surface-muted);
}

.thf-theme-switcher__button {
    display: inline-flex;
    min-height: 31px;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 1px solid transparent;
    border-radius: var(--thf-radius-xs);
    background: transparent;
    color: var(--thf-text-soft);
    font: 650 11px/1 var(--thf-font-body);
    cursor: pointer;
}

.thf-theme-switcher__button:hover,
.thf-theme-switcher__button:focus-visible {
    color: var(--thf-text);
    outline: none;
    border-color: var(--thf-border);
}

.thf-theme-switcher__button.is-active {
    border-color: var(--thf-border-strong);
    background: var(--thf-surface-raised);
    color: var(--thf-text);
    box-shadow: 0 1px 4px color-mix(in srgb, var(--thf-overlay) 12%, transparent);
}

.thf-theme-switcher--compact .thf-theme-switcher__button span { display: none; }
.thf-theme-switcher--compact .thf-theme-switcher__button { width: 31px; justify-content: center; padding-inline: 0; }

.thf-preview-page {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 18% 0%, color-mix(in srgb, var(--thf-gold) 7%, transparent), transparent 30rem),
        var(--thf-bg);
    color: var(--thf-text);
    font-family: var(--thf-font-body);
}

.thf-preview {
    width: min(calc(100% - 32px), 1380px);
    margin: 0 auto;
    padding: 34px 0 72px;
}

.thf-preview-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 18px;
    padding: 26px 28px;
    border: 1px solid var(--thf-border-strong);
    border-radius: var(--thf-radius-sm);
    background: linear-gradient(135deg, var(--thf-surface-raised), color-mix(in srgb, var(--thf-gold) 5%, var(--thf-surface)));
    box-shadow: var(--thf-shadow);
}

.thf-preview-kicker {
    margin-bottom: 8px;
    color: var(--thf-copper);
    font: 750 10px/1.2 var(--thf-font-body);
    letter-spacing: .18em;
    text-transform: uppercase;
}

.thf-preview-lead {
    max-width: 760px;
    margin: 12px 0 0;
    color: var(--thf-text-soft);
    line-height: 1.6;
}

.thf-preview-hero__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.thf-preview .thf-nav {
    margin: 0 0 26px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-sm);
    background: var(--thf-surface);
}

.thf-preview .thf-nav__items { padding-inline: 6px; }

.thf-preview-section {
    scroll-margin-top: 16px;
    margin-top: 28px;
    padding: 24px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-sm);
    background: var(--thf-surface);
    box-shadow: var(--thf-shadow);
}

.thf-preview-section > .thf-heading { margin-bottom: 20px; }
.thf-preview-subheading { margin: 24px 0 10px; font: 650 14px/1.3 var(--thf-font-display); }
.thf-preview-stack { display: grid; gap: 8px; margin-top: 16px; }
.thf-preview-actions { margin-top: 16px; }

.thf-preview-accent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 8px;
}

.thf-preview-accent {
    --thf-context-accent: var(--thf-gold);
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    min-height: 46px;
    padding: 8px 10px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-xs);
}

.thf-preview-accent__swatch {
    width: 10px;
    height: 22px;
    border-radius: 1px;
    background: var(--thf-context-accent);
}

.thf-preview-accent code {
    color: var(--thf-text-faint);
    font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.thf-preview-icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
}

.thf-preview-icon {
    display: grid;
    min-height: 84px;
    place-items: center;
    gap: 8px;
    padding: 12px 8px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-raised);
    color: var(--thf-text-soft);
    font-size: 10px;
}

.thf-preview-icon .thf-icon { color: var(--thf-gold); }

.thf-preview-media-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 22px;
}

.thf-preview-media-row > div { display: grid; gap: 6px; color: var(--thf-text-soft); font-size: 11px; }

.thf-preview-media-placeholder {
    display: grid;
    place-items: center;
    color: var(--thf-text-faint);
    font: 600 11px/1 var(--thf-font-body);
    background:
        linear-gradient(135deg, transparent 49.5%, color-mix(in srgb, var(--thf-border) 70%, transparent) 50%, transparent 50.5%),
        linear-gradient(45deg, transparent 49.5%, color-mix(in srgb, var(--thf-border) 70%, transparent) 50%, transparent 50.5%),
        var(--thf-surface-muted);
}

@media (max-width: 820px) {
    .thf-preview { width: min(calc(100% - 20px), 1380px); padding-top: 18px; }
    .thf-preview-hero { display: grid; padding: 20px; }
    .thf-preview-hero__actions { justify-content: flex-start; }
    .thf-preview-section { padding: 18px; }
}

@media (max-width: 560px) {
    .thf-theme-switcher { width: 100%; }
    .thf-theme-switcher__button { flex: 1 1 0; justify-content: center; }
    .thf-preview-hero__actions { display: grid; grid-template-columns: 1fr; }
    .thf-preview-hero__actions > .thf-button { width: 100%; }
    .thf-preview-section { padding: 14px; }
    .thf-preview-accent-grid { grid-template-columns: 1fr; }
}


/* ============================================================
 * v0.4 Block-02 Abschluss: Page Shell, Toolbar, Filter + A11y
 * ============================================================ */
:root,
html[data-thf-theme="light"],
html[data-thf-theme="dark"] {
    --thf-focus: color-mix(in srgb, var(--thf-gold) 74%, white 6%);
    --thf-focus-ring: 0 0 0 3px color-mix(in srgb, var(--thf-gold) 20%, transparent);
    --thf-page-gap: var(--thf-space-5);
}

.thf-page {
    width: min(calc(100% - 32px), var(--thf-content-max));
    margin-inline: auto;
    color: var(--thf-text);
    font-family: var(--thf-font-body);
}

.thf-page--embedded {
    width: 100%;
    margin: 0;
}

.thf-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--thf-space-5);
    padding-bottom: var(--thf-space-4);
    border-bottom: 1px solid var(--thf-border);
}

.thf-page-header__copy { min-width: 0; }
.thf-page-header__eyebrow {
    margin-bottom: 7px;
    color: var(--thf-copper);
    font: 750 10px/1.2 var(--thf-font-body);
    letter-spacing: .16em;
    text-transform: uppercase;
}
.thf-page-header__description {
    max-width: 800px;
    margin: 11px 0 0;
    color: var(--thf-text-soft);
    line-height: 1.6;
}
.thf-page-header__actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--thf-space-2);
}

.thf-toolbar {
    display: flex;
    min-height: 44px;
    align-items: center;
    justify-content: space-between;
    gap: var(--thf-space-3);
    margin-top: var(--thf-space-4);
    padding: 7px 10px;
    border: 1px solid var(--thf-border);
    border-radius: var(--thf-radius-xs);
    background: color-mix(in srgb, var(--thf-surface-muted) 58%, var(--thf-surface));
}
.thf-toolbar__start,
.thf-toolbar__end {
    display: flex;
    min-width: 0;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--thf-space-2);
}
.thf-toolbar__end { justify-content: flex-end; }

.thf-filterbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: var(--thf-space-3);
    margin-top: var(--thf-space-3);
    padding: var(--thf-space-3);
    border: 1px solid var(--thf-border);
    border-left: 2px solid var(--thf-context-accent, var(--thf-gold));
    border-radius: var(--thf-radius-xs);
    background: var(--thf-surface-raised);
}
.thf-filterbar__fields {
    display: grid;
    min-width: 0;
    flex: 1 1 auto;
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
    gap: var(--thf-space-3);
}
.thf-filterbar__actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: var(--thf-space-2);
}

.thf-error-summary {
    padding: 13px 15px;
    border: 1px solid color-mix(in srgb, var(--thf-error) 52%, var(--thf-border));
    border-left: 3px solid var(--thf-error);
    border-radius: var(--thf-radius-xs);
    background: color-mix(in srgb, var(--thf-error) 7%, var(--thf-surface-raised));
    color: var(--thf-text);
}
.thf-error-summary__title { display: block; margin-bottom: 7px; }
.thf-error-summary ul { margin: 0; padding-left: 20px; color: var(--thf-text-soft); }
.thf-error-summary li + li { margin-top: 3px; }

.thf-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.thf-button:focus-visible,
.thf-tab:focus-visible,
.thf-theme-switcher__button:focus-visible,
.thf-nav__toggle:focus-visible,
.thf-nav__item:focus-visible,
.thf-nav__close:focus-visible,
.thf-input:focus-visible,
.thf-select:focus-visible,
.thf-textarea:focus-visible,
.thf-modal__dialog:focus-visible,
.thf-error-summary:focus-visible {
    outline: 2px solid var(--thf-focus);
    outline-offset: 2px;
    box-shadow: var(--thf-focus-ring);
}

.thf-field[aria-invalid="true"] .thf-input,
.thf-field[aria-invalid="true"] .thf-select,
.thf-field[aria-invalid="true"] .thf-textarea,
.thf-input[aria-invalid="true"],
.thf-select[aria-invalid="true"],
.thf-textarea[aria-invalid="true"] {
    border-color: var(--thf-error);
}

html.thf-modal-open,
body.thf-modal-open { overflow: hidden; }

.thf-modal__dialog:focus { outline: none; }

@media (max-width: 820px) {
    .thf-page { width: min(calc(100% - 20px), var(--thf-content-max)); }
    .thf-page-header { display: grid; gap: var(--thf-space-3); }
    .thf-page-header__actions { justify-content: flex-start; }
    .thf-toolbar { align-items: flex-start; }
    .thf-filterbar { display: grid; align-items: stretch; }
    .thf-filterbar__actions { justify-content: flex-end; }
}

@media (max-width: 560px) {
    :root { --thf-page-gap: var(--thf-space-4); }
    .thf-page { width: calc(100% - 16px); }
    .thf-page-header__actions,
    .thf-toolbar,
    .thf-toolbar__start,
    .thf-toolbar__end,
    .thf-filterbar__actions { width: 100%; }
    .thf-toolbar { display: grid; }
    .thf-toolbar__end { justify-content: flex-start; }
    .thf-filterbar__actions .thf-button { width: 100%; }
    .thf-page-header__actions .thf-button { width: 100%; }
}
