:root {
  color-scheme: light;
  --theme-bg: #f8fafc;
  --theme-surface: #ffffff;
  --theme-surface-soft: #eef2ff;
  --theme-surface-muted: #f1f5f9;
  --theme-text: #172033;
  --theme-text-soft: #334155;
  --theme-muted: #64748b;
  --theme-border: #cbd5e1;
  --theme-accent: #0369a1;
  --theme-purple: #7e22ce;
  --theme-pink: #be185d;
  --theme-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --theme-bg: #11112b;
  --theme-surface: #1e1b4b;
  --theme-surface-soft: #312e81;
  --theme-surface-muted: #17163a;
  --theme-text: #f8fafc;
  --theme-text-soft: #e2e8f0;
  --theme-muted: #a8b1c2;
  --theme-border: #4c4a78;
  --theme-accent: #67e8f9;
  --theme-purple: #c084fc;
  --theme-pink: #f9a8d4;
  --theme-shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
}

html {
  background: var(--theme-bg);
  scroll-behavior: smooth;
}

body {
  background-color: var(--theme-bg) !important;
  color: var(--theme-text) !important;
  min-height: 100vh;
  transition: background-color 180ms ease, color 180ms ease;
}

a, button, textarea, details, section, div, nav, footer, header {
  transition-property: color, background-color, border-color, box-shadow, opacity, transform;
  transition-duration: 180ms;
}

html[data-theme="light"] [class*="bg-ai-card"] {
  background-color: var(--theme-surface) !important;
}

html[data-theme="light"] [class*="bg-ai-dark"] {
  background-color: var(--theme-surface-muted) !important;
}

html[data-theme="light"] [class*="from-ai-dark"] {
  --tw-gradient-from: #f8fafc var(--tw-gradient-from-position) !important;
  --tw-gradient-to: rgb(248 250 252 / 0) var(--tw-gradient-to-position) !important;
}

html[data-theme="light"] [class*="to-ai-card"] {
  --tw-gradient-to: #eef2ff var(--tw-gradient-to-position) !important;
}

html[data-theme="light"] [class*="to-ai-card"].bg-gradient-to-br,
html[data-theme="light"] [class*="from-ai-purple"].bg-gradient-to-br {
  background-image: linear-gradient(to bottom right, #faf5ff, #eef2ff) !important;
}

html[data-theme="light"] .bg-gray-900,
html[data-theme="light"] [class*="bg-gray-900/"],
html[data-theme="light"] .bg-gray-800,
html[data-theme="light"] [class*="bg-gray-800/"],
html[data-theme="light"] .bg-black\/50,
html[data-theme="light"] .bg-black\/30 {
  background-color: var(--theme-surface-muted) !important;
}

html[data-theme="light"] .bg-gray-700,
html[data-theme="light"] [class*="hover:bg-gray-700"]:hover {
  background-color: #e2e8f0 !important;
}

html[data-theme="light"] [class*="bg-white/"] {
  background-color: rgba(255, 255, 255, 0.9) !important;
}

html[data-theme="light"] .text-white,
html[data-theme="light"] [class*="text-gray-100"] {
  color: var(--theme-text) !important;
}

html[data-theme="light"] .text-gray-200,
html[data-theme="light"] .text-gray-300 {
  color: var(--theme-text-soft) !important;
}

html[data-theme="light"] .text-gray-400,
html[data-theme="light"] .text-gray-500,
html[data-theme="light"] .placeholder-gray-500::placeholder {
  color: var(--theme-muted) !important;
}

html[data-theme="light"] [class*="text-ai-accent"] {
  color: var(--theme-accent) !important;
}

html[data-theme="light"] [class*="text-ai-purple"] {
  color: var(--theme-purple) !important;
}

html[data-theme="light"] [class*="text-ai-pink"] {
  color: var(--theme-pink) !important;
}

html[data-theme="light"] .text-green-400,
html[data-theme="light"] .text-green-300 {
  color: #047857 !important;
}

html[data-theme="light"] .text-red-400,
html[data-theme="light"] .text-red-300,
html[data-theme="light"] .text-red-200 {
  color: #b91c1c !important;
}

html[data-theme="light"] .text-yellow-400,
html[data-theme="light"] .text-yellow-300 {
  color: #a16207 !important;
}

html[data-theme="light"] [class*="border-white/"],
html[data-theme="light"] .border-gray-600,
html[data-theme="light"] .border-gray-700,
html[data-theme="light"] [class*="border-ai-purple/"] {
  border-color: var(--theme-border) !important;
}

html[data-theme="light"] [class*="divide-gray"] > :not([hidden]) ~ :not([hidden]) {
  border-color: var(--theme-border) !important;
}

html[data-theme="light"] .hover\:text-white:hover {
  color: var(--theme-text) !important;
}

html[data-theme="light"] .hover\:bg-white:hover {
  background-color: #ecfeff !important;
}

.prompt-box {
  background-color: var(--theme-surface-muted) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text-soft) !important;
  padding-top: 3.25rem !important;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.prompt-box code,
.prompt-text {
  color: inherit !important;
  display: block;
}

.copy-btn {
  background-color: var(--theme-text-soft) !important;
  color: var(--theme-surface) !important;
  border: 1px solid transparent;
}

.copy-btn:hover {
  background-color: var(--theme-accent) !important;
  color: white !important;
}

.copy-btn.copied {
  background-color: #047857 !important;
  color: white !important;
}

textarea {
  background: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

textarea::placeholder {
  color: var(--theme-muted) !important;
}

.draft-clear {
  display: block;
  margin: 0.65rem 0 0 auto;
  border: 1px solid var(--theme-border);
  border-radius: 0.65rem;
  background: var(--theme-surface-muted);
  color: var(--theme-text-soft);
  padding: 0.5rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.draft-clear:hover {
  border-color: var(--theme-accent);
  color: var(--theme-accent);
}

.gradient-text {
  background-image: linear-gradient(90deg, #0369a1, #6d28d9, #be185d) !important;
}

html[data-theme="dark"] .gradient-text {
  background-image: linear-gradient(90deg, #67e8f9, #ffffff, #f9a8d4) !important;
}

.theme-toggle {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--theme-border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--theme-surface) 92%, transparent);
  color: var(--theme-text);
  box-shadow: var(--theme-shadow);
  backdrop-filter: blur(14px);
  font: 700 0.82rem/1 system-ui, sans-serif;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--theme-accent);
  transform: translateY(-2px);
}

.theme-toggle:focus-visible,
a:focus-visible,
button:focus-visible,
summary:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--theme-accent) 55%, transparent);
  outline-offset: 3px;
}

