:root {
  color-scheme: light;
  --ink: #182724;
  --muted: #66736f;
  --line: #d9ddd7;
  --blue: #0072b2;
  --blue-dark: #005a8c;
  --soft: #f4f5f3;
  --focus: #0072b2;
}

* { box-sizing: border-box; }
html, body { margin: 0; color: var(--ink); background: #fff; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
.site-header { min-height: 62px; padding: 8px clamp(20px, 5vw, 72px); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid rgba(24, 39, 36, 0.1); }
.course-title { display: flex; flex-direction: column; color: var(--ink); font-size: 1.05rem; font-weight: 750; line-height: 1.05; text-decoration: none; }
.course-title small { margin-top: 4px; color: var(--muted); font-size: 0.68rem; font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-link { padding: 8px 12px; color: var(--ink); background: #e5e7eb; border-radius: 7px; font-size: 0.8rem; font-weight: 700; line-height: 1; text-decoration: none; }
.top-link:hover { background: #d1d5db; }

main { width: min(1280px, calc(100% - 28px)); margin: 0 auto; padding: 14px 0 8px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
.demo-qr { flex: 0 0 auto; line-height: 0; }
.demo-qr img { width: 88px; height: 88px; display: block; }
h1 { margin: 0; font: 500 clamp(2rem, 3.6vw, 3.5rem)/0.98 Georgia, "Times New Roman", serif; letter-spacing: -0.045em; }
.intro p { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; }
.equations { margin-top: 12px; padding: 10px 14px; display: grid; grid-template-columns: 1.08fr 1fr 1fr; gap: 16px; align-items: center; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; font-size: 0.83rem; overflow-x: auto; }
.equations > div { min-width: max-content; text-align: center; }

.controls { margin-top: 8px; padding: 8px 12px; display: grid; grid-template-columns: auto auto auto auto auto minmax(220px, 1fr); gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; }
button, .image-upload { min-height: 36px; padding: 0 14px; display: grid; place-items: center; color: #fff; background: var(--blue); border: 0; border-radius: 6px; font: inherit; font-size: 0.76rem; font-weight: 750; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled), .image-upload:hover { background: var(--blue-dark); }
button:disabled { cursor: default; opacity: 0.45; }
.secondary-button { color: var(--ink); background: #e5e7eb; }
.secondary-button:hover:not(:disabled) { background: #d1d5db; }
.image-upload input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.runtime-status { min-width: 0; color: var(--muted); font-size: 0.69rem; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runtime-status.is-error { color: #9c2f00; }

.workspace { height: clamp(420px, calc(100vh - 344px), 580px); margin-top: 8px; display: grid; grid-template-columns: minmax(330px, 0.74fr) minmax(0, 1.26fr); gap: 8px; }
.code-card, .image-card { min-width: 0; min-height: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.code-card { padding: 10px; display: flex; flex-direction: column; }
.card-heading { min-height: 28px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-heading h2, .image-card h2 { margin: 0; font: 500 1rem Georgia, "Times New Roman", serif; }
.card-heading span { color: var(--muted); font-size: 0.65rem; }
textarea { width: 100%; flex: 1; min-height: 0; padding: 10px; resize: none; color: #dfe7e4; background: #17211f; border: 0; border-radius: 5px; font: 500 0.72rem/1.42 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; }
.image-workspace { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.prediction-question { margin: 0; padding: 7px 10px; color: var(--ink); background: #edf5f9; border: 1px solid #b5cbd7; border-radius: 7px; font-size: 0.72rem; }
.image-grid { min-width: 0; min-height: 0; flex: 1; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 8px; }
.image-card { padding: 8px; display: flex; flex-direction: column; }
.image-card h2 { min-height: 24px; }
.result-card { border-color: #b5cbd7; }
.image-button { width: 100%; flex: 1; min-height: 0; padding: 0; overflow: hidden; color: inherit; background: var(--soft); border-radius: 0; cursor: zoom-in; }
.image-button:hover:not(:disabled) { background: var(--soft); box-shadow: inset 0 0 0 3px var(--blue); }
.image-button:disabled { opacity: 1; cursor: default; }
canvas { width: 100%; height: 100%; min-height: 0; display: block; background: var(--soft); object-fit: contain; }
.metrics { min-height: 30px; padding: 7px 12px 0; display: flex; justify-content: flex-end; gap: 24px; color: var(--muted); font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.site-footer { padding: 0 20px 8px; color: var(--muted); font-size: 0.7rem; text-align: center; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.image-lightbox[hidden] { display: none; }
.image-lightbox { position: fixed; z-index: 20; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; place-items: center; padding: 22px; color: #fff; background: rgba(8, 15, 14, 0.96); }
.image-lightbox h2 { margin: 0 64px 12px; font: 500 clamp(1.2rem, 3vw, 2rem) Georgia, "Times New Roman", serif; }
.image-lightbox canvas { max-width: 100%; max-height: 100%; background: transparent; object-fit: contain; }
.image-lightbox p { margin: 12px 0 0; color: #b8c3c0; font-size: 0.75rem; }
.close-lightbox { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); width: 46px; height: 46px; padding: 0; color: #fff; background: rgba(255, 255, 255, 0.14); border: 1px solid rgba(255, 255, 255, 0.24); border-radius: 50%; font-size: 2rem; line-height: 1; }
body.lightbox-open { overflow: hidden; }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; gap: 8px; }
  .top-actions { width: 100%; }
  .top-link { flex: 1; text-align: center; }
  main { width: calc(100% - 12px); padding-top: 8px; }
  .intro { align-items: flex-start; }
  .demo-qr img { width: 64px; height: 64px; }
  h1 { font-size: 1.9rem; }
  .intro p { font-size: 0.7rem; }
  .equations { margin-top: 8px; padding: 8px; display: block; overflow: visible; font-size: 0.7rem; }
  .equations > div { min-width: 0; margin: 4px 0; overflow-x: auto; text-align: left; }
  .controls { padding: 6px; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  button, .image-upload { min-height: 34px; padding: 0 8px; font-size: 0.66rem; }
  #restore-button { grid-column: 1 / 3; }
  .runtime-status { grid-column: 1 / 4; text-align: left; }
  .workspace { height: auto; grid-template-columns: 1fr; grid-template-rows: 190px 600px; gap: 6px; }
  .code-card { padding: 5px; }
  .card-heading { min-height: 22px; }
  .card-heading h2, .image-card h2 { font-size: 0.76rem; }
  .card-heading span { display: none; }
  textarea { padding: 6px; font-size: 0.64rem; line-height: 1.35; }
  .image-grid { gap: 5px; }
  .prediction-question { padding: 6px 8px; font-size: 0.66rem; }
  .image-card { padding: 4px; }
  .image-card h2 { min-height: 18px; }
  .metrics { min-height: 24px; padding: 5px 4px 0; flex-wrap: wrap; justify-content: space-between; gap: 4px; font-size: 0.64rem; }
  #outcome-note { order: 3; flex-basis: 100%; }
  .image-lightbox { padding: 10px; }
}

@media (max-width: 390px) {
  .controls { grid-template-columns: 1fr 1fr; }
  #restore-button { grid-column: 1 / 3; }
  .runtime-status { grid-column: 1 / 3; }
}
