.classroom {
  min-height: 100vh;
  --call-h: 0px;
}

.classroom.in-call { --call-h: 146px; }

/* Video call strip */
.cr-call {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  height: calc(var(--call-h) - 1rem);
  margin: 1rem 1.5rem 0;
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.cr-call-tiles {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  height: 100%;
  overflow-x: auto;
  min-width: 0;
}

.cr-tile {
  position: relative;
  flex: 0 0 auto;
  height: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

.cr-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cr-tile.self video { transform: scaleX(-1); }

.cr-tile-avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--gold-light);
  background: radial-gradient(circle at 30% 30%, #3a3020, #15171c);
}

.cr-tile-name {
  position: absolute;
  left: 4px;
  bottom: 4px;
  max-width: calc(100% - 8px);
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.65);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cr-tile-muted {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(192, 57, 43, 0.9);
  font-size: 0.65rem;
}

.cr-tile-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.72rem;
  color: var(--muted);
}

.cr-call-controls {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 0.4rem;
  align-content: center;
}

.cr-call-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 34px;
  padding: 0 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}

.cr-call-btn:hover { border-color: var(--gold); }

.cr-call-btn[aria-pressed="false"] {
  background: rgba(192, 57, 43, 0.2);
  border-color: rgba(192, 57, 43, 0.6);
}

.cr-call-btn.record.active {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
}

.cr-call-btn.leave:hover { border-color: #e06c6c; color: #f2a0a0; }

.cr-rec-badge {
  grid-column: 1 / -1;
  color: #e05050;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  animation: cr-pulse 1.4s ease-in-out infinite;
}

.classroom [hidden] { display: none !important; }

.cr-loading {
  text-align: center;
  color: var(--muted);
  margin-top: 4rem;
}

/* Login */
.cr-login {
  display: grid;
  place-items: center;
  padding: 4rem 1.25rem;
}

.cr-login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.2rem;
  box-shadow: var(--shadow);
}

.cr-login-card h1 {
  font-size: 1.8rem;
  margin-bottom: 0.4rem;
}

.cr-login-card > .cr-muted:first-of-type { margin-bottom: 1.6rem; }

.cr-login-help {
  font-size: 0.85rem;
  text-align: center;
  margin: 0.8rem 0 0;
}

/* Signed-in user */
.cr-user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.9rem;
  color: var(--text);
}

.cr-link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.cr-link-btn:hover { color: var(--text); }

/* Live class bar */
.cr-live-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin: 1rem 1.5rem 0;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: rgba(224, 80, 80, 0.12);
  border: 1px solid rgba(224, 80, 80, 0.45);
  font-size: 0.95rem;
}

.cr-live-bar.notice {
  background: rgba(201, 164, 92, 0.1);
  border-color: rgba(201, 164, 92, 0.45);
}

.cr-live-bar.notice .cr-live-dot { display: none; }

.cr-live-bar.your-move {
  background: rgba(127, 207, 154, 0.14);
  border-color: rgba(127, 207, 154, 0.6);
}

.cr-movers-dialog { width: min(480px, calc(100% - 2rem)); }
.cr-movers-dialog h2 { margin: 0 0 0.4rem; }
.cr-movers { display: grid; gap: 0.4rem; margin-top: 0.8rem; max-height: 50vh; overflow-y: auto; }

.cr-mover {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.cr-mover select {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 0 0.5rem;
}

.cr-live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e05050;
  animation: cr-pulse 1.4s ease-in-out infinite;
}

@keyframes cr-pulse {
  50% { opacity: 0.35; }
}

.cr-live-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

.cr-live-bar:not([hidden]) + .cr-layout {
  height: calc(100vh - 72px - 4rem - var(--call-h));
}

.following .cr-sidebar,
.following .cr-moves,
.following .cr-explore {
  pointer-events: none;
}

.following .cr-sidebar { opacity: 0.5; }

.cr-nav {
  width: auto;
  padding: 0 1.5rem;
}

