:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #667085;
  --line: #e3e7ef;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --interviewer: #4f46e5;
  --candidate: #0e9f6e;
  --danger: #e5484d;
  --room-bg: #0f1115;
  --room-panel: #171a21;
  --room-tile: #1d212a;
  --room-line: #2a2f3a;
  --room-text: #e8eaf0;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
.hidden { display: none !important; }
button, input, select { font: inherit; }
code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }

button, .button {
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--brand); color: #fff; }
.primary:hover:not(:disabled) { background: var(--brand-dark); }
.ghost, .button { background: transparent; border-color: var(--line); color: inherit; }
.ghost:hover { background: rgba(127,127,127,.08); }
.small { padding: 6px 10px; font-size: 13px; }

.banner { background: #fff4e5; border-bottom: 1px solid #f5c88a; color: #7a4a00; padding: 12px 20px; font-size: 14px; }

/* ---------------- join ---------------- */
#join-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.join-card { width: min(1040px, 100%); background: var(--card); border-radius: 20px; box-shadow: 0 10px 40px rgba(20,30,60,.08); padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 22px; }
.logo-dot { width: 14px; height: 14px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), #06b6d4); }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--brand); background: #eef0ff; padding: 3px 8px; border-radius: 999px; }
.join-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 28px; }
@media (max-width: 820px) { .join-grid { grid-template-columns: 1fr; } }

