:root {
  --color-bg: #dfe8f3;
  --color-surface: #e8eef6;
  --color-text: #172033;
  --color-muted: #4b5872;
  --color-brand: #1d4ed8;
  --color-brand-strong: #123a9c;
  --color-accent: #b45309;
  --color-success: #047857;
  --color-focus: #ffb703;
  --color-focus-outer: #111827;
  --color-selection-bg: #1d4ed8;
  --color-selection-text: #ffffff;
  --scrollbar-track: #d7e2ee;
  --scrollbar-thumb: #64748b;
  --scrollbar-thumb-hover: #334155;
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Manrope", "Inter", system-ui, sans-serif;
  --radius-sm: 0.75rem;
  --radius-md: 1rem;
  --radius-lg: 1.5rem;
  --radius-xl: 2rem;
  --radius-full: 9999px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --shadow-focus: 0 0 0 3px var(--color-focus), 0 0 0 6px var(--color-focus-outer);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body,
button,
input,
textarea,
select {
  font: inherit;
}

body::-webkit-scrollbar {
  width: 0.875rem;
}

body::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

body::-webkit-scrollbar-thumb {
  min-height: 3rem;
  border: 0.25rem solid var(--scrollbar-track);
  border-radius: var(--radius-full);
  background: var(--scrollbar-thumb);
}

body::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

::selection {
  background: var(--color-selection-bg);
  color: var(--color-selection-text);
  text-shadow: none;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 4px;
  box-shadow: var(--shadow-focus);
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
a,
label,
li {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

a {
  color: var(--color-brand-strong);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

img,
video,
canvas,
iframe {
  display: block;
  max-width: 100%;
  height: auto;
}

iframe {
  border: 0;
}

button,
input,
select,
textarea {
  max-width: 100%;
}

.hidden {
  display: none !important;
}

/* === Components, Animations & UX Defenses === */

#appShell::before,
#appShell::after {
  content: "";
  position: fixed;
  inset: auto;
  z-index: 1;
  pointer-events: none;
  border-radius: 9999px;
  filter: blur(54px);
  opacity: .55;
  animation: floatGlow 9s ease-in-out infinite;
}

#appShell::before {
  width: 22rem;
  height: 22rem;
  left: -8rem;
  top: 8rem;
  background: radial-gradient(circle, rgba(29,78,216,.42), rgba(125,211,252,.18) 48%, transparent 72%);
}

#appShell::after {
  width: 24rem;
  height: 24rem;
  right: -9rem;
  bottom: 4rem;
  background: radial-gradient(circle, rgba(180,83,9,.36), rgba(251,191,36,.16) 48%, transparent 72%);
  animation-delay: -3s;
}

#mainContent,
#heroGrid {
  position: relative;
  z-index: 2;
}

#temperatureStage,
#converterPanel,
#historyPanel,
#insightPanel,
#controlPanel {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

#temperatureStage::before,
#converterPanel::before,
#historyPanel::before,
#insightPanel::before,
#controlPanel::before {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: -1;
  pointer-events: none;
  border-radius: inherit;
  background:
    linear-gradient(135deg, rgba(255,255,255,.62), rgba(255,255,255,.1) 38%, rgba(29,78,216,.08) 68%, rgba(180,83,9,.08)),
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.72), transparent 32%);
}

#resultHalo > div {
  position: relative;
}

#resultHalo > div::before {
  content: "";
  position: absolute;
  inset: -1.25rem;
  z-index: -1;
  pointer-events: none;
  border-radius: inherit;
  background: conic-gradient(from 140deg, rgba(29,78,216,.08), rgba(4,120,87,.34), rgba(180,83,9,.26), rgba(29,78,216,.08));
  filter: blur(18px);
  opacity: .9;
  animation: spinSoft 14s linear infinite;
}

#resultHalo > div::after {
  content: "";
  position: absolute;
  inset: 10%;
  pointer-events: none;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 12%, rgba(255,255,255,.65), transparent 28%);
  mix-blend-mode: screen;
}

#fahrenheitResult {
  text-shadow: 0 .28rem 1.2rem rgba(29,78,216,.16), 0 .08rem 0 rgba(255,255,255,.55);
  animation: fadeScale .6s cubic-bezier(.2,.8,.2,1) both;
}

#comfortBadge {
  box-shadow: 0 .75rem 1.5rem rgba(4,120,87,.22), inset 0 1px 0 rgba(255,255,255,.35);
}

#themeToggleButton,
button,
[role="button"],
a {
  cursor: pointer;
  touch-action: manipulation;
}

button,
[role="button"],
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
[role="button"],
a {
  transition-property: transform, box-shadow, background-color, color, border-color, opacity, filter;
  transition-duration: .22s;
  transition-timing-function: cubic-bezier(.2,.8,.2,1);
}

button:hover,
[role="button"]:hover,
a:hover {
  transform: translateY(-2px);
  filter: saturate(1.05);
}

