:root {
  color-scheme: light;
  --ink: #15231f;
  --muted: #65716d;
  --line: #d8e0dc;
  --paper: #f6f8f5;
  --panel: #ffffff;
  --kiwi: #126b56;
  --kiwi-bright: #24a47f;
  --danger: #a33a3a;
  --shadow: 0 18px 45px rgb(21 35 31 / 8%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 0%, rgb(36 164 127 / 12%), transparent 27rem),
    var(--paper);
  color: var(--ink);
}

body > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  max-width: 1480px;
  margin: 0 auto;
  padding: 2.5rem 2rem 1.5rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .45rem; font-size: clamp(2rem, 4vw, 3.5rem); letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 1.35rem; letter-spacing: -.02em; }
.subhead { max-width: 750px; margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: .45rem; color: var(--kiwi); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }

main {
  display: grid;
  gap: 1rem;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgb(255 255 255 / 92%);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.section-heading, .button-row, .chat-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  flex-wrap: wrap;
}

.section-heading { margin-bottom: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
label { display: grid; gap: .35rem; color: var(--muted); font-size: .78rem; font-weight: 700; }
input, select, button { font: inherit; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  padding: .7rem .75rem;
}

button {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  padding: .68rem .9rem;
  font-weight: 750;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--kiwi); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.primary { border-color: var(--kiwi); background: var(--kiwi); color: #fff; }
button.danger { color: var(--danger); }
button.quiet { padding: .5rem .75rem; background: transparent; }
button.active { border-color: var(--kiwi-bright); background: rgb(36 164 127 / 12%); color: var(--kiwi); }
.button-row { justify-content: flex-start; margin-top: .9rem; }
.button-row.compact { margin-top: .65rem; }

.badge, .gate, .inline-status {
  border-radius: 999px;
  padding: .45rem .7rem;
  font-size: .75rem;
  font-weight: 800;
}
.badge.offline { background: #e7e9e8; color: #5e6663; }
.badge.online { background: #d9f5e9; color: #0d6d4f; }
.badge.reconnecting { background: #fff1ca; color: #775200; }
.gate { background: #eef0ef; color: #5a6460; }
.gate.waiting { background: #fff1ca; color: #775200; }
.gate.ready { background: #d9f5e9; color: #0d6d4f; }
.gate.failed { background: #ffe0e0; color: #8c2424; }
.inline-status { background: #eef3f1; color: var(--muted); }
.policy-note { margin: .9rem 0; color: var(--muted); font-size: .82rem; }

.stage-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .75fr); gap: 1rem; }
.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 14px;
  background: #10201b;
  color: #dce8e4;
}
.stage video { width: 100%; height: 100%; object-fit: contain; }
#stagePlaceholder { position: absolute; inset: 0; display: grid; place-items: center; color: #9eb0aa; }
.stage-label { position: absolute; left: .75rem; bottom: .75rem; border-radius: 7px; background: rgb(0 0 0 / 64%); padding: .35rem .55rem; font-size: .75rem; }
.laser { position: absolute; width: 18px; height: 18px; transform: translate(-50%, -50%); border: 3px solid #fff; border-radius: 50%; background: #e7223c; box-shadow: 0 0 0 5px rgb(231 34 60 / 30%); pointer-events: none; }
.hidden { display: none !important; }

.source-grid { display: grid; align-content: start; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; max-height: 560px; overflow: auto; }
.source-tile { display: grid; overflow: hidden; padding: 0; text-align: left; }
.source-tile.selected { outline: 3px solid rgb(36 164 127 / 32%); border-color: var(--kiwi-bright); }
.source-media { display: block; aspect-ratio: 16 / 9; background: #172721; }
.source-media video { width: 100%; height: 100%; object-fit: cover; }
.source-meta { display: grid; gap: .1rem; padding: .5rem .6rem; }
.source-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; }
.source-meta small { color: var(--muted); font-size: .66rem; }

.interaction-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .7fr); gap: 1rem; }
.whiteboard-shell { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
#whiteboard { display: block; width: 100%; aspect-ratio: 16 / 9; touch-action: none; cursor: crosshair; }
.color-label { display: flex; align-items: center; gap: .45rem; }
.color-label input { width: 36px; height: 30px; padding: 0; }
.classroom-controls { display: flex; flex-direction: column; min-height: 300px; }
.chat-log { flex: 1; min-height: 230px; max-height: 430px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #f9fbfa; padding: .75rem; }
.chat-message { margin-bottom: .6rem; font-size: .82rem; }
.chat-message strong { color: var(--kiwi); }
.chat-entry { flex-wrap: nowrap; margin-top: .65rem; }
.chat-entry input { flex: 1; }

.capability-summary { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.capability { border: 1px solid var(--line); border-radius: 999px; padding: .35rem .55rem; color: var(--muted); font-size: .72rem; }
.capability.pass { border-color: #8bd0b9; color: #0d6d4f; }
.capability.warn { border-color: #e7c76b; color: #775200; }
#diagnosticLog { max-height: 310px; overflow: auto; margin: 0; border-radius: 12px; background: #10201b; color: #d8eee7; padding: 1rem; font-size: .73rem; white-space: pre-wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 920px) {
  .stage-layout, .interaction-grid { grid-template-columns: 1fr; }
  .source-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  body > header, main { padding-left: 1rem; padding-right: 1rem; }
  body > header { align-items: flex-start; }
  .source-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
