@tailwind base;
@tailwind components;
@tailwind utilities;

/* Prevent horizontal scroll on mobile */
html,
body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* System sans-serif for headings & UI labels (keeps mono for code/content) */
:root {
  --font-sans:
    "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
}

/* Theme CSS variables */
:root,
.dark {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #21262d;
  --surface-2: #1c2129;
  --surface-inset: #010409;
  --border: #30363d;
  --border-subtle: rgba(48, 54, 61, 0.5);
  --text: #c9d1d9;
  --dim: #8b949e;
  --dimmer: #7d8590;

  --green: #3fb950;
  --green-subtle: rgba(63, 185, 80, 0.15);
  --green-emphasis: rgba(63, 185, 80, 0.25);

  --blue: #79b8ff;
  --blue-subtle: rgba(121, 184, 255, 0.15);
  --blue-emphasis: rgba(121, 184, 255, 0.25);

  --orange: #d29922;
  --orange-subtle: rgba(210, 153, 34, 0.15);
  --orange-emphasis: rgba(210, 153, 34, 0.25);

  /* Warm siblings of orange — used to tell the Claude family apart
     (Code = orange, Cowork = sienna, Desktop = yellow). */
  --sienna: #e07a3e;
  --sienna-subtle: rgba(224, 122, 62, 0.15);
  --sienna-emphasis: rgba(224, 122, 62, 0.25);

  --yellow: #f0cb35;
  --yellow-subtle: rgba(240, 203, 53, 0.15);
  --yellow-emphasis: rgba(240, 203, 53, 0.25);

  --red: #f85149;
  --red-subtle: rgba(248, 81, 73, 0.15);
  --red-emphasis: rgba(248, 81, 73, 0.25);

  --purple: #b392f0;
  --purple-subtle: rgba(179, 146, 240, 0.15);
  --purple-emphasis: rgba(179, 146, 240, 0.25);

  --cyan: #56d4dd;
  --cyan-subtle: rgba(86, 212, 221, 0.15);
  --cyan-emphasis: rgba(86, 212, 221, 0.25);

  /* Layered shadow color (hue-matched to dark bg) */
  --shadow-color: 215 28% 4%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.5);
  --shadow-md: 0 1px 2px hsl(var(--shadow-color) / 0.4), 0 4px 8px hsl(var(--shadow-color) / 0.3);
  --shadow-lg:
    0 1px 3px hsl(var(--shadow-color) / 0.4), 0 4px 8px hsl(var(--shadow-color) / 0.3),
    0 12px 24px hsl(var(--shadow-color) / 0.25);
  --shadow-xl:
    0 2px 4px hsl(var(--shadow-color) / 0.4), 0 8px 16px hsl(var(--shadow-color) / 0.3),
    0 24px 48px hsl(var(--shadow-color) / 0.25);
  --surface-subtle-glass: rgba(13, 17, 23, 0.7);
}

.light {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-hover: #e6edf3;
  --surface-2: #ebeef1;
  --surface-inset: #f0f2f5;
  --border: #d0d7de;
  --border-subtle: rgba(208, 215, 222, 0.5);
  --text: #24292f;
  --dim: #57606a;
  --dimmer: #697078;

  --green: #1a7f37;
  --green-subtle: rgba(26, 127, 55, 0.1);
  --green-emphasis: rgba(26, 127, 55, 0.2);

  --blue: #0969da;
  --blue-subtle: rgba(9, 105, 218, 0.1);
  --blue-emphasis: rgba(9, 105, 218, 0.2);

  --orange: #9a6700;
  --orange-subtle: rgba(154, 103, 0, 0.1);
  --orange-emphasis: rgba(154, 103, 0, 0.2);

  /* Warm siblings of orange — Claude family differentiation (see dark block). */
  --sienna: #b8501f;
  --sienna-subtle: rgba(184, 80, 31, 0.1);
  --sienna-emphasis: rgba(184, 80, 31, 0.2);

  --yellow: #9e7700;
  --yellow-subtle: rgba(158, 119, 0, 0.1);
  --yellow-emphasis: rgba(158, 119, 0, 0.2);

  --red: #cf222e;
  --red-subtle: rgba(207, 34, 46, 0.1);
  --red-emphasis: rgba(207, 34, 46, 0.2);

  --purple: #8250df;
  --purple-subtle: rgba(130, 80, 223, 0.1);
  --purple-emphasis: rgba(130, 80, 223, 0.2);

  --cyan: #0e7c86;
  --cyan-subtle: rgba(14, 124, 134, 0.1);
  --cyan-emphasis: rgba(14, 124, 134, 0.2);

  /* Layered shadow color (warm gray for light mode) */
  --shadow-color: 220 10% 50%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.1);
  --shadow-md: 0 1px 2px hsl(var(--shadow-color) / 0.08), 0 4px 8px hsl(var(--shadow-color) / 0.06);
  --shadow-lg:
    0 1px 3px hsl(var(--shadow-color) / 0.08), 0 4px 8px hsl(var(--shadow-color) / 0.06),
    0 12px 24px hsl(var(--shadow-color) / 0.05);
  --shadow-xl:
    0 2px 4px hsl(var(--shadow-color) / 0.08), 0 8px 16px hsl(var(--shadow-color) / 0.06),
    0 24px 48px hsl(var(--shadow-color) / 0.05);
  --surface-subtle-glass: rgba(255, 255, 255, 0.75);
}

