:root {
  --canvas: #f6f5ef;
  --paper: #fffefa;
  --paper-soft: #f1f5ed;
  --mist: #e8f0f2;
  --ink: #171f1b;
  --muted: #68746d;
  --line: #d9ddd2;
  --line-strong: #bcc7ba;
  --primary: #4e7f69;
  --primary-dark: #315f50;
  --aqua: #5a98a2;
  --clay: #bf7561;
  --gold: #b59642;
  --violet: #796fa6;
  --shadow: 0 18px 46px rgba(37, 44, 38, 0.09);
  --shadow-tight: 0 10px 24px rgba(37, 44, 38, 0.08);
  --neutral: #7c8580;
  --red: #c85f6b;
  --orange: #cb7656;
  --yellow: #c5a245;
  --green: #63966b;
  --teal: #4f907f;
  --blue: #5f82bd;
  --purple: #8370ad;
  --pink: #bd6f95;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
.tool-button {
  align-items: center;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  height: 42px;
  justify-content: center;
  min-width: 42px;
  padding: 0 12px;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.tool-button:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button:disabled,
.tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button svg,
.tool-button svg {
  fill: none;
  height: 20px;
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 20px;
}

.tool-button.subtle,
button.subtle {
  background: rgba(255, 254, 250, 0.82);
  border-color: var(--line);
  color: var(--ink);
}

.tool-button.subtle:hover,
button.subtle:hover {
  background: #fff;
  border-color: var(--line-strong);
}

.tool-button.danger,
button.danger {
  background: #fff9f7;
  border-color: #e7beb6;
  color: #a9514b;
}

.tool-button.danger:hover,
button.danger:hover {
  background: #fff0ec;
  border-color: #dba89d;
}

.tool-button.mini {
  height: 32px;
  min-width: 32px;
  padding: 0;
}

.tool-button.wide {
  width: 100%;
}

.play-launch {
  background: #1f5f50;
  border-color: #1f5f50;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 16px 34px rgba(31, 95, 80, 0.28);
  color: #fff;
  gap: 9px;
  min-width: 132px;
  padding: 0 18px;
  position: fixed;
  right: 22px;
  z-index: 40;
}

.play-launch:hover {
  background: #174a3e;
  border-color: #174a3e;
}

.play-launch span {
  font-weight: 780;
}

input,
textarea {
  background: rgba(255, 254, 250, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  outline: none;
  width: 100%;
}

input {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  line-height: 1.6;
  min-height: 220px;
  padding: 14px;
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus-visible,
.tool-button:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(78, 127, 105, 0.16);
}

.study-app {
  min-height: 100vh;
}

.album-rail {
  align-items: center;
  background: rgba(255, 254, 250, 0.88);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 16px;
  grid-template-columns: 230px minmax(220px, 300px) minmax(0, 1fr);
  min-width: 0;
  padding: 14px 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-block {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 44px minmax(0, 1fr);
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: #21352e;
  border-radius: 8px;
  color: #fbfcf7;
  display: inline-flex;
  font-size: 21px;
  font-weight: 820;
  height: 44px;
  justify-content: center;
  width: 44px;
}

.brand-block h1,
.context-strip h2,
.section-head h3,
.lesson-ribbon h3 {
  letter-spacing: 0;
  margin: 0;
}

.brand-block h1 {
  font-size: 20px;
  line-height: 1.12;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  margin: 0 0 5px;
  text-transform: uppercase;
}

.album-create {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
}

.album-list {
  display: grid;
  gap: 10px;
  grid-auto-columns: minmax(190px, 240px);
  grid-auto-flow: column;
  min-width: 0;
  overflow-x: auto;
  padding: 4px 2px;
}

.album-card {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 10px;
  grid-template-columns: 10px minmax(0, 1fr);
  height: 58px;
  justify-content: initial;
  min-width: 0;
  padding: 8px;
  text-align: left;
}

.album-card:hover {
  background: rgba(241, 245, 237, 0.78);
  border-color: var(--line);
}

.album-card.active {
  background: #fff;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-tight);
}

.album-swatch {
  align-self: stretch;
  border-radius: 999px;
  display: block;
}

.album-copy {
  min-width: 0;
}

.album-title,
.unit-title {
  display: block;
  font-weight: 780;
  overflow-wrap: anywhere;
}

.album-title,
.frame-tab strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.album-meta,
.unit-meta,
.frame-tab span,
.asset-footer span {
  color: var(--muted);
  font-size: 13px;
}

.studio {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 18px 22px 96px;
}

.context-strip {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  min-width: 0;
}

.context-strip h2 {
  font-size: clamp(22px, 2vw, 34px);
  overflow-wrap: anywhere;
}

.header-actions,
.row-actions,
.frame-nav-actions,
.split-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.header-actions,
.row-actions {
  flex-wrap: wrap;
}

.workspace-grid {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
}

.map-column {
  min-width: 0;
  position: sticky;
  top: 92px;
}

.section-head,
.lesson-ribbon {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h3,
.lesson-ribbon h3 {
  font-size: 18px;
}

.unit-tree {
  display: grid;
  gap: 8px;
}

.unit-node {
  border-left: 3px solid var(--blue);
  padding-left: calc(8px + var(--depth) * 14px);
}

.unit-line {
  align-items: start;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(0, 1fr);
}

.unit-select {
  align-items: center;
  background: rgba(255, 254, 250, 0.62);
  border: 1px solid transparent;
  color: var(--ink);
  display: grid;
  gap: 10px;
  grid-template-columns: 34px minmax(0, 1fr);
  height: auto;
  justify-content: initial;
  min-height: 52px;
  padding: 8px;
  text-align: left;
  width: 100%;
}

.unit-select:hover {
  background: rgba(255, 254, 250, 0.92);
  border-color: var(--line);
}

.unit-node.active .unit-select {
  background: #fff;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-tight);
}

.unit-icon {
  align-items: center;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary-dark);
  display: inline-flex;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.unit-icon svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.row-actions {
  padding-left: 12px;
}

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

.lesson-ribbon {
  background: rgba(255, 254, 250, 0.64);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.lesson-title {
  min-width: 0;
}

.lesson-title h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.frame-strip {
  display: grid;
  gap: 10px;
  grid-auto-columns: minmax(150px, 190px);
  grid-auto-flow: column;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.frame-tab {
  align-items: center;
  background: rgba(255, 254, 250, 0.68);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--teal);
  color: var(--ink);
  display: grid;
  gap: 10px;
  grid-template-columns: 30px minmax(0, 1fr);
  height: auto;
  justify-content: initial;
  min-height: 66px;
  padding: 10px;
  text-align: left;
}

.frame-tab:hover {
  background: #fff;
  border-color: var(--line-strong);
}

.frame-tab.active {
  background: #fff;
  border-color: var(--line-strong);
  border-bottom-color: var(--primary);
  box-shadow: var(--shadow-tight);
}

.frame-index {
  align-items: center;
  background: var(--paper-soft);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: 13px;
  font-weight: 780;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.frame-tab-copy {
  min-width: 0;
}

.frame-tab strong {
  display: block;
}

.editor {
  min-width: 0;
}

.focus-editor {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 36%);
  align-items: start;
}

.media-board,
.workbench {
  min-width: 0;
}

.media-board {
  display: grid;
  gap: 12px;
}

.frame-toolbar {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.frame-title-input {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  font-size: clamp(22px, 2vw, 34px);
  font-weight: 780;
  min-height: 48px;
  padding: 0;
}

.frame-title-input:focus {
  border-bottom-color: var(--primary);
  box-shadow: none;
}

.stage-media {
  align-items: center;
  background: #111714;
  border: 1px solid #202b25;
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: copy;
  display: flex;
  justify-content: center;
  min-height: clamp(360px, 54vh, 680px);
  overflow: hidden;
}

.stage-media:hover,
.stage-media:focus {
  border-color: #9ab9a8;
  box-shadow: 0 0 0 4px rgba(154, 185, 168, 0.18), var(--shadow);
}

.stage-image {
  display: block;
  height: auto;
  max-height: min(72vh, 760px);
  max-width: 100%;
  object-fit: contain;
  width: auto;
}

.stage-empty {
  color: #ccd6d0;
  padding: 24px;
  text-align: center;
}

.thumbnail-strip {
  display: grid;
  gap: 10px;
  grid-auto-columns: 112px;
  grid-auto-flow: column;
  overflow-x: auto;
}

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

.image-thumb.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 127, 105, 0.14);
}

.image-thumb button:first-child {
  background: #fff;
  border: 0;
  border-radius: 0;
  display: block;
  height: 76px;
  min-height: 76px;
  padding: 0;
  width: 100%;
}

.image-thumb img {
  display: block;
  height: 76px;
  object-fit: cover;
  width: 100%;
}

.thumb-delete {
  background: #fff;
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--line);
  color: #a64d48;
  height: 32px;
  width: 100%;
}

.thumb-delete svg {
  height: 16px;
  width: 16px;
}

.thumb-upload {
  background: rgba(255, 254, 250, 0.78);
  border: 1px dashed var(--line-strong);
  color: var(--ink);
  min-height: 108px;
}

.thumb-upload:hover {
  background: #fff;
}

.workbench {
  display: grid;
  gap: 12px;
}

.tone-tools,
.audio-tools,
.note-grid {
  background: rgba(255, 254, 250, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-tight);
  padding: 12px;
}

.field-stack {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 780;
}

.split-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.asset-list {
  display: grid;
  gap: 10px;
}

.audio-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 8px;
}

.audio-row audio {
  width: 100%;
}

.asset-footer {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 0;
}

.asset-footer span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-grid {
  align-items: stretch;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.markdown-preview {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.65;
  min-height: 180px;
  overflow-wrap: anywhere;
  padding: 14px;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  letter-spacing: 0;
  margin: 0.4em 0;
}

.markdown-preview p {
  margin: 0 0 0.8em;
}

.markdown-preview code {
  background: #edf2ef;
  border-radius: 4px;
  padding: 1px 4px;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.swatch {
  border: 2px solid transparent;
  border-radius: 999px;
  height: 27px;
  min-height: 27px;
  min-width: 27px;
  padding: 0;
  width: 27px;
}

.swatch.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(23, 33, 29, 0.16);
}

.empty-state {
  align-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 160px;
  padding: 22px;
  text-align: center;
}

.empty-state.small {
  min-height: 90px;
}

.empty-state.compact {
  min-height: 74px;
  padding: 12px;
}

.hidden-input {
  display: none;
}

.auth-gate {
  align-items: center;
  background: rgba(246, 245, 239, 0.94);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 100;
}

.auth-card {
  background: rgba(255, 254, 250, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 380px;
  padding: 20px;
  width: 100%;
}

.auth-card h2 {
  font-size: 26px;
  letter-spacing: 0;
  margin: 0;
}

.auth-card label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 760;
  gap: 7px;
}

.auth-message {
  background: #fff0ec;
  border: 1px solid #e7beb6;
  border-radius: 8px;
  color: #9e4b46;
  padding: 10px 12px;
}

.auth-switch {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.auth-switch:hover {
  background: var(--paper-soft);
  border-color: var(--line-strong);
}

.color-neutral {
  border-left-color: var(--neutral);
  border-bottom-color: var(--neutral);
}

.color-red {
  border-left-color: var(--red);
  border-bottom-color: var(--red);
}

.color-orange {
  border-left-color: var(--orange);
  border-bottom-color: var(--orange);
}

.color-yellow {
  border-left-color: var(--yellow);
  border-bottom-color: var(--yellow);
}

.color-green {
  border-left-color: var(--green);
  border-bottom-color: var(--green);
}

.color-teal {
  border-left-color: var(--teal);
  border-bottom-color: var(--teal);
}

.color-blue {
  border-left-color: var(--blue);
  border-bottom-color: var(--blue);
}

.color-purple {
  border-left-color: var(--purple);
  border-bottom-color: var(--purple);
}

.color-pink {
  border-left-color: var(--pink);
  border-bottom-color: var(--pink);
}

[data-bg="neutral"] {
  background: var(--neutral);
}

[data-bg="red"] {
  background: var(--red);
}

[data-bg="orange"] {
  background: var(--orange);
}

[data-bg="yellow"] {
  background: var(--yellow);
}

[data-bg="green"] {
  background: var(--green);
}

[data-bg="teal"] {
  background: var(--teal);
}

[data-bg="blue"] {
  background: var(--blue);
}

[data-bg="purple"] {
  background: var(--purple);
}

[data-bg="pink"] {
  background: var(--pink);
}

@media (max-width: 1180px) {
  .album-rail {
    grid-template-columns: 220px minmax(210px, 280px) minmax(0, 1fr);
  }

  .workspace-grid,
  .focus-editor {
    grid-template-columns: 1fr;
  }

  .map-column {
    position: static;
  }

  .unit-tree {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 860px) {
  .album-rail {
    align-items: stretch;
    grid-template-columns: 1fr;
    padding: 14px;
    position: static;
  }

  .brand-block {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .brand-mark {
    height: 40px;
    width: 40px;
  }

  .album-list {
    grid-auto-columns: minmax(210px, 76vw);
  }

  .studio {
    padding: 14px;
  }

  .context-strip {
    align-items: stretch;
    display: grid;
  }
}

@media (max-width: 640px) {
  .context-strip h2 {
    font-size: 23px;
  }

  .header-actions,
  .row-actions,
  .frame-nav-actions {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
  }

  .row-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding-left: 0;
  }

  .header-actions .tool-button,
  .row-actions .tool-button,
  .frame-nav-actions .tool-button {
    width: 100%;
  }

  .header-actions .play-launch {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    height: 50px;
    left: 14px;
    min-width: 0;
    right: 14px;
    width: auto;
  }

  .lesson-ribbon,
  .frame-toolbar {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .frame-title-input {
    font-size: 22px;
  }

  .stage-media {
    min-height: 270px;
  }

  .thumbnail-strip {
    grid-auto-columns: 92px;
  }

  .image-thumb button:first-child,
  .image-thumb img {
    height: 66px;
    min-height: 66px;
  }

  .thumb-upload {
    min-height: 98px;
  }

  textarea,
  .markdown-preview {
    min-height: 170px;
  }
}
