@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 200 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('/vendor/bricolage-grotesque.woff2') format('woff2');
}

:root {
  --teal: #0A7C6E;
  --teal-dark: #075E54;
  --teal-soft: #E3F1EF;
  --amber: #F59E0B;
  --amber-text: #9A6100;
  --amber-soft: #FDF1DC;
  --orange: #FF6B35;
  --orange-dark: #E04E18;
  --orange-soft: #FFE9E0;
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --ink: #1F2937;
  --muted: #6F7680;
  --line: #E4E2DD;
  --r: 6px;      /* cards, modals */
  --r-sm: 4px;   /* buttons, inputs, chips */
  --shadow-1: 0 1px 2px rgba(31, 41, 55, 0.06), 0 2px 6px rgba(31, 41, 55, 0.06);
  --shadow-2: 0 2px 4px rgba(31, 41, 55, 0.08), 0 10px 28px rgba(31, 41, 55, 0.14);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Bricolage Grotesque', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-optical-sizing: auto;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea { font-family: inherit; }

/* ---------- landing ---------- */

body.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal);
  padding: 24px;
}

.landing-card {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-2);
  padding: 36px;
  width: 100%;
  max-width: 1080px; /* wide layout: classes and boards get real estate */
  max-height: 92vh;
  overflow-y: auto;
}

#landing-columns { display: flex; gap: 36px; align-items: flex-start; }
#landing-left { width: 320px; flex-shrink: 0; }
#landing-right { flex: 1; min-width: 0; }
#landing-right > div:first-child h2 { margin-top: 0; }
@media (max-width: 880px) {
  #landing-columns { flex-direction: column; }
  #landing-left { width: 100%; }
  #landing-right { width: 100%; }
}

/* classes & boards as a responsive card grid */
#my-rooms-list, #personal-boards-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px; max-height: none; overflow: visible;
}
#my-rooms-list li, #personal-boards-list li {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  position: relative; padding: 0 0 10px; overflow: hidden;
}
.card-thumb {
  width: 100%; height: 92px; object-fit: contain; background: #fff;
  border-bottom: 1px solid var(--line); margin-bottom: 8px; display: block;
}
.card-thumb-empty {
  display: flex; align-items: center; justify-content: center;
  color: #D8DCE0; font-size: 26px;
}
#my-rooms-list .room-name, #personal-boards-list .room-name { padding: 0 14px; }
#my-rooms-list .room-meta, #personal-boards-list .room-meta { padding: 0 14px; }
#my-rooms-list .room-name, #personal-boards-list .room-name {
  font-size: 15px; font-weight: 700; white-space: normal;
}
#my-rooms-list .room-meta, #personal-boards-list .room-meta { margin-left: 0; }
#my-rooms-list .room-rename { position: absolute; top: 8px; right: 8px; }

.landing-card h1 { margin: 0 0 4px; font-size: 27px; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { margin: 0 0 24px; color: var(--muted); }

.role-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.role-tab {
  flex: 1; padding: 10px; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: var(--r-sm); font-size: 15px; cursor: pointer; font-weight: 600; color: var(--muted);
}
.role-tab.active { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.role-tab:disabled { opacity: 0.45; cursor: not-allowed; }

.landing-card label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
.landing-card input[type="text"] {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  font-size: 16px; outline: none; background: var(--surface);
}
.landing-card input[type="text"]:focus { border-color: var(--teal); }
#room-input { text-transform: uppercase; letter-spacing: 2px; font-weight: 700; }

.room-row { display: flex; gap: 8px; }
.room-row input { flex: 1; }
#gen-btn, #new-room-btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  font-size: 17px; cursor: pointer; padding: 0 14px; color: var(--ink);
}
#gen-btn:hover, #new-room-btn:hover { border-color: var(--teal); color: var(--teal); }

.primary-btn {
  width: 100%; margin-top: 22px; padding: 13px; border: none; border-radius: var(--r-sm);
  background: var(--teal); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow-1);
}
.primary-btn:hover { background: var(--teal-dark); }
.error { color: var(--orange-dark); font-size: 14px; margin: 10px 0 0; font-weight: 600; }

