:root {
  --ink: #202124;
  --muted: #62676f;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --line: #d9ded8;
  --teal: #0f8f88;
  --teal-dark: #0b615d;
  --red: #c84f3d;
  --yellow: #f5c542;
  --blue: #3459a6;
  --shadow: 0 18px 50px rgba(31, 42, 55, .12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(15, 143, 136, .12), transparent 32%),
    linear-gradient(45deg, transparent 58%, rgba(52, 89, 166, .11)),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.studio-shell {
  width: min(1560px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
p,
figure {
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 2.6vw, 3.1rem);
  line-height: 1.05;
  white-space: nowrap;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.topbar-note {
  border: 1px solid rgba(15, 143, 136, .28);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(255, 255, 255, .7);
  color: var(--teal-dark);
  font-size: .88rem;
  font-weight: 800;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-nav {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tool-nav a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(15, 143, 136, .24);
  border-radius: 999px;
  padding: 8px 15px;
  background: rgba(255, 255, 255, .68);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 860;
  text-decoration: none;
}

.tool-nav a.current {
  border-color: var(--teal);
  background: #e4f5ef;
  color: var(--teal-dark);
}

/* Two columns: controls + preview. Like the Visual Art Lab, the student work
   tray lives in the preview column directly under the canvas, before the course
   notes. The last row absorbs tall tool panels without stretching the canvas. */
.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  align-items: stretch;
}

.workspace > .tools-panel {
  grid-column: 1;
  grid-row: 1 / span 3;
}

.workspace > .canvas-area {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
}

.workspace > #studioFlow {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
}

/* Music Coding gives the left column extra width to hold the code editor. */
.workspace.coding-workspace {
  grid-template-columns: 460px minmax(0, 1fr);
}

.panel,
.canvas-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--shadow);
}

.panel {
  align-self: stretch;
  padding: 16px;
}

.panel-section + .panel-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.panel-section h2 {
  margin-bottom: 10px;
}

.control-label {
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 850;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.control-label:first-of-type {
  margin-top: 4px;
}

.button-row,
.mode-grid {
  display: grid;
  gap: 8px;
}

.button-row {
  grid-template-columns: 1fr 1fr;
}

.button-row.three {
  grid-template-columns: repeat(3, 1fr);
}

.button-row.four {
  grid-template-columns: repeat(4, 1fr);
}

.button-row.five {
  grid-template-columns: repeat(5, 1fr);
}

.mode-grid {
  grid-template-columns: 1fr;
}

.choice-button,
.mode-button,
.secondary-button,
.primary-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 9px 11px;
  font-weight: 850;
  line-height: 1.05;
}

.choice-button,
.mode-button,
.secondary-button {
  border: 1px solid #cbd5d0;
  background: #fbfcf9;
  color: var(--ink);
}

.choice-button.active,
.mode-button.active {
  border-color: var(--teal);
  background: #e4f5ef;
  color: var(--teal-dark);
}

.sliders label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.sliders label span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 800;
}

.sliders output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.actions {
  display: grid;
  gap: 9px;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

.panel-button {
  width: 100%;
  margin-top: 12px;
}

.inline-code,
code.inline-code {
  background: #eef2ee;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--teal-dark);
  font: 700 .85em ui-monospace, Menlo, Consolas, monospace;
}

.secondary-button {
  color: var(--teal-dark);
}

.canvas-area {
  min-width: 0;
}

.canvas-pair {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view-switch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.view-switch-label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 850;
  letter-spacing: .03em;
  text-transform: uppercase;
  margin-right: 2px;
}

.view-button {
  min-height: 40px;
  border: 1px solid #cbd5d0;
  border-radius: 999px;
  padding: 8px 15px;
  background: #fbfcf9;
  color: var(--ink);
  font-weight: 850;
}

.view-button.active {
  border-color: var(--teal);
  background: #e4f5ef;
  color: var(--teal-dark);
}

.canvas-frame {
  display: grid;
  grid-template-rows: auto auto;
  min-height: 0;
  overflow: hidden;
}

.canvas-frame figcaption {
  border-bottom: 1px solid var(--line);
  padding: 11px 13px;
  color: var(--muted);
  font-size: .83rem;
  font-weight: 900;
  text-transform: uppercase;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #fdfdfb;
}

.hero-frame canvas {
  background:
    linear-gradient(90deg, rgba(15, 143, 136, .06), transparent),
    #fdfdfb;
}

.notes-panel {
  display: flex;
  flex-direction: column;
}

/* The "what changed" + course notes sit in a full-width row under the preview.
   Sections flow side by side when there is room. */
.notes-panel.course-notes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px 30px;
  margin-top: 16px;
}

.notes-panel.course-notes .panel-section + .panel-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.notes-panel p {
  color: var(--muted);
  line-height: 1.55;
}

#headline {
  margin-bottom: 12px;
  font-size: 1.15rem;
  color: var(--ink);
}

.change-cards {
  display: grid;
  gap: 10px;
}