.cr-nav-actions {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.cr-back-link {
  color: var(--muted);
  font-size: 0.9rem;
}

.cr-back-link:hover { color: var(--text); }

.cr-lesson-toggle { display: none; }

#open-play,
#open-fees { position: relative; }

.cr-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #e06c6c;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.cr-muted { color: var(--muted); }

.cr-error {
  color: #e06c6c;
  font-size: 0.85rem;
  margin: 0.3rem 0 0;
}

/* Layout */
.cr-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 380px;
  gap: 1.5rem;
  padding: 1.5rem;
  height: calc(100vh - 72px - var(--call-h));
}

.cr-sidebar,
.cr-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
}

/* Sidebar */
.cr-sidebar {
  padding: 1.2rem;
}

.cr-sidebar h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

.cr-level h3 {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 1.2rem 0 0.5rem;
}

.cr-level:first-child h3 { margin-top: 0; }

.cr-lesson { margin-bottom: 0.4rem; }

.cr-lesson-title {
  margin: 0.6rem 0 0.2rem;
  font-weight: 600;
  font-size: 0.92rem;
}

.cr-game-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.cr-game-btn.nested {
  padding-left: 1.2rem;
  color: var(--muted);
}

.cr-game-btn:hover { background: rgba(255, 255, 255, 0.04); }

.cr-game-btn.active {
  background: rgba(201, 164, 92, 0.12);
  border-color: rgba(201, 164, 92, 0.5);
  color: var(--gold-light);
}

.cr-game-btn.has-error { color: #e06c6c; }

/* Board area */
.cr-board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow-y: auto;
}

.cr-board-wrap {
  width: min(100%, calc(100vh - 72px - 3rem - 165px - var(--call-h)));
  width: min(100%, calc(100svh - 72px - 3rem - 165px - var(--call-h)));
  min-width: 260px;
}

.following .cr-board-wrap {
  width: min(100%, calc(100svh - 72px - 4rem - 3rem - 50px - var(--call-h)));
}

.following .cr-controls,
.following #lesson-toggle { display: none; }

.cr-nav .brand,
.cr-link-btn { white-space: nowrap; }

.cr-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.cr-controls button {
  width: 56px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.cr-controls button:hover:not(:disabled) {
  border-color: var(--gold);
  background: rgba(201, 164, 92, 0.08);
}

.cr-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Board tools */
.cr-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem 1.2rem;
  margin-top: 0.9rem;
}

.cr-tool-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
}

.cr-tool {
  height: 36px;
  padding: 0 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}

.cr-tool:hover { border-color: var(--gold); }

.cr-tool.active {
  border-color: var(--gold);
  background: rgba(201, 164, 92, 0.18);
  color: var(--gold-light);
}

.cr-swatches {
  display: flex;
  gap: 0.3rem;
}

.cr-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.cr-swatch[data-color="G"] { background: #15781b; }
.cr-swatch[data-color="R"] { background: #c0392b; }
.cr-swatch[data-color="Y"] { background: #e0a100; }
.cr-swatch[data-color="B"] { background: #1f5fbf; }
.cr-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg); }

.cb-board.draw-mode,
.cb-board.draw-mode .cb-piece { cursor: crosshair; }

.cb-board.editing .cb-square { cursor: pointer; }

.following .cr-tools,
.cr-board-area.editing .cr-tools,
.cr-board-area.editing .cr-controls,
.cr-board-area.editing #board-status { display: none; }

/* Position editor */
.cr-editor {
  width: min(100%, 520px);
  margin-top: 1rem;
  display: grid;
  gap: 0.7rem;
}

.cr-palette {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 0.25rem;
}

.cr-palette-btn {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #eedbb7;
  cursor: pointer;
  padding: 2px;
  font-size: 1rem;
  color: #8a2b2b;
  font-weight: 700;
}

.cr-palette-btn img { width: 100%; height: 100%; }

.cr-palette-btn.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold);
}

.cr-editor-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.cr-editor-row select,
.cr-editor-row input {
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 0 0.6rem;
}

.cr-editor-row input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem; }

.cr-editor .cr-error { margin: 0; min-height: 1.2em; }

.cr-editor #editor-status { margin: 0; }
.cr-editor #editor-status:empty { display: none; }

.cr-editor select.cr-check {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 164, 92, 0.45);
  animation: cr-check 1.1s ease-in-out infinite;
}

