/**
 * Gödel Terminal — Base Styles v2.0
 * Award-winning foundation: atmospheric depth, refined interactions.
 *
 * Anti-flicker measures:
 * 1. visibility: hidden on :root until fonts load
 * 2. GPU-accelerated animations with will-change
 * 3. contain: layout for isolated repaints
 */

/* ========== Anti-Flicker: Hide until ready ========== */

:root {
  /* Prevent FOUC - JS removes this class when ready */
  --app-ready: 0;
}

/* ========== Reset ========== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  scroll-behavior: smooth;
  /* Keep focused/anchored content visible below sticky header */
  scroll-padding-top: calc(56px + var(--space-4));
  /* Prevent text size adjustment on orientation change */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Atmospheric background with subtle noise */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--bg-gradient-radial);
  pointer-events: none;
  z-index: var(--z-deep);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.015;
  background-image: var(--bg-noise);
  pointer-events: none;
  z-index: var(--z-deep);
}

/* ========== Typography ========== */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  letter-spacing: var(--tracking-normal);
  color: var(--text-primary);
}

h1 {
  font-size: var(--text-3xl);
  font-weight: var(--font-weight-bold);
}

h2 {
  font-size: var(--text-2xl);
}

h3 {
  font-size: var(--text-xl);
}

h4 {
  font-size: var(--text-lg);
}

p {
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
}

p:last-child {
  margin-bottom: 0;
}

small {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

strong {
  font-weight: var(--font-weight-semibold);
}

/* Monospace for data/numbers */
.mono,
code,
kbd,
samp {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ========== Links ========== */

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--accent-hover);
}

a:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ========== Focus States ========== */

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--accent-primary);
  color: white;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  z-index: 9999;
  transition: top var(--duration-fast) var(--ease-out);
}

.skip-link:focus {
  top: var(--space-4);
}

/* Button focus states */
button:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: var(--radius);
}

/* Input focus states */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ========== Selection ========== */

::selection {
  background-color: rgba(91, 95, 199, 0.3);
  color: var(--text-primary);
}

/* ========== Scrollbar - Refined ========== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  transition: background 0.2s;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.16);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

/* ========== Form Elements ========== */

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* SOTA Generic Dropdowns */
select {
  appearance: none;
  background-color: var(--bg-surface);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A8D98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1em;
  border: 1px solid var(--border-dim);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
  cursor: pointer;
}

select:hover {
  background-color: var(--bg-hover);
  border-color: var(--border);
}

select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ========== Utilities ========== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Text colors */
.text-primary {
  color: var(--text-primary);
}

.text-secondary {
  color: var(--text-secondary);
}

.text-tertiary {
  color: var(--text-tertiary);
}

.text-success {
  color: var(--color-success);
}

.text-danger {
  color: var(--color-danger);
}

.text-warning {
  color: var(--color-warning);
}

.text-accent {
  color: var(--accent-primary);
}

.text-long {
  color: var(--color-long);
}

.text-short {
  color: var(--color-short);
}

/* Font utilities */
.font-display {
  font-family: var(--font-display);
}

.font-sans {
  font-family: var(--font-sans);
}

.font-mono {
  font-family: var(--font-mono);
}

.font-normal {
  font-weight: var(--font-weight-normal);
}

.font-medium {
  font-weight: var(--font-weight-medium);
}

.font-semibold {
  font-weight: var(--font-weight-semibold);
}

.font-bold {
  font-weight: var(--font-weight-bold);
}

/* Tabular numbers for data */
.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* P&L with sign prefix */
.pnl-positive::before {
  content: '+';
}

.pnl-negative::before {
  content: '';
}

/* ========== Glass Card Utility ========== */

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
}

/* ========== Gradient Text ========== */

