:root {
  --page-bg: #070711;
  --foreground: #f8fafc;
  --muted: rgba(248, 250, 252, 0.74);
  --accent: #22d3ee;
  --accent-2: #a78bfa;
  --stage-bg: #0ea5e9;
  --card: rgba(15, 23, 42, 0.78);
  --border: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--foreground);
  background:
    radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 26rem),
    radial-gradient(circle at 80% 5%, color-mix(in srgb, var(--accent-2) 26%, transparent), transparent 24rem),
    var(--page-bg);
}

body.theme-dark {
  --page-bg: #0b1020;
  --foreground: #e5e7eb;
  --muted: rgba(229, 231, 235, 0.75);
  --accent: #60a5fa;
  --accent-2: #2563eb;
  --card: rgba(15, 23, 42, 0.84);
}

body.theme-pastel {
  --page-bg: #f7f7fb;
  --foreground: #1e293b;
  --muted: rgba(30, 41, 59, 0.72);
  --accent: #8bd3dd;
  --accent-2: #f6c2d9;
  --card: rgba(255, 255, 255, 0.86);
  --border: rgba(30, 41, 59, 0.12);
}

.app {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(340px, auto) auto auto auto;
  gap: 18px;
  padding: 32px 0;
}

.header { text-align: center; }
.header h1 { margin: 0; font-size: clamp(32px, 5vw, 54px); line-height: 1; }
.header p { margin: 12px 0 0; color: var(--muted); font-size: 17px; }

.stage-wrap { display: grid; place-items: center; }
.stage-layout {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  align-items: stretch;
}
.stage {
  width: 100%;
  height: clamp(320px, 45vh, 500px);
  border-radius: 32px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background: var(--stage-bg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  transition: background-color 350ms ease;
}

.glow {
  position: absolute;
  width: min(320px, 58%);
  aspect-ratio: 1;
  border-radius: 999px;
  background: var(--accent-2);
  opacity: 0.25;
  filter: blur(2px);
}

.actor {
  width: 220px;
  height: 220px;
  display: grid;
  place-items: center;
  transform-origin: center;
  will-change: transform, opacity;
  z-index: 1;
}

.shape {
  width: 200px;
  height: 200px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 18px 60px rgba(0,0,0,.24);
}
.shape.circle { border-radius: 999px; }
.shape.square { border-radius: 28px; }
.hidden { display: none !important; }
.model { width: 220px; height: 220px; background: transparent; }

.controls, .animations, .multiplayer {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 18px;
  backdrop-filter: blur(14px);
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1.3fr);
  align-items: center;
  gap: 18px;
}

.field { display: grid; gap: 8px; font-weight: 650; }
select, input[type="range"] { width: 100%; }
select {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255,255,255,.08);
  color: var(--foreground);
  font: inherit;
}
body.theme-pastel select { background: rgba(255,255,255,.9); }

input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { width: 44px; height: 24px; accent-color: var(--accent); }
.toggle-row { display: inline-flex; align-items: center; gap: 10px; color: var(--foreground); font-weight: 650; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.section-title h2 { margin: 0; font-size: 20px; }
.combine { font-size: 14px; }

.animation-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.anim-card {
  border: 0;
  border-radius: 18px;
  padding: 13px 16px;
  background: #1f2937;
  color: white;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .18s ease, box-shadow .18s ease, outline-color .18s ease;
}
.anim-card:hover { transform: translateY(-2px); }
.anim-card.active { outline: 3px solid color-mix(in srgb, var(--accent) 82%, white); box-shadow: 0 10px 26px rgba(0,0,0,.26); }
.dot { width: 16px; height: 16px; border-radius: 999px; }

.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
button {
  border: 0;
  border-radius: 20px;
  padding: 15px 18px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}
.primary { background: var(--accent); color: #020617; }
.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.secondary { background: #cbd5e1; color: #0f172a; }

.entry-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 7, 17, 0.92);
  backdrop-filter: blur(10px);
}

body.session-active .entry-gate {
  display: none;
}

.entry-card {
  width: min(440px, 100%);
  padding: 28px;
  border-radius: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
}

.entry-card h2 {
  margin: 0 0 10px;
  font-size: clamp(24px, 4vw, 32px);
}

.entry-lead {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.45;
}

.entry-form {
  display: grid;
  gap: 14px;
}

.entry-form .required-mark {
  font-style: normal;
  color: #f87171;
  font-weight: 800;
}

.entry-form input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255,255,255,.08);
  color: var(--foreground);
  font: inherit;
}