#auth-section { margin-bottom: 20px; }
#gsi-button { display: flex; justify-content: center; padding: 8px 0 4px; }
#signed-in {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--teal-soft); border: 1px solid var(--teal); border-radius: var(--r-sm);
  padding: 9px 12px; font-size: 13px; color: var(--teal-dark);
}
#signed-in-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#signout-btn {
  border: 1px solid var(--teal); background: var(--surface); border-radius: var(--r-sm);
  padding: 4px 10px; cursor: pointer; font-size: 12px; color: var(--teal-dark); flex-shrink: 0;
}
#signout-btn:hover { background: var(--teal); color: #fff; }

#admin-portal-link {
  display: block; text-align: center; margin-top: 10px; padding: 9px;
  border: 1.5px solid var(--line); border-radius: var(--r-sm); color: var(--teal);
  font-weight: 700; font-size: 14px; text-decoration: none;
}
#admin-portal-link:hover { border-color: var(--teal); background: var(--teal-soft); }

#recent-rooms h2, #my-rooms h2, #personal-boards h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--muted); margin: 24px 0 8px; font-weight: 700;
}
.h2-note, #boards-context { color: var(--muted); font-weight: 400; font-size: 12px; text-transform: none; letter-spacing: 0; }

#rooms-list, #my-rooms-list, #personal-boards-list { list-style: none; margin: 0 0 10px; padding: 0; max-height: 220px; overflow-y: auto; }
#rooms-list li, #my-rooms-list li, #personal-boards-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 6px;
  cursor: pointer; background: var(--surface); box-shadow: var(--shadow-1);
}
#rooms-list li:hover, #my-rooms-list li:hover, #personal-boards-list li:hover { border-color: var(--teal); background: var(--teal-soft); }
.room-code { font-weight: 800; letter-spacing: 1px; color: var(--teal); }
.room-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-meta { color: var(--muted); font-size: 12px; margin-left: auto; flex-shrink: 0; }

.room-rename {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  padding: 2px 7px; cursor: pointer; font-size: 12px; color: var(--muted); flex-shrink: 0;
}
.room-rename:hover { border-color: var(--teal); color: var(--teal); }

.ghost-btn {
  width: 100%; padding: 9px; border: 1.5px dashed var(--line); border-radius: var(--r-sm); background: none;
  color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--teal); color: var(--teal); }

/* ---------- board layout ---------- */

#app {
  display: grid;
  /* minmax(0, 1fr): the content row must never grow past the viewport,
     otherwise tools scroll off the bottom of the screen */
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: auto minmax(0, 1fr) auto; /* toolbar column grows if tools wrap */
  grid-template-areas: "top top top" "tools canvas students";
  height: 100vh;
  height: 100dvh; /* iPad/phone: 100vh overshoots past the browser chrome */
  overflow: hidden;
  background: var(--bg);
}

#topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; /* narrow screens (iPad): wrap to a second row instead of clipping */
  min-height: 48px; row-gap: 4px;
  background: var(--surface); color: var(--ink); padding: 4px 12px; gap: 12px;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-1);
  position: relative; z-index: 10;
}
.topbar-group { flex-wrap: wrap; row-gap: 4px; }
#code-controls {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--teal-soft);
  font-weight: 700; font-size: 14px; color: var(--teal-dark);
}
.topbar-group { display: flex; align-items: center; gap: 8px; }
.badge {
  background: var(--teal); color: #fff; font-weight: 800; letter-spacing: 2px;
  padding: 4px 10px; border-radius: var(--r-sm); font-size: 14px;
}
#user-label { font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.online { background: var(--teal); }
.dot.offline { background: var(--orange); }
#save-indicator { font-size: 12px; color: var(--muted); min-width: 60px; }

.zoom-controls button, .action-btn, #download-menu summary {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 5px 10px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.zoom-controls button:hover, .action-btn:hover, #download-menu summary:hover {
  border-color: var(--teal); color: var(--teal);
}
#zoom-label { min-width: 54px; text-align: center; }
#share-btn.sharing { background: var(--orange); border-color: var(--orange); color: #fff; }
#share-btn.sharing:hover { background: var(--orange-dark); color: #fff; }

