:root {
  --bg-deep: #07060b;
  --bg-primary: #0c0b12;
  --bg-card: rgba(18, 16, 28, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-glow: rgba(168, 85, 247, 0.3);
  --accent-purple: #a855f7;
  --accent-violet: #7c3aed;
  --accent-gold: #f59e0b;
  --accent-rose: #f43f5e;
  --text-primary: #e8e4f0;
  --text-secondary: rgba(232, 228, 240, 0.55);
  --text-dim: rgba(232, 228, 240, 0.3);
}

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

body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Bricolage Grotesque', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

#root { min-height: 100vh; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(168, 85, 247, 0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(168, 85, 247, 0.4); }

/* Particle canvas */
#particles-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

/* Glass card */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  transition: all 0.3s ease;
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.3);
}

/* Inputs */
.novel-input {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 16px;
  padding: 14px 16px;
  width: 100%;
  transition: all 0.3s ease;
  outline: none;
  resize: vertical;
}

.novel-input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.15), 0 0 30px rgba(168, 85, 247, 0.08);
}

.novel-input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

.novel-input-sm {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 14px;
  padding: 10px 14px;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-violet), var(--accent-purple));
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px 32px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.5s ease;
}

.btn-primary:hover::before { left: 100%; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(124, 58, 237, 0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-secondary {
  background: var(--bg-glass);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 20px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

/* Genre chips */
.genre-chip {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  border: 1px solid var(--border-subtle);
  background: var(--bg-glass);
  color: var(--text-secondary);
  user-select: none;
}

.genre-chip:hover {
  border-color: var(--accent-purple);
  color: var(--accent-purple);
  background: rgba(168, 85, 247, 0.08);
}

.genre-chip.active {
  border-color: var(--accent-purple);
  background: rgba(168, 85, 247, 0.15);
  color: var(--accent-purple);
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.15);
}

/* Rating cards */
.rating-card {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 16px;
  padding: 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.rating-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.rating-card:hover { transform: translateY(-3px); }

.rating-card.selected {
  transform: translateY(-3px);
}

.rating-card.selected::before { opacity: 1; }

/* Screen transitions */
.screen-enter {
  animation: screenFadeIn 0.5s ease forwards;
}

@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Typewriter cursor */
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent-purple);
  margin-left: 2px;
  animation: blink 1s infinite;
  vertical-align: text-bottom;
}

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

/* Title shimmer */
.title-shimmer {
  background: linear-gradient(
    120deg,
    #e8e4f0 0%,
    #a855f7 25%,
    #f59e0b 50%,
    #a855f7 75%,
    #e8e4f0 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 4s ease-in-out infinite;
}

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

/* Scene loading skeleton */
.scene-skeleton {
  background: linear-gradient(90deg, rgba(20,18,30,1) 0%, rgba(30,26,50,0.8) 50%, rgba(20,18,30,1) 100%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.8s ease-in-out infinite;
  border-radius: 12px;
}

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

/* Scene image vignette */
.scene-vignette {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(7,6,11,0.7) 100%);
  pointer-events: none;
  border-radius: 12px;
}

/* Dialogue name tag */
.name-tag {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 6px 6px 0 0;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* Character portrait */
.char-portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

.portrait-frame {
  width: 160px;
  height: 160px;
  border-radius: 14px;
  border: 2px solid var(--border-subtle);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s ease;
}

.portrait-frame:hover { border-color: var(--accent-purple); }

/* Relationship meter */
.rel-meter {
  display: flex;
  gap: 2px;
  align-items: center;
}

.rel-heart {
  font-size: 12px;
  transition: all 0.3s ease;
}

/* Pulse animation for begin button */
.pulse-glow {
  animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(124, 58, 237, 0.3); }
  50% { box-shadow: 0 0 40px rgba(124, 58, 237, 0.6), 0 0 60px rgba(168, 85, 247, 0.2); }
}

/* Scene crossfade */
.scene-crossfade {
  transition: opacity 0.8s ease;
}

/* Side panel */
.side-panel {
  position: fixed;
  top: 0; right: -400px;
  width: 380px;
  max-width: 90vw;
  height: 100vh;
  background: rgba(12, 11, 18, 0.98);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border-subtle);
  z-index: 100;
  transition: right 0.35s ease;
  overflow-y: auto;
  padding: 24px;
}

.side-panel.open { right: 0; }

.side-panel-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.side-panel-overlay.open { opacity: 1; pointer-events: all; }

/* Quick action chips */
.action-chip {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  border: 1px solid rgba(168, 85, 247, 0.25);
  background: rgba(168, 85, 247, 0.08);
  color: #c4a5f7;
  font-family: 'Bricolage Grotesque', sans-serif;
}

.action-chip:hover {
  background: rgba(168, 85, 247, 0.2);
  border-color: var(--accent-purple);
  transform: translateY(-1px);
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-dim);
  font-size: 12px;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.app-footer a:hover { color: var(--accent-purple); }

/* Responsive */
@media (max-width: 640px) {
  .portrait-frame { width: 120px; height: 120px; }
  .btn-primary { padding: 12px 24px; font-size: 15px; }
}

/* Ambient bg gradient */
.ambient-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  background: 
    radial-gradient(ellipse at 20% 20%, rgba(124, 58, 237, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(245, 158, 11, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(168, 85, 247, 0.03) 0%, transparent 70%);
  animation: ambientShift 20s ease-in-out infinite alternate;
}

@keyframes ambientShift {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* Loading dots */
.loading-dots::after {
  content: '';
  animation: loadDots 1.5s infinite;
}

@keyframes loadDots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ============================================ */
/* VISUAL NOVEL GAMEPLAY LAYOUT                 */
/* ============================================ */

.vn-gameplay-root {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-deep);
  position: relative;
  z-index: 1;
}

/* Main VN area (takes remaining space) */
.vn-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* Top bar floating over scene */
.vn-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(7,6,11,0.85) 0%, rgba(7,6,11,0) 100%);
  pointer-events: auto;
}

