/* ==========================================================================
   ScreenLink — Design Tokens
   Palette:  void #05060c · panel #0d0f1e · cyan #00e5ff · violet #a855f7
             mint #39ffc0 (online) · danger #ff4d6d · text #eef1ff
   Type:     Chakra Petch (display / latin labels) · Vazirmatn (fa UI text)
             JetBrains Mono (room codes / data)
   Signature: animated node-link mesh — literalizes the P2P WebRTC topology
   ========================================================================== */

:root {
  --bg-void: #05060c;
  --bg-panel: rgba(15, 18, 36, 0.62);
  --bg-panel-solid: #0d0f1e;
  --bg-elevated: #12152a;
  --border-subtle: rgba(148, 163, 220, 0.16);
  --border-strong: rgba(148, 163, 220, 0.32);

  --cyan: #00e5ff;
  --violet: #a855f7;
  --mint: #39ffc0;
  --danger: #ff4d6d;
  --amber: #ffb020;

  --text-primary: #eef1ff;
  --text-muted: #8891b8;
  --text-faint: #575f84;

  --font-display: 'Chakra Petch', 'Vazirmatn', sans-serif;
  --font-body: 'Vazirmatn', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --shadow-glow-cyan: 0 0 24px rgba(0, 229, 255, 0.25);
  --shadow-glow-violet: 0 0 24px rgba(168, 85, 247, 0.25);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

/* Defensive: always honor the native hidden attribute regardless of
   any later class-based display rule (this was the root cause of the
   landing/room views stacking and needing a scroll). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

::selection { background: rgba(0, 229, 255, 0.3); color: #fff; }

button, input {
  font-family: inherit;
  color: inherit;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- Ambient backdrop ---------- */
.grid-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(0, 229, 255, 0.10), transparent 42%),
    radial-gradient(circle at 84% 82%, rgba(168, 85, 247, 0.12), transparent 45%),
    linear-gradient(rgba(148, 163, 220, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 220, 0.05) 1px, transparent 1px);
  background-size: auto, auto, 42px 42px, 42px 42px;
}

/* ---------- Layout shells ---------- */
.view {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* ==========================================================================
   Brand
   ========================================================================== */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand--sm { font-size: 1rem; }
.brand__mark {
  color: var(--cyan);
  font-size: 1.2em;
  text-shadow: 0 0 12px rgba(0, 229, 255, 0.7);
}
.brand__name { font-size: 1.15rem; color: var(--text-primary); }
.brand__accent { color: var(--violet); text-shadow: 0 0 14px rgba(168, 85, 247, 0.6); }

/* ==========================================================================
   Landing view
   ========================================================================== */
.view--landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1.5rem 3rem;
  gap: 1.75rem;
}

.view--landing .brand { margin-top: 0.5rem; }

.mesh-hero {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(900px, 130vw);
  height: 420px;
  z-index: -1;
  opacity: 0.9;
  mask-image: radial-gradient(ellipse 60% 60% at center, black 40%, transparent 78%);
}
.mesh-svg { width: 100%; height: 100%; }
.mesh-node { filter: drop-shadow(0 0 6px currentColor); }
.mesh-edge { stroke-dasharray: 4 6; animation: dash-flow 6s linear infinite; }
@keyframes dash-flow { to { stroke-dashoffset: -100; } }
@keyframes node-pulse {
  0%, 100% { opacity: 0.55; r: 3.4; }
  50% { opacity: 1; r: 5; }
}

.landing-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.1rem 1.9rem;
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
}

.eyebrow {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--cyan);
  text-transform: uppercase;
  margin: 0 0 0.9rem;
  direction: ltr;
}

.landing-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1.45;
  margin: 0 0 0.6rem;
}

.landing-sub {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.7;
  margin: 0 0 1.6rem;
}

.tabs {
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 1.4rem;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.6rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.25s var(--ease);
}
.tab.is-active {
  color: var(--bg-void);
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 6px 18px -6px rgba(0, 229, 255, 0.5);
}

.tab-panel { display: none; text-align: right; }
.tab-panel.is-active { display: block; animation: fade-in 0.25s var(--ease); }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.field-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0.9rem 0 0.4rem;
}
.tab-panel .field-label:first-child { margin-top: 0; }

.text-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.text-input::placeholder { color: var(--text-faint); }
.text-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0, 229, 255, 0.15);
  outline: none;
}
.text-input--mono {
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  direction: ltr;
  text-align: center;
  text-transform: uppercase;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.94rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.3rem;
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease), background 0.2s, border-color 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn--block { width: 100%; margin-top: 1.5rem; }
.btn--primary {
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #04060f;
  box-shadow: 0 10px 26px -10px rgba(0, 229, 255, 0.55);
}
.btn--primary:hover { box-shadow: 0 12px 30px -8px rgba(168, 85, 247, 0.6); }
.btn--primary svg { transition: transform 0.2s var(--ease); }
.btn--primary:hover svg { transform: translateX(3px); }
[dir="rtl"] .btn--primary:hover svg { transform: translateX(-3px) scaleX(-1); }

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-muted);
}
.btn--ghost:hover { color: var(--text-primary); border-color: var(--danger); }

