/* Core KOB Global Theme & Animation Styles */

:root {
  color-scheme: dark;
  --scrollbar-track: #121013;
  --scrollbar-thumb: #3f3f46;
  --scrollbar-thumb-hover: #71717a;

  --font-display: 'Press Start 2P', 'Fraunces', Georgia, serif;
  --font-heading: var(--font-display);
  --font-mono: 'Courier Prime', 'Courier New', monospace;
  --font-hand: 'Caveat', cursive;
  --font-digital: 'VT323', monospace;

  /* 80s Retro CRT Palette */
  --bg-primary: #121013;
  --bg-secondary: #1a161f;
  --bg-surface: #241e2b;
  --bg-paper: #fbf7ec;
  --bg-cork: #b47a46;
  --text-main: #f5f2eb;
  --text-muted: #a8a0b2;
  --text-dark: #1e1b18;

  --accent-amber: #f59e0b;
  --accent-neon-green: #22c55e;
  --accent-neon-cyan: #06b6d4;
  --accent-crimson: #e11d48;
  --border-wood: #78350f;
  --border-neon: rgba(34, 197, 94, 0.4);

  --shadow-retro: 0 4px 14px rgba(0, 0, 0, 0.6);
  --crt-glow: 0 0 12px rgba(34, 197, 94, 0.35);
}

[data-theme="rpg8bit"] {
  color-scheme: dark;
  --scrollbar-track: #050718;
  --scrollbar-thumb: #1e3a8a;
  --scrollbar-thumb-hover: #3b82f6;

  --font-display: 'Press Start 2P', monospace;
  --font-heading: var(--font-display);
  --font-mono: 'Courier Prime', 'Courier New', monospace;
  --font-digital: 'VT323', monospace;

  /* SNES 16-Bit JRPG Palette */
  --bg-primary: #050718;
  --bg-secondary: #000c44;
  --bg-surface: #001566;
  --bg-paper: #000829;
  --bg-cork: #000829;
  --text-main: #ffffff;
  --text-muted: #93c5fd;
  --text-dark: #000824;

  --accent-amber: #f8d870;
  --accent-gold: #f8d870;
  --accent-neon-green: #4ade80;
  --accent-neon-cyan: #38bdf8;
  --accent-crimson: #f43f5e;
  --border-wood: #1e3a8a;
  --border-neon: rgba(96, 165, 250, 0.5);

  --snes-blue-grad: linear-gradient(180deg, #00249c 0%, #001566 55%, #000b3b 100%);
  --snes-window-border: 3px solid #f8fafc;
  --snes-window-shadow: inset 0 0 0 2px #000b3b, inset 0 0 0 4px #60a5fa, 4px 4px 0 #000312;
  --snes-hero-border: 3px solid #f8d870;
  --snes-hero-shadow: inset 0 0 0 2px #000b3b, inset 0 0 0 4px #d97706, 4px 4px 0 #000312;
  --snes-well-bg: #000829;
  --snes-well-border: 2px solid #3b5bdb;

  --shadow-retro: 4px 4px 0 #000312;
  --crt-glow: 0 0 8px rgba(96, 165, 250, 0.4);
}

[data-theme="rpg8bit"] h1,
[data-theme="rpg8bit"] h2,
[data-theme="rpg8bit"] h3,
[data-theme="rpg8bit"] .jrpg-title {
  font-family: 'Press Start 2P', var(--font-display), monospace;
  color: #f8d870;
  text-shadow: 2px 2px 0 #000418;
  line-height: 1.4;
}

[data-theme="studio"] {
  color-scheme: light;
  --scrollbar-track: #f1f5f9;
  --scrollbar-thumb: #94a3b8;
  --scrollbar-thumb-hover: #64748b;

  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-paper: #ffffff;
  --bg-cork: #d1d5db;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dark: #0f172a;

  --accent-amber: #d97706;
  --accent-neon-green: #15803d;
  --accent-neon-cyan: #0284c7;
  --accent-crimson: #be123c;
  --border-wood: #94a3b8;
  --border-neon: #cbd5e1;

  --shadow-retro: 0 4px 12px rgba(0, 0, 0, 0.08);
  --crt-glow: none;
}

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

/* Modern Cross-Browser Scrollbars */
:root, html, body, * {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

@supports not (scrollbar-color: auto) {
  *::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  *::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
  *::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
  }
  *::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
  }
  *::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
  }
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
}

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

/* App Shell Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

/* CRT Scanlines and Retro Screen Effects */
.crt-scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    rgba(18, 16, 19, 0) 50%,
    rgba(0, 0, 0, 0.14) 50%
  );
  background-size: 100% 4px;
  z-index: 9990;
  opacity: 0.16;
}

