:root {
  --bg: #0f1115;
  --card: #181b22;
  --line: #262a34;
  --text: #e9ecf2;
  --muted: #8b93a5;
  --accent: #ff4d5e;
  --danger: #ff6b6b;
  --warn: #3a2c12;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Noto Sans Thai", sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
.tag { font-size: 13px; color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.warn { background: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }

button {
  font: inherit;
  color: var(--text);
  background: #232733;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #2c3140; }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--danger); }
button.ghost { background: none; }
button.big { font-size: 18px; padding: 12px 22px; }
.chip { border-radius: 999px; font-size: 13px; }

.now { display: flex; gap: 14px; }
.now img { width: 180px; aspect-ratio: 16/9; object-fit: cover; border-radius: 10px; flex: none; }
.now-body { flex: 1; min-width: 0; }
.label { font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.now .title { font-size: 18px; font-weight: 600; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 10px; cursor: pointer; overflow: hidden; }
#barFill { height: 100%; background: var(--accent); width: 0; transition: width .4s linear; }
.times { display: flex; justify-content: space-between; font-size: 12px; margin-top: 3px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.vol { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.vol input { width: 110px; accent-color: var(--accent); }

.search { display: flex; gap: 8px; }
.search-field { position: relative; flex: 1; min-width: 0; display: flex; }
.search input {
  flex: 1; min-width: 0; padding-right: 38px !important; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px;
}
.search input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#msg { margin: 6px 0 0; min-height: 1em; }

.row-head { display: flex; justify-content: space-between; align-items: center; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list img { width: 72px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; flex: none; }
.list .meta { flex: 1; min-width: 0; }
.list .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .acts { display: flex; gap: 4px; flex: none; }
.list .acts button { padding: 5px 9px; }
.idx { width: 18px; text-align: right; color: var(--muted); font-size: 13px; flex: none; }
.empty { justify-content: center; }
.activity { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 200px; overflow: auto; }
.activity li { padding: 3px 0; }

.gate { text-align: center; padding: 30px 16px; }
.video { position: relative; aspect-ratio: 16/9; border-radius: 14px; overflow: hidden; background: #000; }
.video iframe, .video #yt { position: absolute; inset: 0; width: 100%; height: 100%; }
.now-text { margin: 12px 0 4px; font-size: 17px; }
.conn { font-size: 13px; color: var(--muted); }

@media (max-width: 560px) {
  .now { flex-direction: column; }
  .now img { width: 100%; }
  .list img { width: 56px; }
  .list li { flex-wrap: wrap; }
  .list .acts { width: 100%; justify-content: flex-end; }
}

/* ---------- header actions ---------- */
.top-actions { display: flex; gap: 8px; }
.chip.share { color: #fff; background: #2a2f3d; }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: rgba(5, 6, 10, .72);
  backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .2s ease;
}
.modal-backdrop.open { opacity: 1; }
.modal {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, #1d212b, var(--card));
  border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 22px 20px; text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  transform: translateY(12px) scale(.97); transition: transform .22s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-backdrop.open .modal { transform: none; }
.modal h2 { font-size: 20px; margin: 10px 0 4px; }
.modal p { margin: 0 0 16px; }
.modal-icon, .avatar {
  width: 68px; height: 68px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-size: 34px;
  background: radial-gradient(circle at 30% 30%, #ff7a86, var(--accent));
  box-shadow: 0 8px 24px rgba(255, 77, 94, .35);
}
.avatar { background: radial-gradient(circle at 30% 30%, #3a4152, #262b37); box-shadow: inset 0 0 0 2px var(--accent); }
.modal-form { display: grid; gap: 10px; }
.modal input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.modal input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.pin-input { text-align: center; font-size: 28px !important; letter-spacing: .35em; font-variant-numeric: tabular-nums; }
.pin-input::placeholder { letter-spacing: .2em; color: #3a4050; }
.modal-err { color: var(--danger); min-height: 1.2em; margin: -2px 0 0 !important; font-size: 14px; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; }
.dice { flex: none; border-radius: 12px; }
button.block { width: 100%; padding: 12px; border-radius: 12px; font-weight: 600; }
.modal button.ghost { color: var(--muted); font-weight: 400; margin-top: 2px; }
.shake { animation: shake .4s; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- share ---------- */
.qr {
  width: 200px; aspect-ratio: 1; margin: 0 auto 14px;
  background: #fff; border-radius: 14px; padding: 8px;
  display: grid; place-items: center;
}
.qr svg { width: 100%; height: 100%; display: block; }
.qr-loading { font-size: 13px; }
.qr.small { width: 132px; margin: 0; flex: none; }
.qr.small:empty { display: none; }
.link-row { display: flex; gap: 8px; margin-bottom: 10px; }
.link-row input { flex: 1; min-width: 0; font-size: 13px; padding: 10px 12px; color: var(--muted); }
.link-row button { flex: none; border-radius: 12px; }
.link-row button.done { color: #6ee7a8; }
.player-info { display: flex; gap: 16px; align-items: center; justify-content: space-between; }

/* ---------- rooms ---------- */
a.btn {
  display: inline-block; text-decoration: none; text-align: center; box-sizing: border-box;
  font: inherit; color: var(--text); background: #232733; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px;
}
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
a.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.modal a.btn.block { width: 100%; margin-top: 4px; }

.room-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.room-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-title > div { min-width: 0; }
.back {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 50%; background: #232733; color: var(--text); text-decoration: none; font-size: 22px; line-height: 1;
}
.back:hover { background: #2c3140; }
.top-actions { flex: none; }

.hero h2 { font-size: 18px; }
.hero p { margin: 0; }
.rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.room-card {
  display: flex; align-items: center; gap: 14px; margin: 0;
  color: inherit; text-decoration: none; transition: border-color .15s, transform .15s;
}
.room-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.room-art {
  width: 96px; aspect-ratio: 16/9; flex: none; border-radius: 10px; overflow: hidden;
  background: #232733; display: grid; place-items: center; font-size: 26px;
}
.room-art img { width: 100%; height: 100%; object-fit: cover; }
.room-body { flex: 1; min-width: 0; }
.room-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-now { margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-stats { display: grid; gap: 4px; justify-items: end; flex: none; color: var(--muted); }
.room-stats .on { color: #6ee7a8; }
.lock { font-size: 13px; opacity: .7; }
.empty-rooms { text-align: center; padding: 30px 16px; }
.empty-rooms p { margin: 12px 0; }
.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 11px; margin-right: 2px; }
.eq i { width: 3px; background: var(--accent); border-radius: 1px; animation: eq 1s infinite ease-in-out; }
.eq i:nth-child(2) { animation-delay: -.4s; }
.eq i:nth-child(3) { animation-delay: -.7s; }
@keyframes eq { 0%, 100% { height: 3px; } 50% { height: 11px; } }

.field-label { text-align: left; font-size: 13px; color: var(--muted); margin: 4px 0 -4px; }
.settings-block {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 16px 0 6px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; text-align: left;
}
.settings-block .field-label { margin: 0; }
.pin-show { font-size: 22px; letter-spacing: .2em; font-variant-numeric: tabular-nums; font-weight: 600; }
.modal > .muted.small { margin-bottom: 14px; }
button.danger-btn { color: var(--danger); background: rgba(255, 107, 107, .08); border-color: rgba(255, 107, 107, .3); }
button.danger-btn:hover:not(:disabled) { background: rgba(255, 107, 107, .16); }
.pin-note { margin: -2px 0 12px !important; }

@media (max-width: 560px) {
  .room-art { width: 72px; }
  .room-title h1 { font-size: 18px; }
}

.clear-q {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; line-height: 1;
  color: var(--muted); background: #2a2f3d; border: 0;
}
.clear-q:hover:not(:disabled) { color: var(--text); background: #353b4b; }
/* Shown whenever the box has text, however it got there (typing, paste, restored on reload). */
.search-field input:placeholder-shown + .clear-q { display: none; }

.no-player { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.no-player[hidden] { display: none; }
.no-player .small { margin-top: 2px; opacity: .85; }
.no-player a.btn { flex: none; padding: 9px 14px; white-space: nowrap; }
@media (max-width: 560px) {
  .no-player { flex-direction: column; align-items: stretch; }
}

/* ---------- room page player ---------- */
.now .video { display: none; }
.now.has-video { flex-direction: column; }
.now.has-video .video { display: block; }
.now.has-video #nowThumb { display: none; }

/* ---------- phones: use the full width ---------- */
@media (max-width: 560px) {
  .wrap { padding: 10px 8px; }
  .top { padding: 0 4px; }
  .card { padding: 12px; border-radius: 12px; margin-bottom: 8px; }
  .now.has-video .video { margin: -12px -12px 2px; border-radius: 12px 12px 0 0; }
  .room-art { width: 64px; }
  .room-card { gap: 10px; }
  .search { gap: 6px; }
  .search > button { padding: 7px 10px; }
  .chip { padding: 6px 10px; }
}

/* ---------- who's online ---------- */
.members { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -2px 2px 12px; font-size: 13px; }
.members:empty { display: none; }
.members b { margin-right: 2px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 3px rgba(61, 220, 132, .18); }
.member { background: #232733; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.member.me { border-color: var(--accent); }

/* ---------- favorites ---------- */
button.fav { color: var(--muted); font-size: 16px; line-height: 1; }
button.fav.on { color: var(--accent); }
.list .acts button.fav { padding: 5px 8px; }
.search-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.search-tools #msg { margin: 0; }
.fav-chip { flex: none; }
.fav-chip #favCount { color: var(--muted); }
.modal .fav-filter { margin-bottom: 8px; }
.fav-list { max-height: 50vh; overflow: auto; margin: 0 -6px 10px; padding: 0 6px; text-align: left; }
.fav-list .acts button { padding: 5px 9px; }

/* ---------- no zoom: scale stays 1.0 ---------- */
/* iOS zooms into any text box under 16px on focus, and ignores user-scalable=no
   for pinch; double-tap zoom is turned off by touch-action. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
input, textarea, select { font-size: 16px !important; }