button:active,
[role="button"]:active,
a:active {
  transform: translateY(1px) scale(.97);
}

#celsiusInput,
#precisionRange,
input[type="number"],
input[type="text"] {
  transition: box-shadow .24s ease, transform .24s ease, background-color .24s ease;
}

#celsiusInput:focus,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  transform: translateY(-1px);
}

input[type="range"] {
  cursor: pointer;
  accent-color: #1d4ed8;
}

input[type="range"]::-webkit-slider-thumb {
  cursor: grab;
  filter: drop-shadow(0 .35rem .55rem rgba(29,78,216,.28));
}

input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
}

#quickStats > *,
.history-item,
[data-history-item],
.conversion-history li {
  position: relative;
  overflow: hidden;
  animation: slideUp .55s cubic-bezier(.2,.8,.2,1) both;
}

#quickStats > *::after,
.history-item::after,
[data-history-item]::after,
.conversion-history li::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 0%, rgba(255,255,255,.35) 45%, transparent 62%);
  transform: translateX(-130%);
  transition: transform .8s cubic-bezier(.2,.8,.2,1);
}

#quickStats > *:hover::after,
.history-item:hover::after,
[data-history-item]:hover::after,
.conversion-history li:hover::after {
  transform: translateX(130%);
}

#brandHeader {
  z-index: 20;
}

.floating-action,
[data-floating],
#themeToggleButton {
  position: relative;
  z-index: 30;
}

.overlay,
.backdrop,
.modal-backdrop,
.dialog-backdrop,
[data-overlay],
[data-backdrop] {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}

.overlay.is-active,
.backdrop.is-active,
.modal-backdrop.is-active,
.dialog-backdrop.is-active,
[data-overlay].is-active,
[data-backdrop].is-active,
[aria-hidden="false"][data-overlay],
[aria-hidden="false"][data-backdrop] {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}

.modal,
.dialog,
[role="dialog"],
[data-modal] {
  z-index: 45;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(1rem) scale(.98);
  transition: opacity .25s ease, visibility .25s ease, transform .25s cubic-bezier(.2,.8,.2,1);
}

.modal.is-active,
.dialog.is-active,
[role="dialog"][aria-modal="true"],
[data-modal].is-active {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.toast,
[role="status"],
[data-toast] {
  z-index: 9999 !important;
  pointer-events: none;
}

.toast.is-active,
[data-toast].is-active {
  pointer-events: auto;
}

.skeleton,
[data-skeleton] {
  position: relative;
  overflow: hidden;
  color: transparent !important;
  background: rgba(255,255,255,.28);
}

.skeleton::after,
[data-skeleton]::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  animation: skeletonWave 1.35s ease-in-out infinite;
}

.fade-in {
  animation: fadeIn .45s ease both;
}

.slide-up {
  animation: slideUp .55s cubic-bezier(.2,.8,.2,1) both;
}

.scale-bounce {
  animation: scaleBounce .55s cubic-bezier(.18,.89,.32,1.28) both;
}

.dark #appShell::before {
  background: radial-gradient(circle, rgba(96,165,250,.28), rgba(29,78,216,.14) 48%, transparent 72%);
}

.dark #appShell::after {
  background: radial-gradient(circle, rgba(251,146,60,.2), rgba(180,83,9,.12) 48%, transparent 72%);
}

.dark #temperatureStage::before,
.dark #converterPanel::before,
.dark #historyPanel::before,
.dark #insightPanel::before,
.dark #controlPanel::before {
  background:
    linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.025) 36%, rgba(96,165,250,.08) 68%, rgba(251,146,60,.06)),
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.12), transparent 34%);
}

.dark #resultHalo > div::before {
  background: conic-gradient(from 140deg, rgba(96,165,250,.12), rgba(52,211,153,.22), rgba(251,146,60,.18), rgba(96,165,250,.12));
}

.dark #fahrenheitResult {
  text-shadow: 0 .32rem 1.35rem rgba(96,165,250,.26);
}

.dark #comfortBadge {
  box-shadow: 0 .75rem 1.5rem rgba(52,211,153,.14), inset 0 1px 0 rgba(255,255,255,.2);
}

.dark input[type="range"] {
  accent-color: #93c5fd;
}

.dark .skeleton,
.dark [data-skeleton] {
  background: rgba(255,255,255,.08);
}

.dark .skeleton::after,
.dark [data-skeleton]::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.14), transparent);
}

@keyframes skeletonWave {
  to { transform: translateX(100%); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeScale {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes scaleBounce {
  0% { opacity: 0; transform: scale(.88); }
  65% { opacity: 1; transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes spinSoft {
  to { transform: rotate(360deg); }
}

@keyframes floatGlow {
  0%, 100% { transform: translate3d(0,0,0) scale(1); }
  50% { transform: translate3d(1.5rem,-1rem,0) scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}