[data-theme="rpg8bit"] .crt-scanlines {
  opacity: 0.08;
}

.crt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at center,
    transparent 60%,
    rgba(0, 0, 0, 0.7) 100%
  );
  z-index: 9991;
}

[data-theme="rpg8bit"] ~ .crt-vignette,
body:has([data-theme="rpg8bit"]) .crt-vignette,
[data-theme="rpg8bit"] .crt-vignette,
html[data-theme="rpg8bit"] .crt-vignette,
body[data-theme="rpg8bit"] .crt-vignette {
  opacity: 0.22;
}

/* Transition Overlays */
#crt-transition-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
}

#crt-transition-overlay.crt-glitch-active {
  animation: crtGlitch 0.4s ease-out forwards;
}

#crt-transition-overlay.film-burn-active {
  animation: filmBurn 0.6s ease-in-out forwards;
}

@keyframes crtGlitch {
  0% { opacity: 0.9; background: #fff; filter: invert(1); }
  25% { opacity: 0.8; background: #10b981; transform: scale(1.02) skewX(2deg); }
  50% { opacity: 0.7; background: #000; transform: scale(0.98) skewX(-2deg); }
  75% { opacity: 0.5; background: #ef4444; }
  100% { opacity: 0; }
}

@keyframes filmBurn {
  0% { opacity: 0; background: radial-gradient(circle, #ffedd5 0%, #ea580c 50%, #7c2d12 100%); }
  40% { opacity: 0.85; filter: contrast(180%) brightness(140%); }
  80% { opacity: 0.4; }
  100% { opacity: 0; }
}

/* Thematic Surfaces */
.notebook-surface {
  color-scheme: light;
  background: var(--bg-paper);
  color: var(--text-dark);
  font-family: var(--font-hand);
  padding: 1.5rem;
  border-radius: 4px;
  box-shadow: 2px 3px 10px rgba(0, 0, 0, 0.25);
  border-left: 12px solid #ef4444;
}

.notebook-paper {
  color-scheme: light;
  background: repeating-linear-gradient(
    transparent,
    transparent 27px,
    #93c5fd 28px
  );
  line-height: 28px;
}

.corkboard-surface {
  background: var(--bg-cork);
  background-image: radial-gradient(#92400e 1px, transparent 1px);
  background-size: 16px 16px;
  border: 12px solid #5c2c16;
  border-radius: 8px;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
  position: relative;
}

.vhs-card {
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 6px;
  padding: 1rem;
  color: #fafafa;
  box-shadow: var(--shadow-retro);
}

.polaroid-frame {
  color-scheme: light;
  background: #ffffff;
  padding: 0.75rem 0.75rem 2rem 0.75rem;
  border-radius: 2px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  color: #18181b;
  font-family: var(--font-hand);
  text-align: center;
}

.cassette-log {
  background: #27272a;
  border: 2px solid #52525b;
  border-radius: 8px;
  padding: 0.75rem;
  font-family: var(--font-digital);
  letter-spacing: 1px;
}

.boombox-sidebar {
  background: #1c1917;
  border-right: 2px solid #44403c;
  padding: 1rem;
}

.manila-folder {
  color-scheme: light;
  background: #fef3c7;
  color: #451a03;
  border-radius: 4px;
  border: 1px solid #d97706;
  padding: 1rem;
}

/* Interactive elements */
button, .btn {
  font-family: var(--font-mono);
  cursor: pointer;
  border: none;
  outline: none;
  transition: opacity 0.15s ease, background 0.15s ease;
}

button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-amber { background: #78350f; color: #fef3c7; border: 1px solid #d97706; }
.badge-green { background: #14532d; color: #bbf7d0; border: 1px solid #22c55e; }
.badge-cyan { background: #164e63; color: #cffafe; border: 1px solid #06b6d4; }
.badge-red { background: #7f1d1d; color: #fecaca; border: 1px solid #ef4444; }

/* App Container Lockdown */
.app-container {
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: grid;
  scrollbar-gutter: stable;
}

.sidebar {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

.main-content {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

/* 3D Dice Canvas Isolation */
#dice-visual-area {
  position: relative;
  width: 100%;
  height: 220px;
  min-height: 220px;
  max-height: 220px;
  overflow: hidden;
  contain: strict;
  border: 1px solid #3f3f46;
}

#dice-canvas-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  display: block;
}

#dice-canvas-container.is-rolling {
  pointer-events: auto;
}

.notebook-paper {
  background-color: #fbf7ec;
  color: #1e1b18;
}

.walkie-drawer {
  background: linear-gradient(180deg, #23252f 0%, #14151b 100%);
  border-top: 3px solid #f59e0b;
}