.vn-top-bar > * { pointer-events: auto; }

.vn-location-tag {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  padding: 3px 10px;
  border-radius: 4px;
}

.vn-menu-btn {
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}
.vn-menu-btn:hover {
  background: rgba(168,85,247,0.2);
  border-color: var(--accent-purple);
}

/* Scene background - fills the entire main area */
.vn-scene-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.vn-scene-vignette {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(7,6,11,0.6) 100%);
  pointer-events: none;
  z-index: 2;
}

.vn-scene-bottom-fade {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 55%;
  background: linear-gradient(to top, rgba(7,6,11,0.95) 0%, rgba(7,6,11,0.7) 40%, transparent 100%);
  pointer-events: none;
  z-index: 3;
}

/* Speaker portrait - overlapping bottom-left like reference */
.vn-speaker-portrait {
  position: absolute;
  bottom: 180px;
  left: 20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid rgba(168,85,247,0.5);
  box-shadow: 0 4px 24px rgba(0,0,0,0.6), 0 0 20px rgba(168,85,247,0.2);
  z-index: 15;
  animation: portraitFadeIn 0.4s ease;
}

@keyframes portraitFadeIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

/* Dialogue area - overlapping bottom of scene */
.vn-dialogue-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
}

/* Name plate - centered like reference image */
.vn-name-plate {
  align-self: center;
  margin-bottom: -1px;
  z-index: 11;
}

.vn-name-plate-text {
  display: inline-block;
  padding: 6px 28px;
  background: linear-gradient(135deg, rgba(40,30,60,0.95), rgba(25,20,45,0.95));
  border: 1px solid rgba(168,85,247,0.4);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1.5px;
  color: #d4b5ff;
  text-transform: uppercase;
}

/* Text box - styled like classic VN dialogue box */
.vn-text-box {
  background: linear-gradient(135deg, rgba(15,12,25,0.92), rgba(20,16,35,0.92));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(168,85,247,0.25);
  border-radius: 12px;
  min-height: 100px;
  max-height: 200px;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Advance indicator triangle */
.vn-advance-indicator {
  position: absolute;
  bottom: 8px;
  right: 14px;
  color: var(--accent-purple);
  font-size: 14px;
  cursor: pointer;
  animation: bounceDown 1.2s ease-in-out infinite;
}

@keyframes bounceDown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

/* Quick action chips below text box */
.vn-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 4px 4px;
  justify-content: center;
}

.vn-quick-actions .action-chip {
  font-size: 12px;
  padding: 6px 14px;
}

/* Chat-style input */
.vn-chat-input {
  display: flex;
  gap: 8px;
  padding: 8px 4px 4px;
  align-items: center;
}

.vn-chat-textfield {
  flex: 1;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(168,85,247,0.2);
  border-radius: 24px;
  color: var(--text-primary);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 15px;
  padding: 10px 18px;
  outline: none;
  transition: all 0.3s;
}

.vn-chat-textfield:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 2px rgba(168,85,247,0.12);
}

.vn-chat-textfield::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

.vn-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-violet), var(--accent-purple));
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.vn-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 20px rgba(124,58,237,0.4);
}

.vn-send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.vn-continue-btn {
  flex: 1;
  background: rgba(168,85,247,0.1);
  border: 1px solid rgba(168,85,247,0.25);
  border-radius: 24px;
  color: #c4a5f7;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.vn-continue-btn:hover {
  background: rgba(168,85,247,0.2);
  border-color: var(--accent-purple);
}

.vn-loading-bar {
  text-align: center;
  padding: 10px;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

/* Right sidebar - character panel */
.vn-right-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: rgba(10,9,16,0.95);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.vn-sidebar-header {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 4px;
}

.vn-char-card {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  transition: all 0.2s;
}

.vn-char-card:hover {
  border-color: rgba(168,85,247,0.3);
  background: rgba(168,85,247,0.04);
}

.vn-char-card-portrait {
  width: 50px;
  height: 50px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
}

.vn-char-card-info {
  flex: 1;
  min-width: 0;
}

.vn-char-name {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vn-char-desc {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Mobile responsive - hide right sidebar, show via hamburger menu */
@media (max-width: 900px) {
  .vn-right-sidebar {
    display: none;
  }

  .vn-speaker-portrait {
    width: 70px;
    height: 70px;
    bottom: 160px;
    left: 12px;
  }
}

@media (max-width: 640px) {
  .portrait-frame { width: 120px; height: 120px; }
  .btn-primary { padding: 12px 24px; font-size: 15px; }

  .vn-text-box {
    min-height: 80px;
    max-height: 160px;
  }

  .vn-speaker-portrait {
    width: 60px;
    height: 60px;
    bottom: 150px;
    left: 10px;
  }

  .vn-name-plate-text {
    font-size: 12px;
    padding: 5px 20px;
  }
}