:root {
  color-scheme: dark;
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
  background: #081018;
  color: #eef6f8;
  --panel: rgba(8, 18, 27, 0.82);
  --panel-border: rgba(190, 225, 231, 0.18);
  --muted: #a9bbc2;
  --accent: #9ed7da;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-height: 560px;
  background: radial-gradient(circle at 50% 20%, #1a3541, #081018 70%);
}

#app {
  position: relative;
  isolation: isolate;
  background: #081018;
}

#app:fullscreen {
  width: 100vw;
  height: 100vh;
}

#terrain {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.title-card {
  position: absolute;
  z-index: 2;
  top: 64px;
  left: clamp(18px, 4vw, 54px);
  max-width: min(660px, calc(100vw - 390px));
  padding: 18px 20px;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(8, 18, 27, 0.82), rgba(8, 18, 27, 0.42));
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(16px) saturate(115%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font: 650 11px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  font-size: clamp(23px, 3vw, 38px);
  font-weight: 680;
  letter-spacing: -0.035em;
  word-break: keep-all;
}

.title-card > p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(12px, 1.4vw, 15px);
  line-height: 1.55;
}

.legend {
  position: absolute;
  z-index: 2;
  left: clamp(18px, 4vw, 54px);
  bottom: clamp(18px, 3vw, 34px);
  display: flex;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.legend span {
  white-space: nowrap;
}

.mouse-icon {
  display: inline-block;
  width: 8px;
  height: 12px;
  margin-right: 3px;
  border: 1px solid currentColor;
  border-radius: 5px;
  vertical-align: -2px;
}

#fullscreen-toggle {
  position: absolute;
  z-index: 3;
  left: 16px;
  top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 7px 11px;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  background: var(--panel);
  color: #dce9eb;
  font: 600 11px/1 Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

#fullscreen-toggle:hover,
#fullscreen-toggle:focus-visible {
  border-color: rgba(158, 215, 218, 0.52);
  background: rgba(20, 42, 54, 0.92);
}

.fullscreen-icon {
  width: 13px;
  height: 13px;
  border: solid currentColor;
  border-width: 2px 0 0 2px;
  box-shadow: 4px 4px 0 -2px #081018, 6px 6px 0 -2px currentColor;
}

#fullscreen-toggle.is-active .fullscreen-icon {
  transform: rotate(180deg);
}

#loading,
#error {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: #081018;
  color: var(--muted);
  text-align: center;
}

#loading.is-hidden {
  opacity: 0;
  visibility: hidden;
  transition: opacity 500ms ease, visibility 500ms;
}

#error[hidden] {
  display: none;
}

#error strong {
  color: #f6f1e8;
  font-size: 18px;
}

.loading-ring {
  width: 38px;
  height: 38px;
  border: 2px solid rgba(158, 215, 218, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.lil-gui.root {
  --background-color: rgba(7, 16, 24, 0.88);
  --widget-color: rgba(156, 196, 201, 0.14);
  --hover-color: rgba(156, 196, 201, 0.22);
  --focus-color: rgba(156, 196, 201, 0.28);
  --text-color: #dce9eb;
  --number-color: #a8dadd;
  --string-color: #b7e2c8;
  --font-size: 11px;
  --name-width: 48%;
  position: absolute;
  z-index: 4;
  top: 16px;
  right: 16px;
  max-height: calc(100% - 32px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: auto;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.lil-gui.root > .children {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.lil-gui .title {
  letter-spacing: -0.01em;
}

.lil-gui .controller.function .widget button {
  border-radius: 4px;
}

@media (max-width: 720px) {
  body {
    min-height: 520px;
  }

  .title-card {
    top: 52px;
    left: 12px;
    max-width: calc(100vw - 24px);
    padding: 12px 14px;
    border-radius: 13px;
  }

  .title-card > p:last-child {
    display: none;
  }

  .legend {
    left: 12px;
    bottom: 12px;
    gap: 9px;
    max-width: calc(100vw - 24px);
    overflow: hidden;
  }

  .legend span:nth-child(n+3) {
    display: none;
  }

  .lil-gui.root {
    top: 10px;
    right: 10px;
    max-height: calc(100% - 20px);
  }

  .lil-gui.root:not(.closed) {
    width: min(310px, calc(100vw - 20px));
  }

  #fullscreen-toggle {
    top: 10px;
    left: 12px;
    min-width: 36px;
    justify-content: center;
  }

  .fullscreen-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-ring {
    animation-duration: 1800ms;
  }
}
