:root {
  --bg-deep: #040611;
  --glass-bg: rgba(12, 16, 36, 0.56);
  --glass-border: rgba(255, 255, 255, 0.16);
  --accent-gold: #ffd166;
  --accent-pink: #ff6b9d;
  --text-main: #f8fafc;
  --text-muted: rgba(248, 250, 252, 0.72);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #111936 0%, #050814 65%, #020308 100%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#scene-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#scene-canvas:active {
  cursor: grabbing;
}

/* Top Header */
.hud-header {
  position: fixed;
  top: 18px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
  z-index: 20;
}

.title-card {
  pointer-events: auto;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 12px 18px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.35);
  max-width: min(440px, 78vw);
}

.title-card h1 {
  font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  font-weight: 700;
  background: linear-gradient(120deg, #fff6d6 0%, #ffd166 45%, #ff8fab 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
}

.title-sub {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.days-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(255, 107, 157, 0.18);
  border: 1px solid rgba(255, 107, 157, 0.4);
  color: #ffb3c9;
  font-size: 0.76rem;
  font-weight: 600;
}

.top-actions {
  pointer-events: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn, .pill-btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  font-family: inherit;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.pill-btn {
  padding: 9px 15px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.icon-btn:hover, .pill-btn:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 209, 102, 0.55);
  box-shadow: 0 6px 20px rgba(255, 209, 102, 0.18);
}

.pill-btn.active, .icon-btn.active {
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.35), rgba(255, 209, 102, 0.3));
  border-color: rgba(255, 209, 102, 0.7);
}

/* Bottom Dock */
.hud-dock {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  z-index: 20;
  max-width: 94vw;
  overflow-x: auto;
}

.hud-dock::-webkit-scrollbar {
  display: none;
}

.hint-bar {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.32);
  padding: 4px 12px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
}

/* Floating Wish / Love Card */
.wish-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  width: min(380px, 88vw);
  background: rgba(14, 18, 40, 0.86);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 30px rgba(255, 107, 157, 0.22);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.wish-popup.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.wish-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.wish-author-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--accent-gold);
}

.wish-color-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}

.wish-message {
  font-size: 1rem;
  line-height: 1.65;
  color: #fff;
  white-space: pre-wrap;
  word-break: break-word;
}

.wish-meta {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.btn-danger-sm {
  background: rgba(255, 77, 109, 0.2);
  border: 1px solid rgba(255, 77, 109, 0.45);
  color: #ff9eb0;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.75rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 12, 0.68);
  backdrop-filter: blur(6px);
  display: none;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.open {
  display: grid;
}

.modal-card {
  width: min(460px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: rgba(15, 20, 44, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.65);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.15rem;
  color: var(--accent-gold);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 10px 12px;
  color: #fff;
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
}

.form-control:focus {
  border-color: var(--accent-gold);
}

textarea.form-control {
  resize: vertical;
  min-height: 88px;
}

.color-swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.swatch.selected {
  border-color: #fff;
  transform: scale(1.18);
}

.primary-btn {
  width: 100%;
  padding: 11px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #ff6b9d 0%, #ffd166 100%);
  color: #161020;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 6px;
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.letter-body {
  font-size: 1.02rem;
  line-height: 1.85;
  color: #fff4e6;
  white-space: pre-wrap;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 209, 102, 0.35);
}

.letter-sign {
  margin-top: 12px;
  text-align: right;
  color: var(--accent-pink);
  font-weight: 600;
}

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(20, 26, 56, 0.92);
  border: 1px solid rgba(255, 209, 102, 0.5);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.ui-hidden .hud-header .title-card,
body.ui-hidden .hud-dock,
body.ui-hidden .hint-bar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 45%, #121c3d 0%, #040713 75%);
  transition: opacity 0.65s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-star {
  font-size: 2.6rem;
  animation: pulseStar 1.4s ease-in-out infinite;
  filter: drop-shadow(0 0 18px rgba(255, 209, 102, 0.85));
}

.loading-text {
  font-size: 0.95rem;
  color: #ffe8b3;
  text-align: center;
  padding: 0 24px;
  line-height: 1.6;
}

@keyframes pulseStar {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.85; }
  50% { transform: scale(1.18) rotate(12deg); opacity: 1; }
}

@media (max-width: 640px) {
  .hud-header {
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    gap: 8px;
  }
  .title-card {
    padding: 8px 12px;
    border-radius: 14px;
    max-width: 60vw;
  }
  .title-card h1 {
    font-size: 0.96rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .title-sub {
    font-size: 0.74rem;
    gap: 5px;
  }
  .top-actions {
    gap: 6px;
    max-width: 34vw;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }
  .hud-dock {
    bottom: max(14px, env(safe-area-inset-bottom));
    padding: 7px 10px;
    gap: 6px;
    max-width: 95vw;
    -webkit-overflow-scrolling: touch;
  }
  .pill-btn {
    padding: 7px 11px;
    font-size: 0.78rem;
    flex-shrink: 0;
  }
  .hint-bar {
    display: none;
  }
}
