/* =========================================================================
   MJL Screen Share — sistem desain
   Tema gelap, dioptimalkan untuk ruang meeting (layar terang menyilaukan
   saat lampu diredupkan).
   ========================================================================= */

:root {
  /* Permukaan — makin tinggi angkanya, makin "dekat" ke mata */
  --bg:        #0b0d12;
  --surface-1: #12151c;
  --surface-2: #181c25;
  --surface-3: #212632;
  --line:      #272d3a;
  --line-soft: #1d222c;

  /* Teks */
  --text:      #eef1f6;
  --text-dim:  #a8b1c1;
  --text-mute: #6f7889;

  /* Aksen */
  --accent:      #4a86ff;
  --accent-hover:#6398ff;
  --accent-dim:  rgba(74, 134, 255, .14);
  --ok:          #2fb87a;
  --ok-dim:      rgba(47, 184, 122, .14);
  --warn:        #e8a33d;
  --danger:      #f0555a;
  --danger-dim:  rgba(240, 85, 90, .14);

  /* Bentuk */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;

  /* Bayangan lembut berlapis */
  --shadow-1: 0 1px 2px rgba(0,0,0,.3);
  --shadow-2: 0 4px 16px rgba(0,0,0,.35);
  --shadow-3: 0 16px 48px rgba(0,0,0,.5);

  /* Gerak — cepat tapi tidak kasar */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --t-fast: .15s;
  --t-mid: .25s;
  --t-slow: .4s;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Hormati preferensi pengguna yang sensitif terhadap gerak */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* =========================================================================
   Animasi dasar
   ========================================================================= */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(47,184,122,.5); }
  70%  { box-shadow: 0 0 0 7px rgba(47,184,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,184,122,0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* =========================================================================
   Tombol
   ========================================================================= */
button {
  font: inherit;
  font-weight: 600;
  letter-spacing: -.01em;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  padding: 11px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease),
              opacity var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .4; cursor: not-allowed; }
button svg { flex: none; }
/* Atribut hidden harus selalu menang atas aturan display di atas */
[hidden] { display: none !important; }

.primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-1); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }

.ghost {
  background: var(--surface-2);
  color: var(--text-dim);
  border-color: var(--line);
}
.ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
  border-color: #333b4a;
}

.share { background: var(--accent); color: #fff; box-shadow: var(--shadow-1); }
.share:hover:not(:disabled) { background: var(--accent-hover); }

.stop { background: var(--danger); color: #fff; box-shadow: var(--shadow-1); }
.stop:hover:not(:disabled) { filter: brightness(1.1); }

/* =========================================================================
   HALAMAN MASUK
   ========================================================================= */
body.landing {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -15%, rgba(74,134,255,.12), transparent 70%),
    var(--bg);
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 36px 32px 30px;
  box-shadow: var(--shadow-3);
  animation: rise var(--t-slow) var(--ease-out) both;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
}
.brand-logo {
  width: 54px;
  height: 54px;
  object-fit: contain;
  margin-bottom: 14px;
  border-radius: var(--r-md);
}
.brand-mark {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  margin-bottom: 14px;
  border-radius: var(--r-md);
  background: var(--accent-dim);
  color: var(--accent);
}
.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -.03em;
}
.brand p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-mute);
  max-width: 30ch;
}

.field { margin-bottom: 18px; }
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--text-dim);
}

input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
input::placeholder { color: var(--text-mute); }
input:hover { border-color: #333b4a; }
input:focus {
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.row { display: flex; gap: 9px; }
.row input { flex: 1; min-width: 0; }

small.help {
  display: block;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-mute);
  line-height: 1.5;
}

.primary.block { width: 100%; margin-top: 8px; padding: 13px; font-size: 15.5px; }

.note {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--text-mute);
  line-height: 1.65;
  display: flex;
  gap: 10px;
}
.note svg { flex: none; margin-top: 2px; color: var(--text-mute); }
.note b { color: var(--text-dim); font-weight: 600; }

/* =========================================================================
   HALAMAN RUANGAN
   ========================================================================= */
body.room {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #000;
}

/* --- Bar atas --- */
header.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
  transition: opacity var(--t-slow) var(--ease),
              transform var(--t-slow) var(--ease);
}

.room-id {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.room-id .lbl { font-size: 12.5px; color: var(--text-mute); }
.room-id .val {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar .spacer { flex: 1; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 6px 13px;
  border-radius: var(--r-full);
  transition: color var(--t-mid) var(--ease),
              border-color var(--t-mid) var(--ease),
              background var(--t-mid) var(--ease);
}
.status .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-mute);
  flex: none;
  transition: background var(--t-mid) var(--ease);
}
.status.is-live { color: #7ee0b0; border-color: rgba(47,184,122,.4); background: var(--ok-dim); }
.status.is-live .dot { background: var(--ok); animation: pulse-ring 2.2s infinite; }
.status.is-bad { color: #ff9498; border-color: rgba(240,85,90,.4); background: var(--danger-dim); }
.status.is-bad .dot { background: var(--danger); }
.status.is-busy .dot {
  background: transparent;
  border: 2px solid var(--text-mute);
  border-top-color: transparent;
  animation: spin .7s linear infinite;
}

/* --- Panggung --- */
main.stage {
  flex: 1;
  position: relative;
  background: #000;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  z-index: 1;
}

video#screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  opacity: 0;
  transition: opacity var(--t-slow) var(--ease);
  pointer-events: none;
}
video#screen.on { opacity: 1; }

/* Keadaan kosong / menunggu */
.placeholder {
  text-align: center;
  padding: 32px 24px;
  max-width: 420px;
  animation: fade var(--t-slow) var(--ease-out) both;
  transition: opacity var(--t-mid) var(--ease);
}
.placeholder .icon {
  width: 76px; height: 76px;
  margin: 0 auto 20px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  color: var(--text-mute);
}
.placeholder h2 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.02em;
  margin: 0 0 8px;
  color: var(--text);
}
.placeholder p {
  margin: 0;
  font-size: 14px;
  color: var(--text-mute);
  line-height: 1.6;
}