/* Smooth theme transition — scoped to avoid interfering with animations */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease;
}

@layer base {
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--bg);
  }
  ::-webkit-scrollbar {
    width: 6px;
  }
  ::-webkit-scrollbar-track {
    background: var(--bg);
  }
  ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
  }
  /* Tabular numbers globally for monospace-feel numeric displays */
  .tabular-nums {
    font-variant-numeric: tabular-nums;
  }
}

@layer components {
  /*
   * Shared UI typography primitives.
   *
   * Keep monospace for code, commands, slugs, paths, models, and numbers.
   * Use these sans-serif classes for chrome, status labels, section titles,
   * and explanatory copy so dense screens keep a clearer reading hierarchy.
   */
  .ui-section-title {
    @apply font-sans text-xs font-semibold tracking-wide text-terminal-dim;
  }

  .ui-section-title-strong {
    @apply font-sans text-xs font-semibold tracking-wide text-terminal-text;
  }

  .ui-caption {
    @apply font-sans text-xs leading-relaxed text-terminal-dim;
  }

  .ui-caption-muted {
    @apply font-sans text-xs leading-relaxed text-terminal-dimmer;
  }

  .ui-caption-strong {
    @apply font-sans text-xs font-medium leading-relaxed text-terminal-text;
  }

  .ui-pill {
    @apply inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-xs font-sans leading-5;
  }

  .ui-pill-compact {
    @apply inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[11px] font-sans leading-4;
  }
}

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

/* Mobile interaction improvements */
button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

/* Focus-visible for keyboard accessibility */
:focus:not(:focus-visible) {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Safe area insets for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  .safe-top {
    padding-top: max(env(safe-area-inset-top), 1.25rem);
  }
  .safe-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.typing-cursor::after {
  content: "\2588";
  animation: blink 1s step-end infinite;
  color: var(--green);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.scene-enter {
  animation: fade-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Pause overlay */
@keyframes pulse-border {
  0%,
  100% {
    border-color: rgba(210, 153, 34, 0.3);
  }
  50% {
    border-color: rgba(210, 153, 34, 0.6);
  }
}

.pause-overlay {
  animation: pulse-border 2s ease-in-out infinite;
}

/* Flash target card after outline/timeline/search jump */
@keyframes jump-target-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(63, 185, 80, 0);
    outline-color: rgba(63, 185, 80, 0);
  }
  30% {
    box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.25);
    outline-color: rgba(63, 185, 80, 0.6);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(63, 185, 80, 0);
    outline-color: rgba(63, 185, 80, 0);
  }
}

.jump-target-flash {
  outline: 1px solid transparent;
  animation: jump-target-flash 0.85s ease-out;
}

@keyframes nav-focus-pulse {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-1px);
  }
}

.scene-nav-focused {
  animation: nav-focus-pulse 0.9s ease-in-out 2;
}

/* Lightweight sticky turn context; keep it stable during fast scrolling. */
.turn-sticky-summary {
  background-color: var(--surface);
  background-image: linear-gradient(var(--green-subtle), var(--green-subtle));
}

/* Landing page start button pulse */
@keyframes landing-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(63, 185, 80, 0);
  }
  50% {
    box-shadow: 0 0 20px 2px rgba(63, 185, 80, 0.15);
  }
}
.landing-pulse {
  animation: landing-glow 2.5s ease-in-out infinite;
}

/* Instant tooltip (no delay, pure CSS) */
.instant-tooltip {
  position: relative;
}
.instant-tooltip .instant-tooltip-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font:
    11px / 1.4 var(--font-sans),
    monospace;
  text-transform: none;
  letter-spacing: normal;
  white-space: pre-line;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.08s ease;
}
.instant-tooltip:hover .instant-tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* Hover lift for interactive cards */
.hover-lift {
  transition:
    transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    box-shadow 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    background-color 0.2s ease;
}
.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Glassmorphism utility */
.glass-effect {
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  background-color: var(--surface-subtle-glass);
}

/* Premium card with subtle gradient border */
.premium-card {
  position: relative;
}

.premium-card::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--green-subtle), var(--blue-subtle));
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.5;
}

/* Skeleton Loading Animation */
@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-hover) 50%,
    var(--surface-2) 75%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 4px;
}

/* Subtle dot-grid background for premium texture */
.bg-dot-grid {
  background-image: radial-gradient(circle, var(--text) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.03;
}

/* Minimap */
.minimap-item {
  transition:
    background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Markdown prose styles */
.prose-terminal {
  line-height: 1.6;
}
.prose-terminal p {
  margin: 0.5em 0;
}
.prose-terminal code {
  background: var(--surface);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}
.prose-terminal pre {
  background: var(--surface);
  padding: 0.75em 1em;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.prose-terminal pre code {
  background: none;
  padding: 0;
}
.prose-terminal ul,
.prose-terminal ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}
.prose-terminal li {
  margin: 0.25em 0;
}
.prose-terminal h1,
.prose-terminal h2,
.prose-terminal h3 {
  margin: 0.75em 0 0.5em;
  font-weight: 600;
}
.prose-terminal blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1em;
  color: var(--dim);
  margin: 0.5em 0;
}
.prose-terminal a {
  color: var(--blue);
  text-decoration: underline;
}
.prose-terminal table {
  border-collapse: collapse;
  margin: 0.5em 0;
}
.prose-terminal th,
.prose-terminal td {
  border: 1px solid var(--border);
  padding: 0.4em 0.8em;
}
