/* ==========================================================================
   KAYS Digital Products — Obsidian Crimson Precision
   Shared Stylesheet (index.html, impressum.html, datenschutz.html)
   ========================================================================== */

:root {
  color-scheme: dark;
  --surface: #131315;
  --surface-lowest: #0e0e10;
  --surface-low: #1c1b1d;
  --surface-container: #201f22;
  --surface-high: #2a2a2c;
  --surface-highest: #353437;
  --on-surface: #e5e1e4;
  --on-surface-variant: #e0bec4;
  --outline: #a8898f;
  --primary: #ffb1c3;
  --primary-container: #be185d;
  --secondary-container: #940532;
}

/* Cross-Document View Transitions (MPA progressive enhancement) */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  html {
    scroll-behavior: smooth;
  }
}

html {
  scroll-padding-top: 5.5rem;
  background-color: var(--surface);
  scrollbar-color: #353437 #0e0e10;
  scrollbar-width: thin;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  overscroll-behavior-y: none;
}

main > :first-child {
  margin-top: 0;
}

main > :last-child {
  margin-bottom: 0;
}

/* Subtle dark scrollbar for WebKit/Chromium */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0e0e10;
}

::-webkit-scrollbar-thumb {
  background: #353437;
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: #be185d;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: fixed;
  top: -100%;
  left: 1rem;
  z-index: 100;
  padding: 0.625rem 1rem;
  background: var(--primary-container);
  color: #ffffff;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.skip-link:focus {
  top: 1rem;
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Focus ring tailored to Obsidian Crimson Precision */
:focus-visible {
  outline: 2px solid var(--primary-container);
  outline-offset: 2px;
}

/* Subtle 45-degree architectural sheen on interactive monolith cards */
.monolith-card {
  position: relative;
}

.monolith-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 177, 195, 0.04) 0%,
    transparent 45%,
    rgba(190, 24, 93, 0.04) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.monolith-card:hover::before {
  opacity: 1;
}

/* Diagonal slash divider accent */
.diagonal-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.12) 20%,
    rgba(190, 24, 93, 0.45) 50%,
    rgba(255, 255, 255, 0.12) 80%,
    transparent 100%
  );
}

/* ==========================================================================
   Scrollspy Navigation (CSS scroll-target-group + IntersectionObserver fallback)
   ========================================================================== */

.scrollspy-nav {
  scroll-target-group: auto;
}