@keyframes cr-check {
  50% { box-shadow: 0 0 0 4px rgba(201, 164, 92, 0.12); }
}

@media (prefers-reduced-motion: reduce) {
  .cr-editor select.cr-check { animation: none; }
}

.cr-editor-picture-row .cr-tool {
  white-space: normal;
  height: auto;
  min-height: 36px;
  padding: 0.35rem 0.8rem;
  text-align: left;
}

.cr-editor-picture {
  width: min(180px, 46%);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.cr-notice {
  margin: 0.6rem 0 0;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  background: rgba(201, 164, 92, 0.12);
  border: 1px solid rgba(201, 164, 92, 0.45);
  font-size: 0.9rem;
}

.cr-editor-actions { justify-content: flex-end; }

/* Load dialog */
.cr-dialog {
  width: min(560px, calc(100% - 2rem));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.6rem;
  box-shadow: var(--shadow);
}

.cr-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.cr-dialog h2 { font-size: 1.4rem; margin-bottom: 0.3rem; }

.cr-dialog textarea {
  width: 100%;
  margin-top: 1rem;
  padding: 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
  resize: vertical;
}

.cr-file-btn { cursor: pointer; }

.cr-dialog .field select,
.cr-inline-form input {
  width: 100%;
  height: 40px;
  padding: 0 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.cr-dialog .field { margin-top: 1rem; }

.cr-dialog-left { margin-right: auto; }

/* Groups manager */
.cr-groups-dialog { width: min(760px, calc(100% - 2rem)); }

.cr-groups {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1rem;
  margin-top: 1rem;
  min-height: 300px;
}

.cr-groups-list,
.cr-group-detail {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
}

#groups-list {
  display: grid;
  gap: 0.3rem;
  max-height: 260px;
  overflow-y: auto;
}

.cr-group-btn {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.cr-group-btn span:last-child { color: var(--muted); font-size: 0.8rem; }

.cr-group-btn.active {
  border-color: var(--gold);
  background: rgba(201, 164, 92, 0.12);
}

.cr-group-detail {
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.cr-inline-form {
  display: flex;
  gap: 0.5rem;
}

.cr-inline-form .btn { flex-shrink: 0; }

.cr-group-count {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.cr-members {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
  max-height: 200px;
  overflow-y: auto;
}

.cr-members li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.9rem;
}

.cr-members li button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.3rem;
}

.cr-members li button:hover { color: #e06c6c; }

.cr-danger { color: #e06c6c; align-self: flex-start; font-size: 0.85rem; }

@media (max-width: 640px) {
  .cr-groups { grid-template-columns: 1fr; }
}

.cr-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.cr-status {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Panel */
.cr-panel {
  display: flex;
  flex-direction: column;
  padding: 1.4rem;
  overflow: hidden;
}

.cr-game-head h1 {
  font-size: 1.5rem;
  margin-bottom: 0.3rem;
}

.cr-game-head p {
  font-size: 0.88rem;
  margin: 0 0 1rem;
}

.cr-explore {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  border-radius: 10px;
  background: rgba(227, 163, 184, 0.12);
  border: 1px solid rgba(227, 163, 184, 0.4);
  font-size: 0.9rem;
}

.cr-explore[hidden] { display: none; }

.cr-explore.success {
  background: rgba(127, 207, 154, 0.12);
  border-color: rgba(127, 207, 154, 0.5);
  color: #9ee0b3;
}

.cr-explore .btn { white-space: nowrap; }

.cr-explore-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.cr-explore-actions[hidden] { display: none; }

/* My work (the student's saved moves) */
.cr-my-work {
  padding-bottom: 0.8rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.cr-my-work h3 { color: #e3a3b8; }

.cr-work-item {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.cr-work-item .cr-game-btn { flex: 1; min-width: 0; }

.cr-work-item .cr-game-btn small {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.cr-work-icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.cr-work-icon:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }

.cr-note-box {
  border-left: 3px solid var(--gold);
  background: rgba(201, 164, 92, 0.06);
  border-radius: 0 10px 10px 0;
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
}

.cr-note-label {
  margin: 0 0 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.cr-note {
  margin: 0;
  font-size: 1rem;
  min-height: 1.6em;
}

.cr-note.empty::before {
  content: "—";
  color: var(--muted);
}

.cr-moves {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  line-height: 2;
  font-size: 0.95rem;
}

.cr-move {
  background: none;
  border: 0;
  padding: 0.1rem 0.35rem;
  margin: 0 0.05rem;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.cr-move:hover { background: rgba(255, 255, 255, 0.07); }

.cr-move.current {
  background: var(--gold);
  color: #1a1408;
}

.cr-move.user {
  color: var(--lotus);
  font-style: italic;
}

.cr-move.user.current {
  background: var(--lotus);
  color: #2a1018;
}

.cr-comment {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0.3rem;
}

.cr-variation {
  margin: 0.2rem 0 0.2rem 0.6rem;
  padding-left: 0.7rem;
  border-left: 2px solid var(--border);
  font-size: 0.9rem;
}

.cr-variation .cr-move { font-weight: 400; color: #cfcbc2; }
.cr-variation .cr-move.current { color: #1a1408; }
.cr-variation.user { border-left-color: rgba(227, 163, 184, 0.5); }
.cr-variation.by-coach { border-left-color: rgba(201, 164, 92, 0.6); }

.cr-move.by-coach { font-style: italic; }

.following .cr-hint { visibility: hidden; }

.cr-result {
  margin: 0.6rem 0 0;
  font-weight: 600;
  color: var(--gold);
}

.cr-hint {
  margin: 1rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Library videos and books, shown in place of the board */
.showing-media .cr-board-area,
.showing-media .cr-panel,
.showing-quiz .cr-board-area,
.showing-quiz .cr-panel,
.showing-quiz .cr-media,
.showing-quiz .cr-sidebar { display: none; }

.showing-quiz .cr-quiz { grid-column: 1 / -1; }

/* Live quiz, shown in place of the board */
.cr-quiz {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 1.2rem;
  min-height: 0;
  align-items: start;
}

.cr-quiz-board-col { display: flex; justify-content: center; min-height: 0; }

.cr-quiz-board-wrap {
  width: min(100%, calc(100svh - 72px - 4rem - 3rem - var(--call-h)));
  min-width: 260px;
}

.cr-quiz-panel {
  display: grid;
  gap: 0.7rem;
  align-content: start;
  max-height: 100%;
  overflow-y: auto;
  padding: 1.2rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
}

.cr-quiz-panel .cr-note-label { margin: 0; }
.cr-quiz-panel h2 { margin: 0; font-size: 1.4rem; }
.cr-quiz-prompt { margin: 0; font-size: 1.1rem; }

.cr-quiz-timer {
  font-size: 2.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold-light);
  line-height: 1;
}

.cr-quiz-timer.warn { color: #e06c6c; }

.cr-quiz-feedback { margin: 0; font-weight: 600; min-height: 1.3em; }
.cr-quiz-feedback.sent { color: var(--gold-light); }
.cr-quiz-feedback.good { color: #7fcf9a; font-size: 1.15rem; }
.cr-quiz-feedback.bad { color: #e06c6c; }

.cr-quiz-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.cr-quiz-actions:empty { display: none; }

.cr-quiz-scores { display: grid; gap: 0.5rem; }
.cr-quiz-scores .cr-note-label { margin: 0.4rem 0 0; }

.cr-quiz-ranking {
  margin: 0;
  padding-left: 1.8rem;
  display: grid;
  gap: 0.25rem;
  font-size: 0.95rem;
}

.cr-quiz-ranking li { padding: 0.2rem 0.4rem; border-radius: 6px; }
.cr-quiz-ranking li::marker { color: var(--muted); }
.cr-quiz-ranking li.me { background: rgba(201, 164, 92, 0.18); }
.cr-quiz-ranking .name { display: inline-block; min-width: 60%; }
.cr-quiz-ranking .pts { float: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.cr-quiz-ranking .pts small { color: #7fcf9a; font-weight: 400; }

.cr-quiz-podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 0.4rem;
  text-align: center;
}

.cr-quiz-podium .place {
  display: grid;
  gap: 0.1rem;
  padding: 0.6rem 0.3rem;
  border-radius: 10px 10px 0 0;
  background: rgba(201, 164, 92, 0.15);
  border: 1px solid rgba(201, 164, 92, 0.4);
}

.cr-quiz-podium .place-1 { order: 2; padding-top: 1.4rem; background: rgba(201, 164, 92, 0.3); }
.cr-quiz-podium .place-2 { order: 1; padding-top: 0.9rem; }
.cr-quiz-podium .place-3 { order: 3; }
.cr-quiz-podium .medal { font-size: 1.8rem; }
.cr-quiz-podium strong { font-size: 0.9rem; }
.cr-quiz-podium small { color: var(--muted); font-size: 0.75rem; }

.cr-quiz-dialog { width: min(560px, calc(100% - 2rem)); }
.cr-quiz-dialog .field input[type="file"] { height: auto; padding: 0.5rem; }

.cr-quiz-past {
  margin-top: 1rem;
  max-height: 260px;
  overflow-y: auto;
  display: grid;
  gap: 0.4rem;
  font-size: 0.88rem;
}

.cr-quiz-past summary { cursor: pointer; }
.cr-quiz-past ol { margin: 0.4rem 0 0.6rem; color: var(--muted); }

.cr-media {
  grid-column: 2 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem 1.1rem;
}

.cr-media-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.cr-media-heading { min-width: 0; }
.cr-media-heading .cr-note-label { margin: 0 0 0.15rem; }
.cr-media-heading h2 { font-size: 1.3rem; margin: 0; }

.cr-media-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.cr-media-actions .btn { white-space: nowrap; }

.cr-media-frame {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.cr-media.is-book .cr-media-frame { background: #fff; }

.cr-media-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.cr-media-message {
  margin: 0;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

.cr-media.is-book .cr-media-message { color: #555; }

/* Book reader (book.js) */
.cr-book {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #222;
}

.cr-book-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.4rem 0.5rem;
  background: #f1efe9;
  border-bottom: 1px solid #ddd8cc;
  font-size: 0.88rem;
}

.cr-book-btn {
  min-width: 34px;
  height: 32px;
  padding: 0 0.6rem;
  border: 1px solid #cfc8b8;
  border-radius: 8px;
  background: #fff;
  color: #333;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.cr-book-btn:hover:not(:disabled) { border-color: var(--gold); }
.cr-book-btn:disabled { opacity: 0.4; cursor: default; }
.cr-book-btn.active { background: #f6ecd6; border-color: var(--gold); }
.cr-book-pos { white-space: nowrap; }
.cr-book-col { color: #8a6d2c; font-weight: 600; }
.cr-book-spacer { flex: 1; }

.cr-book .cr-book-bar input.cr-book-page {
  width: 4.2em;
  height: auto;
  min-width: 0;
  padding: 0.2rem 0.3rem;
  border: 1px solid #cfc8b8;
  border-radius: 6px;
  font: inherit;
  text-align: center;
  background: #fff;
  color: #222;
}

.cr-book-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.5rem;
  touch-action: pan-y pinch-zoom;
  outline: none;
}

.cr-book-stage.zoomed { touch-action: auto; }
.cr-book-sheet { width: max-content; min-width: 100%; display: flex; justify-content: center; }
.cr-book-sheet canvas { display: block; height: auto; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18); }
.cr-book-message { margin: 2rem 1rem; text-align: center; color: #666; }

.cr-book.is-fallback { display: flex; }
.cr-book-note { margin: 0; padding: 0.45rem 0.8rem; font-size: 0.82rem; color: #6b5a2e; background: #f6ecd6; }
.cr-book-note a { color: #8a5a00; font-weight: 600; }
.cr-book-frame { flex: 1; width: 100%; min-height: 0; border: 0; display: block; }

@media (max-width: 640px) {
  .cr-book-bar { font-size: 0.8rem; gap: 0.25rem; padding: 0.3rem; }
  .cr-book-btn { min-width: 30px; height: 30px; padding: 0 0.45rem; }
  .cr-book-stage { padding: 0.25rem; }
}

.cr-media-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.cr-media-hint:empty { display: none; }

.cr-library-dialog { width: min(620px, calc(100% - 2rem)); }

#library-search {
  width: 100%;
  height: 40px;
  margin-top: 1rem;
  padding: 0 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
}

#library-search:focus { outline: none; border-color: var(--gold); }

.cr-library-list {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.8rem;
  max-height: min(55vh, 460px);
  overflow-y: auto;
}

.cr-library-list .cr-muted { margin: 0.5rem 0; }

.cr-library-section {
  font-size: 1.1rem;
  margin: 0.8rem 0 0;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.cr-library-section:first-child { margin-top: 0; }

.cr-library-level {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0.4rem 0 0;
}

.cr-library-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.cr-library-item:hover { border-color: var(--gold); }

.cr-library-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.cr-library-item strong {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
}

.cr-library-item small {
  display: block;
  color: var(--gold);
  font-size: 0.78rem;
}

/* Responsive */
@media (max-width: 1100px) {
  .cr-layout { grid-template-columns: minmax(0, 1fr) 340px; }
  .cr-media,
  .cr-quiz { grid-column: 1 / -1; }
  .classroom:not(.admin):not(.library) .cr-nav-label { display: none; }
  .cr-nav-actions .btn-small { white-space: nowrap; }

  .cr-lesson-toggle { display: inline-block; }

  .cr-sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    z-index: 40;
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-105%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow);
  }

  .cr-sidebar.open { transform: none; }
}

@media (max-width: 760px) {
  .cr-layout {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    padding: 1rem;
  }

  .cr-board-wrap { width: 100%; min-width: 0; }
  .cr-controls button { width: 52px; }
  .cr-panel { overflow: visible; }
  .cr-moves { max-height: 320px; }
  .cr-media { padding: 0.8rem; }
  .cr-quiz { grid-template-columns: 1fr; gap: 0.8rem; }
  .cr-quiz-board-wrap { width: 100%; min-width: 0; }
  .cr-quiz-panel { padding: 0.9rem; }
  .cr-quiz-timer { font-size: 1.8rem; }
  .cr-media-heading h2 { font-size: 1.1rem; }
  .cr-media-frame { flex: none; aspect-ratio: 16 / 9; }
  .cr-media.is-book .cr-media-frame { aspect-ratio: auto; height: 75svh; }
  .cr-back-link { display: none; }
  .cr-nav-label { display: none; }
  #user-name { display: none; }
  .cr-nav-actions .btn-small { padding: 0.45rem 0.75rem; white-space: nowrap; }
  .cr-nav { padding: 0 1rem; }
  .cr-nav .brand { font-size: 1.1rem; gap: 0.45rem; }
  .cr-nav .brand-logo { width: 28px; height: 28px; }
  .cr-nav-actions { gap: 0.7rem; }
  .cr-live-bar {
    margin: 0.6rem 0.75rem 0;
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
  }
  .cr-live-actions { margin-left: auto; }

  .cr-live-bar:not([hidden]) + .cr-layout { height: auto; }
  .cr-board-area { overflow: visible; }

  /* Following a live class on a phone: board, coach's note and moves on one screen */
  .following .cr-layout { padding: 0.6rem 0.75rem; gap: 0.6rem; }
  .following .cr-board-wrap { width: min(100%, calc(100svh - 72px - 3.5rem - 2rem - var(--call-h))); }
  .following .cr-status { margin: 0.3rem 0 0; font-size: 0.8rem; }
  .following .cr-panel { padding: 0.8rem 0.9rem; }
  .following .cr-game-head h1 { font-size: 1.1rem; margin: 0; }
  .following #game-meta { display: none; }
  .following .cr-note-box { padding: 0.5rem 0.8rem; margin: 0.5rem 0; }
  .following .cr-note { font-size: 0.95rem; }
  .following .cr-moves { max-height: max(110px, calc(100svh - 100vw - 18.5rem - var(--call-h))); }
  .following .cr-hint { display: none; }

  .following .cr-live-bar { flex-wrap: nowrap; gap: 0.5rem; }
  .following #live-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .following .cr-live-actions { flex-wrap: nowrap; gap: 0.35rem; }
  .following .cr-live-actions .btn { padding: 0.35rem 0.7rem; font-size: 0.78rem; }

  .classroom.in-call { --call-h: 84px; }
  .in-call.following .cr-moves { max-height: max(80px, calc(100svh - 100vw - 18.5rem - var(--call-h))); }
  .cr-call { margin: 0.5rem 0.75rem 0; padding: 0.35rem; gap: 0.5rem; }
  .cr-call-label { display: none; }
  .cr-call-controls { grid-template-columns: repeat(2, 32px); gap: 4px; }
  .cr-call-btn { height: 30px; padding: 0; justify-content: center; }
  .cr-tile-name { font-size: 0.62rem; }
  .cr-rec-badge { font-size: 0.7rem; }
  .cr-rec-badge #rec-time { display: none; }
}

/* Phones held sideways: board and notes side by side, board fits the screen height */
@media (max-width: 480px) {
  .classroom:not(.admin):not(.library) .cr-nav .brand span { display: none; }
  .cr-nav-actions { gap: 0.35rem; }
  .cr-nav-actions .btn-small { padding: 0.4rem 0.55rem; }
  .cr-nav { padding: 0 0.6rem; }
}

@media (max-width: 400px) {
  .classroom:not(.admin):not(.library) .cr-nav .brand { display: none; }
  .classroom:not(.admin):not(.library) .cr-nav { justify-content: flex-end; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .classroom .nav { height: 52px; }
  .cr-sidebar { top: 52px; }

  .cr-layout,
  .cr-live-bar:not([hidden]) + .cr-layout {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 42%);
    height: calc(100svh - 52px - var(--call-h));
    padding: 0.6rem 0.75rem;
    gap: 0.75rem;
  }

  .cr-live-bar:not([hidden]) + .cr-layout { height: calc(100svh - 52px - 3.2rem - var(--call-h)); }

  .cr-live-bar {
    margin: 0.4rem 0.75rem 0;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
  }

  .cr-board-area { overflow-y: auto; }
  .cr-board-wrap { min-width: 0; width: min(100%, calc(100svh - 52px - 1.2rem - 110px - var(--call-h))); }
  .following .cr-board-wrap { width: min(100%, calc(100svh - 52px - 3.2rem - 1.2rem - 48px - var(--call-h))); }

  .classroom.in-call { --call-h: 74px; }
  .cr-call { margin: 0.4rem 0.75rem 0; padding: 0.35rem; }
  .cr-call-label { display: none; }
  .cr-call-controls { grid-template-columns: repeat(4, 32px); }
  .cr-call-btn { height: 30px; padding: 0; justify-content: center; }
  .cr-rec-badge { display: none; }
  .following .cr-status { margin-top: 0.3rem; font-size: 0.8rem; }

  .cr-panel { overflow: hidden; padding: 0.8rem; }
  .cr-game-head h1 { font-size: 1.15rem; }
  .cr-moves { max-height: none; }
  .following #game-meta,
  .following .cr-hint { display: none; }
}

/* Students wait for their coach (no lessons or board until the class starts) */
body.waiting #app-view,
body.waiting #live-bar { display: none !important; }

.cr-wait {
  display: grid;
  place-items: center;
  min-height: calc(100svh - 72px);
  padding: 1.5rem 1rem;
}

.cr-wait[hidden] { display: none; }

.cr-wait-card {
  display: grid;
  justify-items: center;
  gap: 0.8rem;
  width: min(560px, 100%);
  padding: 2rem 1.5rem;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid rgba(201, 164, 92, 0.45);
  background: var(--surface);
}

.cr-wait-card h1 { margin: 0; font-size: clamp(1.5rem, 4.5vw, 2rem); }
.cr-wait-text { margin: 0; font-size: 1.1rem; line-height: 1.6; color: var(--text); }
.cr-wait-bot { width: 110px; height: 121px; }
.cr-wait-rooms { display: grid; gap: 0.6rem; width: 100%; }
.cr-wait-rooms:empty { display: none; }
.cr-wait-rooms button { font-size: 1.05rem; padding: 0.8rem 1rem; }
.cr-wait-dots { margin: 0.2rem 0 0.6rem; color: var(--gold-light); font-weight: 600; }
.cr-wait-dots[hidden] { display: none; }
.cr-wait-dots span { animation: cr-wait-blink 1.4s infinite both; }
.cr-wait-dots span:nth-child(2) { animation-delay: 0.2s; }
.cr-wait-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cr-wait-blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }
