:root { --rail-width: 57px; --rail-edge: calc(var(--rail-width) + env(safe-area-inset-left, 0px)); }
[hidden] { display: none !important; }
#board-toolbar {
  box-sizing: border-box; inset: 0 auto 0 0; width: var(--rail-edge);
  height: 100vh; height: 100dvh; padding: calc(12px + env(safe-area-inset-top, 0px)) 6px calc(12px + env(safe-area-inset-bottom, 0px)) calc(6px + env(safe-area-inset-left, 0px));
  flex-direction: column; gap: 5px; overflow-y: auto; overflow-x: hidden;
  background: #414042; border: 0; border-radius: 0; backdrop-filter: none;
  box-shadow: 2px 0 12px #0002; z-index: 600; scrollbar-width: thin;
  scrollbar-color: #ffffff50 transparent; overscroll-behavior: contain;
  font: 12px 'Segoe UI', sans-serif; color: #fff; cursor: default;
}
#board-toolbar > * { flex-shrink: 0; }
#board-toolbar .tb-btn, #board-toolbar #home-link,
#board-toolbar #history-header-btns button, #board-toolbar .hist-actions button,
#board-toolbar #mp-confirm-chip button {
  box-sizing: border-box; position: relative; inset: auto; display: flex;
  align-items: center; justify-content: center; width: 44px; height: 44px;
  padding: 10px; margin: 0; border: 1px solid transparent; border-radius: 14px;
  background: transparent !important; color: #fff; box-shadow: none;
  cursor: pointer; opacity: 1; text-decoration: none; backdrop-filter: none;
  transition: background .15s, border-color .15s;
}
#board-toolbar button:hover, #board-toolbar #home-link:hover { background: #ffffff18 !important; }
#board-toolbar .tb-active, #board-toolbar [aria-expanded="true"], #board-toolbar .recording {
  background: #ffffff20 !important; border-color: #ffffff70; box-shadow: none;
}
#board-toolbar button:disabled, #board-toolbar button[aria-disabled="true"] { opacity: .35; cursor: default; }
#board-toolbar :focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
#board-toolbar svg { width: 24px; height: 24px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.classroom-paper-icon { display: inline-block; width: 28px; height: 28px; flex: 0 0 28px; background: url('../assets/game/classroom-paper-icons.webp?v=20261115') var(--paper-x, 0px) 0 / 280px 28px no-repeat; pointer-events: none; }
.classroom-paper-icon.paper-reverse { transform: scaleX(-1); }
#tb-progress svg { display: none; }
#tb-progress::before { content: ''; display: block; width: 28px; height: 28px; background: url('../assets/game/classroom-paper-icons.webp?v=20261115') 0 0 / 280px 28px no-repeat; pointer-events: none; }
#board-toolbar .tb-btn::after { content: none; }
#board-toolbar .tb-sep { width: 28px; height: 1px; margin: 5px 0; background: #ffffff25; }
#board-toolbar #tb-grade { position: absolute !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#board-toolbar .tb-grade-toggle { box-sizing: border-box; width: 44px; height: 34px; border: 1px solid #ffffff45; border-radius: 13px; background: transparent; color: #fff; font: 800 11px 'Segoe UI', sans-serif; letter-spacing: .8px; cursor: pointer; }
#board-toolbar .tb-grade-toggle:hover, #board-toolbar .tb-grade-toggle[aria-expanded="true"] { background: #ffffff18; border-color: #ffffff85; }
.tb-grade-menu { position: fixed; z-index: 10020; left: calc(var(--rail-edge) + 10px); top: calc(14px + env(safe-area-inset-top, 0px)); display: flex; gap: 7px; align-items: center; padding: 8px; border-radius: 17px; background: #414042; box-shadow: 0 8px 24px #0005; border: 1px solid #ffffff2e; }
.tb-grade-choice { white-space: nowrap; border: 1px solid #ffffff30; border-radius: 999px; background: transparent; color: #fff; padding: 8px 11px; font: 700 12px 'Segoe UI', sans-serif; cursor: pointer; }
.tb-grade-choice:hover, .tb-grade-choice.tb-grade-current { background: #ffffff22; border-color: #ffffff90; }
#rail-replies, #mp-confirm-chip { display: flex; flex-direction: row; align-items: center; gap: 5px; }
#rail-tooltip { position: fixed; z-index: 10000; max-width: min(260px, calc(100vw - var(--rail-edge) - 16px)); box-sizing: border-box; padding: 8px 11px; border-radius: 10px; background: #29282b; color: #fff; box-shadow: 0 3px 14px #0003; font: 12px/1.4 'Segoe UI', sans-serif; pointer-events: none; }
#chat-panel { box-sizing: border-box; left: 50%; right: auto; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: min(540px, calc(100vw - var(--rail-edge) - 28px)); max-height: 34dvh; display: flex; flex-direction: column; padding: 9px 10px; background: #343336ee; border-color: #ffffff25; border-radius: 999px; }
#chat-panel:has(#chat-log:not(:empty)) { border-radius: 26px; }
#chat-log { min-height: 0; max-height: 125px; overflow-wrap: anywhere; margin-bottom: 7px; font-size: 12.5px; }
#chat-input-row { gap: 6px; align-items: center; }
#chat-input { min-width: 0; width: 100%; box-sizing: border-box; height: 38px; padding: 8px 12px; border-radius: 999px; font-size: 14px; }
#chat-input:focus-visible { border-color: #fff9; box-shadow: 0 0 0 2px #ffffff20; }

/* Cô hỏi xong, đang chờ đáp án: viền vàng phấn + nhấp nháy nhẹ 3 lần + nhãn chỉ chỗ gõ */
#chat-input-row.ask-cue { position: relative; }
#chat-input-row.ask-cue #chat-input {
  border: 2px solid #ffe27a;
  background: rgba(255, 226, 122, 0.12);
  box-shadow: 0 0 0 3px rgba(255, 226, 122, 0.22);
  animation: ask-cue-pulse 1.3s ease-in-out 3;
}
#chat-input-row.ask-cue #chat-input::placeholder { color: rgba(255, 236, 170, 0.85); }
#chat-input-row.ask-cue::before {
  content: "✍️ Gõ đáp án vào đây, hoặc dùng bút ✏️ viết lên bảng";
  position: absolute; left: 14px; bottom: calc(100% - 7px); z-index: 2;   /* nằm trên mép viền ô, không chui dưới thanh tốc độ */
  padding: 1px 9px; border-radius: 999px; line-height: 15px;
  background: #ffe27a; color: #3a2a00; font-size: 11.5px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  animation: ask-cue-tag 0.35s ease-out;
  pointer-events: none;
}
#chat-input-row.ask-cue.ask-cue-typing #chat-input { animation: none; }
#chat-input-row.ask-cue.ask-cue-typing::before { display: none; }
@keyframes ask-cue-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 226, 122, 0.22); }
  50%      { box-shadow: 0 0 0 7px rgba(255, 226, 122, 0.38); }
}
@keyframes ask-cue-tag {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #chat-input-row.ask-cue #chat-input, #chat-input-row.ask-cue::before { animation: none; }
}
#chat-panel #chat-img, #chat-panel #chat-mic, #chat-panel #chat-send { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 38px; height: 38px; padding: 8px; border: 1px solid #ffffff24; border-radius: 999px; background: #414042; color: #fff; box-shadow: none; }
#chat-panel #chat-send { width: 42px; }
#chat-panel #chat-img:hover, #chat-panel #chat-mic:hover, #chat-panel #chat-send:hover { background: #555458; opacity: 1; }
#chat-panel #chat-mic.recording { background: #9c3b3b; border-color: #fff7; }
#chat-panel button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#history-panel { left: var(--rail-edge); padding: 12px; box-sizing: border-box; }
#history-box { width: min(680px, 100%); max-height: 85dvh; min-width: 0; background: #343336; font-family: "#9Slide03 Roboto Condensed", "Roboto Condensed", "Arial Narrow", Arial, sans-serif; }
#history-list { min-height: 0; overflow-wrap: anywhere; }
#history-header { gap: 12px; }
.hist-entry { cursor: pointer; border-radius: 20px; padding: 12px 18px; margin: 1px 0; border-bottom: 0; }
.hist-entry:hover, .hist-entry.hist-selected { background: #ffffff10; }
.hist-entry:focus-visible { outline: 2px solid #fff8; outline-offset: -2px; }
.hist-icon { width: 30px; height: 30px; padding: 12px; border: 1px solid #ffffff2a; border-radius: 24px; background: #414042; color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.hist-icon:hover { background: #555458; }
.hist-actions button.hist-icon { box-sizing: border-box; width: 30px; height: 30px; padding: 1px; }
.hist-icon svg { flex: 0 0 24px; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.hist-delete { background: #4a2a2a; }
.hist-content { flex: 1; min-width: 0; }
.hist-meta { flex-wrap: wrap; gap: 6px; }
.hist-question { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.hist-question span { flex: 1; min-width: 0; }
.hist-check { appearance: none; flex: 0 0 22px; width: 22px; height: 22px; margin: 0; border: 2px solid #ffffff90; border-radius: 50%; background: transparent; color: #fff; cursor: pointer; display: grid; place-content: center; }
.hist-check:checked { background: #527657; border-color: #fff; }
.hist-check:checked::after { content: ''; width: 9px; height: 5px; border: solid currentColor; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.hist-check:focus-visible, #history-selection button:focus-visible, .hist-icon:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
#history-selection { padding: 8px 18px; flex-shrink: 0; display: flex; align-items: center; gap: 10px; }
#history-selection button { border: 1px solid #ffffff40; border-radius: 12px; padding: 7px 12px; background: #414042; color: #fff; cursor: pointer; }
#history-selection button:disabled { opacity: .45; cursor: not-allowed; }
#history-selected-actions { display: flex; align-items: center; gap: 6px; }
#history-selected-actions .hist-icon { box-sizing: border-box; width: 30px; height: 30px; padding: 2px; }
#mp-confirm-chip { position: static !important; transform: none !important; padding: 12px 0 !important; background: transparent !important; border: 0 !important; box-shadow: none !important; font-size: 10px !important; }
#mp-confirm-chip > span { display: none; }
@media (max-width: 600px) {
  :root { --rail-width: 64px; }
  #board-toolbar { gap: 3px; padding-right: 4px; padding-left: calc(4px + env(safe-area-inset-left, 0px)); }
  #board-toolbar .tb-grade-toggle { width: 42px; height: 32px; font-size: 10px; }
  .tb-grade-menu { left: calc(var(--rail-edge) + 6px); right: 6px; top: calc(8px + env(safe-area-inset-top, 0px)); overflow-x: auto; padding: 7px; gap: 6px; }
  .tb-grade-choice { padding: 7px 9px; font-size: 11px; }
  #chat-panel { left: calc(var(--rail-edge) + ((100vw - var(--rail-edge)) / 2)); width: calc(100vw - var(--rail-edge) - 14px); bottom: calc(8px + env(safe-area-inset-bottom, 0px)); padding: 8px; border-radius: 999px; }
  #chat-panel:has(#chat-log:not(:empty)) { border-radius: 22px; }
  #chat-log { max-height: 96px; font-size: 12px; }
  #chat-input { height: 36px; font-size: 13px; padding: 7px 10px; }
  #chat-panel #chat-img, #chat-panel #chat-mic, #chat-panel #chat-send { width: 36px; height: 36px; padding: 8px; }
  #history-panel { padding: 8px; }
  #history-header, #history-list { padding: 12px; }
}
/* Điện thoại: thanh công cụ thu thành một nút menu 3 gạch, bấm thì các biểu tượng hiện từ dưới lên.
   Bảng được trải rộng tối đa. Bản máy tính không đổi. */
#tb-menu { display: none; }
@media (max-width: 600px) {
  :root { --rail-width: 64px; }
  #tb-menu { position: fixed; z-index: 610; left: calc(8px + env(safe-area-inset-left, 0px)); bottom: calc(10px + env(safe-area-inset-bottom, 0px)); box-sizing: border-box; width: 48px; height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 0; border: 1px solid #ffffff40; border-radius: 16px; background: #414042; box-shadow: 0 4px 14px #0005; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  #tb-menu i { display: block; width: 22px; height: 2.5px; border-radius: 2px; background: #fff; transition: transform .28s cubic-bezier(.3, 1.4, .5, 1), opacity .18s; }
  #tb-menu.open i:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
  #tb-menu.open i:nth-child(2) { opacity: 0; transform: scaleX(.2); }
  #tb-menu.open i:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }
  #tb-menu:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

  #board-toolbar { inset: auto auto calc(70px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px)); width: 60px; height: auto; max-height: calc(100dvh - 92px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); padding: 8px 6px; gap: 3px; justify-content: flex-start; border-radius: 22px; background: transparent; box-shadow: none; pointer-events: none; transition: background-color .25s, box-shadow .25s; }
  /* Ẩn thanh cuộn: khi thu gọn, nền trong suốt nhưng thanh cuộn vẫn hiện thành một gạch dọc xám */
  #board-toolbar { scrollbar-width: none; }
  #board-toolbar::-webkit-scrollbar { display: none; }
  #board-toolbar.tb-open { background: #414042ee; box-shadow: 0 8px 26px #0006; pointer-events: auto; }
  #board-toolbar > :not(.tb-grade-menu) { opacity: 0; visibility: hidden; transform: translateY(26px) scale(.85); transition: opacity .18s ease, transform .2s ease, visibility 0s .2s; }
  #board-toolbar.tb-open > :not(.tb-grade-menu) { opacity: 1; visibility: visible; transform: none; transition: opacity .22s ease calc(var(--i, 0) * 32ms), transform .34s cubic-bezier(.2, .9, .3, 1.25) calc(var(--i, 0) * 32ms), visibility 0s; }
  #board-toolbar .tb-grade-menu { pointer-events: auto; }
  /* Ô chọn sách: thu thành một nút vuông có biểu tượng cuốn sách, bấm vẫn mở danh sách chọn */
  #board-toolbar #tb-textbook { box-sizing: border-box; width: 44px; height: 44px; padding: 0; border: 1px solid transparent !important; border-radius: 14px !important; color: transparent !important; font-size: 16px; -webkit-appearance: none; appearance: none; cursor: pointer;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2Zm0 0v16M8 7h7'/%3E%3C/svg%3E") center / 24px no-repeat !important; }
  #board-toolbar #tb-textbook option { color: #222; font-size: 16px; }
  #history-panel { left: 0; }
  #rail-tooltip { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  #board-toolbar *, #chat-panel .msg-status-live { animation: none !important; transition: none !important; }
}

#chat-panel #chat-mic { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }

/* ===== Hộp "Thành tích và tiến bộ" (nút cúp dưới nút LỚP) ===== */
.pp { margin: auto; box-sizing: border-box; width: min(560px, calc(100vw - 24px)); max-height: 86dvh; padding: 0; border: 1px solid #ffffff2e; border-radius: 24px; background: #343336; color: #fff; box-shadow: 0 18px 60px #0008; font: 15px/1.5 'Segoe UI', sans-serif; overflow: hidden; }
.pp[open] { display: flex; flex-direction: column; }
.pp::backdrop { background: #0006; }
.pp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 8px; }
.pp-head h2 { margin: 0; font-size: 20px; }
.pp-close { box-sizing: border-box; width: 38px; height: 38px; padding: 7px; border: 1px solid #ffffff30; border-radius: 999px; background: #414042; color: #fff; cursor: pointer; }
.pp-close:hover { background: #555458; }
.pp svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.pp-body { padding: 4px 20px 22px; overflow-y: auto; min-height: 0; }
.pp-who { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin-bottom: 12px; }
.pp-avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: #414042; font-size: 26px; }
.pp-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pp-stat { padding: 12px 8px; border-radius: 16px; background: #414042; text-align: center; }
.pp-stat strong { display: block; font-size: 24px; color: #f7e7c9; }
.pp-stat span { font-size: 12.5px; color: #d5d3d8; }
.pp-sub { margin: 20px 0 8px; font-size: 15px; color: #f7e7c9; }
.pp-sub.pp-first { margin-top: 4px; }
.pp-note { margin: 10px 0 0; color: #d5d3d8; }
.pp-missions, .pp-lessons { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.pp-missions li { display: flex; align-items: center; gap: 10px; }
.pp-mark { flex: 0 0 24px; width: 24px; height: 24px; box-sizing: border-box; padding: 3px; border: 2px solid #ffffff80; border-radius: 50%; }
.pp-missions .is-done .pp-mark { background: #527657; border-color: #fff; }
.pp-lessons li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: 12px; background: #414042; }
.pp-q { min-width: 0; overflow-wrap: anywhere; }
.pp-ts { flex: 0 0 auto; font-size: 12.5px; color: #a9a7ae; }
.pp-link { margin-top: 12px; padding: 9px 16px; border: 1px solid #ffffff40; border-radius: 12px; background: #414042; color: #fff; font: 700 14px 'Segoe UI', sans-serif; cursor: pointer; }
.pp-link:hover { background: #555458; }
.pp :focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Đề gợi ý của bộ bài mẫu khi bảng còn trống (src/sample-chips.js) */
#sample-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 4px 9px; }
#sample-chips[hidden] { display: none; }
#chat-panel:has(#sample-chips:not([hidden])) { border-radius: 26px; }
#sample-chips .sc-label { color: rgba(255, 255, 255, 0.72); font-size: 12.5px; margin-right: 2px; white-space: nowrap; }
#sample-chips button { font: inherit; font-size: 13px; line-height: 1.2; min-height: 34px; padding: 6px 12px; border-radius: 17px; cursor: pointer; white-space: nowrap; }
#sample-chips .sc-chip { background: rgba(255, 236, 170, 0.14); border: 1px solid rgba(255, 236, 170, 0.5); color: #fff3c4; }
#sample-chips .sc-chip:hover, #sample-chips .sc-chip:focus-visible { background: rgba(255, 236, 170, 0.26); }
#sample-chips .sc-more { background: transparent; border: 1px dashed rgba(255, 255, 255, 0.35); color: rgba(255, 255, 255, 0.8); }
#sample-chips .sc-more:hover, #sample-chips .sc-more:focus-visible { border-color: rgba(255, 255, 255, 0.7); color: #fff; }

/* Compact classroom composer: suggestions, question, then playback controls. */
#chat-panel, #chat-panel:has(#sample-chips:not([hidden])), #chat-panel:has(#chat-log:not(:empty)) { width: min(580px, calc(100vw - var(--rail-edge) - 28px)); padding: 14px; border: 1px solid #ffffff24; border-radius: 20px; background: #243c3cee; box-shadow: 0 12px 36px #001e2330; max-height: 45dvh; }
#sample-chips { gap: 6px; margin: 0 0 12px; }
#sample-chips .sc-label { flex-basis: 100%; font-size: 11px; letter-spacing: .3px; color: #b0c5c0; margin-bottom: 2px; }
#sample-chips button { min-height: 30px; padding: 6px 10px; border-radius: 8px; font-size: 12px; }
#sample-chips .sc-chip { border: 1px solid transparent; background: #ffffff0d; color: #e4ece7; }
#sample-chips .sc-chip:hover, #sample-chips .sc-chip:focus-visible { background: #ffffff20; }
#sample-chips .sc-more { border: 0; color: #b3c7c2; background: transparent; }
#chat-input-row { gap: 6px; }
#chat-input { height: 44px; border: 1px solid #ffffff20; border-radius: 12px; background: #ffffff0d; color: #fff; padding: 10px 12px; }
#chat-input::placeholder { color: #b2c1be; }
#chat-panel #chat-img, #chat-panel #chat-mic, #chat-panel #chat-send { width: 40px; height: 40px; border: 0; border-radius: 11px; background: transparent; color: #e4ece8; }
#chat-panel #chat-send { background: #d6ebe0; color: #244c40; }
#chat-panel #chat-send:hover { background: #e8f5ed; }
#chat-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 10px; margin-top: 10px; border-top: 1px solid #ffffff10; flex-shrink: 0; }
#chat-controls #speed-ctl { position: static; height: 32px; padding: 0; gap: 8px; width: 200px; max-width: 48%; border: 0; border-radius: 0; background: transparent; box-shadow: none; color: #c8d7d1; }
#chat-controls #speed-range { min-width: 32px; width: 70px; accent-color: #bbd9cc; background: #ffffff30; }
#chat-controls #speed-val { min-width: 32px; font-size: 11px; }
#chat-controls #voice-ctl { position: static; gap: 4px; flex-direction: row; }
#chat-controls #voice-ctl button { width: auto; height: 32px; gap: 5px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: #c8d7d1; box-shadow: none; animation: none; font: 12px 'Segoe UI', sans-serif; }
#chat-controls #voice-ctl button:hover { background: #ffffff12; }
#chat-controls #voice-ctl svg { width: 16px; height: 16px; }
#chat-controls #vc-mute::after { content: 'Âm thanh'; }
#chat-controls #vc-mute[aria-pressed="true"]::after { content: 'Đã tắt'; }
#chat-controls #vc-stop::after { content: 'Tạm dừng'; }
#chat-controls #vc-stop.vc-paused::after { content: 'Tiếp tục'; }
#chat-controls #vc-stop:not(.vc-active):not(.vc-paused) { opacity: .45; }
@media (max-width: 640px) {
  #chat-panel { padding: 10px; width: calc(100vw - var(--rail-edge) - 14px); max-height: 48dvh; }
  #chat-controls { flex-wrap: wrap; gap: 4px; }
  #chat-controls #speed-ctl { width: 160px; max-width: 100%; }
  #chat-controls #voice-ctl { margin-left: auto; }
  #chat-controls #voice-ctl button { padding: 0 5px; }
  #chat-input { font-size: 13px; }
  #chat-panel #chat-img, #chat-panel #chat-mic, #chat-panel #chat-send { width: 34px; height: 38px; padding: 7px; }
}

/* Speed slider: comfortable hit area, precise filled track, quiet numeric badge. */
#chat-controls #speed-ctl { gap: 10px; }
#chat-controls #speed-range { appearance: none; -webkit-appearance: none; height: 28px; padding: 0; background: transparent; border: 0; border-radius: 6px; }
#chat-controls #speed-range::-webkit-slider-runnable-track { height: 4px; border-radius: 9px; background: linear-gradient(to right, #abd9c7 0 var(--speed-fill,33.33%), #ffffff20 var(--speed-fill,33.33%) 100%); }
#chat-controls #speed-range::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border: 3px solid #e8f6ef; border-radius: 50%; background: #609b87; box-shadow: 0 1px 4px #001c3050; transition: box-shadow .15s; }
#chat-controls #speed-range::-moz-range-track { height: 4px; border-radius: 9px; background: #ffffff20; }
#chat-controls #speed-range::-moz-range-progress { height: 4px; border-radius: 9px; background: #abd9c7; }
#chat-controls #speed-range::-moz-range-thumb { width: 8px; height: 8px; border: 3px solid #e8f6ef; border-radius: 50%; background: #609b87; box-shadow: 0 1px 4px #001c3050; }
#chat-controls #speed-range:hover::-webkit-slider-thumb, #chat-controls #speed-range:active::-webkit-slider-thumb { box-shadow: 0 0 0 5px #abd9c71c; }
#chat-controls #speed-range:focus-visible { outline: 2px solid #abd9c7; outline-offset: 3px; }
#chat-controls #speed-val { display: grid; place-items: center; min-width: 39px; height: 25px; padding: 0 5px; box-sizing: border-box; border-radius: 7px; background: #abd9c712; color: #d2ebdf; font-size: 11px; font-weight: 600; }
#sample-chips .sc-last { background: rgba(140, 220, 255, 0.14); border-color: rgba(140, 220, 255, 0.55); color: #d6f1ff; }
#sample-chips .sc-last:hover, #sample-chips .sc-last:focus-visible { background: rgba(140, 220, 255, 0.26); }

/* Hàng nhận xét sau bài giảng (src/lesson-feedback.js): báo cô giảng sai, con chưa hiểu, luyện bài tương tự */
#lesson-feedback { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 4px 8px; }
#lesson-feedback[hidden] { display: none; }
#lesson-feedback .lf-btn { font: inherit; font-size: 12.5px; line-height: 1.2; min-height: 32px; padding: 5px 11px; border-radius: 16px; cursor: pointer; white-space: nowrap; background: transparent; border: 1px solid rgba(255, 255, 255, 0.32); color: rgba(255, 255, 255, 0.85); text-decoration: none; display: inline-flex; align-items: center; }
#lesson-feedback .lf-btn:hover, #lesson-feedback .lf-btn:focus-visible { border-color: rgba(255, 255, 255, 0.7); color: #fff; }
#lesson-feedback .lf-btn:disabled { opacity: 0.45; cursor: default; }
#lesson-feedback .lf-link { border-color: rgba(255, 236, 170, 0.5); color: #fff3c4; }
#lesson-feedback .lf-note { font-size: 12.5px; color: rgba(255, 255, 255, 0.75); }
#sample-chips .sc-review { background: rgba(255, 196, 150, 0.18); border-color: rgba(255, 196, 150, 0.7); color: #ffe2cc; }
#sample-chips .sc-review:hover, #sample-chips .sc-review:focus-visible { background: rgba(255, 196, 150, 0.32); }
#lesson-feedback .lf-badge { flex-basis: 100%; font-size: 12.5px; font-weight: 600; color: #b9f0c8; }
#lesson-feedback .lf-badge[hidden] { display: none; }

/* Chấm vở (notebook-check.js): khung giấy, ảnh vở bên trái, từng dòng cô đọc bên phải */
#sample-chips .sc-check { background: rgba(150, 205, 255, 0.16); border-color: rgba(150, 205, 255, 0.7); color: #dcefff; }
#sample-chips .sc-check:hover, #sample-chips .sc-check:focus-visible { background: rgba(150, 205, 255, 0.3); }
.nb-dialog { width: min(920px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); margin: auto; padding: 0; border: 0; border-radius: 22px; background: #fffdf6; color: #2f3b57; box-shadow: 0 24px 70px #001e2366; overflow: auto; font-family: "Segoe UI", Arial, sans-serif; }
.nb-dialog::backdrop { background: #0d2424b3; }
.nb-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px 20px; border-bottom: 1.5px solid #ecdcb8; background: #fffdf6; }
.nb-head h2 { margin: 0; font: 700 20px "Comfortaa", "Segoe UI", sans-serif; }
.nb-tag { padding: 2px 10px; border-radius: 999px; background: #fff0c7; color: #8a5a00; font-size: 12px; font-weight: 700; }
.nb-close { margin-left: auto; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: #2f3b57; font-size: 26px; line-height: 1; cursor: pointer; }
.nb-close:hover, .nb-close:focus-visible { background: #f1ead8; }
.nb-wrap { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 18px; padding: 18px 20px 20px; }
.nb-photo { width: 100%; max-height: 70dvh; object-fit: contain; border-radius: 12px; background: #f4efe2; }
.nb-body { min-width: 0; }
.nb-wait { margin: 8px 0; font-size: 17px; color: #5b6a86; }
.nb-say { margin: 0 0 12px; padding: 12px 14px; border-radius: 14px; background: #eef4ff; font-size: 17px; line-height: 1.55; }
.nb-sub { margin: 0 0 6px; font-size: 14px; font-weight: 700; color: #5b6a86; }
.nb-lines { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.nb-line { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 2px 8px; padding: 8px 10px; border-radius: 10px; background: #f7f2e6; font-size: 16px; line-height: 1.45; }
.nb-mark { font-weight: 800; text-align: center; color: #9aa3b5; }
.nb-line.is-ok .nb-mark { color: #2f7d32; }
.nb-line.is-wrong { background: #fde9e4; }
.nb-line.is-wrong .nb-mark { color: #c0392b; }
.nb-line.is-first { box-shadow: inset 0 0 0 2px #e07a5f; }
.nb-text { overflow-wrap: anywhere; }
.nb-fix { grid-column: 2; font-weight: 700; color: #a2341f; }
.nb-fine { margin: 10px 0 0; font-size: 13px; color: #7a8599; }
.nb-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.nb-btn { min-height: 46px; padding: 8px 18px; border: 0; border-radius: 14px; background: #1b5fc4; color: #fff; font: 700 15px "Comfortaa", "Segoe UI", sans-serif; cursor: pointer; }
.nb-btn.nb-quiet { border: 1.5px solid #9db3d6; background: transparent; color: #1b5fc4; }
.nb-dialog .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 700px) { .nb-wrap { grid-template-columns: 1fr; padding: 14px; } .nb-photo { max-height: 34dvh; } }

/* Notebook review: one correction at a time, full transcript on demand. */
.nb-dialog { width: min(1000px, calc(100vw - 32px)); background: #fffefb; border: 1px solid #fff8; border-radius: 24px; color: #304943; }
.nb-head { padding: 14px 24px; border-bottom: 1px solid #e7ebe5; background: #fffefb; }
.nb-tag { background: #f1eee5; color: #827451; }
.nb-wrap { grid-template-columns: minmax(220px,.8fr) minmax(0,1.2fr); gap: 32px; padding: 28px; align-items: start; }
.nb-notebook { margin: 0; padding: 16px; background: #f2f1e9; border: 1px solid #e5e4d9; border-radius: 16px; box-shadow: 0 3px 0 #e7e5d9; }
.nb-caption { margin-bottom: 14px; font-size: 14px; font-weight: 700; color: #536b63; }
.nb-photo { display: block; max-height: 48dvh; border-radius: 5px; background: white; }
.nb-photo-note { margin: 12px 0 0; font-size: 12px; color: #78847d; }
.nb-eyebrow { font-size: 11px; letter-spacing: 1.4px; color: #719181; font-weight: 700; }
.nb-summary h3 { margin: 8px 0 12px; font-size: 25px; line-height: 1.3; color: #2b5145; }
.nb-summary .nb-say { padding: 0; margin: 0 0 22px; background: none; color: #61716c; font-size: 15px; line-height: 1.7; }
.nb-correction { padding: 20px 22px; border: 1px solid #e6e5d8; border-radius: 16px; background: #faf8f0; box-shadow: 0 3px 0 #ede9dc; }
.nb-step-label { margin: 0 0 8px; color: #778173; font-size: 12px; font-weight: 700; }
.nb-original { margin: 0 0 22px; padding-left: 12px; border-left: 3px solid #d5a28b; color: #90624e; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }
.nb-answer { margin: 0; color: #255d49; font-size: clamp(21px, 2.6vw, 28px); font-weight: 700; line-height: 1.5; overflow-wrap: anywhere; }
.nb-next { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid #e5e3d5; font-size: 14px; line-height: 1.6; color: #69786c; }
.nb-actions { margin: 20px 0; gap: 10px; }
.nb-btn { background: #326c59; border-radius: 12px; font-size: 14px; }
.nb-btn.nb-quiet { border: 1px solid #d8e1d9; color: #536d60; }
.nb-details { border-top: 1px solid #e7ebe4; padding-top: 16px; }
.nb-details summary { cursor: pointer; color: #5e7569; font-size: 14px; padding: 4px 0 12px; }
.nb-details .nb-line { font-size: 14px; }
.nb-fine { line-height: 1.6; color: #889188; }
.nb-dialog :focus-visible { outline: 3px solid #92b5a3; outline-offset: 3px; }
@media (max-width: 700px) {
 .nb-wrap { display: flex; flex-direction: column; padding: 20px; gap: 24px; }
 .nb-body { width: 100%; order: -1; }
 .nb-notebook { width: 100%; box-sizing: border-box; }
 .nb-head { padding: 10px 16px; }
 .nb-head h2 { font-size: 18px; }
 .nb-summary h3 { font-size: 23px; }
 .nb-correction { padding: 18px; }
 .nb-answer { font-size: 22px; }
}

/* Cool reading palette; color distinguishes feedback without dominating it. */
.nb-dialog { background: #f1f5fa; color: #263d59; border-color: #dce6f1; }
.nb-head { background: #e7eff9; border-color: #d3dfed; }
.nb-tag { background: #d9e6f6; color: #476386; }
.nb-close { color: #34577d; }
.nb-close:hover, .nb-close:focus-visible { background: #d4e2f2; }
.nb-notebook { background: #e5edf6; border-color: #cfddeb; box-shadow: 0 3px 0 #ccd9e8; }
.nb-caption { color: #3e5b7a; }
.nb-photo-note, .nb-fine { color: #596e86; }
.nb-eyebrow { color: #3c6c9f; }
.nb-summary h3 { color: #234b76; }
.nb-summary .nb-say { color: #4b607a; }
.nb-correction { background: #e8f1fc; border-color: #c9dbef; box-shadow: 0 3px 0 #cbdced; }
.nb-step-label { color: #4f6580; }
.nb-original { border-color: #cb815e; color: #98502e; }
.nb-answer { color: #215b9b; }
.nb-next { border-color: #cbdcee; color: #435f7e; }
.nb-btn { background: #315f99; }
.nb-btn:hover { background: #264e81; }
.nb-btn.nb-quiet { background: #f6f9fd; border-color: #bccfe3; color: #3c5b80; }
.nb-btn.nb-quiet:hover { background: #e2ecf8; }
.nb-details { border-color: #d2deec; }
.nb-details summary { color: #3e5e82; }
.nb-line { background: #e5edf7; }
.nb-line.is-ok { background: #e1eee9; }
.nb-line.is-wrong { background: #f8e9e2; }
.nb-dialog :focus-visible { outline-color: #5686bc; }

/* Chấm vở: dặn cách chụp, con xem lại từng dòng cô đọc (dòng tô vàng là cô chưa chắc) */
.nb-notebook[hidden] { display: none; }
.nb-tip-list { margin: 0 0 6px; padding-left: 20px; color: #4b607a; font-size: 16px; line-height: 1.7; }
.nb-edit-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0 0 0 26px; color: #4f6580; font-size: 13px; }
.nb-edit { display: flex; align-items: center; gap: 8px; padding: 4px; border-radius: 12px; }
.nb-edit.is-unsure { background: #fff3cf; box-shadow: inset 0 0 0 1.5px #e3bd57; }
.nb-edit-input { flex: 1; min-width: 0; min-height: 44px; padding: 6px 12px; border: 1.5px solid #c9dbef; border-radius: 10px; background: #fff; color: #263d59; font: 16px "Segoe UI", Arial, sans-serif; }
.nb-edit.is-unsure .nb-edit-input { border-color: #e3bd57; }
.nb-chip { flex: none; min-width: 44px; min-height: 44px; padding: 0 12px; border: 1.5px solid #bccfe3; border-radius: 10px; background: #f6f9fd; color: #315f99; font: 700 14px "Segoe UI", Arial, sans-serif; cursor: pointer; }
.nb-chip:hover { background: #e2ecf8; }
.nb-mic.is-on { background: #315f99; color: #fff; border-color: #315f99; }
.nb-link { margin: 10px 0 0; padding: 8px 0; border: 0; background: none; color: #315f99; font: 700 14px "Segoe UI", Arial, sans-serif; cursor: pointer; min-height: 44px; }
.nb-edit-hint { min-height: 1.4em; margin: 6px 0 0; color: #8a5a00; font-size: 14px; }
.nb-btn:disabled { opacity: .45; cursor: default; }
.nb-wrap:has(> .nb-notebook[hidden]) { grid-template-columns: minmax(0, 1fr); }
.nb-tips { max-width: 560px; }

/* Trò chuyện rảnh tay (chat.js): nút trong hàng điều khiển dưới khung chat */
#chat-controls #vc-talk[aria-pressed="true"] { background: #bbd9cc; color: #143a32; }
#chat-controls #vc-talk span { font: 12px 'Segoe UI', sans-serif; }

/* Unframed captions outside the composer, always two physical lines. */
#teacher-subtitles { position:absolute; bottom:calc(100% + 12px); left:4px; right:4px; pointer-events:none; background:none; border:0; box-shadow:none; text-align:left; font:500 18px/1.55 'Segoe UI',sans-serif; color:#f4f8ee; text-shadow:0 1px 3px #002c26; }
#teacher-subtitles[hidden] { display:none; }
#teacher-subtitles > div { height:1.55em; white-space:nowrap; overflow:hidden; }
#teacher-subtitles .subtitle-previous { opacity:.38; }
#teacher-subtitles .subtitle-current { opacity:1; }
#teacher-subtitles .is-fading { animation:subtitle-rise .45s ease-out,subtitle-dim 2.4s ease-out forwards; }
@keyframes subtitle-rise { from{transform:translateY(5px)}to{transform:translateY(0)} }
@keyframes subtitle-dim { from{opacity:.65}to{opacity:.28} }
@media(max-width:600px) { #teacher-subtitles { font-size:15px; bottom:calc(100% + 8px); } }
@media(prefers-reduced-motion:reduce) { #teacher-subtitles .is-fading { animation:none; opacity:.38; } }

/* Compact composer: ~100px idle, roughly half the previous height. */
#chat-panel, #chat-panel:has(#sample-chips:not([hidden])), #chat-panel:has(#chat-log:not(:empty)) {
  padding: 4px 8px; border-radius: 15px; max-height: min(260px, 38dvh);
}
#sample-chips { flex-wrap: nowrap; gap: 5px; margin: 0 0 3px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
#sample-chips::-webkit-scrollbar { display: none; }
#sample-chips .sc-label { display: none; }
#sample-chips button { flex: 0 0 auto; min-height: 24px; padding: 3px 8px; font-size: 12px; }
#chat-panel #sample-chips button { background: transparent; border: 0; box-shadow: none; color: #dbe8e3; border-radius: 3px; }
#chat-panel #sample-chips button:hover { background: transparent; color: #fff; text-decoration: underline; text-underline-offset: 3px; }
#chat-panel #sample-chips button:focus-visible { background: transparent; outline: 2px solid #abd9c7; outline-offset: -2px; }
#chat-log:empty { display: none; }
#chat-log > [hidden] { display:none !important; }
#chat-log:not(:has(> :not([hidden]))) { display:none; }
#chat-log { max-height: 105px; margin-bottom: 5px; overflow-y: auto; }
#chat-input { height: 34px; padding: 5px 10px; border-radius: 9px; }
#chat-panel #chat-img, #chat-panel #chat-mic, #chat-panel #chat-send { width: 32px; height: 32px; padding: 6px; }
#chat-controls { margin-top: 2px; padding-top: 2px; gap: 6px; flex-wrap: nowrap; }
#chat-controls #speed-ctl { height: 22px; gap: 6px; width: 185px; }
#chat-controls #voice-ctl { gap: 2px; margin-left: auto; }
#chat-controls #voice-ctl button { height: 22px; padding: 0 6px; }
#chat-controls #speed-range { height: 22px; }
#chat-controls #speed-val { height: 22px; }
@media (max-width: 600px) {
  #chat-controls #vc-mute::after, #chat-controls #vc-stop::after { display: none; }
  #chat-controls #vc-talk span { display: none; }
  #chat-controls #voice-ctl button { width: 30px; height: 30px; justify-content: center; padding: 5px; }
  #chat-controls #speed-ctl { width: 160px; max-width: 55%; }
  #chat-panel { max-height: 42dvh; }
}

/* Chat below the left summary area; subtitles follow this same anchor. */
#chat-panel { left: calc(var(--rail-edge) + 18px); right: auto; transform: none; }
@media (max-width: 600px) { #chat-panel { left: calc(var(--rail-edge) + 7px); } }

/* Hàng sau bài giảng: nhãn "Cô đã kiểm" + nút ☰; các nút ít dùng nằm trong menu bật lên phía trên */
#lesson-feedback { position: relative; flex-wrap: nowrap; }
#lesson-feedback .lf-badge { flex: 1 1 auto; flex-basis: auto; min-width: 0; }
#lesson-feedback .lf-note { flex: 0 1 auto; }
#lesson-feedback .lf-more { flex: 0 0 auto; margin-left: auto; width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: rgba(255, 255, 255, 0.8); cursor: pointer; }
#lesson-feedback .lf-more svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#lesson-feedback .lf-more:hover, #lesson-feedback .lf-more:focus-visible, #lesson-feedback .lf-more[aria-expanded="true"] { background: rgba(255, 255, 255, 0.12); color: #fff; }
#lesson-feedback .lf-menu { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 20; display: flex; flex-direction: column; align-items: stretch; gap: 4px; min-width: 190px; padding: 6px; border-radius: 14px; background: #1f3a37; border: 1px solid rgba(255, 255, 255, 0.18); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35); }
#lesson-feedback .lf-menu[hidden] { display: none; }
#lesson-feedback .lf-menu .lf-btn { justify-content: flex-start; border: 0; border-radius: 10px; padding: 8px 12px; font-size: 13.5px; }
#lesson-feedback .lf-menu .lf-btn:hover, #lesson-feedback .lf-menu .lf-btn:focus-visible { background: rgba(255, 255, 255, 0.1); }

/* Điện thoại: nút micro tròn to ở góc phải dưới (ngón cái dễ bấm), giữ để nói, thả tay để gửi.
   chat.js đưa nút ra ngoài khung chat (khung có làm mờ nền nên giữ chặt vị trí "fixed" bên trong nó).
   Nút "Trò chuyện" rảnh tay ẩn đi cho khỏi hai nút micro (nút đó tự nghe lại liên tục, khó tắt). */
@media (max-width: 600px) {
  #chat-panel { width: calc(100vw - var(--rail-edge) - 14px - 70px); }
  body > #chat-mic { position: fixed; z-index: 615; right: calc(10px + env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; width: 60px; height: 60px; padding: 15px;
    border: 2px solid #ffffff55; border-radius: 50%; background: #d9558b; color: #fff; box-shadow: 0 4px 16px #0006; cursor: pointer;
    touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
    transition: transform .15s ease, background-color .15s ease; }
  body > #chat-mic:hover { background: #d9558b; opacity: 1; }
  body > #chat-mic svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
  body > #chat-mic.recording { background: #e5484d; transform: scale(1.18); animation: mic-hold-ring 1.1s ease-out infinite; }
  body > #chat-mic.recording::before { content: 'Đang nghe… thả tay để gửi'; position: absolute; right: 0; bottom: calc(100% + 14px); padding: 6px 10px;
    border-radius: 10px; background: #e5484d; color: #fff; font: 600 12px/1.3 'Segoe UI', sans-serif; white-space: nowrap; box-shadow: 0 4px 12px #0005; pointer-events: none; }
  #chat-controls #vc-talk { display: none !important; }
}
@keyframes mic-hold-ring {
  0%   { box-shadow: 0 0 0 0 rgba(229, 72, 77, .55), 0 4px 16px #0006; }
  100% { box-shadow: 0 0 0 22px rgba(229, 72, 77, 0), 0 4px 16px #0006; }
}
@media (prefers-reduced-motion: reduce) { body > #chat-mic.recording { animation: none; box-shadow: 0 0 0 6px rgba(229, 72, 77, .45); } }
/* Nút về trang chủ trong thanh công cụ lớp học: logo Trò Giỏi */
#board-toolbar #home-link { padding: 4px; }
#board-toolbar #home-link img { width: 36px; height: 36px; object-fit: contain; pointer-events: none; }
