/* The playground's palette: dark by default, light when the system asks for it. */
:root {
  color-scheme: dark;
  --bg: #101412; --panel: #171d19; --raised: #202922; --editor: #111713;
  --text: #e4e9e2; --muted: #95a392; --line: #303b31; --accent: #b4e579; --accent-ink: #1b2b10;
  --bad: #f6a392; --code: #d9e1d6; --comment: #80917e; --keyword: #c4de87; --string: #e8c690;
  --number: #a1d8d1; --hole: #f6a392; --selection: #3e583c;
  --mono: ui-monospace, SFMono-Regular, Consolas, Menlo, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f5ed; --panel: #fcfdf8; --raised: #e9eee1; --editor: #fffef9;
    --text: #202d20; --muted: #687361; --line: #d4dccb; --accent: #476d22; --accent-ink: #fff;
    --bad: #ad422f; --code: #263f31; --comment: #78806d; --keyword: #48651e; --string: #936023;
    --number: #18726d; --hole: #ad422f; --selection: #d7e9be;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { padding: 8px 14px; background: var(--raised); border: 1px solid var(--line); border-radius: 7px; font-weight: 550; white-space: nowrap; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.link { border: none; background: none; color: var(--accent); padding: 0 4px; font-weight: 500; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input { background: var(--editor); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; min-width: 0; }
input[type=checkbox] { padding: 0; accent-color: var(--accent); }
[role=alert] { color: var(--bad); }

/* Joining */
.join { max-width: 380px; margin: 14vh auto; display: grid; gap: 14px; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.join label { display: grid; gap: 6px; color: var(--muted); }
.join button[type=submit] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* The room */
.room { display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto auto minmax(0, 1fr); height: 100vh; }
.room > header { grid-column: 1 / -1; display: flex; gap: 16px; align-items: center; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.room > header [role=status] { color: var(--muted); }
.admin-bar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.admin-bar label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.room > main { overflow: auto; padding: 18px; display: grid; gap: 18px; align-content: start; }

/* Slides */
.slides { display: grid; gap: 10px; justify-items: center; }
.slide { width: 100%; max-width: 1280px; min-width: 0; }
.slide > svg { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border: 1px solid var(--line); border-radius: 10px; }
.slide > details { margin-top: 12px; }
.slide > details p { margin: 6px 0 0; }
.slide-code { color: #edf2ff; }
.slide-code :is(.hl-keyword, .hl-invalid) { color: #ff8fa3; }
.slide-code :is(.hl-type, .hl-tag) { color: #c4a5ff; }
.slide-code .hl-function { color: #79e5cb; }
.slide-code :is(.hl-constant, .hl-number, .hl-property, .hl-attribute, .hl-macro) { color: #ffc28a; }
.slide-code :is(.hl-string, .hl-escape) { color: #b7e88c; }
.slide-code .hl-comment { color: #92a4be; }
.slide-code :is(.hl-operator, .hl-punctuation) { color: #b8c9e4; }
.position { color: var(--muted); margin: 0; }
.slide-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
body:not([data-role=admin]) #slide details { display: none; }

/* The exercise */
.exercise { display: grid; gap: 10px; }
.exercise p { margin: 0; color: var(--muted); }
.exercise-prompt { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.exercise-prompt-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.exercise-prompt pre { margin: 10px 0 0; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.exercise-prompt .prompt-preview { max-height: 4.5em; overflow: hidden; }
.exercise-prompt .prompt-expanded { max-height: 22rem; overflow: auto; }
.code-surface { display: grid; min-height: 320px; max-height: 70vh; overflow: auto; background: var(--editor); border: 1px solid var(--line); border-radius: 10px; }
.code-surface:focus-within { border-color: var(--accent); }
.code-highlight, .code-input {
  grid-area: 1 / 1; margin: 0; padding: 14px 16px; border: 0; font: 14px/1.7 var(--mono); tab-size: 2;
  font-variant-ligatures: none; letter-spacing: 0; white-space: pre; overflow-wrap: normal; min-height: 320px;
}
.code-highlight { color: transparent; pointer-events: none; user-select: none; }
.code-surface[data-highlighted] .code-highlight { color: var(--code); }
.code-input { background: transparent; color: var(--code); caret-color: var(--text); resize: none; overflow: hidden; outline: none; width: 100%; }
.code-input::selection { background: var(--selection); }
.code-surface[data-highlighted] .code-input,
.code-surface[data-highlighted] .code-input::selection { color: transparent; }
.syntax-comment { color: var(--comment); }
.syntax-keyword { color: var(--keyword); }
.syntax-string { color: var(--string); }
.syntax-number { color: var(--number); }
.syntax-hole { color: var(--hole); text-decoration: underline dotted; }
@media (forced-colors: active) { .code-highlight { display: none; } .code-surface .code-input,
  .code-surface[data-highlighted] .code-input,
  .code-surface[data-highlighted] .code-input::selection { color: CanvasText; } }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
pre.report, pre.code { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-height: 80px; font: 13px/1.6 var(--mono); white-space: pre-wrap; color: var(--code); }

/* People (admin) */
.people { display: grid; gap: 12px; }
.seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.seat { display: grid; text-align: left; gap: 2px; background: var(--panel); }
.seat span { color: var(--muted); font-weight: 400; }
.seat.has-errors { border-color: var(--bad); }
.seat.has-errors span { color: var(--bad); }
.seat.correct { border-color: var(--accent); }
.seat.correct span { color: var(--accent); }
.seat.offline { opacity: .55; }
.detail { display: grid; gap: 8px; }

/* Chat */
.chat { border-left: 1px solid var(--line); background: var(--panel); display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; min-height: 0; min-width: 0; padding: 12px 14px; gap: 10px; }
.chat ul { list-style: none; margin: 0; padding: 0; overflow: auto; display: grid; gap: 8px; align-content: start; }
.chat li { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; align-items: baseline; }
.chat li strong { color: var(--accent); }
.chat li .quote { grid-column: 1 / -1; color: var(--muted); }
.replying { margin: 0; color: var(--muted); }
.chat form { display: flex; gap: 6px; min-width: 0; }
.chat form input { flex: 1; }
.chat form button { flex-shrink: 0; }
@media (max-width: 800px) { .room { grid-template-columns: 1fr; height: auto; } .chat { border-left: none; border-top: 1px solid var(--line); } }

pre.report.correct { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.exercise-result { position: relative; }
.confetti { position: absolute; top: 0; left: 50%; z-index: 10; pointer-events: none; }
.confetti span {
  position: absolute; width: 7px; height: 10px; border-radius: 2px;
  --x: 110px; --rise: -100px; --spin: 320deg;
  background: #b4e579;
  animation: confetti-fall 1s ease-out both;
}
.confetti span:nth-child(2n) { --x: -125px; background: #ffd166; }
.confetti span:nth-child(3n) { --rise: -145px; --spin: -280deg; background: #f6a392; }
.confetti span:nth-child(4n) { --x: 185px; animation-delay: 55ms; background: #a1d8d1; }
.confetti span:nth-child(5n) { --x: -190px; --rise: -65px; background: #c4b5fd; }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } }
@keyframes confetti-fall {
  from { transform: translate(0, 0); }
  38% { transform: translate(calc(var(--x) * 0.55), var(--rise)) rotate(calc(var(--spin) * 0.45)); }
  to { transform: translate(var(--x), 125px) rotate(var(--spin)); opacity: 0; }
}