/* Header navigation links (reserve bold width to prevent any layout shift) */
.header-nav-link {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  color: var(--on-surface-variant);
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.header-nav-link::after {
  content: attr(data-label);
  content: attr(data-label) / "";
  height: 0;
  visibility: hidden;
  overflow: hidden;
  user-select: none;
  pointer-events: none;
  font-weight: 600;
}

.header-nav-link:hover {
  color: var(--on-surface);
}

/* Use :is() so unsupported :target-current does not invalidate the fallback class */
.header-nav-link:is(:target-current, .\:target-current) {
  color: var(--on-surface);
  font-weight: 600;
  border-bottom-color: var(--primary-container);
}

/* Sidebar Table of Contents scrollspy (datenschutz.html) */
.toc-link {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-left: 2px solid rgba(255, 255, 255, 0.08);
  color: var(--on-surface-variant);
  transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.toc-link:hover {
  color: var(--on-surface);
  border-left-color: rgba(190, 24, 93, 0.5);
  background-color: rgba(255, 255, 255, 0.02);
}

.toc-link:is(:target-current, .\:target-current) {
  color: var(--on-surface);
  font-weight: 500;
  border-left-color: var(--primary-container);
  background-color: rgba(190, 24, 93, 0.1);
}

.toc-link:is(:target-current, .\:target-current) .toc-index {
  color: var(--primary);
}

/* ==========================================================================
   Mobile Navigation Drawer (Popover + Scroll Snap + Scroll-Driven Backdrop)
   ========================================================================== */

.Drawer {
  --drawer-width: min(20rem, 84dvw);
  --drawer-backdrop: 0;

  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  background: transparent;
  border: 0;
  overflow: visible;
  z-index: 60;
}

/* Fallback visibility when browser does not support Popover API */
.Drawer.is-fallback-hidden {
  display: none;
}

.Drawer::backdrop {
  background: #050507;
  opacity: calc(var(--drawer-backdrop) * 0.75);
}

.Drawer-scroller {
  position: relative;
  display: grid;
  grid-template-columns: var(--drawer-width) 100%;
  width: 100%;
  height: 100%;
  overflow-x: scroll;
  overflow-y: hidden;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

.Drawer-scroller::-webkit-scrollbar {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .Drawer-scroller {
    scroll-behavior: smooth;
  }
}

.Drawer-scroller::after {
  content: "";
  scroll-snap-align: end;
  scroll-initial-target: nearest;
}

.Drawer-sheet {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100svh;
  background: #131315;
  color: var(--on-surface);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  overflow-y: auto;
  scroll-snap-align: start;
  scrollbar-width: none;
  box-shadow: 16px 0 48px rgba(0, 0, 0, 0.6);
}

.Drawer-sheet::-webkit-scrollbar {
  display: none;
}

.Drawer-sheet:focus {
  outline: none;
}

@supports (animation-timeline: scroll()) {
  .Drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }

  .Drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }

  @property --drawer-backdrop {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
  }

  @keyframes fade-drawer-backdrop {
    0% {
      --drawer-backdrop: 1;
    }
    100% {
      --drawer-backdrop: 0;
    }
  }
}

/* ==========================================================================
   Contact Modal Dialog (<dialog> + :user-invalid Validation)
   ========================================================================== */

.contact-dialog {
  margin: auto;
  padding: 0;
  width: min(36rem, calc(100% - 2rem));
  max-height: calc(100svh - 2rem);
  background: transparent;
  border: 0;
  color: var(--on-surface);
  overflow: visible;
}

.contact-dialog[open] {
  display: flex;
  flex-direction: column;
}

/* Prevent background page scrolling while modal is open */
.contact-dialog:modal {
  overscroll-behavior: contain;
}

.contact-dialog::backdrop {
  background: rgba(5, 5, 7, 0.78);
  backdrop-filter: blur(8px);
  overflow: hidden;
  overscroll-behavior: contain;
}

@media (prefers-reduced-motion: no-preference) {
  .contact-dialog[open] {
    animation: dialog-enter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes dialog-enter {
    from {
      opacity: 0;
      transform: translateY(8px) scale(0.985);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }
}

.contact-dialog-panel {
  max-height: calc(100svh - 2rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Form controls tailored to Obsidian Crimson Precision */
.form-control {
  width: 100%;
  padding: 0.6875rem 0.875rem;
  background: rgba(9, 9, 11, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.25rem;
  color: var(--on-surface);
  font-family: "Geist", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 22px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.form-control::placeholder {
  color: rgba(168, 137, 143, 0.55);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-container);
  box-shadow: 0 0 0 1px var(--primary-container);
}

/* Show validation errors ONLY after user interaction (:user-invalid) */
.form-control:user-invalid {
  border-color: #ffb4ab;
  background-color: rgba(147, 0, 10, 0.18);
}

.form-control:user-invalid:focus {
  border-color: #ffb4ab;
  box-shadow: 0 0 0 1px #ffb4ab;
}

.form-error {
  display: none;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.375rem;
  color: #ffb4ab;
  font-size: 12px;
  line-height: 18px;
}

.form-control:user-invalid + .form-error {
  display: flex;
}

/* Geometric checkbox */
.form-checkbox {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.125rem;
  background: rgba(9, 9, 11, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.125rem;
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.form-checkbox::after {
  content: "";
  width: 0.625rem;
  height: 0.625rem;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: #ffffff;
  transform: scale(0);
  transition: transform 0.12s ease;
}

.form-checkbox:checked {
  background: var(--primary-container);
  border-color: var(--primary-container);
}

.form-checkbox:checked::after {
  transform: scale(1);
}

.form-checkbox:user-invalid {
  border-color: #ffb4ab;
}

.privacy-field:has(.form-checkbox:user-invalid) .form-error {
  display: flex;
}

/* ==========================================================================
   Forced Colors Mode (Windows High Contrast)
   ========================================================================== */

@media (forced-colors: active) {
  .header-nav-link:is(:target-current, .\:target-current),
  .footer-link-active {
    border-bottom: 2px solid Highlight;
    color: LinkText;
  }

  .toc-link:is(:target-current, .\:target-current) {
    border-left: 3px solid Highlight;
  }

  .diagonal-divider {
    background: none;
    border-top: 1px solid CanvasText;
  }

  .monolith-card,
  .contact-dialog-panel,
  .form-control {
    border: 1px solid CanvasText;
  }

  .form-checkbox {
    appearance: auto;
    -webkit-appearance: auto;
  }
}
