* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1419;
  --bg-panel: #1a1f2e;
  --border: #2d3748;
  --accent: #00d4ff;
  --accent-warm: #ffd700;
  --text: #e8eaed;
  --text-dim: #8b95a7;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  height: -webkit-fill-available;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  touch-action: pan-x;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== TOP BAR ===== */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  background: linear-gradient(180deg, #16212b 0%, #1a2a3a 100%);
  border-bottom: 2px solid var(--accent);
  height: 52px;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.nav-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.nav-btn:active {
  background: rgba(0,212,255,0.2);
  transform: scale(0.92);
}

.topbar-center {
  flex: 1;
  text-align: center;
  min-width: 0;
}

.room-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clock {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
}

/* ===== MAIN ROOM VIEW ===== */
#roomView {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  height: calc(100vh - 52px - 72px);
  height: calc(100dvh - 52px - 72px);
  background: linear-gradient(135deg, #0a0e14, #0f1419);
  touch-action: pan-x;
}

#room {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
}

/* ===== BOTTOM TABS ===== */
#roomTabs {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: linear-gradient(0deg, #0d1117, #16212b);
  border-top: 2px solid var(--border);
  height: 72px;
  flex-shrink: 0;
  padding-bottom: var(--safe-bottom);
  gap: 2px;
  padding: 4px 4px calc(4px + var(--safe-bottom));
}

#roomTabs::-webkit-scrollbar { display: none; }

.room-tab {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.2s;
  font-family: inherit;
}

.room-tab:active {
  transform: scale(0.94);
}

.room-tab.active {
  background: rgba(0,212,255,0.12);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px rgba(0,212,255,0.15);
}

.tab-icon {
  font-size: 22px;
  line-height: 1;
}

.tab-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

/* ===== AGENT POPUP ===== */
.popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.25s;
}

.popup.hidden {
  display: none;
}

.popup-content {
  background: linear-gradient(135deg, #1a2a3a, #16212b);
  border: 2px solid var(--accent);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 -8px 30px rgba(0,212,255,0.15);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.popup-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.popup-close:active { color: var(--accent); }

.popup-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-avatar canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.popup-content h3 {
  text-align: center;
  color: var(--accent);
  font-size: 20px;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}

.popup-details {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
}

.detail-icon {
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.popup-progress {
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.popup-progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ===== LAYOUT: body as flex column ===== */
body {
  display: flex;
  flex-direction: column;
}

/* ===== ANIMATIONS ===== */
@keyframes glow {
  0%, 100% { text-shadow: 0 0 6px rgba(0,212,255,0.3); }
  50% { text-shadow: 0 0 16px rgba(0,212,255,0.7); }
}

.room-title { animation: glow 3s ease-in-out infinite; }

/* ===== SWIPE TRANSITION ===== */
#roomView.swipe-left {
  animation: swipeOutLeft 0.25s ease forwards;
}
#roomView.swipe-right {
  animation: swipeOutRight 0.25s ease forwards;
}
#roomView.swipe-in-left {
  animation: swipeInLeft 0.25s ease forwards;
}
#roomView.swipe-in-right {
  animation: swipeInRight 0.25s ease forwards;
}

@keyframes swipeOutLeft {
  to { transform: translateX(-100%); opacity: 0; }
}
@keyframes swipeOutRight {
  to { transform: translateX(100%); opacity: 0; }
}
@keyframes swipeInLeft {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes swipeInRight {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== TABLET (768px+) ===== */
@media (min-width: 768px) {
  .room-title { font-size: 20px; }
  .clock { font-size: 13px; }
  .tab-label { font-size: 10px; }
  .tab-icon { font-size: 26px; }
  .room-tab { min-width: 90px; }
  #roomTabs { height: 80px; justify-content: center; }
  #topbar { height: 56px; padding: 8px 16px; }
  .nav-btn { width: 48px; height: 48px; font-size: 28px; }
  #roomView { height: calc(100vh - 56px - 80px); }
  .popup-content { max-width: 500px; border-radius: 20px; margin-bottom: 20px; border-bottom: 2px solid var(--accent); }
  .popup { align-items: center; }
}

/* ===== DESKTOP (1024px+) ===== */
@media (min-width: 1024px) {
  #roomTabs { justify-content: center; gap: 8px; }
  .room-tab { min-width: 120px; padding: 8px 16px; }
  .tab-label { font-size: 11px; }
  .nav-btn:hover { background: rgba(0,212,255,0.15); border-color: var(--accent); }
  .room-tab:hover { background: rgba(0,212,255,0.08); }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 0; height: 0; }