body.theme-pastel .entry-form input[type="text"] {
  background: rgba(255,255,255,.9);
}

.entry-form input.invalid {
  outline: 2px solid #f87171;
  outline-offset: 2px;
}

.entry-status {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: pre-line;
}

.entry-status.online { color: #34d399; }
.entry-status.offline { color: var(--muted); }

.session-badge {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.session-badge.online { color: #34d399; }

.multiplayer-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 16px;
  min-height: 220px;
}

.online-panel h3,
.feed-panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--muted);
}

.online-users {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.online-users li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
}
.user-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.activity-feed {
  max-height: 280px;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}

.feed-item {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px 10px;
  align-items: baseline;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  font-size: 14px;
}
body.theme-pastel .feed-item { background: rgba(255,255,255,.55); }

.feed-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.feed-user { font-weight: 750; white-space: nowrap; }
.feed-text { color: var(--foreground); }

.feed-join .feed-text,
.feed-leave .feed-text { font-style: italic; color: var(--muted); }

@media (max-width: 720px) {
  .multiplayer-grid { grid-template-columns: 1fr; }
  .app { width: min(100% - 24px, 1060px); padding: 20px 0; }
  .controls { grid-template-columns: 1fr; }
  .actor, .model { width: 180px; height: 180px; }
  .shape { width: 165px; height: 165px; }
}

/* Надёжная 3D-модель без внешних библиотек: работает даже при запуске с локального сервера на ПК. */
.css-model {
  width: 190px;
  height: 190px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-18deg) rotateY(28deg);
  will-change: transform;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.css-model.dragging { cursor: grabbing; }
