:root {
  --bg-night: #02050c;
  --text-primary: #f5f9ff;
  --text-muted: rgba(214, 229, 250, 0.72);
  --surface-panel: rgba(8, 15, 29, 0.88);
  --surface-pill: rgba(10, 18, 34, 0.76);
  --border-subtle: rgba(168, 206, 255, 0.22);
  --border-strong: rgba(194, 226, 255, 0.48);
  --accent-blue: #3b82f6;
  --accent-ice: #93c5fd;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-night);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: none;
}

#scene-root {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#scene-root canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

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

/* Subtle cinematic edge vignette focusing attention toward the center valley */
.cinema-vignette {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(
    ellipse 78% 74% at 50% 48%,
    rgba(2, 5, 12, 0) 48%,
    rgba(2, 5, 12, 0.36) 82%,
    rgba(1, 3, 9, 0.68) 100%
  );
}

.icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.is-hidden {
  display: none;
}

/* ===== TOP-LEFT HUD ===== */
.hud-top-left {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: max(22px, env(safe-area-inset-left));
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 360ms var(--ease-out), transform 360ms var(--ease-out);
}

body.state-lit .hud-top-left {
  opacity: 1;
  transform: translateY(0);
}

.hud-badge {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.26em;
  color: rgba(232, 242, 255, 0.78);
  text-shadow: 0 0 12px rgba(147, 197, 253, 0.35);
}

/* ===== INTRO OVERLAY ===== */
.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: auto;
  opacity: 1;
  transform: scale(1);
  transition: opacity 380ms var(--ease-out), transform 380ms var(--ease-out);
}

body.state-lit .intro-overlay {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}

.intro-content {
  text-align: center;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transform: translateY(10px);
}

.intro-kicker {
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--accent-ice);
  opacity: 0.85;
}

.intro-heading {
  font-size: clamp(24px, 4.2vw, 38px);
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1.35;
  color: #ffffff;
  text-shadow: 0 2px 24px rgba(147, 197, 253, 0.45);
}

.btn-ignite {
  margin-top: 8px;
  min-height: 46px;
  padding: 12px 30px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(14, 27, 52, 0.86);
  color: #ffffff;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.12em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 0 28px rgba(59, 130, 246, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 160ms var(--ease-out), opacity 160ms var(--ease-out), border-color 160ms ease;
}

.btn-ignite:hover {
  transform: scale(1.04);
  border-color: #ffffff;
}

.btn-ignite:active {
  transform: scale(0.97);
}

/* ===== BOTTOM-CENTER GREETING ===== */
.greeting-overlay {
  position: fixed;
  left: 50%;
  bottom: max(56px, calc(env(safe-area-inset-bottom) + 52px));
  z-index: 10;
  text-align: center;
  pointer-events: none;
  width: min(92vw, 680px);
  padding: 18px 28px 14px;
  transform: translateX(-50%);
}

/* Feather-soft dark atmospheric scrim behind credits so lettering never clashes with bright ice reflection */
.greeting-overlay::before {
  content: "";
  position: absolute;
  inset: -12px -40px -18px;
  z-index: -1;
  background: radial-gradient(
    ellipse 62% 68% at 50% 56%,
    rgba(2, 6, 16, 0.56) 0%,
    rgba(2, 6, 16, 0.24) 52%,
    rgba(2, 6, 16, 0) 100%
  );
  opacity: 0;
  transition: opacity 400ms var(--ease-out);
}

body.state-greeting .greeting-overlay::before {
  opacity: 1;
}

.greeting-title,
.greeting-sub {
  opacity: 0;
  transform: translateY(14px);
}

