:root {
  --bg-color: #0f0f1a;
  --text-color: #ffffff;
  --panel-bg: rgba(0, 0, 0, 0.6);
  --border-color: rgba(255, 255, 255, 0.2);
  --pill-bg: rgba(0, 0, 0, 0.4);
  --pill-hover: rgba(255, 255, 255, 0.6);
  --pill-active: #4a90e2;
  --hover-text-color: #1d1d1f;
}

[data-theme="light"] {
  --bg-color: #f5f5f7;
  --text-color: #1d1d1f;
  --panel-bg: rgba(255, 255, 255, 0.8);
  --border-color: rgba(0, 0, 0, 0.2);
  --pill-bg: rgba(255, 255, 255, 0.4);
  --pill-hover: rgba(0, 0, 0, 0.6);
  --pill-active: #0071e3;
  --hover-text-color: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { 
  background: var(--bg-color); color: var(--text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden; width: 100vw; height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

#canvas-wrap {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(ellipse at bottom, rgba(255, 255, 255, 0.08) 0%, transparent 65%);
  overflow: hidden;
  will-change: contents;
}
[data-theme="light"] #canvas-wrap {
  background: radial-gradient(ellipse at bottom, rgba(0, 0, 0, 0.08) 0%, transparent 65%);
}

#canvas-wrap canvas {
  opacity: 0;
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
  transition: opacity 0.15s ease;
}
#canvas-wrap.canvas-ready canvas {
  opacity: 1;
}

#loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  justify-content: center;
  align-items: center;
  aspect-ratio: 16 / 9;
  width: min(100vw, calc(100dvh * 16 / 9));
  z-index: 50;
  pointer-events: none;
  filter: invert(0.9);
  line-height: 0;
}
#loading-spinner img {
  width: 10.625%; /* 204 / 1920 */
  aspect-ratio: 1;
  opacity: 0.5;
}
[data-theme="light"] #loading-spinner {
  filter: contrast(0.8);
}

/* Pan-mode cursor is handled by PixiJS stage.cursor */
#canvas-wrap.is-loading,
#canvas-wrap.is-loading canvas {
  cursor: not-allowed !important;
}

#toolbar, #model-nav { user-select: none; }

#toolbar {
  position: absolute; top: 16px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; z-index: 10; flex-wrap: wrap; gap: 8px;
}

#toolbar-left {
  display: flex; gap: 8px; flex-wrap: wrap; flex-wrap: nowrap;
}
#toolbar-left > button {
  white-space: nowrap;
}

#toolbar-right { display: flex; gap: 8px; pointer-events: auto; }
#github-link { text-decoration: none; }
#theme-toggle, #pan-toggle, #reset-view, #github-link {
  pointer-events: auto; background: var(--panel-bg);
  border: 1px solid var(--border-color); color: var(--text-color);
  border-radius: 20px; height: 36px; padding: 0 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.2s;
  backdrop-filter: blur(4px);
}
#theme-toggle:hover, #pan-toggle:hover, #reset-view:hover, #github-link:hover { background: var(--pill-hover); color: var(--hover-text-color); }
#pan-toggle[aria-pressed="true"] { background: var(--pill-active); color: #fff; border-color: transparent; }
#theme-toggle { width: 36px; padding: 0; border-radius: 50%; font-size: 16px; cursor: pointer !important; }
.hidden { display: none !important; }

#info {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel-bg); padding: 6px 16px; border-radius: 12px;
  font-size: 13px; backdrop-filter: blur(4px);
  z-index: 20; transition: opacity 0.35s ease 0.45s; white-space: nowrap;
}
#info.info-hidden { opacity: 0; }

.playground-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}
.playground-controls span {
  display: inline-block;
}
.playground-controls span:not(:last-child)::after {
  content: "|";
  margin-left: 12px;
  opacity: 0.3;
}



@media (max-width: 1070px) {
  body[data-active-pill="playground"] #info {
    top: 60px;
    background: unset;
    backdrop-filter: unset;
    pointer-events: none;
  }
  .playground-controls-wrapper {
    display: flex;
    width: 100vw;
    justify-content: center;
  }
  body[data-active-pill="playground"] .playground-controls {
    padding: 6px 16px;
    border-radius: 12px;
    background: transparent;
    backdrop-filter: blur(4px);
  }
}

@media (max-width: 529px) {
  body[data-active-pill="playground"] .playground-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: calc(100vw - 30px);
  }
}

@media (max-width: 819px) {
  #info {
    top: 60px;
  }
}
@media (max-width: 400px) {
  #toolbar {
    justify-content: center;
  }
  #info {
    top: 105px;
    background: transparent;
  }
  body[data-active-pill="playground"] #info {
    top: 105px;
  }
}

#model-nav {
  position: absolute; bottom: 24px;
  display: flex; flex-direction: column; align-items: center;
  z-index: 10; width: 100vw; pointer-events: none;
}

#mode-tabs { display: flex; gap: 12px; flex-direction: column-reverse;
  align-items: end; margin-bottom: 12px;
}

#mode-tabs .wrapper {
  display: flex;
  gap: 12px;
}

.mode-tab { background: var(--panel-bg); backdrop-filter: blur(8px); 
  background: transparent; border: none; color: var(--text-color);
  padding: 6px 20px; border-radius: 16px; cursor: pointer;
  font-weight: 500; transition: background 0.2s; background: var(--pill-bg);
  pointer-events: auto;
}
.mode-tab.active { background: var(--pill-active); color: #fff; }

#model-pills {
  display: flex; flex-wrap: nowrap; overflow-x: unset;
  white-space: nowrap; padding: 0 16px; gap: 8px;

  -webkit-overflow-scrolling: touch;
  flex-wrap: wrap;
}
#model-pills::-webkit-scrollbar { display: none; }
#model-pills { scrollbar-width: none; }

.model-pill {
  background: var(--pill-bg); border: 1px solid var(--border-color);
  color: var(--text-color); border-radius: 20px; padding: 6px 16px;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  transition: all 0.2s; backdrop-filter: blur(4px);
  animation: pillSlideIn 0.35s ease both; flex-grow: 1;
  justify-content: center; pointer-events: auto;
}

@keyframes pillSlideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.model-pill:hover { background: var(--pill-hover); color: var(--hover-text-color); }
#dorm-toggle { transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease; }
#dorm-toggle.hidden { display: flex !important; opacity: 0; transform: translateY(24px); visibility: hidden; pointer-events: none; }
.model-pill.active { background: var(--pill-active); color: #fff; border-color: transparent; }

.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 8px; font-weight: bold;
}
.badge-c2 { background: #ff9f0a; color: #fff; }
.badge-c3 { background: #ff7f75; color: #fff; }
.badge-spine { background: #bf5af2; color: #fff; }
.badge-playground { background: #c39e20; color: #fff; }

#model-select-visible { display: none; pointer-events: auto; }
#model-select, #mode-select { opacity: 0; position: absolute; z-index: -1; pointer-events: none; }


/* Radial theme transition overrides */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 9999; }