.change-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcf9;
}

.change-word {
  margin-bottom: 4px;
  color: var(--teal-dark);
  font-size: .8rem;
  font-weight: 900;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.change-kid {
  color: var(--ink) !important;
  font-weight: 820;
  line-height: 1.4 !important;
}

.change-why {
  margin-top: 6px;
  font-size: .88rem;
}

.change-empty {
  line-height: 1.55;
}

.prompt-list p {
  border-left: 4px solid var(--yellow);
  padding: 8px 0 8px 12px;
  color: var(--ink) !important;
  font-weight: 820;
}

.prompt-list p + p {
  margin-top: 8px;
}

.research-note {
  margin-top: auto;
}

button:disabled,
input:disabled {
  opacity: .45;
  cursor: default;
}

@media (max-width: 820px) {
  .studio-shell {
    width: min(100% - 18px, 760px);
    padding-top: 12px;
  }

  h1 {
    font-size: clamp(1.7rem, 6vw, 2.3rem);
    white-space: normal;
  }

  .topbar {
    display: block;
  }

  .topbar-actions,
  .tool-nav {
    justify-content: flex-start;
  }

  .topbar-note {
    display: inline-block;
    margin-top: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }

  .workspace > .tools-panel,
  .workspace > .canvas-area,
  .workspace > #studioFlow {
    grid-column: auto;
    grid-row: auto;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .button-row.three {
    grid-template-columns: repeat(3, 1fr);
  }

  .button-row.four,
  .button-row.five {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- Music Coding: iPad-safe editor (transparent textarea over a highlighted
   <pre>, the academy's offline editor pattern) ------------------------------ */
.code-shell {
  position: relative;
  height: 300px;
  margin-top: 10px;
  border: 1px solid #cbd5d0;
  border-radius: 8px;
  background: #fbfcf9;
  overflow: hidden;
}

.code-shell:focus-within {
  outline: 2px solid var(--teal);
  outline-offset: -1px;
}

.code-text {
  margin: 0;
  padding: 12px;
  font: 600 14px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre;
  tab-size: 2;
}

.code-highlight {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: var(--ink);
}

.code-highlight code {
  font: inherit;
  white-space: inherit;
}

.code-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--ink);
  resize: none;
  overflow: auto;
  outline: none;
}

.code-input::selection {
  background: rgba(15, 143, 136, .22);
}

.tok-comment { color: #79806f; font-style: italic; }
.tok-string { color: #0f8f88; }
.tok-keyword { color: #3459a6; font-weight: 800; }
.tok-number { color: #c84f3d; }
.tok-builtin { color: #5c4db1; font-weight: 750; }
.tok-call { color: #8a5a00; }

.code-status {
  margin-top: 10px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .86rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: pre-wrap;
}

.code-status.ok { background: #e4f5ef; color: var(--teal-dark); }
.code-status.err { background: #faeae6; color: #8c3628; }

.contract-line {
  margin-top: 10px;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.6;
}

.contract-line code {
  background: #eef2ee;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--teal-dark);
  font: 700 .82rem ui-monospace, Menlo, Consolas, monospace;
}

.sidebar-import {
  margin-top: 10px;
}

.sidebar-import-card {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.sidebar-import-message {
  min-height: 0;
  margin: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
  line-height: 1.45;
}

.sidebar-import-message.ok:not(:empty) {
  padding: 8px 9px;
  background: #e4f5ef;
  color: var(--teal-dark);
}

.sidebar-import-message.err:not(:empty) {
  padding: 8px 9px;
  background: #faeae6;
  color: #8c3628;
}

.preset-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* --- Music Paint ----------------------------------------------------------- */
#paintCanvas {
  width: auto;
  max-width: none;
  cursor: crosshair;
  transform-origin: left top;
  touch-action: none;
}

.paint-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  background: #fdfdfb;
}

.paint-scroll canvas {
  min-width: 100%;
}

.mood-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.mood-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(32, 33, 36, .12);
}

/* A view switch that sits between stacked canvas frames. */
.canvas-pair .view-switch {
  margin: 2px 0 0;
}

.paint-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 750;
  line-height: 1.5;
}

/* --- Music Lego ------------------------------------------------------------ */
.lego-palette {
  display: grid;
  gap: 8px;
}

.lego-block {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 2px 9px;
  min-height: 58px;
  border: 1px solid #cbd5d0;
  border-radius: 8px;
  padding: 8px 9px;
  background: #fbfcf9;
  color: var(--ink);
  text-align: left;
}

.lego-block span {
  grid-row: 1 / span 2;
  align-self: center;
  justify-self: center;
  min-width: 36px;
  border-radius: 6px;
  padding: 6px 5px;
  background: #e4f5ef;
  color: var(--teal-dark);
  font-size: .72rem;
  font-weight: 950;
  text-align: center;
  text-transform: uppercase;
}

.lego-block strong {
  font-size: .92rem;
  line-height: 1.1;
}

.lego-block small {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.25;
}

.lego-board {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.lego-source {
  color: var(--muted);
  font-size: .83rem;
  font-weight: 900;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.lego-chain {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, .72);
}

.lego-empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.lego-chain-block {
  flex: 0 0 150px;
  display: grid;
  gap: 7px;
  border: 1px solid rgba(15, 143, 136, .28);
  border-radius: 8px;
  padding: 10px;
  background: #e4f5ef;
}

.lego-chain-block strong {
  color: var(--teal-dark);
  font-size: .98rem;
  line-height: 1.15;
}

.lego-chain-block span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 950;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.lego-chain-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.lego-chain-actions button {
  min-height: 30px;
  border: 1px solid rgba(15, 143, 136, .24);
  border-radius: 6px;
  background: #fff;
  color: var(--teal-dark);
  font-weight: 900;
}

/* --- Image Music ----------------------------------------------------------- */
.upload-control {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  border: 1px dashed #b8c5be;
  border-radius: 8px;
  padding: 10px;
  background: #fbfcf9;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 800;
}

.upload-control input {
  width: 100%;
  color: var(--muted);
  font-size: .82rem;
}

.upload-status {
  min-height: 1rem;
  color: var(--teal-dark);
  font-size: .78rem;
  font-weight: 900;
}

.manual-editor {
  width: 100%;
  min-height: 116px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
  font: 800 .9rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.range-label {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.range-label input,
.range-label select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
  font: 900 .95rem/1.2 Inter, system-ui, sans-serif;
}

.score-preview {
  min-height: 360px;
  background: #fdfdfb;
}

.score-preview canvas {
  display: block;
  width: 100%;
  height: auto;
}

.score-pdf {
  display: block;
  width: 100%;
  min-height: 620px;
  border: 0;
  background: #fff;
}

.model-list {
  display: grid;
  gap: 8px;
}

.model-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 2px 9px;
  min-height: 62px;
  border: 1px solid #cbd5d0;
  border-radius: 8px;
  padding: 8px 9px;
  background: #fbfcf9;
  color: var(--ink);
  text-align: left;
}

.model-button.active {
  border-color: var(--teal);
  background: #e4f5ef;
}

.model-button span {
  grid-row: 1 / span 2;
  align-self: center;
  justify-self: center;
  min-width: 36px;
  border-radius: 6px;
  padding: 6px 5px;
  background: #eef2ee;
  color: var(--teal-dark);
  font-size: .72rem;
  font-weight: 950;
  text-align: center;
  text-transform: uppercase;
}

.model-button strong {
  font-size: .92rem;
  line-height: 1.1;
}

.model-button small {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.25;
}

.mix-list {
  display: grid;
  gap: 8px;
}

.mix-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid #cbd5d0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcf9;
  color: var(--ink);
  font-weight: 850;
}

.mix-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.mix-check.disabled {
  opacity: .58;
}

.mix-check.disabled span {
  color: var(--muted);
}

.tray-layer-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  border-radius: 8px;
  padding: 9px 10px;
  background: #eef2ee;
  color: var(--teal-dark);
  font-size: .82rem;
  font-weight: 850;
  line-height: 1.35;
}

.tray-layer-pill span {
  min-width: 0;
}

.tray-layer-pill button {
  flex: 0 0 auto;
  min-height: 30px;
  border: 1px solid rgba(15, 143, 136, .28);
  border-radius: 8px;
  padding: 5px 9px;
  background: #fff;
  color: var(--teal-dark);
  font-size: .76rem;
  font-weight: 900;
}

/* --- Student work tray ----------------------------------------------------- */
.studio-flow {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--shadow);
}

.flow-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.flow-head h2 {
  font-size: 1.2rem;
}

.flow-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.flow-import-input {
  display: none;
}

.flow-message {
  margin-bottom: 12px;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: .88rem;
  font-weight: 800;
}

.flow-message.ok {
  background: #e4f5ef;
  color: var(--teal-dark);
}

.flow-message.err {
  background: #faeae6;
  color: #8c3628;
}

.flow-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.flow-empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.flow-thumb {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
}

.flow-thumb img,
.flow-blank {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 7;
  background: #fdfdfb;
  object-fit: cover;
}

.flow-blank {
  display: grid;
  place-items: center;
  color: var(--teal-dark);
  font-weight: 900;
}

.flow-thumb figcaption {
  display: grid;
  gap: 3px;
  border-top: 1px solid var(--line);
  padding: 9px 10px;
}

.flow-thumb figcaption strong {
  color: var(--ink);
  font-size: .92rem;
  line-height: 1.25;
}

.flow-thumb figcaption span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
}

.flow-thumb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 10px 10px;
}

.flow-thumb-actions button {
  min-height: 34px;
  border: 1px solid #cbd5d0;
  border-radius: 8px;
  padding: 6px 9px;
  background: #fff;
  color: var(--teal-dark);
  font-size: .78rem;
  font-weight: 850;
}
