/* play.emmerix.net — mathematical playground */

:root {
  color-scheme: light dark;

  --bg: #fbfaf7;
  --bg-raised: #ffffff;
  --bg-sunken: #f2efe9;
  --border: #e2ddd2;
  --border-strong: #cfc8b8;
  --text: #22201c;
  --text-soft: #6b6559;
  --text-faint: #938c7d;
  --accent: #9a4a1f;
  --accent-soft: #f3e5da;
  --link: #1f5c8b;
  --danger: #a32c22;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(40 34 24 / 6%), 0 6px 18px rgb(40 34 24 / 5%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16151a;
    --bg-raised: #1e1d23;
    --bg-sunken: #121116;
    --border: #33313b;
    --border-strong: #46434f;
    --text: #e9e6e0;
    --text-soft: #a8a296;
    --text-faint: #7d7769;
    --accent: #e0894f;
    --accent-soft: #33251b;
    --link: #78b6e0;
    --danger: #e8756a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); }

/* ---------------------------------------------------------------- header */

.masthead {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.masthead-inner,
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

.masthead-inner {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding-block: 22px 20px;
}

.wordmark {
  font-family: var(--sans);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text);
  text-decoration: none;
}

.wordmark .dim { color: var(--text-faint); font-weight: 400; }

.tagline {
  margin: 0;
  color: var(--text-soft);
  font-size: 15px;
  flex: 1 1 320px;
}

/* ------------------------------------------------------------------ intro */

.intro {
  padding-block: 34px 8px;
}

.intro p {
  max-width: 62ch;
  color: var(--text-soft);
  margin: 0 0 14px;
}

.intro strong { color: var(--text); font-weight: 600; }

/* ----------------------------------------------------------------- filter */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding-block: 18px 26px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg) 72%, transparent);
  z-index: 5;
}

.chip {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text-soft);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.chip:hover { color: var(--text); border-color: var(--text-faint); }

.chip[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.lead-count {
  font-size: 14.5px;
}

.lead-count strong { color: var(--text); }

/* ------------------------------------------------------------------ cards */

.category { margin-bottom: 42px; }

.category h2 {
  font-family: var(--sans);
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 4px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.category h2 .count {
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-faint);
}

.category-rule {
  height: 1px;
  background: var(--border);
  margin: 0 0 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 17px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  text-decoration: none;
  color: inherit;
  transition: border-color 130ms, transform 130ms, box-shadow 130ms;
}

.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
  font-family: var(--sans);
  line-height: 1.3;
}

.card p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-soft);
  line-height: 1.5;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.badge {
  text-transform: uppercase;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.07em;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
}

.empty {
  color: var(--text-faint);
  padding: 40px 0;
  text-align: center;
}

/* Shown when the catalogue cannot load -- most often because the page was
   opened from disk instead of through a server. */
.notice {
  max-width: 60ch;
  margin: 30px auto 60px;
  padding: 20px 24px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text-soft);
  font-size: 14.5px;
}

.notice p { margin: 0 0 10px; }
.notice p:last-child { margin-bottom: 0; }
.notice strong { color: var(--text); font-size: 15.5px; }

.notice code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ----------------------------------------------------------------- footer */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 30px;
  padding-block: 26px 44px;
  color: var(--text-faint);
  font-size: 13.5px;
}

.site-footer p { margin: 0 0 6px; }

/* ================================================================ player  */

.player-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.back {
  text-decoration: none;
  color: var(--text-soft);
  font-size: 14px;
  white-space: nowrap;
}

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

.player-title {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls { display: flex; gap: 8px; align-items: center; }

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 6px 15px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { border-color: var(--text-faint); }

.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.status {
  font-size: 12.5px;
  color: var(--text-faint);
  font-family: var(--mono);
  white-space: nowrap;
}

.status.is-error { color: var(--danger); }

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

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  background: var(--border);
  flex: 1;
  min-height: 0;
}

/* Source left, output right. Once the panes stack there is no left and right,
   and putting a few hundred lines of Python above the canvas would mean
   scrolling past the code to see the app run -- so the output goes first. */
@media (max-width: 980px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .pane-output { order: 1; }
  .pane-source { order: 2; }
}

.pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--bg-sunken);
}

.pane-head .hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 12px;
}

/* -- output ------------------------------------------------------------- */

.viewport {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--bg-sunken);
}

#canvas {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  box-shadow: var(--shadow);
  background: #fff;
  outline: none;
  touch-action: none;
}

#canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

#canvas[hidden] { display: none; }

.figures {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  align-items: center;
}

.figures img {
  max-width: 100%;
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.console {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 12px 16px;
  max-height: 34vh;
  overflow: auto;
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-soft);
}

.console:empty { display: none; }

.console .err { color: var(--danger); }

.placeholder {
  color: var(--text-faint);
  font-size: 14px;
  margin: auto;
  text-align: center;
  max-width: 34ch;
  line-height: 1.6;
}

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

.editor-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
}

.cm-editor { height: 100%; font-size: 13px; }
.cm-editor.cm-focused { outline: none; }
.cm-scroller { font-family: var(--mono) !important; line-height: 1.6 !important; }

.source-fallback {
  margin: 0;
  padding: 16px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  overflow: auto;
  height: 100%;
  color: var(--text);
}

.notes {
  border-top: 1px solid var(--border);
  padding: 14px 18px;
  font-size: 13.5px;
  color: var(--text-soft);
  background: var(--bg-sunken);
  max-height: 26vh;
  overflow: auto;
}

.notes:empty { display: none; }

.notes h1, .notes h2, .notes h3 {
  font-size: 14px;
  margin: 0 0 6px;
  color: var(--text);
  font-family: var(--sans);
}

.notes p, .notes ul { margin: 0 0 8px; }
.notes code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-raised);
  padding: 1px 4px;
  border-radius: 3px;
}

.dirty-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  margin-left: 2px;
}
