/* codelab: the page (view/page.js). A solid look: square corners, plain fills,
   dark rules; the colours are the custom properties below, which widgets,
   checks and parts use too. Touch targets are at least 44 px, and text inputs
   at least 16 px on touch devices, as iOS zooms into anything smaller
   (design.md 2, engine.md Code input). */
:root {
  --fg: #111; --muted: #595959; --line: #c4c4c4; --rule: #111; --bg: #fff; --soft: #f1f1f1;
  --accent: #0047c2; --ok: #00703c; --ng: #c8102e; --on-strong: #fff;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 17px; color: var(--fg); background: var(--bg); line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --fg: #f2f2f2; --muted: #a6a6a6; --line: #4a4a4a; --rule: #f2f2f2; --bg: #121212; --soft: #1f1f1f;
          --accent: #7aa2ff; --ok: #2fbf71; --ng: #ff5c6c; --on-strong: #121212; }
}
/* A tablet and up: a little larger, with room around. */
@media (min-width: 700px) {
  :root { font-size: 18px; }
}
body { margin: 0; }
main { max-width: 46rem; margin: 0 auto; padding: 0 1rem 2rem; }
@media (min-width: 700px) {
  main { padding: 0 2rem 3rem; }
}
pre, code, textarea, input { font-family: var(--mono); }

/* ---- the activity: title, where the student is, the parts ---------------- */
.activity-head {
  display: flex; align-items: baseline; gap: 1rem; padding: 1rem 0 0.5rem;
  border-bottom: 3px solid var(--rule);
}
.activity-title { font-size: 1.2rem; font-weight: 800; margin: 0; flex: 1; letter-spacing: 0.02em; }
.activity-progress { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.activity-meter { height: 6px; background: var(--soft); }
.activity-meter > span { display: block; height: 100%; width: 0; background: var(--fg); transition: width 0.3s; }
.activity-parts { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding-top: 0.75rem; }
.activity-parts:empty { display: none; }

/* ---- an item ------------------------------------------------------------- */
.item { display: grid; gap: 1rem; padding: 1.25rem 0; }
/* A grid item is as wide as its content by default: a long line of code
   would widen the page instead of scrolling in its own box. */
.item > * { min-width: 0; }
.item-ask { font-size: 1.05rem; }
.item-ask > :first-child { margin-top: 0; }
.item-ask > :last-child { margin-bottom: 0; }
.item-ask code { background: var(--soft); border: 1px solid var(--line); padding: 0 0.3em; font-size: 0.95em; }
.item-ask pre { background: var(--soft); border-left: 4px solid var(--rule); padding: 0.5rem 0.75rem; overflow-x: auto; }
.item-ask pre code { background: none; border: 0; padding: 0; }
.item-template {
  background: var(--soft); border-left: 4px solid var(--rule); padding: 0.75rem 1rem;
  overflow-x: auto; margin: 0; font-size: 1rem; line-height: 1.6;
}
/* Room for the inputs in the lines of code. */
.item-template:has(.slot) { line-height: 2.4; }
@media (max-width: 599px) {
  .item-template { font-size: 0.92rem; padding: 0.6rem 0.75rem; }
}
.input-label { font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; }

.in-line, .in-area {
  box-sizing: border-box; font-size: 1rem; color: inherit; background: var(--bg);
  border: 2px solid var(--rule); padding: 0.35rem 0.5rem;
}
.in-line { max-width: 100%; min-height: 44px; }
.in-area { width: 100%; resize: vertical; tab-size: 4; }
[aria-invalid] { border-color: var(--ng); outline: 2px solid var(--ng); }

/* ---- buttons ------------------------------------------------------------- */
.item-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.item-actions button {
  min-height: 48px; min-width: 48px; padding: 0 1.5rem; font: inherit; font-weight: 700;
  border: 2px solid var(--rule); background: var(--bg); color: var(--fg); cursor: pointer;
}
.item-actions button.answer, .item-actions button.run { background: var(--fg); color: var(--on-strong); }
@media (hover: hover) {
  .item-actions button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent); color: #fff; }
}
.item-actions button:disabled { opacity: 0.4; cursor: default; }
/* A phone: the main button takes the width, under the thumb. */
@media (max-width: 599px) {
  .item-actions button.answer, .item-actions button.run { flex: 1 1 auto; }
}
.item-actions button:focus-visible, .item input:focus-visible, .item textarea:focus-visible,
.item [tabindex]:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ---- what happened: colour, symbol and text together (design 5) ---------- */
.item-feedback:empty { display: none; }
.item-feedback { margin: 0; padding: 0.6rem 0.9rem; font-weight: 800; font-size: 1.05rem; }
/* Scoped: a widget's own .ok or .ng must not take these colours. */
.item-feedback.ok { background: var(--ok); color: #fff; }
.item-feedback.ng, .item-feedback.fail { background: var(--ng); color: #fff; }
.item-feedback.hint { background: var(--soft); color: var(--fg); border-left: 6px solid var(--accent); font-weight: 700; }
.item-feedback:not(.ok):not(.ng):not(.fail):not(.hint) { background: var(--soft); border-left: 6px solid var(--rule); }

.out-text {
  background: var(--soft); border-left: 4px solid var(--muted); padding: 0.6rem 0.9rem; margin: 0;
  min-height: 1.7em; white-space: pre-wrap; word-break: break-all;
}
.out-text:empty { display: none; }
.out-error { color: var(--ng); font-weight: 700; white-space: pre-wrap; }

/* The input line of a program that waits for input (view/page.js). */
.item-console { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.item-console[hidden] { display: none; }
.item-console .console-line {
  flex: 1; min-width: 0; min-height: 48px; box-sizing: border-box; font-size: max(16px, 1rem);
  font-family: var(--mono); color: inherit; background: var(--bg);
  border: 2px solid var(--accent); padding: 0.25rem 0.5rem;
}
.item-console .console-end {
  min-height: 48px; padding: 0 0.9rem; font: inherit; font-weight: 700;
  border: 2px solid var(--rule); background: var(--bg); color: var(--fg); cursor: pointer;
}

/* ---- the end ------------------------------------------------------------- */
.activity-summary h2 { font-size: 1.2rem; margin: 1.25rem 0 0.5rem; }
.activity-summary ol { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--rule); }
.activity-summary li { padding: 0.6rem 0.25rem; border-bottom: 1px solid var(--line); font-weight: 700; }
.activity-summary li.ok { color: var(--ok); }
.activity-summary li.ng { color: var(--ng); }
.activity-summary li.none { color: var(--muted); }
.load-error { white-space: pre-wrap; color: var(--ng); }

@media (pointer: coarse) {
  .in-line, .in-area { font-size: max(16px, 1rem); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