.cube3d {
  position: absolute;
  inset: 35px;
  transform-style: preserve-3d;
}
.face {
  position: absolute;
  width: 120px;
  height: 120px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255,255,255,.58);
  box-shadow: inset 0 0 35px rgba(255,255,255,.16), 0 14px 34px rgba(0,0,0,.18);
  color: white;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: .06em;
  backface-visibility: visible;
}
.face.front { transform: translateZ(60px); background: linear-gradient(135deg, #22d3ee, #2563eb); }
.face.back { transform: rotateY(180deg) translateZ(60px); background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.face.right { transform: rotateY(90deg) translateZ(60px); background: linear-gradient(135deg, #34d399, #059669); }
.face.left { transform: rotateY(-90deg) translateZ(60px); background: linear-gradient(135deg, #f472b6, #db2777); }
.face.top { transform: rotateX(90deg) translateZ(60px); background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.face.bottom { transform: rotateX(-90deg) translateZ(60px); background: linear-gradient(135deg, #94a3b8, #475569); }
.stage { perspective: 900px; }
body.theme-pastel .face { border-color: rgba(30,41,59,.28); }
@media (max-width: 720px) {
  .css-model { width: 160px; height: 160px; }
  .cube3d { inset: 25px; }
  .face { width: 110px; height: 110px; }
  .face.front { transform: translateZ(55px); }
  .face.back { transform: rotateY(180deg) translateZ(55px); }
  .face.right { transform: rotateY(90deg) translateZ(55px); }
  .face.left { transform: rotateY(-90deg) translateZ(55px); }
  .face.top { transform: rotateX(90deg) translateZ(55px); }
  .face.bottom { transform: rotateX(-90deg) translateZ(55px); }
}

/* Правая панель моделей всех подключившихся пользователей */
.local-actor {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.models-sidebar {
  height: clamp(430px, 45vh, 500px);
  border-radius: 28px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.models-sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.models-sidebar-head h2 {
  margin: 0;
  font-size: 18px;
}

.models-sidebar-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.users-showcase {
  position: relative;
  z-index: 2;
  display: grid;
  grid-auto-rows: 82px;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 6px 2px 2px;
  scroll-snap-type: y proximity;
  -webkit-overflow-scrolling: touch;
}

.user-model-card {
  min-height: 82px;
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  gap: 8px 10px;
  padding: 10px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.34);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 14px 32px rgba(0,0,0,.18);
  backdrop-filter: blur(10px);
  scroll-snap-align: start;
}
@media (max-width: 900px) {
  .stage-layout { grid-template-columns: 1fr; }
  .models-sidebar { height: 450px; }
}

@media (max-width: 720px) {
  .stage-layout { gap: 12px; }
  .models-sidebar { height: 430px; }
  .user-model-card { grid-template-columns: 78px minmax(0, 1fr); }
}

body.theme-pastel .user-model-card {
  background: rgba(255,255,255,.58);
}

.user-model-card.self {
  outline: 3px solid color-mix(in srgb, var(--user-color) 70%, white);
}

.user-model-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 14px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-model-stage {
  grid-row: 1 / 3;
  min-height: 62px;
  display: grid;
  place-items: center;
  perspective: 700px;
}

.user-model-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  align-self: end;
}

.showcase-empty {
  padding: 18px 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.10);
  color: white;
  font-weight: 700;
  text-align: center;
}

.mini-actor {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  transform-origin: center;
  will-change: transform, opacity;
}

.mini-shape {
  width: 52px;
  height: 52px;
  background: var(--user-color);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22), 0 14px 34px rgba(0,0,0,.24);
}

.mini-shape.circle { border-radius: 999px; }
.mini-shape.square { border-radius: 18px; }

.anim-pulse { animation: miniPulse calc(1.2s / var(--speed)) ease-in-out infinite; }
.anim-rotate { animation: miniRotate calc(3s / var(--speed)) linear infinite; }
.anim-slide { animation: miniSlide calc(2s / var(--speed)) ease-in-out infinite; }
.anim-fade { animation: miniFade calc(1.5s / var(--speed)) ease-in-out infinite; }
.anim-bounce { animation: miniBounce calc(1.5s / var(--speed)) ease-in-out infinite; }
.anim-combine { animation: miniRotate calc(3s / var(--speed)) linear infinite, miniPulse calc(1.2s / var(--speed)) ease-in-out infinite; }

@keyframes miniPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes miniRotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes miniSlide { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(14px); } 75% { transform: translateX(-14px); } }
@keyframes miniFade { 0%, 100% { opacity: 1; } 50% { opacity: .28; } }
@keyframes miniBounce { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-16px); } }

.mini-css-model {
  width: 58px;
  height: 58px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  will-change: transform;
}

.mini-css-model.mini-rotate {
  animation: miniCubeSpin calc(3s / var(--speed)) linear infinite;
}

.mini-cube3d {
  position: absolute;
  inset: 14px;
  transform-style: preserve-3d;
}

.mini-face {
  position: absolute;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.58);
  box-shadow: inset 0 0 18px rgba(255,255,255,.16), 0 10px 22px rgba(0,0,0,.16);
  color: white;
  font-size: 10px;
  font-weight: 900;
  backface-visibility: visible;
}

.mini-front { transform: translateZ(15px); background: linear-gradient(135deg, var(--user-color), #2563eb); }
.mini-back { transform: rotateY(180deg) translateZ(15px); background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.mini-right { transform: rotateY(90deg) translateZ(15px); background: linear-gradient(135deg, #34d399, #059669); }
.mini-left { transform: rotateY(-90deg) translateZ(15px); background: linear-gradient(135deg, #f472b6, #db2777); }
.mini-top { transform: rotateX(90deg) translateZ(15px); background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.mini-bottom { transform: rotateX(-90deg) translateZ(15px); background: linear-gradient(135deg, #94a3b8, #475569); }

@keyframes miniCubeSpin {
  from { transform: rotateX(var(--rx)) rotateY(var(--ry)); }
  to { transform: rotateX(var(--rx)) rotateY(calc(var(--ry) + 360deg)); }
}

/* 3D можно вращать мышью по всей сцене на ноутбуке/ПК. */
.stage:has(.css-model:not(.hidden)) { cursor: grab; touch-action: none; }
.stage.dragging-3d { cursor: grabbing; }

/* Можно вращать свой 3D-куб в правой панели мышью на ноутбуке и пальцем на телефоне. */
.user-model-card.self .mini-css-model,
.user-model-card.self .user-model-stage {
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.user-model-card.self.dragging-3d .mini-css-model,
.user-model-card.self.dragging-3d .user-model-stage,
.mini-css-model.dragging {
  cursor: grabbing;
}


/* FIX 2026-05-22: нормальная мобильная раскладка и живая 3D-анимация в панели пользователей. */
.mini-model-motion {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  transform-origin: center;
  will-change: transform, opacity;
}

@media (max-width: 820px) {
  html, body {
    min-height: 100%;
    overflow-x: hidden;
  }

  .app {
    width: 100%;
    min-height: 100svh;
    padding: 12px;
    display: block;
  }

  .header {
    margin-bottom: 12px;
  }

  .header h1 {
    font-size: 28px;
  }

  .header p {
    display: none;
  }

  .stage-wrap {
    display: block;
    width: 100%;
  }

  .stage-layout {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .stage {
    width: 100%;
    min-width: 0;
    height: 58svh;
    min-height: 360px;
    max-height: 560px;
    flex: 0 0 auto;
    border-radius: 24px;
  }

  .models-sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 0;
    max-height: none;
    flex: 0 0 auto;
    border-radius: 24px;
    padding: 12px;
    overflow: visible;
  }

  .models-sidebar-head {
    margin-bottom: 10px;
  }

  .users-showcase {
    height: 358px; /* 4 карточки по 82px + 3 промежутка по 10px */
    max-height: 358px;
    display: grid;
    grid-auto-rows: 82px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .user-model-card {
    min-width: 0;
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .controls, .animations, .multiplayer {
    margin-top: 12px;
  }
}

@media (max-width: 420px) {
  .app { padding: 10px; }
  .stage {
    height: 55svh;
    min-height: 330px;
    border-radius: 22px;
  }
  .users-showcase {
    height: 344px;
    max-height: 344px;
    grid-auto-rows: 79px;
    gap: 9px;
  }
  .user-model-card {
    min-height: 79px;
  }
}

/* FIX 2026-05-22: на телефоне список пользователей горизонтальный, свайп вбок. */
@media (max-width: 820px) {
  .models-sidebar {
    overflow: hidden;
  }

  .users-showcase {
    height: 116px;
    max-height: 116px;
    display: flex;
    flex-direction: row;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 4px 8px 2px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }

  .user-model-card {
    flex: 0 0 calc((100% - 30px) / 4);
    min-width: calc((100% - 30px) / 4);
    min-height: 96px;
    grid-template-columns: 1fr;
    grid-template-rows: 58px auto;
    gap: 6px;
    padding: 8px;
    scroll-snap-align: start;
  }

  .user-model-stage {
    grid-row: 1;
    min-height: 58px;
  }

  .user-model-name {
    grid-row: 2;
    justify-content: center;
    font-size: 11px;
    text-align: center;
  }

  .user-model-meta {
    display: none;
  }

  .showcase-empty {
    flex: 0 0 100%;
  }
}

@media (max-width: 420px) {
  .users-showcase {
    height: 112px;
    max-height: 112px;
    grid-auto-rows: unset;
  }

  .user-model-card {
    flex-basis: calc((100% - 24px) / 4);
    min-width: calc((100% - 24px) / 4);
    min-height: 92px;
    padding: 7px;
  }

  .user-model-name {
    font-size: 10px;
  }
}
