/* ==============================
   Valentine Diorama — UI styles
   ============================== */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --card-bg: rgba(255, 228, 241, 0.92);
  --card-text: #3d2040;
  --hud-bg: rgba(30, 15, 40, 0.55);
  --hud-text: #f0e0f6;
  --btn-min: 44px;
}

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

/* Screen-reader only utility */
.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;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  background: #0d0618;
}

#root {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ——— Overlay (sits above canvas) ——— */
.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding:
    calc(12px + var(--safe-top))
    calc(12px + var(--safe-right))
    calc(12px + var(--safe-bottom))
    calc(12px + var(--safe-left));
}

.overlay > * { pointer-events: auto; }

/* ——— Top HUD ——— */
.controls-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--hud-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 14px;
  color: var(--hud-text);
  font-size: 0.95rem;
  font-weight: 600;
}

.hud-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-btn {
  min-width: var(--btn-min);
  min-height: var(--btn-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  color: var(--hud-text);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 12px;
  transition: background 0.15s, border-color 0.15s;
}
.hud-btn:hover { background: rgba(255, 255, 255, 0.22); }
.hud-btn:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 2px;
}

.replay-btn { font-size: 0.9rem; font-weight: 700; }

/* ——— Hint text ——— */
.overlay-hint {
  margin-top: auto;
  align-self: center;
  margin-bottom: 16px;
  padding: 10px 24px;
  background: var(--hud-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 20px;
  color: var(--hud-text);
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  animation: hint-fade-in 0.6s ease;
}

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

/* ——— Message Card ——— */
.message-card {
  position: absolute;
  bottom: calc(20px + var(--safe-bottom));
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  display: flex;
  justify-content: center;
  animation: card-slide-up 0.35s ease;
}

@keyframes card-slide-up {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-card-inner {
  position: relative;
  max-width: 420px;
  width: 100%;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 18px;
  padding: 20px 22px 18px;
  color: var(--card-text);
  box-shadow: 0 8px 32px rgba(80, 20, 100, 0.25);
}

.message-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: capitalize;
}

.message-card-body {
  font-size: 0.95rem;
  line-height: 1.5;
}

.message-card-close {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: var(--btn-min);
  min-height: var(--btn-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(60, 30, 80, 0.1);
  border: none;
  border-radius: 50%;
  color: var(--card-text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.message-card-close:hover { background: rgba(60, 30, 80, 0.2); }
.message-card-close:focus-visible {
  outline: 2px solid #9333ea;
  outline-offset: 2px;
}

/* ——— Hotspot list (EXPLORE phase) ——— */
.hotspot-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

.hotspot-list-btn {
  min-height: var(--btn-min);
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  color: var(--hud-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.hotspot-list-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
}
.hotspot-list-btn.discovered {
  background: rgba(160, 120, 255, 0.2);
  border-color: rgba(160, 120, 255, 0.5);
}
.hotspot-list-btn:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 2px;
}

/* ——— Dev buttons (temp) ——— */
.dev-controls {
  position: absolute;
  bottom: calc(16px + var(--safe-bottom));
  right: calc(16px + var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}

.dev-btn {
  min-height: var(--btn-min);
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: white;
  cursor: pointer;
}
.dev-btn:hover { background: rgba(255, 255, 255, 0.25); }

/* ——— WebGL Fallback ——— */
.fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(40px + var(--safe-top)) 20px calc(40px + var(--safe-bottom));
  background: linear-gradient(135deg, #1a0533 0%, #0d0618 50%, #120824 100%);
  color: var(--hud-text);
  overflow-y: auto;
}

.fallback-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.fallback-subtitle {
  font-size: 0.95rem;
  opacity: 0.7;
  margin-bottom: 24px;
  text-align: center;
}

.fallback-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
}

.fallback-btn {
  min-height: var(--btn-min);
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  color: var(--hud-text);
  cursor: pointer;
}
.fallback-btn:hover { background: rgba(255, 255, 255, 0.2); }

.fallback-card {
  max-width: 400px;
  width: 100%;
  background: var(--card-bg);
  border-radius: 18px;
  padding: 20px 22px 18px;
  color: var(--card-text);
  margin-bottom: 20px;
  text-align: center;
}
.fallback-card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.fallback-card p {
  font-size: 0.95rem;
  line-height: 1.5;
}

.fallback-close {
  margin-top: 14px;
  min-height: var(--btn-min);
  padding: 8px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(60, 30, 80, 0.15);
  border: 1.5px solid rgba(60, 30, 80, 0.3);
  border-radius: 10px;
  color: var(--card-text);
  cursor: pointer;
}

.fallback-finale {
  text-align: center;
  margin-top: 20px;
}
.fallback-finale h2 {
  font-size: 2rem;
  font-weight: 700;
  font-style: italic;
  margin-bottom: 16px;
}

/* ——— Error / Context Lost Overlay ——— */
.error-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(13, 6, 24, 0.92);
  color: var(--hud-text);
  text-align: center;
  padding: 20px;
}
.error-overlay p {
  font-size: 1.1rem;
  margin-bottom: 16px;
}
.error-retry-btn {
  min-height: var(--btn-min);
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  color: var(--hud-text);
  cursor: pointer;
}
.error-retry-btn:hover { background: rgba(255, 255, 255, 0.22); }
.error-retry-btn:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 2px;
}

/* ——— Finale Text + Replay ——— */
.finale-bottom {
  margin-top: auto;
  align-self: center;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.finale-text {
  text-align: center;
  animation: finale-text-in 2s ease 2.5s both;
}

.finale-name {
  font-size: 2.4rem;
  font-weight: 700;
  font-style: italic;
  color: #ffe680;
  text-shadow:
    0 0 20px rgba(255, 230, 128, 0.6),
    0 0 40px rgba(255, 220, 100, 0.3),
    0 2px 8px rgba(0, 0, 0, 0.4);
  letter-spacing: 0.04em;
}

@keyframes finale-text-in {
  0%   { opacity: 0; transform: translateY(12px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.finale-replay-btn {
  min-width: 140px;
  min-height: var(--btn-min);
  padding: 14px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: rgba(192, 132, 252, 0.2);
  border: 2px solid rgba(192, 132, 252, 0.5);
  border-radius: 28px;
  color: #f0e0f6;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  animation: finale-text-in 1s ease 4s both;
}
.finale-replay-btn:hover {
  background: rgba(192, 132, 252, 0.35);
  border-color: rgba(192, 132, 252, 0.7);
  transform: scale(1.05);
}
.finale-replay-btn:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 2px;
}

@media (max-width: 600px) {
  .finale-name {
    font-size: 1.8rem;
  }
}

/* ——— Reduced Motion ——— */
@media (prefers-reduced-motion: reduce) {
  .overlay-hint,
  .message-card,
  .hotspot-list-btn {
    animation: none !important;
    transition: none !important;
  }
}

/* ——— Canvas pointer ——— */
canvas { touch-action: none; }

/* ——— Photo Gallery ——— */
.gallery-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: gallery-fade-in 0.3s ease;
}

@keyframes gallery-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 2, 12, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.gallery-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 85vh;
  padding: 16px;
  user-select: none;
  -webkit-user-select: none;
}

.gallery-close {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 2;
  min-width: var(--btn-min);
  min-height: var(--btn-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
}
.gallery-close:hover { background: rgba(255, 255, 255, 0.25); }
.gallery-close:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 2px;
}

.gallery-photo-wrapper {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(80, 20, 120, 0.4);
  border: 3px solid rgba(255, 255, 255, 0.15);
  background: #1a0f2e;
}

.gallery-photo {
  display: block;
  max-width: 80vw;
  max-height: 60vh;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

.gallery-caption {
  margin-top: 14px;
  color: rgba(240, 224, 246, 0.85);
  font-size: 0.95rem;
  font-weight: 500;
  font-style: italic;
  text-align: center;
}

.gallery-dots {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.gallery-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  background: transparent;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s, border-color 0.2s;
}
.gallery-dot.active {
  background: #c084fc;
  border-color: #c084fc;
}
.gallery-dot:hover { border-color: rgba(255, 255, 255, 0.7); }

.gallery-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  min-width: var(--btn-min);
  min-height: var(--btn-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: 1.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.gallery-arrow:hover { background: rgba(255, 255, 255, 0.18); }
.gallery-arrow:focus-visible {
  outline: 2px solid #c084fc;
  outline-offset: 2px;
}
.gallery-arrow-left { left: -56px; }
.gallery-arrow-right { right: -56px; }

@media (max-width: 600px) {
  .gallery-arrow-left { left: -4px; }
  .gallery-arrow-right { right: -4px; }
  .gallery-arrow { background: rgba(255, 255, 255, 0.15); }
}