#download-menu { position: relative; }
#download-menu summary { list-style: none; }
#download-menu summary::-webkit-details-marker { display: none; }
#download-menu .menu {
  position: absolute; right: 0; top: 34px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 6px; z-index: 50; display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow-2);
}
#download-menu .menu button {
  background: none; border: none; color: var(--ink); padding: 7px 14px; cursor: pointer;
  border-radius: var(--r-sm); text-align: left; white-space: nowrap; font-size: 13px;
}
#download-menu .menu button:hover { background: var(--teal-soft); color: var(--teal); }

/* ---------- toolbar ---------- */

#toolbar {
  grid-area: tools;
  background: var(--surface); display: flex; flex-direction: column; align-content: flex-start;
  flex-wrap: wrap; /* short screens: tools wrap into a second column instead of vanishing */
  padding: 8px 6px; gap: 4px; overflow: visible;
  border-right: 1px solid var(--line);
  min-width: 56px;
}
.tool {
  width: 42px; height: 38px; border: 1px solid transparent; background: transparent;
  color: var(--ink); border-radius: var(--r-sm); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tool:hover { background: var(--teal-soft); }
.tool.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.tb-sep { width: 32px; height: 1px; background: var(--line); margin: 6px 0; }

#swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.swatch {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--teal); }
#color-input { width: 40px; height: 28px; border: none; background: none; cursor: pointer; margin-top: 4px; }
#width-input { width: 44px; margin: 6px 0; accent-color: var(--teal); }
#fill-label { color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 3px; cursor: pointer; }
#fill-label input { accent-color: var(--teal); }

/* ---------- canvas ---------- */

#canvas-wrap {
  grid-area: canvas;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background: #E9E7E2;
}

