/* Mobile-first safety layer loaded after all component styles. */
html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  overflow-x: clip;
}

main,
section,
article,
form,
figure,
div { min-width: 0; }

img,
svg { max-width: 100%; }

button,
a,
input,
select,
textarea { touch-action: manipulation; }

.mobile-menu-toggle,
.mobile-nav-order { display: none; }

@media (max-width: 1050px) {
  body:not(.admin-page):not(.legal-page) .site-header {
    position: fixed;
    height: 76px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: .7rem;
    padding: 0 1rem;
    background: rgba(4, 13, 8, .94);
    border-bottom: 1px solid rgba(216, 189, 120, .24);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
    backdrop-filter: blur(12px);
  }

  body:not(.admin-page):not(.legal-page) .brand { min-width: 0; }
  body:not(.admin-page):not(.legal-page) .brand > span:last-child { white-space: nowrap; }

  .mobile-menu-toggle {
    position: relative;
    z-index: 22;
    display: grid;
    width: 46px;
    height: 46px;
    padding: 11px;
    place-content: center;
    gap: 5px;
    border: 1px solid rgba(216, 189, 120, .55);
    border-radius: 50%;
    background: rgba(9, 25, 17, .92);
    color: var(--parchment);
    cursor: pointer;
  }

  .mobile-menu-toggle span {
    display: block;
    width: 20px;
    height: 1px;
    background: currentColor;
    transition: transform .22s ease, opacity .22s ease;
  }

  .mobile-menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .mobile-menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .mobile-menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  .site-header .main-navigation {
    position: fixed;
    inset: 76px 0 auto;
    z-index: 20;
    display: flex !important;
    max-height: calc(100dvh - 76px);
    padding: 1rem;
    flex-direction: column;
    gap: .25rem;
    overflow-y: auto;
    border-bottom: 1px solid rgba(216, 189, 120, .35);
    background: linear-gradient(180deg, rgba(5, 16, 10, .99), rgba(8, 27, 18, .98));
    box-shadow: 0 24px 45px rgba(0, 0, 0, .52);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-14px);
    transition: opacity .22s ease, transform .22s ease;
  }

  .mobile-menu-open .site-header .main-navigation {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }

  .mobile-menu-open { overflow: hidden; }

  .site-header .main-navigation a {
    display: flex;
    min-height: 50px;
    align-items: center;
    padding: .85rem 1rem;
    border-bottom: 1px solid rgba(216, 189, 120, .14);
    font-size: .72rem;
  }

  .site-header .main-navigation a::after { display: none; }
  .mobile-nav-order { display: flex; color: var(--gold); }

  .header-actions { gap: .5rem; }
  .header-actions .header-spell { display: none; }
  .crystal-admin { min-width: 44px; min-height: 44px; justify-content: center; }
  .crystal-admin b { display: none !important; }
  .admin-crystal { width: 28px; height: 39px; }
  .admin-crystal::after { width: 46px; height: 46px; }
}

