/* ---- Page layout --------------------------------------------------------- */

:root {
  --topbar: 3rem;
  /* One square's size; each page sets it so the board fills the window. */
  --sq: min(calc((100vh - var(--topbar) - 8rem) / 8), 9vw);
}

.page-lessons,
.page-puzzles {
  /* Leave room for the menu and the explanation panel beside the board. */
  --sq: min(calc((100vh - var(--topbar) - 3rem) / 8), calc((100vw - 42rem) / 8));
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #2b2b2b;
  color: #ddd;
  font-family: system-ui, sans-serif;
}

.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 1.5rem;
  background: #1f1f1f;
}

.brand {
  font-weight: 700;
  color: #f0d9b5;
}

.topbar nav {
  display: flex;
  gap: 1.25rem;
}

.topbar a {
  color: #aaa;
  text-decoration: none;
}

.topbar a:hover,
.topbar a.active {
  color: #fff;
}

.topbar .source-link {
  margin-left: auto;
  font-size: 0.85rem;
}

.page-body {
  min-height: calc(100vh - var(--topbar));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.board-wrap {
  flex: none;
  width: calc(var(--sq) * 8);
  height: calc(var(--sq) * 8);
}

#board {
  width: 100%;
  height: 100%;
}

button {
  font: inherit;
  border: none;
  border-radius: 4px;
  background: #555;
  color: #eee;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #666;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.muted {
  color: #999;
}

/* ---- Board coordinates ----------------------------------------------------
   Scaled with the board so they are readable on a projector. Rank numbers sit
   in the top-left corner of the edge squares, file letters in the bottom-right. */

.cg-wrap coords {
  font-size: calc(var(--sq) * 0.17);
  font-weight: 600;
}

.cg-wrap coords.ranks {
  top: 0;
  left: 0;
  width: auto;
  height: 100%;
}

.cg-wrap coords.files {
  bottom: 0;
  left: 0;
  width: 100%;
  height: auto;
}

.cg-wrap coords coord {
  flex: 1 1 0;
  line-height: 1;
}

.cg-wrap coords.ranks coord {
  transform: none;
  padding: calc(var(--sq) * 0.04) 0 0 calc(var(--sq) * 0.05);
}

.cg-wrap coords.files coord {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 calc(var(--sq) * 0.05) calc(var(--sq) * 0.04) 0;
}

/* ---- Board editor -------------------------------------------------------- */

.editor {
  display: flex;
  align-items: center;
  gap: calc(var(--sq) * 0.4);
}

/* Spare-piece trays. They carry the cg-wrap class so the piece images apply. */
.cg-wrap.tray {
  display: flex;
  flex-direction: column;
  width: var(--sq);
  padding: calc(var(--sq) * 0.1);
  background: #3a3a3a;
  border-radius: 6px;
}

.cg-wrap.tray piece {
  position: static;
  display: block;
  width: var(--sq);
  height: var(--sq);
  pointer-events: auto;
  cursor: grab;
  will-change: auto;
}

.cg-wrap.tray piece:hover {
  background-color: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

/* A tray piece selected for placing with a click. */
.cg-wrap.tray piece.selected {
  background-color: rgba(155, 199, 0, 0.45);
  border-radius: 4px;
  box-shadow: inset 0 0 0 3px rgba(155, 199, 0, 0.9);
}

/* While a tray piece is selected, clicks on the board place it. */
#board.placing cg-board {
  cursor: copy;
}

.controls {
  display: flex;
  gap: 0.75rem;
}

.controls button {
  font-size: 1rem;
  padding: 0.5rem 1rem;
}

.hint {
  margin: 0;
  color: #999;
  font-size: 0.9rem;
}

/* ---- Lessons and puzzles ------------------------------------------------------------- */

.page-body.viewer {
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem;
  box-sizing: border-box;
}

.menu {
  flex: none;
  width: 15rem;
  max-height: calc(var(--sq) * 8);
  overflow-y: auto;
}

.menu h2 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #999;
}

.menu ul {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
}

.menu a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  color: #ddd;
  text-decoration: none;
}

.menu a:hover {
  background: #3a3a3a;
}

.menu a.active {
  background: #4a4a4a;
  color: #fff;
}

.load-errors {
  margin-top: 1rem;
  padding: 0.75rem;
  border-left: 3px solid #c0504d;
  background: #3a2b2b;
  font-size: 0.85rem;
}

.load-errors p {
  margin: 0.5rem 0 0;
  overflow-wrap: anywhere;
}

.error {
  color: #e88;
}

.panel {
  flex: none;
  width: 22rem;
  max-height: calc(var(--sq) * 8);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel h1 {
  margin: 0;
  font-size: 1.6rem;
  color: #fff;
}

.chapters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chapters:empty {
  display: none;
}

.chapters button {
  padding: 0.3rem 0.7rem;
  font-size: 0.9rem;
  background: #3a3a3a;
}

.chapters button.active {
  background: #6a6a6a;
  color: #fff;
}

.move-label {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f0d9b5;
  min-height: 1.4em;
}

/* The explanation is the main thing the class reads, so make it large. */
.big-text {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.45;
  min-height: 6em;
}

.step-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-controls button {
  font-size: 1.2rem;
  padding: 0.4rem 0.9rem;
}

.step-count {
  margin-left: 0.5rem;
  color: #999;
}

.move-list {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.3rem;
  overflow-y: auto;
}

.move-number {
  color: #888;
  margin-left: 0.3rem;
}

.move-list .move {
  padding: 0.1rem 0.35rem;
  background: none;
  color: #ccc;
}

.move-list .move:hover {
  background: #3a3a3a;
}

/* A move the lesson hasn't reached yet, while moves are hidden. */
.move-list .move.hidden-move {
  min-width: 2.2em;
  color: #777;
  background: #333;
}

.move-list-options button {
  padding: 0.3rem 0.8rem;
  font-size: 0.9rem;
  background: #3a3a3a;
}

.move-list .move.current {
  background: #f0d9b5;
  color: #222;
}

/* ---- Puzzles ------------------------------------------------------------- */

.puzzle-actions {
  display: flex;
  gap: 0.6rem;
}

.puzzle-actions button {
  font-size: 1.05rem;
  padding: 0.5rem 1rem;
}

.feedback {
  padding: 0.8rem 1rem;
  border-radius: 6px;
  border-left: 5px solid;
  font-size: 1.2rem;
}

.feedback strong {
  font-size: 1.45rem;
}

.feedback p {
  margin: 0.4rem 0 0;
  line-height: 1.4;
}

.feedback.correct {
  background: #263a26;
  border-color: #6fbf4a;
}

.feedback.correct strong {
  color: #9fe07a;
}

.feedback.wrong {
  background: #3d2626;
  border-color: #d9534f;
}

.feedback.wrong strong {
  color: #ff8a85;
}

.feedback.solved {
  background: #3b3420;
  border-color: #f0c040;
}

.feedback.solved strong {
  color: #ffd866;
}

.solution {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-top: 1px solid #444;
  padding-top: 1rem;
}

/* The question is short; don't reserve room for a long explanation. */
#puzzle-prompt {
  min-height: 0;
}
