.classroom {
  min-height: 100vh;
}

.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-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);
}

.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; }

.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);
}

.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));
  width: min(100%, calc(100svh - 72px - 3rem - 165px));
  min-width: 260px;
}

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

.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;
  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 .cr-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-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-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-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);
}

/* Responsive */
@media (max-width: 1100px) {
  .cr-layout { grid-template-columns: minmax(0, 1fr) 340px; }

  .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: 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-back-link { display: none; }
  #user-name { display: none; }
  .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)); }
  .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)); }
  .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; }
}

/* Phones held sideways: board and notes side by side, board fits the screen height */
@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);
    padding: 0.6rem 0.75rem;
    gap: 0.75rem;
  }

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

  .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)); }
  .following .cr-board-wrap { width: min(100%, calc(100svh - 52px - 3.2rem - 1.2rem - 48px)); }
  .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; }
}
