:root {
  font-family: system-ui, -apple-system, "Noto Sans Thai", sans-serif;
  color: #eef4f8;
  background: #081119;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; }
body { min-height: 100dvh; background: #081119; }
button, input { font: inherit; }
button { cursor: pointer; border: 0; }
button:focus-visible, input:focus-visible { outline: 3px solid #76e5cc; outline-offset: 2px; }
.hidden { display: none !important; }
.page { min-height: 100dvh; padding: 20px; }
.brand { color: #72dcc5; font-size: .72rem; font-weight: 800; letter-spacing: .16em; }

.home-card {
  width: min(100%, 490px);
  margin: 12vh auto;
  padding: 32px;
  border: 1px solid #355064;
  border-radius: 26px;
  background: #152a3b;
  box-shadow: 0 20px 70px #0005;
}
.home-card h1 { margin: 25px 0; font-size: clamp(2rem, 8vw, 3.3rem); line-height: 1.2; }
.home-card h1 span { color: #7de2cb; }
.home-card p, .pre-panel p { color: #b6cbd8; line-height: 1.6; }
label { display: block; font-weight: 700; }
input {
  width: 100%;
  margin: 8px 0 18px;
  padding: 14px 16px;
  border: 1px solid #60788b;
  border-radius: 12px;
  background: #132d3f;
  color: #fff;
}
.primary {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 15px 20px;
  border-radius: 14px;
  background: #73dec6;
  color: #062133;
  font-weight: 800;
}
.primary:hover { background: #9bf3dd; }
.error { min-height: 1.5em; color: #ffb7ae; }
.top { display: flex; max-width: 1100px; margin: auto; align-items: center; justify-content: space-between; color: #a9c1d0; }
.pre-grid { display: grid; max-width: 1100px; margin: 5vh auto; grid-template-columns: 1.3fr 1fr; gap: 30px; align-items: center; }
.preview {
  position: relative;
  display: grid;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  place-items: center;
  border: 1px solid #38576b;
  border-radius: 23px;
  background: #07121b;
  color: #a8bdc9;
}
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#preview-placeholder { position: absolute; }
.pre-panel { padding: 20px; }
.eyebrow { color: #73dec6; font-size: .8rem; font-weight: 800; }
.pre-panel h1 { margin: 8px 0; font-size: clamp(1.7rem, 6vw, 2.7rem); }
.pre-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.pre-controls button, .link-box button { min-height: 44px; padding: 11px; border-radius: 11px; background: #274357; color: #fff; }
.link-box { display: flex; overflow: hidden; margin-top: 25px; padding: 10px; align-items: center; gap: 8px; border: 1px solid #3f5e71; border-radius: 12px; }
.link-box span { overflow: hidden; flex: 1; color: #b6cad7; font-size: .8rem; white-space: nowrap; text-overflow: ellipsis; }

#meeting { position: relative; display: flex; width: 100%; height: 100dvh; min-height: 0; flex-direction: column; overflow: hidden; background: #070d12; }
.meeting-header { display: flex; min-height: 64px; padding: 10px 20px; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid #263843; background: #0d171f; }
.meeting-heading { min-width: 0; }
.meeting-heading strong { display: block; overflow: hidden; margin-top: 4px; font-size: 1rem; white-space: nowrap; text-overflow: ellipsis; }
.meeting-status { display: flex; align-items: center; gap: 10px; }
.connection-status { color: #a9bdc9; font-size: .8rem; white-space: nowrap; }
.connection-status.connected { color: #7de2cb; }
.connection-status.unstable { color: #ffd37d; }
.live-pill { padding: 7px 12px; border: 1px solid #427878; border-radius: 50px; background: #17363d; white-space: nowrap; }
.live-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #7de2cb; }

.stage { position: relative; flex: 1; min-height: 0; padding: 14px; overflow: hidden; }
.speaker-view { position: relative; width: 100%; height: 100%; min-height: 0; }
.main-video {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border-radius: 18px;
  background: #101c25;
}
.main-video.solo { background: transparent; }
.main-video.solo .video-tile { width: min(100%, 720px); height: auto; max-height: 65vh; aspect-ratio: 16 / 9; box-shadow: 0 20px 60px #0008; }
.video-tile { position: relative; display: grid; width: 100%; height: 100%; min-height: 0; place-items: center; overflow: hidden; border-radius: 16px; background: #15242f; }
.video-tile video { display: block; width: 100%; height: 100%; object-fit: cover; }
.video-tile video.camera-disabled { opacity: 0; }
.video-tile.local video { transform: scaleX(-1); }
.video-avatar { display: grid; width: clamp(72px, 16vw, 144px); aspect-ratio: 1; place-items: center; border-radius: 50%; background: linear-gradient(145deg, #28566b, #193748); color: #dff9f2; font-size: clamp(1.6rem, 5vw, 3.4rem); font-weight: 800; }
.video-label { position: absolute; left: 10px; bottom: 10px; z-index: 2; max-width: calc(100% - 20px); overflow: hidden; padding: 5px 9px; border-radius: 7px; background: #07141edb; font-size: .78rem; white-space: nowrap; text-overflow: ellipsis; }
.camera-off { position: absolute; bottom: 40px; color: #9eb2bf; font-size: .72rem; }

.local-pip { position: absolute; z-index: 3; top: 14px; right: 14px; width: clamp(180px, 16vw, 220px); aspect-ratio: 16 / 9; filter: drop-shadow(0 10px 24px #000a); }
.local-pip .video-tile { border: 1px solid #76909e; border-radius: 14px; }
.local-pip .video-avatar { width: 54px; font-size: 1.25rem; }
.thumbs { position: absolute; z-index: 2; right: 14px; bottom: 14px; left: 14px; display: flex; height: 112px; justify-content: center; gap: 9px; overflow-x: auto; pointer-events: none; }
.thumb { flex: 0 0 min(22%, 180px); min-width: 130px; aspect-ratio: 16 / 9; pointer-events: auto; }
.thumb .video-tile { border: 1px solid #314957; border-radius: 12px; }
.thumb .video-avatar { width: 48px; font-size: 1.1rem; }
.thumb .camera-off { display: none; }

.gallery-view { display: grid; width: 100%; height: 100%; min-height: 0; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 12px; overflow: auto; align-content: center; }
.gallery-view .video-tile { min-height: 150px; max-height: min(42vh, 420px); aspect-ratio: 16 / 9; cursor: pointer; }
.gallery-view.count-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.gallery-view.count-3, .gallery-view.count-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.people { position: absolute; right: 12px; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 8; width: min(340px, calc(100vw - 24px)); max-height: 60vh; overflow: auto; padding: 18px; border: 1px solid #66818c; border-radius: 16px; background: #203b4d; box-shadow: 0 12px 30px #0008; }
.people h2 { margin: 0 0 12px; }
.person { padding: 10px; border-bottom: 1px solid #456272; }
.participant-state { color: #a9bdc9; font-size: .76rem; }

.toolbar { z-index: 10; display: flex; flex: 0 0 auto; padding: 9px max(10px, env(safe-area-inset-right)) calc(9px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); justify-content: center; gap: 10px; border-top: 1px solid #263843; background: #0d171fee; backdrop-filter: blur(12px); }
.toolbar button { width: 62px; min-width: 48px; min-height: 50px; border-radius: 14px; background: #253b49; color: #fff; font-size: 1.15rem; }
.toolbar button:hover { background: #365364; }
.toolbar small { display: block; margin-top: 2px; font-size: .61rem; }
.toolbar .off { background: #634444; }
.toolbar .leave { background: #c3474d; }
.toolbar .leave:hover { background: #dc555c; }
.more-menu { position: absolute; z-index: 11; right: 14px; bottom: calc(82px + env(safe-area-inset-bottom)); display: grid; width: min(250px, calc(100vw - 28px)); gap: 6px; padding: 9px; border: 1px solid #66818c; border-radius: 14px; background: #203b4d; box-shadow: 0 12px 30px #0008; }
.more-menu button { min-height: 46px; padding: 10px 12px; border-radius: 9px; background: #29495a; color: #fff; text-align: left; }

.toast { position: absolute; z-index: 12; bottom: calc(82px + env(safe-area-inset-bottom)); left: 50%; width: max-content; max-width: 90vw; padding: 11px 14px; transform: translateX(-50%); border-radius: 9px; background: #305265; text-align: center; }
.media-unlock { position: absolute; z-index: 14; top: 50%; left: 50%; min-height: 48px; padding: 12px 18px; transform: translate(-50%, -50%); border: 1px solid #8ae8d3; border-radius: 999px; background: #143b45ee; color: #fff; box-shadow: 0 12px 35px #000a; font-weight: 800; }

@media (max-width: 700px) {
  .page { padding: 16px; }
  .home-card { margin: 8vh auto; padding: 24px; }
  .pre-grid { display: block; margin: 20px auto; }
  .preview { aspect-ratio: 16 / 9; }
  .pre-panel { padding: 20px 2px; }
  .pre-controls button { flex: 1; }
  .meeting-header { min-height: 52px; padding: 7px 10px; }
  .meeting-header .brand { display: none; }
  .meeting-heading strong { max-width: 42vw; margin: 0; font-size: .9rem; }
  .connection-status { max-width: 30vw; overflow: hidden; font-size: .68rem; white-space: nowrap; text-overflow: ellipsis; }
  .live-pill { padding: 5px 8px; font-size: .75rem; }
  .stage { padding: 8px; }
  .main-video { border-radius: 12px; }
  .main-video.solo .video-tile { width: 100%; max-height: 62vh; }
  .local-pip { top: 8px; right: 8px; width: min(30vw, 132px); }
  .local-pip .video-tile { border-radius: 10px; }
  .local-pip .video-label { left: 5px; bottom: 5px; padding: 3px 6px; font-size: .62rem; }
  .local-pip .camera-off { display: none; }
  .thumbs { right: 8px; bottom: 8px; left: 8px; height: 74px; justify-content: flex-start; }
  .thumb { min-width: 108px; flex-basis: 108px; }
  .gallery-view { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: auto; gap: 7px; align-content: center; }
  .gallery-view .video-tile { min-height: 0; max-height: 32vh; aspect-ratio: 16 / 9; border-radius: 10px; }
  .gallery-view .video-avatar { width: 54px; font-size: 1.2rem; }
  .gallery-view .camera-off { display: none; }
  .toolbar { padding-right: max(4px, env(safe-area-inset-right)); padding-left: max(4px, env(safe-area-inset-left)); gap: 4px; justify-content: space-around; }
  .toolbar button { width: auto; min-width: 46px; min-height: 50px; padding: 5px; border-radius: 12px; }
  .people, .toast { bottom: calc(78px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .toolbar button { min-width: 43px; font-size: 1rem; }
  .toolbar small { font-size: .55rem; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .meeting-header { min-height: 42px; padding-top: 4px; padding-bottom: 4px; }
  .toolbar { padding-top: 5px; padding-bottom: calc(5px + env(safe-area-inset-bottom)); }
  .toolbar button { min-height: 44px; }
  .local-pip { width: min(24vw, 160px); }
  .thumbs { height: 68px; }
}
