/* Read2gether — full-screen co-reading room (fitted page + shared drawing + chat) */
.room {
  position: fixed; inset: 0; z-index: 90;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(124,58,237,0.09), transparent 60%), #07070b;
  display: flex; flex-direction: column;
}

/* top bar */
.room-bar {
  flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(10,10,16,0.74); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border-soft);
}
.room-back { width: 38px; height: 38px; flex-shrink: 0; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--text); }
.room-back svg { width: 20px; height: 20px; }
.room-back:hover { background: var(--surface-3); }
.room-bar-l { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.room-title { font-size: 15px; font-weight: 750; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-chapter { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-members { display: flex; align-items: center; }
.room-member { position: relative; display: inline-flex; margin-left: -8px; padding: 0; border: 0; background: none; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg); }
.room-member:first-child { margin-left: 0; }
.room-member .avatar { width: 30px; height: 30px; border: 2px solid var(--bg); border-radius: 50%; }
.room-member.clickable { cursor: pointer; }
.room-member.has-control { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--c, var(--accent)); }
.room-member.has-control::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--c, var(--accent)); border: 2px solid var(--bg);
}
.room-bar-r { display: flex; align-items: center; gap: 8px; }
.room-code { display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 13px; letter-spacing: 0.12em; cursor: pointer; transition: border-color 0.15s; }
.room-code b { font-weight: 800; }
.room-code svg { width: 15px; height: 15px; color: var(--muted); }
.room-code:hover { border-color: var(--accent); }
.room-leave:hover { color: #fca5a5; }

/* stage — the whole page fits, no scrolling */
.room-stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; padding: 12px; }
/* .room-page is sized to the fitted page in px by JS; the image fills it exactly. */
.room-page { position: relative; line-height: 0; max-width: 100%; max-height: 100%; }
.room-img { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: 6px; background: var(--surface); }
.room-img.in { animation: fadein 0.25s var(--ease); }
.room-canvas { position: absolute; inset: 0; z-index: 2; touch-action: none; cursor: crosshair; border-radius: 6px; }

/* bottom controls */
.room-controls {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: rgba(10,10,16,0.74); backdrop-filter: blur(14px); border-top: 1px solid var(--border-soft);
}
.room-nav { display: flex; align-items: center; gap: 12px; }
.room-nav.locked .rtool { opacity: 0.4; cursor: not-allowed; }
.room-pageinfo { color: var(--muted); font-size: 14px; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.room-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.room-swatches { display: flex; gap: 6px; margin-right: 6px; }
.room-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); background: var(--c); cursor: pointer; padding: 0; transition: transform 0.12s var(--ease); }
.room-swatch:hover { transform: scale(1.15); }
.room-swatch.sel { box-shadow: 0 0 0 2px #07070b, 0 0 0 4px var(--c); }
.room .rtool.on { background: var(--accent-soft); color: #fff; box-shadow: inset 0 0 0 1px var(--accent); }

/* host: join requests */
.room-requests { position: absolute; top: 12px; right: 12px; z-index: 30; width: min(320px, 86vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 12px 14px; animation: qDrop 0.2s var(--ease); }
.room-req-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin-bottom: 8px; }
.room-req { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.room-req .avatar { width: 30px; height: 30px; border-radius: 50%; }
.room-req-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-req .rtool { width: 34px; height: 34px; }
.rtool.acc { color: #6ee7b7; } .rtool.acc:hover { background: rgba(16,185,129,0.15); }
.rtool.dec { color: #fca5a5; } .rtool.dec:hover { background: rgba(220,38,38,0.15); }

/* chat */
.room-chat { position: absolute; top: 0; right: 0; bottom: 0; width: min(340px, 90vw); z-index: 40; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; transform: translateX(101%); transition: transform 0.28s var(--ease); }
.room-chat.open { transform: translateX(0); box-shadow: -24px 0 60px rgba(0,0,0,0.5); }
.room-chat-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); font-weight: 700; }
.room-chat-list { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.room-msg { display: flex; flex-direction: column; gap: 3px; max-width: 92%; }
.room-msg.mine { align-self: flex-end; align-items: flex-end; }
.room-msg-name { font-size: 11px; color: var(--faint); font-weight: 700; padding: 0 4px; }
.room-msg-text { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 12px; padding: 8px 12px; font-size: 14px; line-height: 1.45; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.room-msg.mine .room-msg-text { background: var(--accent-soft); border-color: var(--accent); color: #eadcff; }
.room-chat-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border-soft); }
.room-chat-input { margin-bottom: 0; }

/* waiting-for-approval screen */
.room-wait-wrap { min-height: 66vh; display: grid; place-items: center; padding: 24px; }
.room-wait { text-align: center; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.room-wait h2 { margin: 6px 0 0; font-size: 22px; font-weight: 800; }
.room-wait p { color: var(--muted); margin: 0; }
.room-wait .room-code { pointer-events: none; }

/* create / join modal */
.r2g-modal { max-width: 400px; }
.r2g-body { padding: 20px 22px 24px; }
.r2g-body .btn-primary { width: 100%; justify-content: center; }
.r2g-or { display: flex; align-items: center; gap: 12px; margin: 18px 0 14px; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.r2g-or::before, .r2g-or::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }
.r2g-code { text-transform: uppercase; letter-spacing: 0.18em; text-align: center; font-weight: 700; margin-bottom: 0; }

@media (max-width: 640px) {
  /* top bar — condensed */
  .room-bar { gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  .room-back { width: 34px; height: 34px; }
  .room-back svg { width: 18px; height: 18px; }
  .room-bar-l { flex: 1 1 auto; min-width: 0; margin-right: 6px; } /* title shrinks first */
  .room-title { font-size: 13.5px; }
  .room-chapter { display: none; }
  .room-members { flex-shrink: 0; } /* kept: host taps a member to grant page control */
  .room-member { margin-left: -10px; }
  .room-member .avatar { width: 26px; height: 26px; }
  .room-code { flex-shrink: 0; padding: 6px 10px; font-size: 12px; letter-spacing: 0.08em; }
  .room-code svg { display: none; }
  .room-bar-r { flex-shrink: 0; gap: 6px; }
  .room-bar-r .rtool { width: 36px; height: 36px; }

  .room-stage { padding: 8px; }

  /* bottom controls — two centred rows, wrap if needed */
  .room-controls { gap: 8px; padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); justify-content: center; }
  .room-nav { width: 100%; justify-content: center; order: 1; gap: 18px; }
  .room-tools { width: 100%; justify-content: center; order: 2; gap: 6px; }
  .room-tools .rtool { width: 38px; height: 38px; }
  .room-swatches { gap: 5px; margin-right: 4px; }
  .room-swatch { width: 20px; height: 20px; }

  .room-chat { width: 100vw; top: 0; }
  .room-requests { top: 8px; right: 8px; left: 8px; width: auto; }
}
/* very narrow phones: let the swatch strip scroll instead of pushing tools off */
@media (max-width: 380px) {
  .room-swatches { flex-wrap: nowrap; overflow-x: auto; max-width: 46vw; scrollbar-width: none; }
  .room-swatches::-webkit-scrollbar { display: none; }
}
