:root {
  --bg: #f5f5f2;
  --card: #fff;
  --ink: #1d1f23;
  --muted: #646a73;
  --line: #e2e2dc;
  --accent: #2f5bea;
  --red: #e5342b;
  --green: #1f8a4c;
  --amber: #b26b00;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .4rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.page { max-width: 760px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(110px + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.narrow { max-width: 440px; margin: 8vh auto 0; }
.center { text-align: center; }
.lead { color: var(--muted); margin: 0 0 1.25rem; }
.fine-print { color: var(--muted); font-size: .875rem; margin: 1rem 0 0; }
.flash { padding: 12px 16px; border-radius: 10px; margin: 0 0 16px; }
.flash.alert, .error { background: #fdecea; color: #8a1c14; padding: 12px 16px; border-radius: 10px; }
.flash.notice { background: #e8f5ec; color: #135c32; }
.big-check { width: 64px; height: 64px; border-radius: 50%; background: var(--green); color: #fff; font-size: 34px; line-height: 64px; margin: 0 auto 16px; }

label { font-weight: 600; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; font: inherit; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
.stack { display: grid; gap: 8px; }
.stack .button { margin-top: 8px; }
.code-form { display: grid; gap: 8px; }
.code-form input { font-size: 1.5rem; letter-spacing: .15em; text-transform: uppercase; text-align: center; font-family: ui-monospace, Menlo, monospace; }
.code-form .button { margin-top: 8px; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  padding: 12px 20px; min-height: 48px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  cursor: pointer; text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.block { width: 100%; }
.button.small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }
.button.ghost { background: transparent; }
.button.danger { color: var(--red); background: transparent; border-color: transparent; }
.button.record { background: var(--red); border-color: var(--red); color: #fff; min-width: 150px; }
.button.record i { width: 14px; height: 14px; border-radius: 50%; background: #fff; }
.button.finish { background: var(--ink); border-color: var(--ink); color: #fff; }

/* Applicant interview */
.interview-head { margin-bottom: 12px; }
.interview-head .lead { margin-bottom: 0; }
.stage { position: relative; background: #111; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-height: 56vh; width: 100%; }
.preview { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.timer { position: absolute; right: 12px; top: 12px; background: rgba(0,0,0,.55); color: #fff; padding: 4px 10px; border-radius: 999px; font: 600 .9rem ui-monospace, Menlo, monospace; }
.timer.warning { background: var(--amber); }
.rec-indicator { position: absolute; left: 12px; top: 12px; display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.55); color: #fff; padding: 4px 12px 4px 10px; border-radius: 999px; font-weight: 600; font-size: .9rem; }
.rec-indicator i { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1.2s infinite; }
.rec-indicator.paused i { background: var(--amber); animation: none; }
@keyframes blink { 50% { opacity: .2; } }

.panel { margin-top: 16px; }
.checks { list-style: none; padding: 0; margin: 16px 0 8px; display: grid; gap: 10px; }
.checks li { display: grid; grid-template-columns: 24px 1fr; gap: 4px 10px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.checks b { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 13px; color: #fff; }
.checks [data-state=pending] b { border-color: var(--accent); border-top-color: transparent; animation: spin 1s linear infinite; }
.checks [data-state=ok] b { background: var(--green); border-color: var(--green); }
.checks [data-state=ok] b::after { content: "✓"; }
.checks [data-state=error] b { background: var(--red); border-color: var(--red); }
.checks [data-state=error] b::after { content: "!"; }
.checks [data-state=error] span { color: #8a1c14; }
.meter { grid-column: 2; height: 8px; background: #eceae4; border-radius: 4px; overflow: hidden; --level: 0; }
.meter div { height: 100%; width: calc(var(--level) * 100%); background: var(--green); transition: width 80ms linear; }
.device-pickers { display: grid; gap: 8px; margin-bottom: 8px; }
.device-pickers label { display: grid; gap: 4px; }
.panel > .button { margin-top: 12px; }

.hint { font-size: 1.05rem; font-weight: 600; text-align: center; margin: 4px 0 12px; min-height: 1.5em; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.controls .button { min-width: 130px; }
.upload-status { text-align: center; color: var(--muted); font-size: .875rem; margin: 10px 0 0; min-height: 1.3em; }
.upload-status.warning { color: var(--amber); font-weight: 600; }
.spinner { width: 40px; height: 40px; margin: 8px auto 16px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The interviewer button, fixed at the bottom right */
.agent {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 10;
  display: flex; align-items: center; gap: 12px; padding: 10px 18px 10px 10px; border-radius: 999px; border: 0;
  background: var(--ink); color: #fff; font: inherit; text-align: left; cursor: pointer; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  -webkit-tap-highlight-color: transparent;
}
.agent-text { display: grid; line-height: 1.25; }
.agent-text span { font-size: .85rem; opacity: .8; }
.agent-orb { position: relative; width: 48px; height: 48px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #8fb0ff, var(--accent) 60%, #1b3aa8); flex: none; }
.agent-orb i { position: absolute; inset: -6px; border-radius: 50%; border: 3px solid rgba(143,176,255,.7); opacity: 0; }
.agent[data-state=idle] .agent-orb i { animation: ring 1.8s ease-out infinite; }
.agent[data-state=connecting] .agent-orb { animation: pulse 1s ease-in-out infinite; }
.agent[data-state=speaking] .agent-orb i { opacity: 1; animation: talk .5s ease-in-out infinite alternate; }
.agent[data-state=listening] .agent-orb i { opacity: .5; }
@keyframes ring { 0% { transform: scale(.9); opacity: .9; } 100% { transform: scale(1.4); opacity: 0; } }
@keyframes pulse { 50% { transform: scale(.9); } }
@keyframes talk { to { transform: scale(1.15); } }

@media (max-width: 600px) {
  .stage { aspect-ratio: 3 / 4; max-height: 52vh; }
  h1 { font-size: 1.35rem; }
  .controls .button { flex: 1 1 40%; min-width: 0; }
  .agent { padding: 8px 14px 8px 8px; }
  .agent-orb { width: 40px; height: 40px; }
}

/* Admin */
.admin-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.admin-bar nav { display: flex; gap: 8px; align-items: center; }
.admin-bar nav form { margin: 0; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.admin .narrow { margin-top: 0; }
.tabs { display: flex; gap: 4px; margin: 12px 0 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ink); border-color: var(--ink); font-weight: 600; }
.tabs small { background: #eceae4; border-radius: 999px; padding: 0 7px; margin-left: 4px; color: var(--muted); }
.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list th, .list td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.list small { color: var(--muted); }
.empty { color: var(--muted); }
.pill { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: #eceae4; color: var(--muted); }
.pill.completed { background: #e6ecfd; color: #1f3fa8; }
.pill.in_progress { background: #fff3dc; color: var(--amber); }
.pill.decision-yes { background: #e3f4e9; color: var(--green); }
.pill.decision-no { background: #fdecea; color: var(--red); }
.meta { color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.review { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.review-side { position: sticky; top: 16px; }
.recording { margin: 20px 0; }
.recording video { width: 100%; max-height: 70vh; background: #111; border-radius: var(--radius); display: block; }
.recording h2 small { font-weight: 400; color: var(--muted); font-size: .85rem; }
.analysis { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-top: 16px; }
.criteria { padding-left: 18px; }
.criteria li { margin: 6px 0; }
.criteria .success strong { color: var(--green); }
.criteria .failure strong { color: var(--red); }
.transcript { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 20px; margin-top: 12px; }
.transcript summary { cursor: pointer; font-weight: 600; }
.transcript p { margin: 8px 0; }
.transcript .turn-agent b { color: var(--accent); }
.row-actions { display: flex; gap: 8px; }
.row-actions form { margin: 0; }
.invite { margin: 16px 0; }
.invite-code { display: flex; gap: 12px; align-items: center; margin: 6px 0; }
.invite-code span { width: 44px; color: var(--muted); font-size: .9rem; }
.invite-code code { font-size: 1.1rem; background: #f1f0ea; padding: 4px 10px; border-radius: 8px; }
.invite textarea { margin-top: 8px; font-size: .9rem; }
.decision { display: flex; gap: 8px; }
.decision input { position: absolute; opacity: 0; pointer-events: none; }
.decision label { flex: 1; text-align: center; padding: 10px 0; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 600; }
.decision input:checked + label { background: var(--ink); color: #fff; border-color: var(--ink); }
.decision input:checked + label.yes { background: var(--green); border-color: var(--green); }
.decision input:checked + label.no { background: var(--red); border-color: var(--red); }
.decision input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.review-side > form.button_to, .review-side form:last-child { margin-top: 12px; }

@media (max-width: 900px) {
  .review { grid-template-columns: 1fr; }
  .review-side { position: static; }
  .admin-main { padding: 16px; }
}

@media (max-width: 600px) {
  /* Keep the checklist visible next to the preview while checking devices. */
  .interview[data-step=check] .stage { max-height: 34vh; }
}