/* Rangka berkedip saat menyambung */
.placeholder.loading .icon {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-3) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

/* --- Bar kontrol --- */
footer.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
  transition: opacity var(--t-slow) var(--ease),
              transform var(--t-slow) var(--ease);
}
.controls .spacer { flex: 1; }

/* Auto-hide saat presentasi berlangsung */
body.room.immersive header.bar {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}
body.room.immersive footer.controls {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}
/* Saran memutar HP ikut memudar bersama kontrol */
body.room.immersive .rotate-tip {
  opacity: 0;
  transition: opacity var(--t-slow) var(--ease);
  pointer-events: none;
}

/* --- Daftar peserta --- */
.peers {
  display: flex;
  gap: 7px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 46vw;
  padding: 2px;
}
.peers::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  color: var(--text-dim);
  white-space: nowrap;
  flex: none;
  animation: fade var(--t-mid) var(--ease-out) both;
  transition: border-color var(--t-mid) var(--ease), color var(--t-mid) var(--ease);
}
.chip.self { color: var(--text); font-weight: 600; }
.chip.presenting {
  border-color: rgba(47,184,122,.45);
  background: var(--ok-dim);
  color: #7ee0b0;
}
.chip .live-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}

/* --- Tombol mikrofon aktif --- */
.ghost.mic-live {
  background: var(--ok-dim);
  border-color: rgba(47,184,122,.45);
  color: #7ee0b0;
}
.ghost.mic-live:hover:not(:disabled) { background: rgba(47,184,122,.22); }

/* --- Tombol rekam aktif --- */
.ghost.rec-live {
  background: var(--danger-dim);
  border-color: rgba(240,85,90,.5);
  color: #ff9498;
}
.ghost.rec-live:hover:not(:disabled) { background: rgba(240,85,90,.24); }

/* --- Penanda "sedang direkam" di bar atas --- */
.rec-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #ff9498;
  background: var(--danger-dim);
  border: 1px solid rgba(240,85,90,.45);
  padding: 6px 13px;
  border-radius: var(--r-full);
  white-space: nowrap;
  animation: fade var(--t-mid) var(--ease-out) both;
}
.rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex: none;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* Chip peserta yang mic-nya aktif / sedang merekam */
.chip .mic-icon { color: var(--ok); flex: none; }
.chip .rec-icon { color: var(--danger); flex: none; animation: blink 1.6s ease-in-out infinite; }

/* --- Saran memutar HP --- */
/* Layar presentasi 16:9 jadi sangat kecil di HP tegak. Sarankan diputar. */
.rotate-tip {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 9px;
  background: rgba(24, 28, 37, .94);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  padding: 9px 15px;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  z-index: 15;
  animation: fade var(--t-slow) var(--ease-out) both;
  backdrop-filter: blur(8px);
}
.rotate-tip svg { color: var(--accent); flex: none; }

/* Hanya di HP tegak, dan hanya saat ada gambar tampil */
@media (max-width: 720px) and (orientation: portrait) {
  body.room.has-video .rotate-tip { display: inline-flex; }
}

/* --- Toast --- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(14px);
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 13px 20px;
  border-radius: var(--r-md);
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-mid) var(--ease), transform var(--t-mid) var(--ease-out);
  box-shadow: var(--shadow-3);
  max-width: min(90vw, 460px);
  text-align: center;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================================================
   Responsif — HP
   ========================================================================= */
@media (max-width: 720px) {
  .card { padding: 30px 22px 26px; border-radius: var(--r-md); }

  header.bar { padding: 10px 13px; gap: 10px; }
  .room-id .val { max-width: 34vw; }
  .status { padding: 6px 11px; font-size: 12.5px; }
  .status .txt { display: none; }      /* sisakan titik indikator saja */
  .status.is-bad .txt { display: inline; } /* kecuali saat bermasalah */

  footer.controls { padding: 10px 13px; gap: 8px; }
  .peers { display: none; }            /* daftar peserta tidak muat di HP */

  /* Target sentuh minimal 44px */
  button { padding: 12px 15px; min-height: 44px; }
  .btn-label-sm { display: none; }     /* tombol jadi ikon saja */

  #toast { bottom: 84px; font-size: 13.5px; padding: 12px 16px; }
  .placeholder .icon { width: 64px; height: 64px; }
  .placeholder h2 { font-size: 16.5px; }
  .placeholder p { font-size: 13.5px; }
}

/* HP melintang — ruang vertikal sangat sempit, rapatkan */
@media (max-height: 480px) and (orientation: landscape) {
  header.bar { padding: 7px 12px; }
  footer.controls { padding: 7px 12px; }
  button { padding: 9px 13px; min-height: 38px; font-size: 13.5px; }
  .placeholder .icon { width: 48px; height: 48px; margin-bottom: 12px; }
  .placeholder h2 { font-size: 15px; margin-bottom: 4px; }
  .placeholder p { font-size: 13px; }
  #toast { bottom: 62px; }
}

/* Layar sangat kecil */
@media (max-width: 380px) {
  .room-id .lbl { display: none; }
  button { padding: 11px 13px; }
}
