/* Surrealist Channel Visualization */
:root {
  --bg: #095DDC;
  --fill: #000000;
  --stroke: #F0E6D2;
  --stroke-accent: #095DDC;
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* System dark mode: black fill, white stroke */
@media (prefers-color-scheme: dark) {
  :root {
    --fill: #000000;
    --stroke: #F0E6D2;
  }
}

/* System light mode: white fill, black stroke */
@media (prefers-color-scheme: light) {
  :root {
    --fill: #F0E6D2;
    --stroke: #000000;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-touch-callout: none;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--fill);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- View transitions --- */

.loading, .room {
  animation: viewIn 0.4s var(--ease) both;
}

@keyframes viewIn {
  from {
    transform: translateY(10px);
  }
}

/* --- Loading --- */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  gap: 16px;
}

.loading-icon {
  width: 64px;
  height: 64px;
  stroke: var(--fill);
  fill: none;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: loadingPulse 1.6s var(--ease) infinite;
}

@keyframes loadingPulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* --- Room --- */

.room {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
}


.room-code-svg {
  cursor: pointer;
}

.btn-leave-svg {
  cursor: pointer;
}

/* --- Room Controls (HTML overlay) --- */

.room-controls {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

.room-code {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  font-size: clamp(14px, 4vmin, 28px);
  font-weight: 900;
  color: var(--stroke);
  letter-spacing: 0;
  cursor: pointer;
}

.room-controls button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.room-controls svg {
  width: clamp(18px, 4vmin, 28px);
  height: clamp(18px, 4vmin, 28px);
  stroke: var(--stroke);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
  transition: transform 0.2s var(--ease);
}

.room-controls button:hover svg {
  transform: scale(1.1);
}

.room-controls button:active svg {
  transform: scale(0.95);
}

/* --- Channel Container (Full screen flex centering) --- */

.channel-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
  padding-top: calc(8px + env(safe-area-inset-top));
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  padding-left: calc(8px + env(safe-area-inset-left));
  padding-right: calc(8px + env(safe-area-inset-right));
}

/* --- Figure Wrapper (Relative container for layering) --- */

.figure-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

/* --- Figure SVG (Base layer) --- */

.figure-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- Peer Layer (Overlay for HTML peer icons) --- */

.peer-layer {
  position: absolute;
  inset: 0;
  pointer-events: none; /* Let clicks pass through to figure, except on peer icons */
}

/* --- Peer Icons (Individual positioned elements) --- */

.peer-icon {
  position: absolute;
  transform: translate(-50%, -50%); /* Center on position point */
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.2s var(--ease);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2px, 0.5vmin, 4px);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.peer-icon:hover {
  transform: translate(-50%, -50%) scale(1.1);
}

.peer-icon:active {
  transform: translate(-50%, -50%) scale(0.95);
}

/* --- Peer SVG (Icon inside peer element) --- */

.peer-svg {
  width: clamp(80px, 22vmin, 180px);
  height: clamp(80px, 22vmin, 180px);
  stroke: var(--stroke);
  fill: var(--fill);
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.peer-svg.mouth-svg {
  height: auto;
  aspect-ratio: 115 / 90;
}

.peer-icon:has(.mouth-svg) .peer-label {
  position: absolute;
  top: 55%;
  margin-top: 0;
}

/* --- My Mouth (PTT area - larger than other peers) --- */

.peer-icon.my-mouth {
  gap: 0;
  touch-action: none;
}

.peer-icon.my-mouth .peer-label {
  position: absolute;
  top: 55%;
  z-index: 1;
}

.peer-icon.my-mouth .peer-svg {
  width: clamp(140px, 35vmin, 300px);
  height: auto;
  aspect-ratio: 115 / 90;
}

.peer-icon.my-mouth:hover {
  transform: translate(-50%, -50%) scale(1.05);
}

.peer-icon.my-mouth:active {
  transform: translate(-50%, -50%) scale(0.98);
}

/* --- Peer Labels (HTML text elements) --- */

.peer-label {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  font-size: clamp(14px, 4vmin, 28px);
  font-weight: 900;
  color: var(--stroke);
  text-align: center;
  pointer-events: none;
  letter-spacing: 0;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

.peer-label[data-peer-id] {
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
}

/* --- Error view --- */

.error-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  gap: 20px;
  padding: 16px;
  animation: viewIn 0.4s var(--ease) both;
}

.error-icon svg {
  width: 64px;
  height: 64px;
  stroke: var(--fill);
  fill: none;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.error-msg {
  font-size: 14px;
  font-weight: 400;
  text-align: center;
  line-height: 1.5;
  color: rgba(245, 240, 230, 0.7);
}

.btn-retry {
  background: none;
  border: 1.5px solid var(--fill);
  border-radius: 12px;
  color: var(--fill);
  font-size: 14px;
  font-weight: 400;
  padding: 10px 28px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.04em;
  transition: transform 0.2s var(--spring),
              background 0.15s var(--ease);
}
.btn-retry:active {
  background: rgba(245, 240, 230, 0.1);
  transform: scale(0.94);
}

/* --- Offline icon --- */

.icon-offline {
  width: 20px;
  height: 20px;
  stroke: rgba(245, 240, 230, 0.5);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
}

/* Scrollbar */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(245, 240, 230, 0.2); border-radius: 3px; }

/* Landscape orientation adjustments */
@media (orientation: landscape) {
  .room-controls {
    flex-direction: row;
  }
}

/* --- Room transition animations --- */

@keyframes slide-out-left {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

@keyframes slide-in-from-bottom {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.room.slide-out {
  animation: slide-out-left 0.4s ease forwards;
}

.room.slide-in {
  animation: slide-in-from-bottom 0.4s ease forwards !important;
  opacity: 1 !important;
}

