* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: #0f172a;
  background: #0b1220;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.muted { color: #64748b; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  height: 52px;
  background: #0f172a;
  color: #e2e8f0;
  border-bottom: 1px solid #1e293b;
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 10px #22c55e; }
.room { display: flex; align-items: center; gap: 8px; }
.chip { background: #1e293b; padding: 4px 10px; border-radius: 999px; font-size: 13px; color: #cbd5e1; }
.spacer { flex: 1; }
.status { font-size: 12px; color: #94a3b8; }
.status.ok { color: #4ade80; }
.status.bad { color: #f87171; }
.peers { display: flex; gap: 6px; }
.peer {
  display: flex; align-items: center; gap: 6px;
  background: #1e293b; border-radius: 999px; padding: 3px 10px 3px 3px; font-size: 13px; color: #e2e8f0;
}
.peer .av { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: #111827;
  border-bottom: 1px solid #1f2937;
  flex: none;
}
.tool {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 18px;
  background: #1f2937; color: #e5e7eb;
  border: 1px solid #374151; border-radius: 10px;
  cursor: pointer; transition: all .12s;
}
.tool:hover { background: #374151; }
.tool.active { background: #2563eb; border-color: #3b82f6; color: #fff; box-shadow: 0 0 0 2px rgba(59,130,246,.35); }
.sep { width: 1px; height: 28px; background: #374151; margin: 0 6px; }
.colors { display: flex; gap: 6px; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #374151; cursor: pointer; }
.sw.active { border-color: #fff; box-shadow: 0 0 0 2px #2563eb; }
input[type=range] { width: 120px; }
.btn {
  height: 38px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid #374151; background: #1f2937; color: #e5e7eb; font-size: 14px;
}
.btn:hover { background: #374151; }
.btn.ghost { background: transparent; }
.btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; width: 100%; height: 44px; font-weight: 600; }
.btn.primary:hover { background: #1d4ed8; }
.file { display: inline-grid; place-items: center; }
.btn.on { background: #16a34a; border-color: #16a34a; color: #fff; }
.btn.off { background: #b91c1c; border-color: #b91c1c; color: #fff; }

/* ---------- stage ---------- */
.stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 12px;
  background:
    radial-gradient(1200px 600px at 50% 0%, #1e293b 0%, #0b1220 70%);
  overflow: hidden;
}
#board {
  background: #ffffff no-repeat center / contain;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
  touch-action: none;
  cursor: crosshair;
}
.hint {
  position: absolute;
  bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,.85); color: #e2e8f0;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  pointer-events: none; transition: opacity .5s;
}

/* ---------- lobby ---------- */
.lobby {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(2,6,23,.72);
  backdrop-filter: blur(6px);
}
.lobby.hidden { display: none; }
.card {
  width: 380px; max-width: calc(100vw - 32px);
  background: #fff; border-radius: 16px; padding: 26px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.card h1 { margin: 0; font-size: 22px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #334155; }
.card input, .card select {
  height: 42px; border: 1px solid #cbd5e1; border-radius: 10px; padding: 0 12px; font-size: 15px; outline: none;
}
.card input:focus, .card select:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.hidden { display: none !important; }

/* ---------- видео ---------- */
.call {
  position: absolute;
  right: 14px; top: 14px;
  width: 306px;
  background: rgba(15,23,42,.94);
  border: 1px solid #1e293b;
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.call.hidden { display: none; }
.remote { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.remote video { width: 100%; height: 100%; object-fit: cover; display: block; }
.callEmpty { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; font-size: 13px; }
.local {
  position: absolute; right: 20px; top: 20px; width: 108px; aspect-ratio: 16 / 9;
  border-radius: 8px; overflow: hidden; border: 2px solid #0f172a; z-index: 21; background: #000;
}
.local video { width: 100%; height: 100%; object-fit: cover; display: block; }
.callControls { display: flex; gap: 6px; }
.callControls .btn { flex: 1; height: 34px; padding: 0 8px; font-size: 13px; }
.callToggle {
  position: absolute; right: 16px; bottom: 16px; z-index: 22;
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid #374151; background: #1f2937; color: #e5e7eb; font-size: 20px;
  cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.callToggle:hover { background: #374151; }

/* ---------- домашнее задание ---------- */
.hw {
  position: absolute;
  left: 14px; top: 14px;
  width: 340px;
  max-height: calc(100% - 28px);
  background: rgba(15,23,42,.96);
  border: 1px solid #1e293b;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 20;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  color: #e2e8f0;
}
.hw.hidden { display: none; }
.hwHead { display: flex; align-items: center; justify-content: space-between; }
.hw textarea {
  min-height: 220px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #e2e8f0;
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.45;
}
.hw textarea[readonly] { background: #0f172a; color: #cbd5e1; }
.hwRow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hwDone { display: flex; align-items: center; gap: 6px; font-size: 14px; color: #cbd5e1; }
.hwRow .btn.primary { width: auto; height: 38px; }
.hwHint { font-size: 12px; color: #94a3b8; min-height: 16px; }

/* ---------- напоминание об уроке ---------- */
#lessonChip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reminder {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(245,158,11,.97); color: #3b2402; border-radius: 12px;
  padding: 12px 18px; font-size: 15px; z-index: 30; max-width: 90%;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.reminder.hidden { display: none; }
.reminder a { color: #7c2d12; font-weight: 600; }
.reminder .remClose { margin-left: 10px; cursor: pointer; font-weight: 700; }

/* ---------- адаптивность (любые экраны) ---------- */
body { height: 100vh; height: 100dvh; }
.rotateHint {
  position: absolute; bottom: 56px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,.92); color: #e2e8f0;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  z-index: 25; box-shadow: 0 8px 24px rgba(0,0,0,.35);
  max-width: calc(100% - 24px);
}
.rotateHint .remClose { cursor: pointer; font-weight: 700; color: #94a3b8; }

/* средние экраны / планшеты */
@media (max-width: 1100px) {
  .tool { width: 38px; height: 38px; font-size: 17px; }
  .call { width: min(280px, 46vw); }
}

/* телефоны и узкие окна */
@media (max-width: 820px) {
  .stage { padding: 6px 8px; }
  .topbar { gap: 8px; padding: 0 8px; height: 48px; overflow-x: auto; }
  .topbar > * { flex: 0 0 auto; }
  .topbar .spacer { flex: 1; }
  .brand { font-size: 14px; }
  .chip { font-size: 12px; padding: 3px 8px; }
  #lessonChip { max-width: 130px; }
  .status { display: none; }
  .peer { max-width: 132px; overflow: hidden; }

  .toolbar {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: thin;
    gap: 4px; padding: 6px 8px;
  }
  .toolbar > * { flex: 0 0 auto; }
  .tool { width: 36px; height: 36px; font-size: 16px; }
  input[type=range] { width: 90px; }
  .btn { height: 34px; padding: 0 10px; font-size: 13px; }

  .call { right: 8px; top: 8px; width: min(250px, 56vw); padding: 6px; gap: 6px; border-radius: 12px; }
  .local { right: 10px; top: 10px; width: 62px; }
  .callControls { flex-wrap: wrap; }
  .callControls .btn { flex: 1 1 38%; height: 30px; font-size: 12px; padding: 0 6px; }
  .callToggle { right: 10px; bottom: 10px; width: 44px; height: 44px; font-size: 18px; }

  .hw {
    left: 0; right: 0; top: auto; bottom: 0; width: auto;
    max-height: 66%; border-radius: 16px 16px 0 0;
    border-left: none; border-right: none; border-bottom: none;
  }
  .hw textarea { min-height: 120px; }

  .reminder { top: 8px; font-size: 14px; padding: 10px 14px; border-radius: 10px; }

  .lobby { align-items: flex-start; padding: 20px 12px; }
  .card { padding: 20px; }
}

/* маленькие телефоны */
@media (max-width: 520px) {
  .brandName { display: none; }
  .brand { gap: 5px; }
  .hideXs { display: none !important; }
  .tool { width: 34px; height: 34px; font-size: 15px; }
  input[type=range] { width: 62px; }
  .card h1 { font-size: 20px; }
}

/* низкие экраны (альбомная ориентация телефона) */
@media (max-height: 480px) {
  .topbar { height: 40px; }
  .toolbar { padding: 4px 8px; }
  .tool { width: 32px; height: 32px; font-size: 14px; }
  .call { width: min(220px, 40vw); }
}
