:root {
  --bg: #e7edf2;
  --surface: #ffffff;
  --stage: #f5f7fa;
  --ink: #1a2330;
  --muted: #5d6d7e;
  --line: #d9e2ea;
  --accent: #2563eb;
  --danger: #d64545;
  --ok: #17804a;
  --warn: #a16207;
  --video: #243044;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 2px 2px rgba(22, 34, 51, 0.2);
  --font: "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

a { color: inherit; }

button, input, select { font: inherit; color: inherit; }

.panel,
.tile,
.btn,
.field input,
.field select,
.bubble,
.person,
.dialog,
.preview {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel,
.dialog,
.preview {
  background: var(--surface);
}

.btn,
.field input,
.field select {
  border-radius: var(--radius-sm);
}

h1, h2, p { margin: 0; }

h1 { font-size: 1.35rem; letter-spacing: -0.02em; }
h2 { font-size: 1rem; }

.muted { color: var(--muted); font-size: 0.92rem; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  background: #fff;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn.is-on { background: var(--ink); color: #fff; }
.btn:disabled, .btn.is-disabled {
  background: #e5ebf0;
  color: #8a97a3;
  box-shadow: none;
  cursor: default;
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }
.field span { color: var(--muted); }
.field input, .field select {
  height: 40px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
}

.pill-warn { color: var(--warn); }
.pill-ok { color: var(--ok); }

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 16px;
}

.shell-bar { padding: 12px 16px; }

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.8fr);
  gap: 12px;
  align-content: start;
}

.card { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--stage);
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }

.person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: #3b82f6;
  color: #fff;
  font-size: 0.85rem;
  flex: 0 0 auto;
}

.person .who { display: flex; flex-direction: column; min-width: 0; }
.person .who strong { font-size: 0.92rem; }
.person .who span { color: var(--muted); font-size: 0.8rem; }
.grow { flex: 1; min-width: 0; }

.preview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 12px;
}

.preview {
  min-height: 320px;
  background: var(--video);
  position: relative;
  overflow: hidden;
}

.preview video { width: 100%; height: 100%; object-fit: cover; display: block; }

.preview-name {
  position: absolute;
  left: 12px;
  bottom: 12px;
  color: #fff;
  background: rgba(16, 22, 32, 0.72);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 4px 8px;
  font-size: 0.85rem;
}

.wait-card, .after-card {
  width: min(560px, 100%);
  margin: 12vh auto 0;
  padding: 28px 24px;
}

.wait-list { display: flex; flex-direction: column; gap: 8px; }

.room {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
}

.topbar, .toolbar { padding: 10px 12px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar-title { display: flex; flex-direction: column; }
.topbar-title strong { font-size: 1rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.room-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
}

.stage {
  min-height: 0;
  background: var(--stage);
  padding: 12px;
  display: grid;
}

.tiles {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  grid-auto-rows: minmax(140px, 1fr);
  gap: 8px;
  align-content: start;
}

.tile {
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

.tile-video {
  position: relative;
  flex: 1;
  min-height: 96px;
  background: var(--video);
  display: grid;
  place-items: center;
}

.tile-video video { width: 100%; height: 100%; object-fit: cover; }
.tile-video .avatar { width: 48px; height: 48px; font-size: 1.1rem; }

.tile-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #fff;
}

.tile-name { font-size: 0.82rem; font-weight: 650; }
.flag {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  box-shadow: var(--shadow);
  background: #fff;
}
.flag-hand { color: var(--warn); }

.tile[data-role="teacher"] {
  box-shadow: var(--shadow), 0 0 0 2px rgba(37, 99, 235, 0.45);
}

.room-body.is-speaker .stage {
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
}

.room-body.is-speaker .tiles { display: none; }

.spot {
  min-height: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--video);
  color: #fff;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.spot .avatar { width: 72px; height: 72px; font-size: 1.5rem; }
.spot .tile-name {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(16, 22, 32, 0.72);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 4px 8px;
}

.filmstrip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filmstrip .tile { flex: 0 0 160px; min-height: 108px; }

.side {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--stage);
}

.tabs { display: flex; gap: 8px; padding: 12px 12px 0; }
.tab {
  flex: 1;
  text-align: center;
  text-decoration: none;
  padding: 8px 0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  background: #fff;
  font-size: 0.9rem;
}
.tab.is-on { background: var(--ink); color: #fff; }

.pane { min-height: 0; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }

.bubble {
  align-self: flex-start;
  max-width: 92%;
  background: #fff;
  padding: 8px 10px;
  font-size: 0.88rem;
}
.bubble strong { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 650; }
.bubble.mine { align-self: flex-end; background: #e8f0fe; }

.chat-form { display: flex; gap: 8px; margin-top: auto; }
.chat-form input {
  flex: 1;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 0 10px;
}

.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool {
  min-width: 72px;
  min-height: 52px;
  padding: 6px 8px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #fff;
  text-decoration: none;
  font-size: 0.75rem;
  cursor: pointer;
}
.tool b { font-size: 0.95rem; font-weight: 700; }
.tool.danger { background: var(--danger); color: #fff; }
.tool.is-on { background: var(--ink); color: #fff; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 34, 51, 0.28);
  display: grid;
  place-items: center;
  padding: 16px;
}

.dialog { width: min(420px, 100%); padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--stage);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat b { font-size: 1.25rem; }

@media (max-width: 800px) {
  .home-grid,
  .preview-layout,
  .room-body { grid-template-columns: 1fr; }
  .room { height: 100dvh; }
  .room-body { grid-template-rows: minmax(0, 1fr) minmax(160px, 32dvh); }
  .side { min-height: 0; }
  .toolbar { justify-content: flex-start; overflow-x: auto; }
  .stats { grid-template-columns: 1fr; }
}