#text-toolbar {
  position: absolute; z-index: 6; display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2); padding: 3px;
}
#text-toolbar button {
  border: none; background: none; width: 30px; height: 28px; border-radius: var(--r-sm);
  cursor: pointer; color: var(--ink); font-size: 13px;
}
#text-toolbar button:hover { background: var(--teal-soft); }
#text-toolbar button.on { background: var(--teal); color: #fff; }
#text-toolbar #tt-color { width: auto; padding: 0 8px; font-size: 12px; }
.tt-sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-bottom: 6px; }
.grid2 label, .transfer-body > label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 8px 0 4px; font-weight: 700; }
.grid2 input, #graph-title, #chart-title, #chart-labelcol {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 7px 9px; font-size: 13px;
}
.chart-types { display: flex; gap: 8px; margin-bottom: 4px; }
.chart-type {
  flex: 1; padding: 9px; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: var(--r-sm); cursor: pointer; font-weight: 600; color: var(--muted); font-size: 13px;
}
.chart-type.active { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.chart-valcols { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.chart-valcols .chk { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }
.chart-valcols input { accent-color: var(--teal); }

/* ---------- polls ---------- */
#poll-compose, #poll-results, #poll-overlay {
  position: fixed; inset: 0; z-index: 120; background: rgba(31, 41, 55, 0.45);
  display: flex; align-items: center; justify-content: center;
}
#poll-compose .modal-box, #poll-results .modal-box { height: auto; max-height: 90vh; }
.poll-option-row { display: flex; gap: 8px; margin-bottom: 6px; }
.poll-option-row input {
  flex: 1; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 13px;
}
.poll-option-row .btn-block { padding: 4px 10px; }
#poll-options-wrap > label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 10px 0 6px; font-weight: 700; }

.poll-results-body { padding: 16px 18px; overflow-y: auto; }
.poll-status { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-weight: 600; color: var(--muted); }
.poll-bar-row { display: grid; grid-template-columns: 140px 1fr 74px; align-items: center; gap: 10px; margin-bottom: 10px; }
.poll-bar-label { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poll-bar-track { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); height: 26px; overflow: hidden; }
.poll-bar-fill { height: 100%; border-radius: var(--r-sm) 0 0 var(--r-sm); transition: width 0.4s ease; min-width: 2px; }
.poll-bar-val { font-size: 12px; color: var(--muted); font-weight: 600; }
.poll-insert-row { display: flex; align-items: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

#poll-wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.poll-wall-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow-1); }
.poll-wall-text { font-size: 15px; color: var(--ink); line-height: 1.35; word-break: break-word; }
.poll-wall-name { margin-top: 8px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.poll-card {
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-2);
  padding: 30px 34px; width: min(520px, 92vw); text-align: center;
}
.poll-ask { color: var(--teal); font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; font-size: 12px; }
.poll-card h2 { margin: 8px 0 22px; font-size: 24px; letter-spacing: -0.01em; }
.poll-choice-opts { display: flex; flex-direction: column; gap: 10px; }
.poll-opt-btn {
  padding: 14px; border: 1.5px solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  font-size: 16px; font-weight: 600; cursor: pointer; color: var(--ink);
}
.poll-opt-btn:hover { border-color: var(--teal); background: var(--teal-soft); }
.poll-opt-btn.chosen { border-color: var(--teal); background: var(--teal); color: #fff; }
#poll-text-input textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 12px;
  font-size: 15px; font-family: inherit; resize: vertical; margin-bottom: 12px;
}
#poll-text-input textarea:focus { outline: none; border-color: var(--teal); }
.poll-sent { margin-top: 16px; color: var(--teal); font-weight: 700; }

/* home + join-code toggle */
#home-btn { text-decoration: none; font-size: 16px; line-height: 1; padding: 5px 9px; }
#room-badge { display: inline-flex; align-items: center; gap: 6px; }
#code-toggle {
  border: none; background: rgba(255, 255, 255, 0.25); color: #fff; border-radius: 3px;
  padding: 0 4px; cursor: pointer; font-size: 12px; line-height: 18px;
}

/* shapes flyout */
#shapes-menu {
  position: fixed; left: 62px; z-index: 60; display: grid; grid-template-columns: repeat(4, 38px);
  gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2); padding: 6px;
}
.shape-opt {
  width: 38px; height: 36px; border: 1px solid transparent; background: none; border-radius: var(--r-sm);
  font-size: 17px; cursor: pointer; color: var(--ink);
}
.shape-opt:hover { background: var(--teal-soft); border-color: var(--teal); }
#opacity-input { width: 44px; margin: 2px 0 6px; accent-color: var(--orange); }

/* insert flyout */
#insert-menu {
  position: fixed; left: 62px; z-index: 60; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2); padding: 4px; min-width: 170px;
}
.insert-opt {
  display: flex; align-items: center; gap: 8px; border: none; background: none;
  padding: 8px 10px; font-size: 15px; cursor: pointer; border-radius: 3px; color: var(--ink);
  text-align: left; font-family: inherit;
}
.insert-opt span { font-size: 13px; font-weight: 600; }
.insert-opt:hover { background: var(--teal-soft); }
.insert-opt:disabled { opacity: 0.35; pointer-events: none; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu-danger { color: var(--orange-dark) !important; }

/* Short screens: pack the toolbar row-first into balanced columns
   instead of one full column plus a sparse straggler */
@media (max-height: 940px) {
  #toolbar {
    display: grid;
    grid-template-columns: repeat(2, 44px);
    grid-auto-rows: min-content;
    align-content: start; justify-items: center;
    gap: 4px; overflow-y: auto;
  }
  .tb-sep { grid-column: 1 / -1; width: 100%; margin: 4px 0; }
  #swatches { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); width: 100%; justify-items: center; }
  #fill-label { grid-column: 1 / -1; justify-content: center; }
}
@media (max-height: 500px) {
  #toolbar { grid-template-columns: repeat(3, 44px); }
}

/* students panel controls */
#students-header { display: flex; align-items: center; justify-content: space-between; }
.panel-btns button {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  padding: 2px 7px; cursor: pointer; font-size: 13px; color: var(--ink); margin-left: 4px;
}
.panel-btns button:hover { border-color: var(--teal); color: var(--teal); }
#panel-reopen {
  position: fixed; right: 12px; top: 60px; z-index: 40;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  padding: 6px 10px; cursor: pointer; font-size: 15px; box-shadow: var(--shadow-1);
}

