/* Three widths. Desktop: playgrounds | lesson | code and output. Under 900px: lesson above code, the list a
   drawer that ☰ opens. Under 700px (phones): one pane at a time (Lesson, Code, Output), Run at the bottom. */
[hidden] { display: none !important; }
:root { color-scheme: light dark; --bg: #fff; --fg: #1c1e21; --muted: #6b7280; --line: #e2e5e9; --panel: #f6f7f9; --code: #f1f3f5; --accent: #007d9c; }
@media (prefers-color-scheme: dark) { :root { --bg: #16181c; --fg: #e6e8eb; --muted: #9aa1ab; --line: #2c3037; --panel: #1d2025; --code: #23272d; --accent: #3cc4e4; } }
* { box-sizing: border-box; }
html, body { height: 100%; height: 100dvh; margin: 0; overscroll-behavior: none; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--fg); font: 15px/1.55 system-ui, sans-serif; }
button { font: inherit; padding: 4px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (hover: none) { button:active:not(:disabled) { filter: brightness(.92); } }
header { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
header h1 { font-size: 17px; margin: 0; white-space: nowrap; }
header h1 a { color: inherit; text-decoration: none; }
#crumb { flex: 1; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pill { color: var(--accent); font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
#mtabs { display: none; }
#app { flex: 1; display: grid; grid-template-columns: 240px minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
#app.nav-toggled { grid-template-columns: 0 minmax(0, 1fr) minmax(0, 1fr); }
#app.nav-toggled #nav { visibility: hidden; overflow: hidden; border: 0; padding: 0; }
#nav { display: flex; flex-direction: column; overflow: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 8px 0; }
#nav button { border: 0; border-left: 3px solid transparent; border-radius: 0; background: none; padding: 6px 14px; text-align: left; }
#nav button:hover { background: var(--code); }
#nav button.active { border-left-color: var(--accent); background: var(--code); font-weight: 600; }
#lesson { overflow: auto; padding: 16px 28px 60px; }
#lesson img { max-width: 100%; }
#lesson a { color: var(--accent); }
#lesson pre { background: var(--code); padding: 10px 12px; border-radius: 6px; overflow: auto; }
#lesson :not(pre) > code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: 90%; }
#lesson blockquote { margin: 12px 0; padding: 2px 14px; border-left: 3px solid var(--accent); background: var(--panel); }
#work { display: flex; flex-direction: column; border-left: 1px solid var(--line); min-height: 0; }
#files { display: flex; gap: 2px; padding: 6px 8px 0; background: var(--panel); }
#files button { border-radius: 6px 6px 0 0; border-bottom: 0; }
#files button.active { background: var(--bg); border-color: var(--accent); }
#editor { flex: 1; min-height: 120px; resize: none; border: 0; outline: 0; padding: 10px 12px; background: var(--bg); color: var(--fg); font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; tab-size: 4; white-space: pre; }
#envbar { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 10px; background: #fff4d6; color: #4a3b00; border-top: 1px solid #ecd58a; font-size: 13px; }
@media (prefers-color-scheme: dark) { #envbar { background: #3a3217; color: #f1e3b0; border-color: #5d5124; } }
#bar { display: flex; gap: 8px; align-items: center; padding: 8px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--panel); }
#bar a { color: var(--accent); font-size: 13px; }
#status { color: var(--muted); font-size: 13px; }
#out { flex: 0 0 38%; margin: 0; overflow: auto; padding: 10px 12px; background: var(--code); font: 12.5px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); width: min(560px, 92vw); }
dialog::backdrop { background: #0006; }
#env-text { width: 100%; height: min(240px, 35vh); font: 13px/1.5 ui-monospace, monospace; background: var(--code); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; }
/* The home page (no playground in the URL), laid out like a landing page: a centred column, a
   card per playground, one, two or three across. Each card is one link (.cta::after covers it). */
#home { display: none; flex: 1; overflow: auto; padding: 6vh max(1rem, env(safe-area-inset-right)) 2rem max(1rem, env(safe-area-inset-left)); background: #f9f7f6; color: #2e2d2d; --card: #fff; --cline: #eeebea; --chover: #dad6d5; --text2: #444342; }
@media (prefers-color-scheme: dark) { #home { background: #1b1a19; color: #eeebea; --card: #242322; --cline: #353332; --chover: #57534f; --text2: #cfcbc8; } }
body[data-page="home"] > :not(#home, dialog, script) { display: none; }
body[data-page="home"] #home { display: block; }
#home > * { max-width: 72rem; margin-left: auto; margin-right: auto; }
#home h1 { font-size: 2.5rem; font-weight: 500; letter-spacing: -.035rem; line-height: 1.2; margin-bottom: .5rem; }
#home > p { color: var(--text2); }
#cards { display: grid; grid-template-columns: 1fr; gap: .75rem; margin-top: 1.5rem; }
@media (min-width: 640px) { #cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { #cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { position: relative; display: flex; flex-direction: column; padding: 2rem; border: 1px solid var(--cline); border-radius: 1rem; background: var(--card); box-shadow: 0 0 10px #1f1e1e05; transition: border-color .3s, box-shadow .3s; }
.card:hover, .card:focus-within { border-color: var(--chover); box-shadow: 0 4px 10px #0003; }
.art { display: flex; align-items: center; justify-content: center; aspect-ratio: 3 / 1; margin-bottom: 1rem; border-radius: .5rem; font: 500 1rem ui-monospace, Menlo, Consolas, monospace; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.pill { padding: .5rem; border-radius: .25rem; font-size: .875rem; font-weight: 500; line-height: 1.2; }
.meta { font-size: .875rem; font-weight: 500; color: var(--muted); }
.card h3 { margin: .75rem 0; font-size: 1.375rem; font-weight: 500; line-height: 1.2; }
.card .body { margin: 0 0 1rem; color: var(--text2); }
.foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.cta { font-size: .875rem; font-weight: 500; color: var(--accent); text-decoration: none; }
.cta::after { content: ""; position: absolute; inset: 0; border-radius: 1rem; }
/* The card holding the visitor's one sandbox: outlined, and its Stop sits above the card link. */
.card.live { border-color: var(--accent); }
.foot .end { position: relative; z-index: 1; }
dialog progress { width: 100%; }
[data-tone="1"] { background: #f8e5b9; color: #571f0d; }
[data-tone="2"] { background: #cbf4c9; color: #0b3733; }
[data-tone="3"] { background: #d9e6fb; color: #12284f; }
[data-tone="4"] { background: #f6d6e4; color: #4d1230; }
[data-tone="5"] { background: #e6dcf7; color: #2c1757; }
[data-tone="6"] { background: #d4eef0; color: #0a3d44; }
@media (max-width: 640px) { #home { padding-top: 3vh; } #home h1 { font-size: 2rem; } .card { padding: 1.25rem; } .art { margin-bottom: .75rem; } }
@media (max-width: 900px) {
  #app, #app.nav-toggled { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); position: relative; }
  #nav, #app.nav-toggled #nav { position: absolute; z-index: 4; inset: 0 auto 0 0; width: min(280px, 85vw); box-shadow: 0 0 18px #0004; border-right: 1px solid var(--line); padding: 8px 0; overflow: auto; visibility: hidden; }
  #app.nav-toggled #nav { visibility: visible; }
  #lesson { padding: 12px 14px 40px; }
  #work { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 700px) {
  header { gap: 8px; padding: calc(6px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left)); }
  #pill { display: none; }
  #crumb { font-size: 14px; font-weight: 600; color: var(--fg); }
  button { min-height: 40px; }
  #toggle-nav { min-width: 44px; }
  #mtabs { display: flex; gap: 4px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
  #mtabs button { flex: 1; border-color: transparent; background: none; color: var(--muted); }
  #mtabs button[aria-selected="true"] { background: var(--bg); border-color: var(--line); color: var(--fg); font-weight: 600; }
  #app, #app.nav-toggled { grid-template-rows: minmax(0, 1fr); padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  #lesson, #work { grid-area: 1 / 1; border: 0; }
  body[data-view="lesson"] #work { display: contents; }
  body[data-view="lesson"] #work > :not(#bar), body[data-view="code"] #lesson, body[data-view="code"] #out { display: none; }
  body[data-view="out"] #lesson, body[data-view="out"] #files, body[data-view="out"] #editor { display: none; }
  #out { flex: 1; }
  #out:empty::before { content: "Output shows up here."; color: var(--muted); }
  #bar { position: fixed; inset: auto 0 0 0; z-index: 3; padding: 8px calc(12px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); }
  #bar button { flex: 1; min-height: 44px; font-size: 17px; }
  #run:disabled, #stop:disabled { display: none; }
  #stop { background: #b42318; border-color: #b42318; color: #fff; }
  #status { position: absolute; inset: auto 0 100% 0; padding: 3px 10px; background: var(--panel); border-top: 1px solid var(--line); text-align: center; }
  #status:empty { display: none; }
  dialog { margin: auto 0 0; width: 100%; max-width: none; border-width: 1px 0 0; border-radius: 16px 16px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); animation: sheet .22s ease-out; }
  dialog menu { flex-direction: column; } dialog menu button { min-height: 48px; }
}
@keyframes sheet { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { dialog { animation: none; } }
