/* Karven's Threshold - Cinematic Dark Visual Novel WebGL Theme */
:root {
  --bg-primary: #0d0f14;
  --bg-surface: #151821;
  --bg-surface-elevated: #1e2230;
  --accent-gold: #c9a45c;
  --accent-gold-glow: rgba(201, 164, 92, 0.25);
  --accent-gold-hover: #dfbc74;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-gold: rgba(201, 164, 92, 0.3);
  --error-bg: rgba(220, 38, 38, 0.15);
  --error-border: #ef4444;
  --error-text: #fca5a5;
  --canvas-aspect: 16 / 9;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 50% 30%, #1a1e2a 0%, #0d0f14 70%),
    radial-gradient(circle at 80% 80%, rgba(201, 164, 92, 0.03) 0%, transparent 40%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#game-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 8px 12px;
  overflow: hidden;
}

#unity-container {
  position: relative;
  width: 100%;
  max-width: 1280px;
  max-height: calc(100vh - 46px);
  aspect-ratio: var(--canvas-aspect);
  background: #000;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.85), 0 0 0 1px var(--border-subtle);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Мгновенное изменение размеров без CSS-анимаций для защиты WebGL буфера */
  transition: none;
}

#unity-canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  display: block;
  background: #000;
  outline: none;
  cursor: default;
}

@supports not (aspect-ratio: 16 / 9) {
  #unity-container {
    height: 0;
    padding-bottom: 56.25%;
  }
  #unity-canvas {
    position: absolute;
    top: 0;
    left: 0;
  }
}

#unity-container.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
  border: none !important;
  box-shadow: none !important;
  z-index: 99999 !important;
  background: #000 !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Нативная поддержка полноэкранного режима браузера */
#unity-container:fullscreen,
#unity-container:-webkit-full-screen,
#unity-container:-moz-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
  border: none !important;
  background: #000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

#unity-canvas:fullscreen,
#unity-canvas:-webkit-full-screen,
#unity-canvas:-moz-full-screen {
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: 16 / 9 !important;
  object-fit: contain !important;
  background: #000 !important;
}

/* Плавающая кнопка выхода из полноэкранного режима */
.btn-fullscreen-floating {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 55;
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(21, 24, 33, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-main);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.3s;
  opacity: 0.6;
}

.btn-fullscreen-floating:hover {
  background: rgba(30, 34, 48, 0.95);
  color: var(--accent-gold);
  opacity: 1;
}

.btn-fullscreen-floating svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

#unity-container.is-fullscreen .btn-fullscreen-floating,
#unity-container:fullscreen .btn-fullscreen-floating,
#unity-container:-webkit-full-screen .btn-fullscreen-floating {
  display: inline-flex;
}

/* Atmospheric Loading Overlay */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #12151c 0%, #0a0c10 100%);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.6s;
  padding: 24px;
}

#loading-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.emblem-wrapper {
  position: relative;
  width: 68px;
  height: 68px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emblem-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(201, 164, 92, 0.15);
  border-top-color: var(--accent-gold);
  animation: emblem-spin 1.4s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}

.emblem-core {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-gold) 0%, rgba(201, 164, 92, 0.2) 70%, transparent 100%);
  box-shadow: 0 0 18px var(--accent-gold-glow);
  animation: core-pulse 2s ease-in-out infinite;
}

@keyframes emblem-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes core-pulse {
  0%, 100% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
}

.game-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-main);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  margin-bottom: 6px;
  text-align: center;
}

.game-subtitle {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--accent-gold);
  margin-bottom: 32px;
  text-transform: uppercase;
  text-align: center;
}

.progress-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
  position: relative;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #9a7632 0%, var(--accent-gold) 70%, #f6e3b4 100%);
  border-radius: 999px;
  transition: width 0.2s ease-out;
  box-shadow: 0 0 12px var(--accent-gold-glow);
}

.progress-meta {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.progress-status {
  font-weight: 400;
}

.progress-percentage {
  font-weight: 600;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

/* Error Card */
#error-card {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(13, 15, 20, 0.96);
  backdrop-filter: blur(8px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}

#error-card.is-visible {
  display: flex;
}

.error-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: #ef4444;
  margin-bottom: 16px;
}

.error-title {
  font-size: 18px;
  font-weight: 600;
  color: #f87171;
  margin-bottom: 8px;
}

.error-desc {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 440px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-retry {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-gold);
  color: #0f1115;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-retry:hover {
  background: var(--accent-gold-hover);
  transform: translateY(-1px);
}

.btn-retry:active {
  transform: translateY(0);
}

/* Control Bar (Footer) */
#game-bar {
  width: 100%;
  max-width: 1280px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.game-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-brand-title {
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.04em;
}

.game-brand-author {
  font-size: 12px;
  color: var(--accent-gold);
}

.game-hints {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.game-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-fullscreen {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.btn-fullscreen:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-gold);
  color: var(--accent-gold);
}

.btn-fullscreen svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Banner for non-fatal Unity warnings */
#unity-warning {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid var(--border-gold);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  display: none;
  max-width: 90%;
  pointer-events: none;
}

/* Mobile & Small Screen Adaptations */
@media (max-width: 768px) {
  #game-page {
    padding: 0;
    justify-content: flex-start;
  }
  #unity-container {
    border-radius: 0;
    max-height: 100vh;
  }
  #game-bar {
    padding: 8px 12px;
  }
  .game-hints {
    display: none;
  }
}