/* expanded students panel: live board grid grows leftward into the canvas */
#students-panel { transition: width 0.2s ease; }
#students-panel.expanded { width: min(calc(100vw - 340px), 1280px); } /* board always keeps ~250px */
#students-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--preview-w, 300px), 1fr));
  gap: 12px; padding: 10px 12px 14px; overflow-y: auto; flex: 1; align-content: start;
}
#preview-size { width: 110px; accent-color: var(--teal); vertical-align: middle; }
.overview-cell {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow-1);
}
.overview-cell:hover { border-color: var(--teal); }
.overview-cell canvas { display: block; margin: 0 auto; }
.overview-name { padding: 6px 10px; font-weight: 600; font-size: 13px; border-top: 1px solid var(--line); }
.modal-hint { margin: 0; padding: 6px 14px; border-top: 1px solid var(--line); background: var(--bg); }

/* comments */
.comment-pin {
  position: absolute; z-index: 7; min-width: 22px; height: 22px; border-radius: 50% 50% 50% 3px;
  background: var(--amber); color: #fff; border: 2px solid #fff; font-size: 11px; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow-1); padding: 0 4px;
}
#comment-pop {
  position: absolute; z-index: 65; width: 270px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-2); padding: 10px;
}
#comment-thread { max-height: 180px; overflow-y: auto; margin-bottom: 8px; }
.comment-row { border-bottom: 1px solid var(--line); padding: 6px 0; }
.comment-meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.comment-meta b { color: var(--ink); }
.comment-meta .c-del { margin-left: auto; border: none; background: none; color: var(--orange-dark); cursor: pointer; font-size: 11px; }
.comment-text { font-size: 13px; margin-top: 2px; white-space: pre-wrap; }
#comment-input {
  width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 7px 9px;
  font-size: 13px; font-family: inherit; resize: none;
}
#comment-pop .role-actions { margin-top: 8px; }

/* messaging */
#msg-panel {
  position: fixed; right: 12px; top: 56px; bottom: 12px; width: 320px; z-index: 90;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-2); display: flex; flex-direction: column; overflow: hidden;
}
#msg-head {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
  font-weight: 700; border-bottom: 1px solid var(--line); background: var(--bg);
}
#msg-head button { border: none; background: none; cursor: pointer; font-size: 14px; color: var(--muted); }
#msg-to {
  margin: 8px 10px 0; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: 13px; background: var(--surface);
}
#msg-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg-row { max-width: 85%; align-self: flex-start; }
.msg-row.mine { align-self: flex-end; text-align: right; }
.msg-meta { font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.msg-text {
  display: inline-block; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 7px 10px; font-size: 13px; text-align: left; white-space: pre-wrap;
}
.msg-row.mine .msg-text { background: var(--teal-soft); border-color: var(--teal); }
#msg-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
#msg-form input {
  flex: 1; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; font-size: 13px;
}
#msg-btn .count-badge { margin-left: 2px; }
.toast-action {
  border: 1px solid #fff; background: none; color: #fff; border-radius: 3px;
  padding: 2px 8px; margin-left: 6px; cursor: pointer; font-size: 12px; font-weight: 700;
}
.send-all-row { display: flex; gap: 6px; margin-bottom: 10px; font-weight: 600; }

/* text toolbar font menu */
#tt-font { width: auto !important; padding: 0 8px; font-size: 12px; }
#tt-font-menu {
  position: absolute; z-index: 8; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2); padding: 4px; min-width: 170px;
}
#tt-font-menu button {
  border: none; background: none; text-align: left; padding: 7px 10px; font-size: 14px;
  cursor: pointer; border-radius: 3px; color: var(--ink);
}
#tt-font-menu button:hover { background: var(--teal-soft); }

