:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #16181d;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #12b76a;
  --ok-soft: #e7f8ef;
  --warn: #f79009;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Noto Sans KR', 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e8eaef;
    --muted: #9aa3b2;
    --faint: #687083;
    --line: #262b35;
    --accent: #6b9bff;
    --accent-soft: #1b2640;
    --ok: #3ccf8e;
    --ok-soft: #132a20;
    --danger-soft: #3a1a1c;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0f1115;
  --panel: #171a21;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --faint: #687083;
  --line: #262b35;
  --accent: #6b9bff;
  --accent-soft: #1b2640;
  --ok: #3ccf8e;
  --ok-soft: #132a20;
  --danger-soft: #3a1a1c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input[type='text'], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  outline: none;
}
input[type='text']:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
input[type='range'] { width: 100%; accent-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.big { padding: 14px 18px; font-size: 16px; border-radius: 10px; width: 100%; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.pill.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.pill.ok .dot { background: var(--ok); }
.pill.live { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.pill.live .dot { background: var(--danger); animation: pulse 1.2s infinite; }
.pill.warn { color: var(--warn); }
.pill.warn .dot { background: var(--warn); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ───────── 방 만들기 ───────── */
.create { max-width: 760px; margin: 40px auto; padding: 0 20px 60px; }
.create header h1 { font-size: 24px; margin: 0 0 4px; }
.create header p { margin: 0 0 24px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-size: 14px; user-select: none;
  background: var(--bg);
}
.chip input { display: none; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip small { color: var(--muted); font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* ───────── 교수 대시보드 ───────── */
.host-top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.host-top h1 { font-size: 17px; margin: 0; }
.host-top .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; letter-spacing: 1px; }
.host-grid {
  display: grid; grid-template-columns: 360px 1fr; gap: 16px;
  padding: 16px 20px; max-width: 1400px; margin: 0 auto;
}
@media (max-width: 960px) { .host-grid { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.meter { width: 100%; height: 96px; display: block; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.gate-state { font-weight: 700; font-size: 14px; }
.gate-state.on { color: var(--ok); }
.gate-state.off { color: var(--muted); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.qr-box { display: flex; gap: 16px; align-items: center; }
.qr-box img { width: 132px; height: 132px; border-radius: 8px; background: #fff; padding: 6px; border: 1px solid var(--line); }
.qr-box .url { font-size: 13px; word-break: break-all; }

.monitor { display: flex; flex-direction: column; min-height: 420px; }
.monitor .lines { flex: 1; overflow-y: auto; max-height: calc(100vh - 330px); min-height: 300px; padding-right: 4px; }
.mline { padding: 10px 0; border-bottom: 1px solid var(--line); }
.mline .src { font-size: 14px; color: var(--muted); }
.mline .tr { font-size: 16px; margin-top: 2px; }
.mline .tr .eng { font-size: 11px; font-weight: 700; color: var(--faint); margin-right: 6px; text-transform: uppercase; }
.mline .tr .ms { font-size: 11px; color: var(--faint); margin-left: 6px; }
.mline .err { color: var(--danger); font-size: 13px; }
.partial-line { padding: 10px 0; color: var(--muted); font-style: italic; min-height: 42px; }
.partial-line:empty::before { content: '…'; color: var(--faint); }
.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.warn-log { font-size: 12.5px; color: var(--warn); max-height: 90px; overflow-y: auto; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 50;
  display: none; align-items: center; justify-content: center; flex-direction: column; gap: 20px; color: #fff; text-align: center;
}
.overlay.show { display: flex; }
.overlay img { width: min(70vh, 80vw); height: min(70vh, 80vw); background: #fff; padding: 16px; border-radius: 16px; }
.overlay h2 { font-size: 32px; margin: 0; }
.overlay p { font-size: 22px; margin: 0; opacity: 0.85; }

/* ───────── 학생 화면 ───────── */
.student { display: flex; flex-direction: column; height: 100dvh; }
.s-top {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.s-top .title { flex: 1; min-width: 0; font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  min-width: 36px; height: 34px; padding: 0 9px; cursor: pointer; font-weight: 700; font-size: 13px;
}
.icon-btn[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.s-body { flex: 1; overflow-y: auto; padding: 14px 18px 8px; -webkit-overflow-scrolling: touch; }
.s-line { margin: 0 0 18px; }
.s-line .t { font-size: calc(var(--fs, 22px)); line-height: 1.45; font-weight: 500; }
.s-line .t.pending { color: var(--faint); }
.s-line .t.streaming::after { content: '▍'; color: var(--accent); animation: pulse 1s infinite; margin-left: 1px; }
.s-line .alt { font-size: calc(var(--fs, 22px) * 0.8); color: var(--muted); margin-top: 4px; }
.s-line .badge { font-size: 10.5px; font-weight: 800; letter-spacing: 0.5px; color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-right: 6px; vertical-align: 2px; }
.s-line .o { font-size: calc(var(--fs, 22px) * 0.62); color: var(--muted); margin-top: 3px; }
.s-line.latest .t { color: var(--text); }
.s-line:not(.latest) .t { opacity: 0.86; }
.s-partial {
  padding: 10px 18px 14px; border-top: 1px solid var(--line); background: var(--panel);
  color: var(--muted); font-size: calc(var(--fs, 22px) * 0.68); min-height: 52px;
}
.s-partial .live { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); margin-right: 8px; animation: pulse 1.2s infinite; vertical-align: 1px; }
.s-empty { color: var(--muted); text-align: center; margin-top: 30vh; font-size: 17px; }
.new-below {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px;
  background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 700;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); display: none; cursor: pointer;
}
.new-below.show { display: block; }
.conn { font-size: 12px; }

.lang-pick { max-width: 520px; margin: 0 auto; padding: 32px 20px; }
.lang-pick h1 { font-size: 22px; margin: 0 0 4px; }
.lang-pick p { color: var(--muted); margin: 0 0 22px; }
.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lang-list button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px;
  padding: 16px 12px; cursor: pointer; text-align: left;
}
.lang-list button:hover { border-color: var(--accent); }
.lang-list b { display: block; font-size: 18px; }
.lang-list span { font-size: 13px; color: var(--muted); }
[dir='rtl'] { text-align: right; }

/* ───────── 교수 화면: 폰 ───────── */
.mobile-note {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: var(--accent-soft); color: var(--text); font-size: 13.5px; line-height: 1.45;
}
@media (max-width: 720px) {
  .desktop-only { display: none !important; }
  .host-top { padding: 10px 12px; gap: 6px; }
  .host-top h1 { font-size: 15px; flex-basis: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .host-grid { padding: 10px; gap: 10px; display: flex; flex-direction: column; }
  .host-grid > .stack { display: contents; }
  .p-mic { order: 1; }
  .p-monitor { order: 2; }
  .p-qr { order: 3; }
  .p-usage { order: 4; }
  .p-settings { order: 5; }
  .panel { padding: 14px; }
  .btn.big { padding: 18px; font-size: 18px; }
  .meter { height: 72px; }
  .monitor { min-height: 0; }
  .monitor .lines { max-height: 45vh; min-height: 160px; }
  .qr-box { flex-direction: column; align-items: flex-start; }
  .qr-box img { width: 160px; height: 160px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat b { font-size: 16px; }
  input[type='text'], select, textarea { font-size: 16px; } /* iOS 확대 방지 */
}