.greeting-title {
  font-family: "Snell Roundhand", "Brush Script MT", "Apple Chancery", Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(34px, 5.2vw, 62px);
  line-height: 1.12;
  letter-spacing: 0.025em;
  background: linear-gradient(180deg, #ffffff 18%, #fce4f0 74%, #dbeafe 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 224, 240, 0.45)) drop-shadow(0 2px 10px rgba(2, 6, 18, 0.85));
}

.greeting-sub {
  margin-top: 9px;
  font-size: clamp(13px, 1.55vw, 15px);
  font-weight: 400;
  letter-spacing: 0.24em;
  color: rgba(242, 238, 248, 0.86);
  text-shadow: 0 1px 12px rgba(2, 6, 18, 0.95);
}

/* ===== BOTTOM-LEFT SHORTCUT HINTS ===== */
.hud-shortcuts {
  position: fixed;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: rgba(206, 222, 245, 0.62);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 320ms var(--ease-out), transform 320ms var(--ease-out);
}

body.state-lit .hud-shortcuts {
  opacity: 1;
  transform: translateY(0);
}

.hud-shortcuts .dot {
  opacity: 0.45;
}

/* ===== BOTTOM-RIGHT CONTROL BAR ===== */
.control-bar {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 320ms var(--ease-out), transform 320ms var(--ease-out);
}

body.state-lit .control-bar {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.pill-btn {
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-pill);
  color: var(--text-primary);
  font-size: 12px;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: transform 150ms var(--ease-out), opacity 150ms var(--ease-out), border-color 150ms ease;
}

.pill-btn:hover {
  transform: scale(1.04);
  border-color: var(--border-strong);
}

.pill-btn:active {
  transform: scale(0.95);
}

.pill-btn-accent {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(30, 58, 138, 0.72);
}

/* ===== MINIMAL / CLEAN RECORDING MODE (Zero UI Elements on Screen) ===== */
body.state-minimal .hud-top-left,
body.state-minimal .hud-shortcuts,
body.state-minimal .control-bar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
}

/* ===== MODALS ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 5, 12, 0.74);
  opacity: 0;
  transition: opacity 220ms var(--ease-out);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop.is-open {
  opacity: 1;
}

.modal-card {
  width: min(100%, 420px);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  transform: scale(0.96) translateY(8px);
  transition: transform 240ms var(--ease-out);
}

.modal-backdrop.is-open .modal-card {
  transform: scale(1) translateY(0);
}

.modal-card-wide {
  width: min(100%, 760px);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(168, 206, 255, 0.14);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 150ms var(--ease-out), color 150ms ease;
}

.modal-close:hover {
  color: #ffffff;
  transform: scale(1.06);
}

.modal-close:active {
  transform: scale(0.92);
}

.modal-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  color: var(--text-muted);
}

.field-input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(3, 8, 18, 0.92);
  color: #ffffff;
  font-size: 16px;
  outline: none;
  transition: border-color 160ms ease;
}

.field-input:focus {
  border-color: var(--accent-ice);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.btn-primary,
.btn-secondary {
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 150ms var(--ease-out), opacity 150ms ease;
}

.btn-primary {
  border: 1px solid rgba(147, 197, 253, 0.55);
  background: var(--accent-blue);
  color: #ffffff;
}

.btn-secondary {
  border: 1px solid var(--border-subtle);
  background: rgba(15, 25, 45, 0.72);
  color: var(--text-primary);
}

.btn-compact {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 12px;
}

.btn-primary:hover,
.btn-secondary:hover {
  transform: scale(1.03);
}

.btn-primary:active,
.btn-secondary:active {
  transform: scale(0.96);
}

.code-viewer-wrap {
  padding: 14px 18px 18px;
  overflow: auto;
  flex: 1;
  user-select: text;
}

.code-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: #dbeafe;
  white-space: pre;
  tab-size: 2;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: max(22px, env(safe-area-inset-top));
  left: 50%;
  z-index: 40;
  max-width: min(90vw, 440px);
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(8, 18, 36, 0.94);
  color: #ffffff;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== MOBILE ADAPTATION ===== */
@media (max-width: 767px) {
  .hud-shortcuts {
    display: none;
  }

  .greeting-overlay {
    bottom: max(84px, calc(env(safe-area-inset-bottom) + 78px));
  }

  .control-bar {
    left: 50%;
    right: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: translate(-50%, 10px);
    gap: 6px;
    width: calc(100vw - 20px);
    justify-content: center;
  }

  body.state-lit .control-bar {
    transform: translate(-50%, 0);
  }

  body.state-minimal .control-bar {
    transform: translate(-50%, 10px);
  }

  .pill-btn {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 12px;
    flex: 1 1 auto;
    max-width: 82px;
  }

  .modal-close {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud-top-left,
  .intro-overlay,
  .greeting-overlay,
  .hud-shortcuts,
  .control-bar,
  .modal-backdrop,
  .modal-card,
  .toast,
  .pill-btn,
  .btn-ignite {
    transition-duration: 1ms;
  }
}