@media (max-width: 760px) {
  .grain { opacity: .08; }
  .motes { opacity: .38; }

  .brand > span:last-child { font-size: .86rem; letter-spacing: .08em; }
  .brand small { font-size: .38rem; }
  .rune-mark { width: 36px; height: 42px; flex: 0 0 auto; }

  .hero {
    min-height: 780px;
    padding: 116px 1rem 5.5rem;
    align-items: flex-start;
  }

  .hero::before {
    background: linear-gradient(180deg, rgba(7, 17, 13, .98) 0%, rgba(7, 17, 13, .88) 58%, rgba(7, 17, 13, .35) 100%);
  }

  .hero-copy { width: 100%; max-width: 590px; }
  .hero .eyebrow { max-width: 30rem; font-size: .52rem; line-height: 1.6; }
  .hero .eyebrow span { padding-inline: .25rem; }
  .hero h1 { font-size: clamp(2.65rem, 12vw, 4.2rem); line-height: .98; overflow-wrap: anywhere; }
  .hero-lead { max-width: 34rem; font-size: 1.05rem; line-height: 1.55; }
  .hero-actions { width: 100%; align-items: stretch; }
  .hero-actions .spell-button { width: 100%; min-height: 52px; }
  .hero-actions .ink-link { width: fit-content; min-height: 44px; display: flex; align-items: center; }
  .hero-scroll { display: none; }

  .portal {
    width: 120vw;
    height: 440px;
    right: -55vw;
    top: auto;
    bottom: 0;
    opacity: .32;
    pointer-events: none;
  }

  .portal-label { display: none; }
  .forest { height: 34%; opacity: .45; }
  .lore-ribbon { height: 44px; }

  .section { padding: 5.5rem 1rem; }
  .chapter { flex-wrap: wrap; line-height: 1.5; }
  .chapter i { width: 32px; }
  .section-title,
  .quest > .section-title { margin: 2.5rem 0 0; }
  .section-title h2,
  .commission h2,
  .qr-gate h2,
  .guestbook-heading h2 { font-size: clamp(2.25rem, 11vw, 3.6rem); overflow-wrap: anywhere; }
  .section-intro { margin: 1.5rem 0 0; font-size: 1rem; }

  .spellbook { grid-template-columns: 1fr; margin-top: 3rem; }
  .craft-card { min-height: 330px; padding: 1.6rem 1.25rem; }

  .relics { padding-bottom: 5.5rem; }
  .relics-head { grid-template-columns: 1fr; gap: 2rem; }
  .relics-head .section-title { margin-top: .5rem; }
  .relic-grid { grid-template-columns: 1fr; padding: 0 1rem; }
  .relic-main,
  .relic-wide { grid-column: auto; grid-row: auto; }
  .relic-main .relic-visual,
  .relic-wide .relic-visual,
  .relic-visual { height: clamp(300px, 105vw, 430px); }
  .relic-card { padding: .45rem; }
  .relic-card > div:last-child { padding: 1.2rem 1rem 1.1rem; }
  .relic-card h3 { font-size: 1.25rem; }
  .relic-card p { font-size: .9rem; line-height: 1.55; }

  .elements { grid-template-columns: 1fr; gap: 2rem; }
  .elements > .chapter,
  .elements > .section-title,
  .element-wheel,
  .element-list { grid-column: auto; }
  .element-wheel { width: min(86vw, 320px); justify-self: center; }
  .element-list article { grid-template-columns: 34px 1fr; }

  .quest-path { margin-top: 3.5rem; padding-left: 0; }
  .quest-path li { padding-right: 0; }
  .quest-path p { max-width: none; }

  .guestbook-section { min-height: 0; padding: 5.5rem 1rem 7rem; }
  .guestbook-heading .chapter { margin-bottom: 3rem; }
  .floating-book { width: 100%; margin-top: 4rem; animation: none; }
  .book-cover { inset: 8px -4px -12px; }
  .book-pages { min-height: 0; }
  .book-page { padding: 2rem 1.2rem; }
  .book-page-left { min-height: 0; }
  .guestbook-entries { max-height: 380px; padding-right: .25rem; }
  .guest-entry footer { align-items: flex-start; flex-direction: column; gap: .35rem; }
  .quill-submit { min-height: 64px; padding-left: 4.4rem; }
  .glowing-quill { width: 58px; height: 82px; }

  .commission { padding: 5.5rem 1rem; gap: 3rem; }
  .commission-copy .chapter { margin-bottom: 3rem; }
  .parchment { padding: 2.25rem 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  input,
  select,
  textarea { width: 100%; min-height: 46px; font-size: 16px; }
  textarea { min-height: 125px; }
  input[type="checkbox"] { width: 18px; min-height: 18px; flex: 0 0 18px; }
  .consent span,
  .guestbook-consent span { font-size: .72rem; }
  .seal-button,
  .spell-button,
  .outline-button { min-height: 50px; }

  .qr-gate { grid-template-columns: 1fr; gap: 3rem; }
  .qr-copy .chapter { margin-bottom: 3rem; }
  .qr-talisman { width: min(100%, 360px); padding: 1rem; justify-self: center; }
  .qr-talisman figcaption { gap: 1rem; }

  body > footer:not(.legal-footer) {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 3rem 1rem;
    gap: 1.8rem;
  }

  .footer-links { flex-wrap: wrap; row-gap: .8rem; }
  .footer-links a,
  .footer-legal a { min-height: 38px; display: flex; align-items: center; }
  .footer-legal { align-items: flex-start; }

  dialog:not(.showroom-lightbox) { width: calc(100% - 1rem); padding: 2rem 1rem 1.2rem; }
  dialog:not(.showroom-lightbox) h2 { font-size: 2rem; }
  .dialog-close { width: 44px; height: 44px; }
  pre { max-height: 34vh; font-size: .66rem; }
  .dialog-actions { flex-direction: column; }

  /* Verwaltung */
  .admin-header,
  .legal-header {
    height: 72px;
    padding: 0 1rem;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .75rem;
  }

  .admin-header .brand small,
  .legal-header .brand small { display: none; }
  .admin-back,
  .legal-back { max-width: 9.5rem; font-size: .5rem; line-height: 1.35; text-align: right; }

  .admin-shell { width: calc(100% - 1rem); padding: 2rem 0 5rem; }
  .login-vault { min-height: calc(100dvh - 110px); }
  .vault-rings { width: 390px; height: 390px; opacity: .7; }
  .vault-card { width: 100%; padding: 2rem 1rem; }
  .vault-card h1,
  .admin-titlebar h1 { font-size: clamp(2rem, 11vw, 3.2rem); overflow-wrap: anywhere; }
  .admin-titlebar { margin-bottom: 2rem; }
  .admin-titlebar .admin-secondary,
  .panel-heading .admin-secondary { width: 100%; min-height: 46px; }
  .admin-tabs { width: 100%; margin-bottom: .7rem; gap: .35rem; scrollbar-width: thin; }
  .admin-tab { flex: 0 0 auto; min-height: 44px; padding-inline: 1rem; }
  .admin-panel { padding: 1rem; }
  .panel-heading h2 { font-size: clamp(1.55rem, 8vw, 2.4rem); }
  .order-card { padding: 1rem; }
  .order-details { grid-template-columns: 1fr; }
  .order-actions { display: grid; grid-template-columns: 1fr; }
  .order-actions .admin-action { width: 100%; min-height: 44px; }
  .archive-toggle { min-height: 62px; padding: .9rem; }
  .archive-list { padding: 0 .55rem .55rem; }
  .admin-entry { grid-template-columns: 1fr; padding: 1rem; }
  .admin-entry-actions { display: grid; grid-template-columns: 1fr; }
  .admin-entry-actions .admin-action { width: 100%; min-height: 44px; }
  .showroom-editor { grid-template-columns: 1fr; }
  .showroom-edit-card { padding: 1rem; }
  .showroom-preview { aspect-ratio: 4 / 3; }
  .showroom-card-actions { display: grid; grid-template-columns: 1fr; }
  .showroom-card-actions .admin-action { width: 100%; min-height: 44px; }

  /* Rechtliche Seiten */
  .legal-shell { width: calc(100% - 2rem); padding: 3rem 0 5rem; }
  .legal-hero { padding: 2rem 0 2.5rem; }
  .legal-hero h1 { font-size: clamp(2.25rem, 12vw, 3.7rem); overflow-wrap: anywhere; hyphens: auto; }
  .legal-content { gap: 1rem; }
  .legal-section,
  .legal-toc,
  .legal-notice,
  .legal-summary { padding: 1.1rem; }
  .legal-section p,
  .legal-section li,
  .legal-meta,
  .legal-notice,
  .legal-summary { font-size: .92rem; line-height: 1.65; overflow-wrap: anywhere; }
  .legal-section ul,
  .legal-section ol { padding-left: 1.25rem; }
  .legal-table th,
  .legal-table td { padding: .75rem; overflow-wrap: anywhere; }
  .legal-footer { padding: 1.5rem 1rem; }
}

@media (max-width: 420px) {
  body:not(.admin-page):not(.legal-page) .site-header { padding-inline: .7rem; gap: .45rem; }
  body:not(.admin-page):not(.legal-page) .brand > span:last-child { font-size: .76rem; }
  body:not(.admin-page):not(.legal-page) .brand small { display: none; }
  .mobile-menu-toggle { width: 42px; height: 42px; }
  .crystal-admin { min-width: 40px; }
  .admin-crystal { width: 25px; height: 35px; }
  .hero { min-height: 740px; padding-inline: .85rem; }
  .hero h1 { font-size: clamp(2.35rem, 12.5vw, 3.2rem); }
  .hero-lead { font-size: .98rem; }
  .section,
  .commission,
  .guestbook-section { padding-inline: .85rem; }
  .relic-grid { padding-inline: .85rem; }
  .book-page { padding-inline: 1rem; }
  .quill-submit { padding-left: 3.9rem; font-size: .55rem; }
  .glowing-quill { width: 52px; }
  .admin-header .brand > span:last-child,
  .legal-header .brand > span:last-child { font-size: .74rem; }
  .admin-back,
  .legal-back { max-width: 7.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-menu-toggle span,
  .site-header .main-navigation { transition: none; }
}
