:root {
  color-scheme: dark;
  font-family:
    Inter, Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --bg: #090b10;
  --panel: rgba(16, 19, 28, 0.84);
  --panel-solid: #11141d;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f6fb;
  --muted: #9aa3b5;
  --accent: #9dfcda;
  --accent-strong: #5ceab8;
  --warning: #ffc970;
  --danger: #ff6f7d;
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
}

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

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

body {
  background:
    radial-gradient(circle at 50% 35%, #202638 0%, var(--bg) 55%),
    var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.ui-layer button,
.ui-layer a {
  touch-action: manipulation;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

#camera-feed {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: none;
  object-fit: cover;
  background: #000;
}

#camera-feed.active {
  display: block;
}

#app {
  position: relative;
  z-index: 1;
}

#scene {
  position: absolute;
  inset: 0;
  touch-action: none;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.ui-layer {
  position: fixed;
  z-index: 10;
}

.topbar {
  top: var(--safe-top);
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.17em;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

h1 {
  font-size: clamp(24px, 6vw, 34px);
}

h2 {
  font-size: 22px;
}

.icon-button,
.log-actions button,
.adjust-controls button {
  touch-action: manipulation;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(12, 15, 23, 0.72);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.icon-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent-strong), transparent 25%);
}

.status-dot.error {
  background: var(--danger);
}

.error-count {
  min-width: 19px;
  padding: 2px 5px;
  border-radius: 999px;
  background: var(--danger);
  font-size: 10px;
  text-align: center;
}

.loading-card {
  top: 50%;
  left: 50%;
  width: min(360px, calc(100% - 38px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(18px);
  transform: translate(-50%, -50%);
  transition: 220ms ease;
}

.loading-card.hidden {
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, calc(-50% + 8px));
}

.loading-spinner {
  float: left;
  width: 38px;
  height: 38px;
  margin: 1px 14px 14px 0;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.loading-copy {
  display: grid;
  gap: 4px;
  min-height: 46px;
}

.loading-copy strong {
  font-size: 16px;
}

.loading-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.progress-track {
  clear: both;
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.progress-bar {
  width: 3%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-strong), #a8ffef);
  transition: width 160ms ease;
}

.message-card {
  top: calc(var(--safe-top) + 68px);
  left: 50%;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  width: min(480px, calc(100% - 36px));
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(12, 15, 23, 0.7);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
  transition: 180ms ease;
}

.message-card.hidden {
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, -7px);
}

.mode-badge {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.message-card p {
  margin: 0;
  color: #dfe4ee;
  font-size: 12px;
  line-height: 1.5;
}

.xr-install-card {
  top: 50%;
  left: 50%;
  z-index: 30;
  width: min(420px, calc(100% - 36px));
  padding: 22px;
  border: 1px solid rgba(157, 252, 218, 0.34);
  border-radius: 20px;
  background: rgba(10, 13, 20, 0.96);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(20px);
  transform: translate(-50%, -50%);
}

.xr-install-card.hidden {
  display: none;
}

.xr-install-card h2 {
  margin: 0 30px 10px 0;
  font-size: 22px;
}

.xr-install-card p {
  margin: 0 0 18px;
  color: #dfe4ee;
  font-size: 13px;
  line-height: 1.65;
}

.xr-install-close {
  position: absolute;
  top: 12px;
  right: 14px;
}

.xr-install-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, #b8ffe7 0%, #62eabb 100%);
  color: #07130f;
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.xr-install-link:focus-visible {
  outline: 2px solid white;
  outline-offset: 3px;
}

.xr-copy-link {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 11px 16px;
  border: 1px solid rgba(157, 252, 218, 0.35);
  border-radius: 14px;
  background: rgba(157, 252, 218, 0.08);
  color: #dffff4;
  font-size: 14px;
  font-weight: 850;
}

.xr-copy-link:active {
  background: rgba(157, 252, 218, 0.16);
}

.xr-copy-link:focus-visible {
  outline: 2px solid white;
  outline-offset: 3px;
}

.xr-page-url {
  box-sizing: border-box;
  width: 100%;
  min-height: 39px;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
}

.xr-page-url:focus {
  border-color: rgba(157, 252, 218, 0.5);
  outline: none;
  color: var(--text);
}

.xr-install-card .xr-install-footnote {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.message-close {
  padding: 0 3px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.toast {
  z-index: 60;
  bottom: calc(var(--safe-bottom) + 146px);
  left: 50%;
  max-width: calc(100% - 44px);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.78);
  color: white;
  font-size: 12px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: 180ms ease;
}

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

.control-dock {
  right: 16px;
  bottom: var(--safe-bottom);
  left: 16px;
  display: grid;
  gap: 10px;
  margin: auto;
  max-width: 520px;
}

.adjust-controls {
  display: grid;
  grid-template-columns: 48px 48px 48px 48px 48px 1fr;
  gap: 8px;
}

.adjust-controls button {
  background: rgba(13, 16, 24, 0.78);
  font-size: 20px;
  font-weight: 700;
  backdrop-filter: blur(15px);
}

.adjust-controls button:last-child {
  font-size: 13px;
}

.adjust-controls #greeting-animation {
  font-size: 19px;
}

.adjust-controls #outfit-toggle {
  position: relative;
  overflow: hidden;
  font-size: 19px;
}

.adjust-controls #outfit-toggle.off {
  border-color: rgba(255, 111, 125, 0.72);
  background: rgba(255, 77, 94, 0.12);
}