.gradient-text {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ========== Animations ========== */

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

@keyframes pulse-subtle {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* Value change flash - calm green/red highlight */
@keyframes value-flash-up {
  0% {
    background-color: transparent;
  }

  15% {
    background-color: var(--color-long-bg);
  }

  100% {
    background-color: transparent;
  }
}

@keyframes value-flash-down {
  0% {
    background-color: transparent;
  }

  15% {
    background-color: var(--color-short-bg);
  }

  100% {
    background-color: transparent;
  }
}

/* Gentle glow pulse for active elements */
@keyframes glow-pulse {

  0%,
  100% {
    box-shadow: 0 0 8px var(--color-long-glow);
  }

  50% {
    box-shadow: 0 0 16px var(--color-long-glow), 0 0 24px var(--color-long-glow);
  }
}

/* Ripple effect for touch */
@keyframes ripple {
  0% {
    transform: scale(0);
    opacity: 0.4;
  }

  100% {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* Subtle breathe for live indicators */
@keyframes breathe {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.7;
    transform: scale(0.95);
  }
}

/* Smooth counter tick — 1px shift over 80ms */
@keyframes tick-up {
  0% {
    transform: translateY(1px);
  }

  100% {
    transform: translateY(0);
  }
}

@keyframes tick-down {
  0% {
    transform: translateY(-1px);
  }

  100% {
    transform: translateY(0);
  }
}

/* Card entrance with stagger */
@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Underline grow animation */
@keyframes underline-grow {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

/* Animation utilities */
.animate-fade-in {
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

.animate-fade-in-up {
  animation: fadeInUp var(--duration-slow) var(--ease-out);
}

.animate-scale-in {
  animation: scaleIn var(--duration-normal) var(--ease-out);
}

/* Stagger delays for lists */
.stagger-1 {
  animation-delay: 30ms;
}

.stagger-2 {
  animation-delay: 60ms;
}

.stagger-3 {
  animation-delay: 90ms;
}

.stagger-4 {
  animation-delay: 120ms;
}

.stagger-5 {
  animation-delay: 150ms;
}

.stagger-6 {
  animation-delay: 180ms;
}

.stagger-7 {
  animation-delay: 210ms;
}

.stagger-8 {
  animation-delay: 240ms;
}

/* Value change utilities */
.value-flash-up {
  animation: value-flash-up 600ms var(--ease-out);
}

.value-flash-down {
  animation: value-flash-down 600ms var(--ease-out);
}

.tick-up {
  animation: tick-up 80ms var(--ease-out);
}

.tick-down {
  animation: tick-down 80ms var(--ease-out);
}

/* Live indicator glow */
.glow-live {
  animation: glow-pulse 2s var(--ease-in-out) infinite;
}

.breathe {
  animation: breathe 3s var(--ease-in-out) infinite;
}

/* Card entrance animation */
.animate-card-enter {
  animation: card-enter var(--duration-slow) var(--ease-smooth) backwards;
}

/* ========== Phosphor Flash — CRT amber glow on value updates ========== */

.phosphor-flash {
  text-shadow: var(--phosphor-amber-text);
  transition: text-shadow var(--phosphor-decay) var(--ease-out);
}

.phosphor-idle {
  text-shadow: none;
  transition: text-shadow var(--phosphor-decay) var(--ease-out);
}

/* Scan-in entrance for dashboard sections */
@keyframes scan-in {
  from {
    clip-path: inset(0 100% 0 0);
    opacity: 0.7;
  }

  to {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}

.scan-enter {
  --scan-delay: 0ms;
  animation: scan-in var(--duration-slower) var(--ease-smooth) both;
  animation-delay: var(--scan-delay);
}

/* Touch ripple container */
.ripple-container {
  position: relative;
  overflow: hidden;
}

.ripple-effect {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  animation: ripple 500ms var(--ease-out);
}

/* Smooth transitions for interactive elements */
.transition-transform {
  transition: transform var(--duration-fast) var(--ease-out);
}

.transition-all {
  transition: all var(--duration-normal) var(--ease-out);
}

.transition-colors {
  transition: color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

/* Hover lift effect */
.hover-lift {
  transition: transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Active press effect */
.active-press:active {
  transform: scale(0.98);
}

/* ========== Performance: GPU Acceleration & Containment ========== */

/* GPU-accelerated elements - prevent layout thrashing */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Layout containment for isolated repaints */
.contain-layout {
  contain: layout;
}

.contain-paint {
  contain: paint;
}

.contain-strict {
  contain: strict;
}

/* Prevent content shift during animations */
.stable-height {
  min-height: var(--stable-height, auto);
}

/* ========== Anti-Flicker: Smooth Mounting ========== */

/* Cards and panels should fade in, not pop */
[data-mounted="false"] {
  opacity: 0;
}

[data-mounted="true"] {
  opacity: 1;
  transition: opacity var(--duration-normal) var(--ease-out);
}

/* Prevent animation on initial load */
.no-transition {
  transition: none !important;
}

/* Applied briefly during page load to prevent animation flash */
.loading * {
  animation-duration: 0s !important;
  transition-duration: 0s !important;
}

/* ========== Smooth Value Updates ========== */

/* For numbers that change frequently - prevent layout shift */
.value-stable {
  display: inline-block;
  min-width: var(--value-width, 4ch);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Prevent text from causing reflows */
.text-nowrap {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== Spacing Utilities ========== */

.gap-0 {
  gap: 0;
}

.gap-1 {
  gap: var(--space-1);
}

.gap-2 {
  gap: var(--space-2);
}

.gap-3 {
  gap: var(--space-3);
}

.gap-4 {
  gap: var(--space-4);
}

.gap-5 {
  gap: var(--space-5);
}

.gap-6 {
  gap: var(--space-6);
}

.p-0 {
  padding: 0;
}

.p-1 {
  padding: var(--space-1);
}

.p-2 {
  padding: var(--space-2);
}

.p-3 {
  padding: var(--space-3);
}

.p-4 {
  padding: var(--space-4);
}

.p-5 {
  padding: var(--space-5);
}

.p-6 {
  padding: var(--space-6);
}

.m-0 {
  margin: 0;
}

.mt-1 {
  margin-top: var(--space-1);
}

.mt-2 {
  margin-top: var(--space-2);
}

.mt-3 {
  margin-top: var(--space-3);
}

.mt-4 {
  margin-top: var(--space-4);
}

.mt-5 {
  margin-top: var(--space-5);
}

.mt-6 {
  margin-top: var(--space-6);
}

.mb-1 {
  margin-bottom: var(--space-1);
}

.mb-2 {
  margin-bottom: var(--space-2);
}

.mb-3 {
  margin-bottom: var(--space-3);
}

.mb-4 {
  margin-bottom: var(--space-4);
}

.mb-5 {
  margin-bottom: var(--space-5);
}

.mb-6 {
  margin-bottom: var(--space-6);
}

/* ========== Flexbox Utilities ========== */

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-row {
  flex-direction: row;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
}

.flex-none {
  flex: none;
}

.flex-shrink-0 {
  flex-shrink: 0;
}

.items-start {
  align-items: flex-start;
}

.items-center {
  align-items: center;
}

.items-end {
  align-items: flex-end;
}

.items-baseline {
  align-items: baseline;
}

.justify-start {
  justify-content: flex-start;
}

.justify-center {
  justify-content: center;
}

.justify-end {
  justify-content: flex-end;
}

.justify-between {
  justify-content: space-between;
}

/* ========== Grid Utilities ========== */

.grid {
  display: grid;
}

.grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* ========== Border Utilities ========== */

.border {
  border: 1px solid var(--border);
}

.border-dim {
  border: 1px solid var(--border-dim);
}

.border-bright {
  border: 1px solid var(--border-bright);
}

.border-t {
  border-top: 1px solid var(--border-dim);
}

.border-b {
  border-bottom: 1px solid var(--border-dim);
}

.rounded {
  border-radius: var(--radius);
}

.rounded-lg {
  border-radius: var(--radius-lg);
}

.rounded-xl {
  border-radius: var(--radius-xl);
}

.rounded-full {
  border-radius: var(--radius-full);
}

/* ========== Width/Height ========== */

.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

.min-w-0 {
  min-width: 0;
}

.min-h-0 {
  min-height: 0;
}

/* ========== Overflow ========== */

.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}

.overflow-y-auto {
  overflow-y: auto;
}

/* ========== Visibility ========== */

.hidden {
  display: none;
}

.invisible {
  visibility: hidden;
}

.visible {
  visibility: visible;
}

/* ========== Opacity ========== */

.opacity-0 {
  opacity: 0;
}

.opacity-50 {
  opacity: 0.5;
}

.opacity-75 {
  opacity: 0.75;
}

.opacity-100 {
  opacity: 1;
}

/* ========== Cursor ========== */

.cursor-pointer {
  cursor: pointer;
}

.cursor-default {
  cursor: default;
}

.cursor-not-allowed {
  cursor: not-allowed;
}

/* ========== Print Styles ========== */

@media print {

  body::before,
  body::after {
    display: none;
  }
}

/* ========== Reduced Motion ========== */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
