* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: #111;
  background: white;
  font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 19px;
  line-height: 1.55;
}

body.big { font-size: 23px; }
body.big textarea,
body.big .gutter,
body.big .stdout,
body.big .traceout,
body.big .expect,
body.big .static-code { font-size: 19px; }
body.big textarea,
body.big .gutter { line-height: 26px; }

a { color: #0645ad; }

.layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  min-height: 100vh;
}

.nav {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px 14px;
  border-right: 1px solid #ddd;
}

.nav-head a {
  display: block;
  margin-bottom: 12px;
  color: #111;
  font-weight: 600;
  text-decoration: none;
}

#larger { width: 100%; margin-bottom: 16px; }

#nav-links { display: flex; flex-direction: column; gap: 2px; }

#nav-links a {
  color: #444;
  text-decoration: none;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 4px;
}

#nav-links a.on,
#nav-links a:hover { background: #f0f0f0; color: #111; }

main {
  padding: 36px 48px 120px;
  max-width: 1240px;
}

h1, h2, h3 { font-weight: 600; line-height: 1.2; }
h1 { font-size: 2.4rem; margin: 0 0 12px; }
h2 { font-size: 1.75rem; margin: 0 0 12px; }
h3 { font-size: 1.25rem; margin: 2rem 0 0.5rem; }

section {
  padding: 32px 0 40px;
  border-top: 1px solid #ddd;
  scroll-margin-top: 12px;
}

section:first-child { border-top: 0; padding-top: 0; }

p, ul, ol { max-width: 44rem; }
ul, ol { padding-left: 1.3rem; }
li + li { margin-top: 0.3rem; }

code, .expect, .stdout, .traceout, textarea, .gutter, .static-code, .ide-file {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

code { font-size: 0.9em; }

.disclaimer {
  margin: 16px 0 20px;
  padding: 12px 16px;
  max-width: 44rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.92rem;
}

.disclaimer p { margin: 0 0 8px; }
.disclaimer ul { margin: 0; }

.question {
  margin: 16px 0;
  padding: 12px 16px;
  max-width: 44rem;
  border-left: 4px solid #111;
  background: #f6f6f6;
}

.question strong { margin-right: 4px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin: 16px 0;
  align-items: center;
}

.shape {
  display: grid;
  place-items: center;
  text-align: center;
  width: 180px;
  height: 90px;
  padding: 10px;
  border: 2px solid #111;
  font-size: 0.9rem;
}

.shape.io { border-radius: 999px; }
.shape.dec {
  width: 200px;
  height: 120px;
  border: 0;
  background: #111;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  position: relative;
}
.shape.dec::before {
  content: "";
  position: absolute;
  inset: 3px;
  background: white;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.shape.dec span { position: relative; }

.chart-wrap {
  margin: 12px 0;
  max-width: 760px;
  overflow-x: auto;
}

.flow { width: 100%; height: auto; display: block; }
.flow text { font-family: -apple-system, "Helvetica Neue", Arial, sans-serif; font-size: 16px; fill: #111; }
.flow .tag { font-size: 13px; font-weight: 700; }

table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.95rem;
}

th, td {
  border: 1px solid #ccc;
  padding: 6px 12px;
  text-align: left;
  vertical-align: top;
}

th { background: #f6f6f6; font-weight: 600; }

.static-code, .expect {
  background: #f6f6f6;
  padding: 12px 14px;
  overflow: auto;
  max-width: 44rem;
  font-size: 15px;
  line-height: 1.45;
}

.ide {
  margin: 16px 0;
  max-width: 860px;
  border: 1px solid #bbb;
  border-radius: 6px;
  overflow: hidden;
}

.ide-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  background: #f6f6f6;
  border-bottom: 1px solid #ddd;
}

.ide-file { font-size: 0.85rem; color: #444; }

.ide-actions { display: flex; gap: 6px; }

button {
  font: inherit;
  font-size: 0.88rem;
  border-radius: 4px;
  border: 1px solid #111;
  background: #111;
  color: white;
  padding: 5px 14px;
  cursor: pointer;
}

button.ghost, #larger {
  background: white;
  color: #111;
  border-color: #bbb;
}

button:focus-visible, a:focus-visible, summary:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid #0645ad;
  outline-offset: 2px;
}

.editor {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
}

.gutter, textarea {
  margin: 0;
  border: 0;
  resize: none;
  background: white;
  color: #111;
  font-size: 15px;
  line-height: 22px;
  padding: 12px 8px;
  tab-size: 4;
}

.gutter {
  overflow: hidden;
  text-align: right;
  color: #999;
  user-select: none;
}

textarea { width: 100%; outline: none; }

.in-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-top: 1px solid #ddd;
  font-size: 0.9rem;
}