.adjust-controls #outfit-toggle.off::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 3px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 8px rgba(255, 77, 94, 0.55);
  content: "";
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-45deg);
}

.adjust-controls #greeting-animation.active {
  border-color: rgba(157, 252, 218, 0.7);
  background: rgba(98, 234, 187, 0.2);
  box-shadow: 0 0 24px rgba(98, 234, 187, 0.2);
}

.ar-button {
  min-height: 58px;
  border: 1px solid rgba(157, 252, 218, 0.5);
  border-radius: 18px;
  background: linear-gradient(135deg, #b8ffe7 0%, #62eabb 100%);
  box-shadow: 0 15px 40px rgba(70, 224, 172, 0.22);
  color: #07130f;
  font-size: 16px;
  font-weight: 900;
}

.ar-button.active {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(13, 16, 24, 0.82);
  color: var(--text);
}

.button-icon {
  margin-right: 6px;
  font-size: 20px;
}

.log-panel {
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(460px, 100%);
  padding: var(--safe-top) 16px var(--safe-bottom);
  border-left: 1px solid var(--line);
  background: rgba(8, 10, 15, 0.97);
  box-shadow: -24px 0 80px rgba(0, 0, 0, 0.42);
  visibility: hidden;
  opacity: 0;
  transform: translateX(100%);
  transition: 220ms ease;
}

.log-panel.open {
  visibility: visible;
  opacity: 1;
  transform: translateX(0);
}

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

.log-header .icon-button {
  min-width: 42px;
  padding: 0;
  justify-content: center;
  font-size: 24px;
}

.diagnostic-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
}

.summary-item {
  padding: 9px 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.035);
}

.summary-item span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-item strong {
  display: block;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}

.log-actions button {
  min-height: 38px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
}

.log-list {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #080a0f;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  scrollbar-color: #394052 transparent;
}

.log-empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.log-entry {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  line-height: 1.45;
  word-break: break-word;
}

.log-entry:last-child {
  border-bottom: 0;
}

.log-entry.error {
  background: rgba(255, 77, 94, 0.08);
}

.log-entry.warn {
  background: rgba(255, 196, 97, 0.055);
}

.log-meta {
  display: flex;
  gap: 7px;
  margin-bottom: 3px;
  color: #687186;
}

.log-level {
  font-weight: 900;
  text-transform: uppercase;
}

.log-entry.error .log-level {
  color: var(--danger);
}

.log-entry.warn .log-level {
  color: var(--warning);
}

.log-entry.info .log-level {
  color: var(--accent);
}

.log-message {
  color: #dfe4ee;
  white-space: pre-wrap;
}

.log-detail {
  margin: 5px 0 0;
  overflow: auto;
  color: #8791a6;
  white-space: pre-wrap;
}

body.camera-mode {
  background: #000;
}

body.camera-mode .topbar,
body.xr-active .topbar {
  opacity: 0.72;
}

body.xr-active {
  background: transparent;
}

@media (min-width: 720px) {
  .topbar {
    right: 26px;
    left: 26px;
  }

  .control-dock {
    grid-template-columns: 280px 1fr;
    max-width: 620px;
  }

  .adjust-controls {
    order: 2;
  }

  .toast {
    bottom: calc(var(--safe-bottom) + 82px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