/* feature switches */
.feature-off { opacity: 0.35; pointer-events: none; }
.features-box { width: min(760px, 94vw); height: auto; max-height: 88vh; }
.features-body { padding: 14px 18px 18px; overflow-y: auto; }
.features-h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--muted); margin: 18px 0 8px; font-weight: 700;
}
#features-room-row, .f-student-row {
  display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 8px;
  background: var(--surface); box-shadow: var(--shadow-1);
}
#features-room-row { border-color: var(--teal); }
.f-row-name { font-weight: 700; font-size: 13px; min-width: 110px; padding-top: 3px; }
.f-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.f-chip {
  border: 1.5px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: var(--r-sm); padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.f-chip.f-off { border-color: var(--orange); background: var(--orange-soft); color: var(--orange-dark); text-decoration: line-through; }
.f-chip.f-on { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.hint .f-chip { cursor: default; }

#hand-mode, #eraser-mode {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); box-shadow: var(--shadow-1); overflow: hidden; z-index: 5;
}

/* zoom lives on the canvas (bottom-right), not in the top bar */
#zoom-dock {
  position: absolute; bottom: 16px; right: 16px; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); box-shadow: var(--shadow-1); padding: 4px;
}
#zoom-dock button { border: none; }
#zoom-dock button:hover { background: var(--teal-soft); }
.hand-opt {
  border: none; background: none; padding: 7px 14px; font-size: 13px;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.hand-opt.active { background: var(--teal); color: #fff; }

.ctx-btn { border-color: var(--teal); color: var(--teal); }
.ctx-apply { background: var(--teal); color: #fff; border-color: var(--teal); }
.ctx-apply:hover { background: var(--teal-dark); color: #fff; }

/* ---------- teacher students panel ---------- */

#students-panel {
  grid-area: students;
  width: 230px; background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
  border-left: 1px solid var(--line);
}
#students-header {
  padding: 10px 12px; font-weight: 700; font-size: 12px; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--muted);
}
#student-count { background: var(--orange); color: #fff; border-radius: 9px; padding: 1px 8px; margin-left: 4px; }
#student-tiles { overflow-y: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer;
  overflow: hidden; box-shadow: var(--shadow-1);
}
.tile:hover { border-color: var(--teal); }
.tile img { width: 100%; height: 118px; object-fit: contain; background: #fff; display: block; border-bottom: 1px solid var(--line); }
.tile .tile-empty {
  width: 100%; height: 118px; background: #fff; color: #C4C9CF; display: flex;
  align-items: center; justify-content: center; font-size: 13px; border-bottom: 1px solid var(--line);
}
.tile .tname { padding: 6px 10px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tile.offline { opacity: 0.55; }
.tile.offline .tname::after { content: "offline"; color: var(--muted); font-weight: 400; font-size: 11px; margin-left: auto; }

/* ---------- overlays & modals ---------- */

#share-overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; flex-direction: column;
}
.overlay-banner {
  padding: 10px 16px; background: var(--teal); color: #fff; font-weight: 700; text-align: center;
}
.overlay-canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #fff; }

#student-modal, #board-viewer-modal, #boards-modal, #transfer-modal, #roster-modal,
#graph-modal, #chart-modal, #features-modal, #suspend-modal, #user-boards-modal, #history-modal {
  position: fixed; inset: 0; z-index: 110; background: rgba(31, 41, 55, 0.45);
  display: flex; align-items: center; justify-content: center;
}
#boards-modal, #transfer-modal, #graph-modal, #chart-modal, #suspend-modal { z-index: 120; }
#graph-modal .modal-box, #chart-modal .modal-box, #suspend-modal .modal-box { height: auto; max-height: 90vh; }

.modal-box {
  background: var(--surface); border-radius: var(--r); width: min(1000px, 92vw); height: min(700px, 88vh);
  display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; color: var(--ink); font-weight: 700;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.modal-head button {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 6px 12px; cursor: pointer; font-size: 13px; margin-left: 6px;
}
.modal-head button:hover { border-color: var(--teal); color: var(--teal); }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: var(--r-sm);
  font-size: 14px; z-index: 200; box-shadow: var(--shadow-2);
  border-left: 3px solid var(--teal);
}

