:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-dim: #2563c7;
  --danger: #e55;
  --ok: #3dba7a;
  font-family: "Segoe UI", "PingFang HK", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100dvh; }
a { color: var(--accent); }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-wrap: wrap; gap: 0.5rem;
}
.brand { font-weight: 700; letter-spacing: -0.02em; }
.topbar nav a { margin-left: 1rem; text-decoration: none; color: var(--muted); }
.topbar nav a.active { color: var(--text); }

.page { padding: 1.5rem; max-width: 960px; margin: 0 auto; }
.page.narrow { max-width: 420px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.room-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  margin-top: 1rem;
}
.room-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem;
}
.room-card h3 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.room-card .meta { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }
.room-card button {
  background: var(--accent); color: #fff; border: none;
  padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; width: 100%;
}
.room-card button:hover { background: var(--accent-dim); }

.card-form label { display: block; margin-bottom: 1rem; }
.card-form input {
  width: 100%; margin-top: 0.35rem; padding: 0.6rem;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
button.primary { background: var(--accent); color: #fff; border: none; padding: 0.6rem 1rem; border-radius: 8px; cursor: pointer; }
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.block { width: 100%; margin-top: 0.5rem; }
button.danger { background: var(--danger); color: #fff; border: none; padding: 0.4rem 0.75rem; border-radius: 8px; cursor: pointer; }
button.muted-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 0.5rem; border-radius: 8px; cursor: pointer; }

dialog {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); padding: 1.25rem; max-width: 90vw; width: 360px;
}
dialog label { display: block; margin: 0.75rem 0; }
dialog input { width: 100%; padding: 0.5rem; margin-top: 0.25rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* Room layout */
.room-body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.room-top { flex-shrink: 0; }
.room-title-wrap { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.room-title-wrap h1 { margin: 0; font-size: 1.1rem; }
.back { text-decoration: none; font-size: 0.9rem; }

.teacher-tools { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; font-size: 0.85rem; }
.teacher-tools button, .file-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 0.35rem 0.6rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.file-btn { display: inline-block; }

.room-layout {
  flex: 1; display: grid; grid-template-columns: 1fr 320px;
  min-height: 0; overflow: hidden;
}
@media (max-width: 900px) {
  .room-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { max-height: 42vh; border-top: 1px solid var(--border); }
  .mobile-only { display: block; font-size: 0.95rem; margin: 0 0 0.5rem; }
}
@media (min-width: 901px) {
  .mobile-only { display: none; }
}

.stage-wrap { position: relative; min-height: 0; background: #1e1e1e; overflow: auto; }
.stage { position: relative; width: 100%; min-height: 100%; display: flex; align-items: flex-start; justify-content: center; padding: 0.5rem; }
.pdf-layer, .wb-layer { display: block; max-width: 100%; }
.wb-layer { position: absolute; top: 0.5rem; left: 50%; transform: translateX(-50%); touch-action: none; cursor: crosshair; pointer-events: none; }
.wb-layer.teacher { pointer-events: auto; }
.stage-hint { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: var(--muted); pointer-events: none; }

.sidebar {
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; padding: 0.65rem; background: transparent; border: none;
  color: var(--muted); cursor: pointer; font-size: 0.9rem;
}
.tab.active { color: var(--text); border-bottom: 2px solid var(--accent); }

.tab-panel { display: none; flex: 1; flex-direction: column; min-height: 0; padding: 0.75rem; overflow: hidden; }
.tab-panel.active { display: flex; }

.chat-log { flex: 1; overflow-y: auto; font-size: 0.9rem; margin-bottom: 0.5rem; }
.chat-msg { margin-bottom: 0.6rem; }
.chat-msg .who { font-weight: 600; font-size: 0.8rem; color: var(--accent); }
.chat-msg.teacher .who { color: var(--ok); }
.chat-form { display: flex; gap: 0.35rem; }
.chat-form input { flex: 1; padding: 0.5rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

.hands-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
.hands-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}
.hands-list button { font-size: 0.8rem; padding: 0.25rem 0.5rem; border-radius: 6px; border: none; background: var(--accent); color: #fff; cursor: pointer; }

#typing-area {
  width: 100%; resize: vertical; padding: 0.5rem;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.typing-feed { margin-top: 0.75rem; font-size: 0.85rem; overflow-y: auto; max-height: 120px; }
.typing-feed .item { border-left: 3px solid var(--accent); padding-left: 0.5rem; margin-bottom: 0.5rem; }
.granted { color: var(--ok); font-size: 0.9rem; }