.in-row input {
  flex: 1;
  font: 15px/1.4 ui-monospace, Menlo, monospace;
  padding: 5px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
}

.stdout, .traceout {
  margin: 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.45;
  border-top: 1px solid #ddd;
}

.stdout { min-height: 2.6rem; background: white; }
.stdout.bad { color: #a00; }
.stdout.quiet { color: #999; }
.traceout { background: #fafafa; max-height: 260px; overflow: auto; }

details { margin: 12px 0; max-width: 50rem; }
summary { cursor: pointer; font-weight: 600; }
details > :not(summary) { margin-top: 8px; }
details[open] { padding-bottom: 4px; }

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 50rem;
}

.two h3 { margin-top: 0.5rem; }

/* ---------- flowchart builder ---------- */

.fb { margin-top: 20px; }

.fb-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid #bbb;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #f6f6f6;
}

.fb-palette, .fb-tools { display: flex; gap: 10px; align-items: center; }

.fb-pal {
  background: white;
  color: #111;
  border: 2px solid #111;
  height: 44px;
  min-width: 120px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.fb-pal.io { border-radius: 999px; }
.fb-pal.op { border-radius: 0; }
.fb-pal.dec {
  border: 0;
  min-width: 130px;
  height: 56px;
  background: #111;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  position: relative;
}
.fb-pal.dec::before {
  content: "";
  position: absolute;
  inset: 2px;
  background: white;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.fb-pal.dec span { position: relative; }

.fb-ghost {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  opacity: 0.7;
}

.fb-tools select, .fc-top select {
  font: inherit;
  font-size: 0.88rem;
  padding: 5px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: white;
}

.fb-main {
  position: relative;
  border: 1px solid #bbb;
}

.fb-canvas {
  display: block;
  width: 100%;
  touch-action: none;
  user-select: none;
}

.fb-below {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border: 1px solid #bbb;
  border-top: 0;
  border-radius: 0 0 6px 6px;
}

.fb-bg { fill: white; }

.fb-shape { fill: white; stroke: #111; stroke-width: 1.8; }
.fb-node { cursor: move; }
.fb-node.sel .fb-shape { stroke: #0645ad; stroke-width: 3; }
.fb-node.cur .fb-shape { fill: #fff3b0; stroke-width: 3; }
.fb-node.err .fb-shape { fill: #fde2e2; stroke: #a00; stroke-width: 3; }
.fb-label { font: 15px -apple-system, "Helvetica Neue", Arial, sans-serif; fill: #111; pointer-events: none; }

.fb-port { fill: #0645ad; opacity: 0; cursor: crosshair; }
.fb-node:hover .fb-port, .fb-node.sel .fb-port { opacity: 0.85; }

.fb-line { fill: none; stroke: #111; stroke-width: 1.8; }
.fb-temp { stroke-dasharray: 5 4; pointer-events: none; }
.fb-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.fb-edge.sel .fb-line { stroke: #0645ad; stroke-width: 3; }
.fb-tag { font: 700 13px -apple-system, "Helvetica Neue", Arial, sans-serif; fill: #111; pointer-events: none; }
.fb-bend { fill: white; stroke: #0645ad; stroke-width: 2; cursor: grab; }

.fb-panel {
  border-right: 1px solid #ddd;
  padding: 12px 14px;
  font-size: 0.88rem;
  background: #fafafa;
}

.fb-panel h4 { margin: 0 0 10px; font-size: 1rem; }
.fb-panel ul { padding-left: 1.1rem; margin: 0 0 12px; }

.fb-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
  font-size: 0.82rem;
  color: #444;
}

.fb-field input, .fb-field select {
  font: 15px/1.4 ui-monospace, Menlo, monospace;
  padding: 5px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: white;
  color: #111;
}

.fb-field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.fb-field.inline input { width: 220px; }

.fb-hint { margin: 4px 0 6px; color: #444; font-size: 0.82rem; }

.fb-inserts { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.fb-inserts button {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
  padding: 3px 7px;
}

.fb-actions { display: flex; gap: 6px; margin: 6px 0 12px; }

.fb-help summary { font-size: 0.85rem; }
.fb-help ul { margin-top: 6px; }
.fb-help li { font-size: 0.8rem; }

.fb-status {
  position: absolute;
  left: 10px;
  bottom: 6px;
  margin: 0;
  color: #a00;
  font-size: 0.9rem;
  pointer-events: none;
}

.fb-run { padding: 12px 14px; min-width: 0; }
.fb-run h4 { margin: 0 0 10px; font-size: 1rem; }
.fb-run .stdout { border: 1px solid #ddd; border-radius: 4px; }

.fb-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: #444;
}

.fb-run-buttons { display: flex; gap: 6px; margin-bottom: 10px; }

.fb-vars { overflow-x: auto; }
.fb-vars table { margin: 10px 0; font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; }

/* ---------- flashcards ---------- */

.fc-top { display: flex; align-items: center; gap: 16px; margin: 12px 0 18px; }
.fc-tabs { display: flex; gap: 0; }
.fc-tabs button { border-radius: 0; }
.fc-tabs button:first-child { border-radius: 4px 0 0 4px; }
.fc-tabs button:last-child { border-radius: 0 4px 4px 0; border-left: 0; }
.fc-tabs button.on { background: #111; color: white; border-color: #111; }

.fc-card {
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  max-width: 640px;
  min-height: 280px;
  padding: 40px 32px;
  background: white;
  color: #111;
  border: 1px solid #bbb;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-size: 1.6rem;
  line-height: 1.35;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.fc-card:active { transform: scale(0.99); }
.fc-card .fc-back-text { display: none; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.fc-card.back .fc-front-text { display: none; }
.fc-card.back .fc-back-text { display: block; }
.fc-card.back { background: #f6f6f6; }

.fc-side {
  position: absolute;
  top: 12px;
  left: 16px;
  font-size: 0.8rem;
  color: #777;
}

.fc-nav { display: flex; align-items: center; gap: 10px; margin-top: 14px; max-width: 640px; }
.fc-count { min-width: 70px; text-align: center; color: #444; }
.fc-nav [data-shuffle] { margin-left: auto; }
.fc-hint { color: #777; font-size: 0.85rem; }

.fc-progress { display: flex; align-items: center; gap: 12px; max-width: 640px; margin-bottom: 18px; }
.fc-bar { flex: 1; height: 10px; background: #eee; border-radius: 99px; overflow: hidden; }
.fc-bar span { display: block; height: 100%; width: 0; background: #111; transition: width 0.2s; }
.fc-progress-text { font-size: 0.9rem; color: #444; white-space: nowrap; }

.fc-quiz, .fc-done { max-width: 640px; }

.fc-prompt {
  padding: 32px 28px;
  border: 1px solid #bbb;
  border-radius: 10px;
  font-size: 1.5rem;
  line-height: 1.35;
  text-align: center;
  margin-bottom: 14px;
}

.fc-entry { display: flex; gap: 8px; }
.fc-answer {
  flex: 1;
  font: 18px/1.4 ui-monospace, Menlo, monospace;
  padding: 8px 10px;
  border: 1px solid #999;
  border-radius: 4px;
}
.fc-answer.shake { animation: fc-shake 0.3s; border-color: #a00; }
@keyframes fc-shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.fc-feedback { min-height: 1.6em; margin: 10px 0; }
.fc-feedback.right { color: #1a6b34; font-weight: 600; }
.fc-feedback.wrong { padding: 10px 14px; border-left: 4px solid #a00; background: #fdf0f0; }
.fc-feedback.wrong div + div { margin-top: 4px; }
.fc-copy-note { color: #444; font-size: 0.9rem; }

.fc-entry-tools { display: flex; gap: 8px; }

@media (max-width: 900px) {
  .fb-below { grid-template-columns: 1fr; }
  .fb-panel { border-right: 0; border-bottom: 1px solid #ddd; }
  .layout { display: block; }
  .nav {
    position: sticky;
    height: auto;
    z-index: 2;
    padding: 10px 12px;
    background: white;
    border-right: 0;
    border-bottom: 1px solid #ddd;
  }
  #nav-links { flex-direction: row; overflow: auto; }
  #nav-links a { white-space: nowrap; }
  #larger { width: auto; margin: 0 0 8px; }
  main { padding: 22px 16px 72px; }
  .two { grid-template-columns: 1fr; }
}