/* ---------- boards drawer ---------- */

#boards-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px; padding: 16px; overflow-y: auto; flex: 1;
  align-content: start; color: var(--ink); background: var(--bg);
}
.board-switch-card { display: flex; flex-direction: column; }
.board-switch-card.current { border-color: var(--teal); box-shadow: 0 0 0 2px var(--teal-soft), var(--shadow-1); }
.board-card-actions { display: flex; gap: 4px; padding: 0 8px 8px; flex-wrap: wrap; }
.board-card-actions button { margin-right: 0; }

/* transfer picker */
.transfer-box { width: min(440px, 92vw); height: auto; }
.transfer-body { padding: 16px 18px 20px; color: var(--ink); }
.transfer-body label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 8px; font-weight: 700; }
.transfer-body select {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 9px 10px; font-size: 14px; margin-bottom: 14px;
}

/* teacher close-up board tabs */
#modal-board-strip {
  display: flex; gap: 8px; padding: 8px 14px; overflow-x: auto; flex-shrink: 0;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
#modal-board-strip:empty { display: none; }
.strip-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 5px 7px;
  cursor: pointer; color: var(--muted); font-size: 11px; min-width: 84px; max-width: 120px;
}
.strip-item img { width: 74px; height: 46px; object-fit: contain; background: #fff; border-radius: 2px; border: 1px solid var(--line); }
.strip-item .strip-empty { width: 74px; height: 46px; display: flex; align-items: center; justify-content: center; background: #fff; color: #C4C9CF; border-radius: 2px; border: 1px solid var(--line); font-size: 18px; }
.strip-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.strip-item.active { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal); color: var(--teal); }

/* ---------- roster ---------- */

.roster-body { display: flex; gap: 18px; padding: 14px 18px; flex: 1; overflow: auto; color: var(--ink); background: var(--bg); }
.roster-col { flex: 1; min-width: 0; }
.roster-col h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 14px 0 8px; font-weight: 700; }
.roster-col h3:first-child { margin-top: 0; }
.roster-col input[type="text"], .roster-col textarea, #bulk-emails {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 13px; font-family: inherit; margin-bottom: 8px;
}
.roster-col input[type="text"]:focus, .roster-col textarea:focus, #bulk-emails:focus { outline: none; border-color: var(--teal); }
#roster-results, #roster-list { max-height: 320px; overflow-y: auto; }
.roster-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 6px;
  background: var(--surface); box-shadow: var(--shadow-1);
}
.roster-who { display: flex; flex-direction: column; min-width: 0; }
.roster-name { font-weight: 600; font-size: 13px; }
.roster-email { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.roster-tags { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- admin portal ---------- */

body.admin { background: var(--bg); color: var(--ink); min-height: 100vh; }
#admin-header {
  display: flex; align-items: center; gap: 16px; padding: 14px 22px;
  background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-1);
}
#admin-header h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
#admin-me { color: var(--muted); font-size: 13px; flex: 1; }
.admin-header-actions { display: flex; gap: 8px; align-items: center; }
.admin-link { color: var(--teal); text-decoration: none; font-size: 13px; margin-right: 6px; font-weight: 600; }
.admin-link:hover { text-decoration: underline; }

#admin-nav { display: flex; gap: 8px; padding: 14px 22px 0; }
.nav-pill {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 7px 16px; font-size: 13px; cursor: pointer; font-weight: 600; box-shadow: var(--shadow-1);
}
.nav-pill:hover { border-color: var(--teal); color: var(--teal); }
.nav-pill.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.count-badge {
  background: var(--orange); color: #fff; border-radius: 9px; padding: 0 7px;
  font-size: 11px; margin-left: 4px;
}
.nav-pill.active .count-badge { background: rgba(255, 255, 255, 0.28); }

#admin-main { padding: 16px 22px 40px; max-width: 1100px; }
.admin-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow-1);
}
.admin-card h2 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }

.add-user-row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.add-user-row input, .add-user-row select, .admin-table select {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 10px; font-size: 13px;
}
.add-user-row input:focus { outline: none; border-color: var(--teal); }
.add-user-row input { flex: 1; min-width: 200px; }
.primary-sm {
  background: var(--teal); color: #fff; border: none; border-radius: var(--r-sm);
  padding: 8px 16px; font-size: 13px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow-1);
}
.primary-sm:hover { background: var(--teal-dark); }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  text-align: left; color: var(--muted); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 1.5px; padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.admin-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.row-pending { background: var(--amber-soft); }
.u-name { font-weight: 600; }
.u-email { color: var(--muted); font-size: 12px; }

.status-badge { padding: 3px 10px; border-radius: 3px; font-size: 11px; font-weight: 700; }
.status-approved { background: var(--teal-soft); color: var(--teal-dark); }
.status-pending { background: var(--amber-soft); color: var(--amber-text); }
.status-suspended { background: var(--amber-soft); color: var(--amber-text); }
.status-blocked { background: var(--orange-soft); color: var(--orange-dark); }
.status-sub { font-size: 10px; color: var(--muted); margin-top: 2px; }
.user-actions { white-space: nowrap; }
.user-actions button { margin-right: 4px; }
.btn-suspend { border: 1px solid var(--amber); background: var(--surface); color: var(--amber-text); border-radius: var(--r-sm); padding: 5px 10px; font-size: 12px; cursor: pointer; }
.btn-suspend:hover { background: var(--amber-soft); }
.btn-delete { border: 1px solid var(--orange); background: var(--orange); color: #fff; border-radius: var(--r-sm); padding: 5px 10px; font-size: 12px; cursor: pointer; }
.btn-delete:hover { background: var(--orange-dark); }
.badge-super { color: var(--teal); font-weight: 800; font-size: 12px; }

.btn-approve, .btn-block, .btn-view {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--r-sm);
  padding: 5px 10px; font-size: 12px; cursor: pointer; margin-right: 6px;
}
.btn-approve { border-color: var(--teal); color: var(--teal); }
.btn-approve:hover { background: var(--teal-soft); }
.btn-block { border-color: var(--orange); color: var(--orange-dark); }
.btn-block:hover { background: var(--orange-soft); }
.btn-view:hover { border-color: var(--teal); color: var(--teal); }

.domain-list { list-style: none; margin: 8px 0 0; padding: 0; }
.domain-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 6px;
  font-weight: 600; background: var(--surface);
}

.room-group-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted);
  margin: 18px 0 8px; font-weight: 700; border-bottom: 1px solid var(--line); padding-bottom: 4px;
}
.badge-sm { font-size: 11px; padding: 2px 7px; letter-spacing: 1px; }
.room-card { border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow-1); }
.room-card-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; flex-wrap: wrap; }
.room-title { font-weight: 700; }
.room-card-actions { margin-left: auto; }
.room-boards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; padding: 12px 14px; background: var(--bg); border-top: 1px solid var(--line);
}
.board-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; box-shadow: var(--shadow-1); }
.board-item img, .board-item .tile-empty {
  width: 100%; height: 110px; object-fit: contain; background: #fff; display: block; border-bottom: 1px solid var(--line);
}
.board-item .tile-empty { display: flex; align-items: center; justify-content: center; color: #C4C9CF; font-size: 12px; }
.board-item-foot { display: flex; justify-content: space-between; align-items: center; padding: 7px 9px; gap: 6px; }
.board-item-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-roster-panel { padding: 12px 14px; background: var(--bg); border-top: 1px solid var(--line); }
.room-roster-panel .add-user-row input { flex: 1; }

/* roles */
.perm-grid { display: flex; flex-direction: column; gap: 7px; margin: 10px 0 4px; }
.perm-item {
  display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--ink);
  cursor: pointer; line-height: 1.35;
}
.perm-item input { margin-top: 2px; accent-color: var(--teal); }
.perm-item:has(input:disabled) { opacity: 0.5; cursor: default; }
.role-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.role-head h2 { margin: 0; }
.role-meta { margin: 0; }
.role-actions { display: flex; gap: 8px; margin-top: 12px; }