.preview { position: relative; aspect-ratio: 16/9; background: #11141a; border-radius: var(--radius); overflow: hidden; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: #aab; background: #11141a; }
.preview-controls { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 12px; }
.round { width: 46px; height: 46px; padding: 0; border-radius: 50%; background: rgba(255,255,255,.92); }
.round svg { width: 22px; height: 22px; fill: #1c2333; }
.round.off { background: var(--danger); }
.round.off svg { fill: #fff; }
.meter-row { display: flex; align-items: center; gap: 10px; margin: 14px 0 8px; font-size: 13px; color: var(--muted); }
.meter { flex: 1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
#mic-level { height: 100%; width: 0; background: var(--candidate); transition: width .08s linear; }
.device-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.device-row label { font-size: 13px; color: var(--muted); display: grid; gap: 6px; }

#join-form { display: flex; flex-direction: column; gap: 8px; }
#join-form h1 { font-size: 22px; margin: 0 0 6px; }
#join-form > label, #passcode-field label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 6px; }
#passcode-field { display: flex; flex-direction: column; gap: 8px; }
input:not([type=radio]):not([type=checkbox]), select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid #c7cbff; border-color: var(--brand); }
input[readonly] { background: #f6f7fa; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

.roles { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.roles legend { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; padding: 0; }
.role-card { position: relative; cursor: pointer; }
.role-card input { position: absolute; opacity: 0; }
.role-card span { display: grid; gap: 2px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; }
.role-card small { color: var(--muted); font-size: 12px; }
.role-card input:checked + span { border-color: var(--brand); background: #f3f4ff; }
.role-card input:focus-visible + span { outline: 2px solid #c7cbff; }

.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.consent input { margin-top: 2px; }
.error { color: var(--danger); font-size: 13px; margin: 2px 0; }
#join-btn { margin-top: 6px; padding: 12px 16px; }

/* ---------------- room ---------------- */
#room-view { height: 100%; display: grid; grid-template-rows: auto 1fr auto; background: var(--room-bg); color: var(--room-text); }
.room-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--room-line); }
.bar-left, .bar-right { display: flex; align-items: center; gap: 10px; }
.bar-right { justify-content: flex-end; }
#timer { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .03em; }
.role-chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: #2a2f3a; }
.role-chip.interviewer { background: rgba(79,70,229,.25); color: #c7c4ff; }
.role-chip.candidate { background: rgba(14,159,110,.22); color: #9ae6c6; }
.rec-badge { color: #ff6b6e; font-weight: 700; font-size: 13px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: #2a2f3a; }
.pill.ok { background: rgba(14,159,110,.2); color: #8fe3c1; }
.pill.warn { background: rgba(245,158,11,.2); color: #fcd28a; }
#room-view .ghost { border-color: var(--room-line); color: var(--room-text); }

.room-main { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
@media (max-width: 900px) { .room-main { grid-template-columns: 1fr; grid-template-rows: 1fr 220px; } }
.stage-wrap { position: relative; padding: 14px; min-height: 0; }
.audio-unlock { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); z-index: 5; }

.stage { position: relative; height: 100%; display: grid; gap: 12px; }
.stage[data-layout="grid"] { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); grid-auto-rows: 1fr; }
.stage[data-layout="pip"] { grid-template-columns: 1fr; }
.stage[data-layout="pip"] .tile.local { position: absolute; right: 16px; bottom: 16px; width: min(26%, 280px); aspect-ratio: 16/9; height: auto; z-index: 2; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.stage[data-layout="screen"] { grid-template-columns: 1fr 260px; grid-auto-rows: minmax(0, 1fr); }
.stage[data-layout="screen"] .tile.screen { grid-row: 1 / span 6; }

.tile { position: relative; background: var(--room-tile); border-radius: var(--radius); overflow: hidden; min-height: 0; border: 2px solid transparent; transition: border-color .15s; }
.tile.speaking { border-color: #22c55e; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.screen video { object-fit: contain; background: #000; }
.tile.mirror video { transform: scaleX(-1); }
.tile.no-video video { visibility: hidden; }
.tile .avatar { display: none; position: absolute; inset: 0; margin: auto; width: 96px; height: 96px; border-radius: 50%; background: #3b4252; color: #e5e9f0; font-size: 34px; font-weight: 600; place-items: center; }
.tile.no-video .avatar { display: grid; }
.tile .label { position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.55); padding: 5px 9px; border-radius: 8px; font-size: 13px; max-width: calc(100% - 20px); }
.tile .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .role { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; }
.tile .role.interviewer { background: rgba(79,70,229,.6); }
.tile .role.candidate { background: rgba(14,159,110,.6); }
.tile .mic-off svg { width: 14px; height: 14px; fill: #ff6b6e; display: block; }
.tile .q { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; flex: none; }
.tile .q.excellent { background: #22c55e; }
.tile .q.good { background: #a3e635; }
.tile .q.poor { background: #f59e0b; }
.tile .q.lost { background: #ef4444; }
.tile.placeholder { display: grid; place-items: center; border: 2px dashed var(--room-line); background: transparent; }
.wait { text-align: center; color: #aab1c2; padding: 20px; }
.wait p { margin: 14px 0 4px; font-size: 16px; }
.wait small { color: #7d8597; }
.spinner { width: 34px; height: 34px; margin: auto; border-radius: 50%; border: 3px solid #2a2f3a; border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.side { background: var(--room-panel); border-left: 1px solid var(--room-line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--room-line); }
.side-head h2 { font-size: 15px; margin: 0; }
.note { margin: 10px 16px 0; font-size: 12px; color: #fcd28a; background: rgba(245,158,11,.12); padding: 8px 10px; border-radius: 8px; }
.transcript { flex: 1; overflow-y: auto; padding: 10px 16px; }
.transcript .empty { color: #7d8597; font-size: 13px; }
.line { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; margin: 10px 0; font-size: 14px; }
.line .t { color: #7d8597; font-size: 11px; font-variant-numeric: tabular-nums; }
.line .who { font-weight: 600; font-size: 12px; }
.line.interviewer .who { color: #a5a1ff; }
.line.candidate .who { color: #6ee7b7; }
.line p { grid-column: 1 / -1; margin: 2px 0 0; line-height: 1.45; }
.live { padding: 10px 16px; border-top: 1px solid var(--room-line); min-height: 46px; font-size: 13px; color: #c9cfdb; }
.live .cap { margin: 2px 0; font-style: italic; }
.live .cap.interviewer b { color: #a5a1ff; }
.live .cap.candidate b { color: #6ee7b7; }

.controls { display: flex; justify-content: center; gap: 10px; padding: 12px; border-top: 1px solid var(--room-line); flex-wrap: wrap; }
.ctl { flex-direction: column; gap: 4px; min-width: 92px; padding: 8px 12px; background: #232833; color: var(--room-text); font-size: 12px; font-weight: 500; }
.ctl:hover { background: #2c3240; }
.ctl .ic svg { width: 22px; height: 22px; fill: currentColor; display: block; }
.ctl.off { background: rgba(229,72,77,.18); color: #ff8a8d; }
.ctl.active { background: rgba(79,70,229,.3); color: #c7c4ff; }
.ctl.recording { background: rgba(229,72,77,.25); color: #ff8a8d; }
.ctl.danger { background: var(--danger); color: #fff; }
.ctl.danger:hover { background: #cf3c41; }

/* ---------------- end ---------------- */
#end-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.end-card { background: var(--card); border-radius: 20px; padding: 36px; text-align: center; width: min(520px, 100%); box-shadow: 0 10px 40px rgba(20,30,60,.08); }
.end-card h2 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.3); z-index: 50; }