.theme-toggle__icon {
  font-size: 1rem;
}

.learning-note {
  border: 1px solid var(--theme-border);
  border-left: 4px solid var(--theme-accent);
  border-radius: 0.9rem;
  background: var(--theme-surface);
  color: var(--theme-text-soft);
  padding: 1rem 1.15rem;
}

.safety-note {
  border: 1px solid color-mix(in srgb, #d97706 42%, var(--theme-border));
  border-left: 4px solid #d97706;
  border-radius: 0.9rem;
  background: color-mix(in srgb, #fef3c7 55%, var(--theme-surface));
  color: #713f12;
  padding: 1rem 1.15rem;
}

html[data-theme="dark"] .safety-note {
  background: rgba(120, 53, 15, 0.28);
  color: #fde68a;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 10001;
  border-radius: 0.5rem;
  background: var(--theme-text);
  color: var(--theme-surface);
  padding: 0.75rem 1rem;
  font-weight: 700;
}

.skip-link:focus {
  top: 1rem;
}

/* Standalone IVC simulator uses its own variable system. */
html[data-theme="light"] {
  --bg-color: #eaf0f8;
  --panel-bg: rgba(255, 255, 255, 0.96);
  --panel-border: #94a3b8;
  --text-main: #172033;
  --text-muted: #52647a;
  --accent-color: #075985;
  --safe-fill: #f1f5f9;
  --safe-stroke: #64748b;
  --btn-fill: #e2e8f0;
  --btn-stroke: #94a3b8;
  --btn-active: #cbd5e1;
  --btn-disabled-fill: #f1f5f9;
  --btn-disabled-stroke: #cbd5e1;
}

html[data-theme="light"] .tab-bar {
  background: rgba(248, 250, 252, 0.94) !important;
}

html[data-theme="light"] .screen:not(#screen-field) {
  background: rgba(248, 250, 252, 0.58) !important;
}

html[data-theme="light"] .risk-card.caution {
  background: rgba(254, 243, 199, 0.92) !important;
  color: #713f12;
}

html[data-theme="light"] .risk-card.danger {
  background: rgba(254, 226, 226, 0.94) !important;
  color: #7f1d1d;
}

@media (max-width: 640px) {
  nav {
    gap: 0.6rem;
    padding: 1rem !important;
  }

  nav > a {
    max-width: 36%;
    font-size: 0.75rem;
  }

  nav > div {
    font-size: 0.9rem !important;
    white-space: nowrap;
  }

  .theme-toggle__label {
    display: none;
  }

  .theme-toggle {
    width: 2.75rem;
    justify-content: center;
    padding-inline: 0;
  }
}

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