/* =========================================
   THEME VARIABLES
========================================= */
:root {
  --bg: #0a0810;
  --fg: #e9e6ff;
  --accent: #b19cff;
  --accent-glow: rgba(177, 156, 255, 0.35);
  --grad-1: #120d1d;
  --grad-2: #07060c;
}

[data-theme="light"] {
  --bg: #ffffff;
  --fg: #161616;
  --accent: #4b2fff;
  --accent-glow: rgba(75, 47, 255, 0.75);
  --grad-1: #ffffff;
  --grad-2: #dcdcff;
}

/* =========================================
   BASE THEME APPLICATION
========================================= */
html, body {
  color: var(--fg);
}

body {
  background: radial-gradient(
    1200px 800px at 80% 20%,
    var(--grad-1) 0%,
    var(--bg) 45%,
    var(--grad-2) 100%
  );
  transition: background 0.6s ease, color 0.4s ease;
}

/* =========================================
   VIEW TRANSITIONS
========================================= */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-new(root) {
  clip-path: circle(0 at var(--reveal-x) var(--reveal-y));
  animation: themeReveal 700ms cubic-bezier(.65,0,.35,1) forwards;
}

@keyframes themeReveal {
  to { clip-path: circle(150vmax at var(--reveal-x) var(--reveal-y)); }
}

/* =========================================
   THEME TOGGLE
========================================= */
#theme-toggle {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 999;
  perspective: 600px;
  transition: transform 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#theme-toggle:not(.flipping):hover {
  transform: rotate(15deg);
}

@media (hover: none) {
  #theme-toggle:not(.flipping):hover {
    transform: none;
  }
}

#theme-toggle.flipping {
  pointer-events: none;
}

#theme-icon {
  width: 28px;
  height: 28px;
  display: block;
  backface-visibility: hidden;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  transition:
    transform 0.6s cubic-bezier(.4,0,.2,1),
    opacity 0.25s ease,
    filter 0.25s ease;
}

#theme-toggle.flipping #theme-icon {
  transform: rotateY(180deg);
}

#theme-toggle.ghost #theme-icon {
  opacity: 0.85;
  filter: drop-shadow(0 0 14px var(--accent-glow)) blur(0.6px);
}

@media (max-width: 600px) {
  #theme-toggle { width: 44px; height: 44px; top: 0.75rem; right: 0.75rem; }
  #theme-icon { width: 26px; height: 26px; margin: auto; }
}

@media (max-width: 480px) {
  #theme-toggle { width: 40px; height: 40px; right: 1rem; top: env(safe-area-inset-top, 0.5rem); }
  #theme-icon { width: 22px; height: 22px; }
}

/* =========================================
   LINK SYSTEM
========================================= */
a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  position: relative;
  transition:
    color 0.25s ease,
    text-shadow 0.25s ease,
    transform 0.15s ease,
    opacity 0.2s ease;
}

a.underline::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -3px;
  width: 0%;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  transition: width 0.3s ease;
}

a:hover { text-shadow: 0 0 8px var(--accent-glow); }
a:hover::after { width: 100%; }
a:active { transform: scale(0.96); opacity: 0.8; }
a:visited { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}