.landing-error {
  margin-top: 1rem;
  color: var(--danger);
  background: rgba(255, 77, 109, 0.1);
  border: 1px solid rgba(255, 77, 109, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
}

.landing-footnote {
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: center;
  max-width: 380px;
}

/* ==========================================================================
   Room view
   ========================================================================== */
.view--room {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(8, 10, 20, 0.7);
  backdrop-filter: blur(14px);
  flex-wrap: wrap;
}
.room-header__left, .room-header__right {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.room-code-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 229, 255, 0.07);
  border: 1px solid rgba(0, 229, 255, 0.25);
  border-radius: 999px;
  padding: 0.35rem 0.5rem 0.35rem 0.8rem;
  cursor: pointer;
  direction: ltr;
  transition: background 0.2s, border-color 0.2s;
}
.room-code-chip:hover { background: rgba(0, 229, 255, 0.14); border-color: var(--cyan); }
.room-code-chip__label {
  font-family: var(--font-display);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--cyan);
}
.room-code-chip__code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}
.copy-icon { color: var(--text-muted); }

.user-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot--online { background: var(--mint); box-shadow: 0 0 8px var(--mint); }
.dot--sharing { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.room-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  border-left: 1px solid var(--border-subtle);
  padding: 1.2rem 1rem;
  overflow-y: auto;
}
.sidebar__title {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin: 0 0 1rem;
  font-family: var(--font-display);
}
.user-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.user-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.user-item.is-me { border-color: rgba(0, 229, 255, 0.3); }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.avatar__letter { font-family: var(--font-display); font-weight: 700; font-size: 0.8rem; color: #04060f; }
.user-item__name {
  flex: 1;
  font-size: 0.87rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-chip {
  font-size: 0.68rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  color: var(--text-faint);
  white-space: nowrap;
}
.status-chip.is-sharing {
  color: var(--cyan);
  border-color: rgba(0, 229, 255, 0.4);
  background: rgba(0, 229, 255, 0.08);
}

.stage {
  flex: 1;
  position: relative;
  padding: 1.4rem;
  overflow-y: auto;
}

.stage__empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  gap: 0.4rem;
  padding: 1rem;
}
.stage__empty.is-hidden { display: none; }
.stage__empty-sub { color: var(--text-faint); font-size: 0.85rem; }
.pulse-orb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-bottom: 0.8rem;
  background: radial-gradient(circle, rgba(0, 229, 255, 0.35), transparent 70%);
  border: 1px solid rgba(0, 229, 255, 0.3);
  animation: orb-pulse 2.4s ease-in-out infinite;
}
@keyframes orb-pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.tile {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.tile.is-live {
  border-color: rgba(0, 229, 255, 0.45);
  box-shadow: 0 0 0 1px rgba(0, 229, 255, 0.2), var(--shadow-glow-cyan);
}
.tile__video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.tile__overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.7rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
  font-size: 0.8rem;
}
.tile__name { font-weight: 600; }
.tile__live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  animation: live-blink 1.6s ease-in-out infinite;
}
@keyframes live-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Per-tile controls (volume + fullscreen) ---------- */
.tile__controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}
.tile:hover .tile__controls,
.tile:focus-within .tile__controls,
.tile.is-fullscreen .tile__controls {
  opacity: 1;
  transform: translateY(0);
}
.tile__ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  background: rgba(13, 15, 30, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.tile__ctrl-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.tile__volume-slider {
  flex: 1 1 auto;
  height: 4px;
  min-width: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}
.tile__fullscreen-btn { margin-inline-start: auto; }
/* The local self-preview has no meaningful volume (it's muted to avoid
   echo), so its slider/mute button are hidden — only fullscreen stays. */
.tile.is-self .tile__volume-btn,
.tile.is-self .tile__volume-slider { display: none; }
.tile:fullscreen { aspect-ratio: unset; }
.tile:fullscreen .tile__video { object-fit: contain; }

/* ---------- Action bar ---------- */
.action-bar {
  display: flex;
  justify-content: center;
  padding: 1rem;
  border-top: 1px solid var(--border-subtle);
  background: rgba(8, 10, 20, 0.7);
  backdrop-filter: blur(14px);
}
.btn--share {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 0.85rem 2rem;
  border-radius: 999px;
  font-size: 0.95rem;
}
.btn--share__icon { display: inline-flex; color: var(--mint); }
.btn--share:hover { border-color: var(--mint); }
.btn--share.is-sharing {
  background: linear-gradient(135deg, var(--danger), #c9184a);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 26px -10px rgba(255, 77, 109, 0.6);
}
.btn--share.is-sharing .btn--share__icon { color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 6.2rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  pointer-events: none;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 780px) {
  .sidebar {
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.8rem 1rem;
  }
  .user-list { flex-direction: row; overflow-x: auto; padding-bottom: 0.3rem; }
  .user-item { flex-shrink: 0; min-width: 150px; }
  .room-body { flex-direction: column; }
  .room-header { padding: 0.75rem 1rem; }
  .landing-title { font-size: 1.3rem; }
  .stage { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
