/* Pet Studio: warm, tactile UI shell layered over the 3D studio.
   Layout targets: phone portrait (<600px), tablet (600-1099px), desktop (>=1100px). */
:root {
  --ink: #3d2c3e;
  --ink-soft: #76617a;
  --glass: rgba(255, 250, 244, 0.86);
  --sheet-bg: #fffaf6;
  --line: rgba(110, 72, 92, 0.14);
  --shadow: 0 12px 30px rgba(110, 66, 78, 0.16), 0 2px 6px rgba(110, 66, 78, 0.1);
  --shadow-sm: 0 4px 12px rgba(110, 66, 78, 0.12);
  --accent: #ff8873;
  --accent-deep: #f0645a;
  --lav: #8f7cf0;
  --hunger: #ff8f45;
  --energy: #e9a81f;
  --hygiene: #3fa8e6;
  --mood: #ef6299;
  --curiosity: #9070f0;
  --bond: #ff5d74;
  --r-lg: 22px;
  --r: 16px;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.3;
  color: var(--ink);
  background: radial-gradient(130% 95% at 25% 0%, #fff4e6 0%, #fde6dd 42%, #eadcf5 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button, input { font: inherit; color: inherit; }
button { -webkit-touch-callout: none; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--lav); outline-offset: 2px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; inset: 0; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.glass {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
}

/* ---------- top bar ---------- */
.top-overlay {
  position: absolute;
  top: calc(var(--st) + 10px);
  left: calc(var(--sl) + 10px);
  right: calc(var(--sr) + 10px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}
.topbar {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto auto;
  grid-template-areas: "id status views actions";
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.topbar > *, .meters { pointer-events: auto; min-width: 0; }
.tb-id { grid-area: id; display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; }
.avatar {
  position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--pet-body, #ffb8c9);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.08), 0 0 0 3px var(--pet-accent, #fff1dc);
}
.avatar::before, .avatar::after {
  content: ""; position: absolute; top: 42%; width: 4px; height: 6px; border-radius: 3px; background: #2b2034;
}
.avatar::before { left: 32%; }
.avatar::after { right: 32%; }
.tb-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pet-name {
  margin: 0; font-size: 18px; font-weight: 800; letter-spacing: 0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 11em;
}
.badges { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; min-width: 0; overflow: hidden; }
.badge {
  font-size: 11.5px; font-weight: 800; padding: 3px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--b-bg, #ece6ff); color: var(--b-ink, #5b47b8);
}
.badge[data-trait="playful"] { --b-bg: #ffe6cf; --b-ink: #a8520d; }
.badge[data-trait="calm"] { --b-bg: #dcf2e7; --b-ink: #2d7553; }
.badge[data-trait="curious"] { --b-bg: #ece6ff; --b-ink: #5440b4; }
.badge[data-trait="dramatic"] { --b-bg: #ffe0ec; --b-ink: #a92c62; }
.badge[data-trait="stubborn"] { --b-bg: #ece6dc; --b-ink: #685538; }
.badge[data-trait="neat"] { --b-bg: #dbf0fb; --b-ink: #1d6b95; }
.badge[data-trait="chaotic"] { --b-bg: #fff0c4; --b-ink: #806200; }
.status-pill {
  grid-area: status; justify-self: start; display: inline-flex; align-items: center; gap: 8px;
  max-width: 100%; min-height: 40px; padding: 7px 14px; border-radius: 999px; font-weight: 800; font-size: 14px;
}
.status-pill .ico { width: 20px; height: 20px; color: var(--lav); }
.status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.status-text .s-short { display: none; }
.status-source {
  flex: none; font-size: 11.5px; font-weight: 800; color: var(--ink-soft);
  background: rgba(143, 124, 240, 0.13); padding: 2px 8px; border-radius: 999px;
}
.status-source:empty { display: none; }
.views { grid-area: views; display: flex; gap: 2px; padding: 4px; border-radius: 999px; }
.view-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 12px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink-soft); cursor: pointer; font-weight: 800; font-size: 13px; white-space: nowrap;
}
.view-btn .ico { width: 19px; height: 19px; }
.view-btn:hover { color: var(--ink); }
.view-btn[aria-checked="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }
.tb-actions { grid-area: actions; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; color: var(--ink);
}
.icon-btn[aria-pressed="true"] { color: var(--accent-deep); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 0; border-radius: 999px; cursor: pointer; font-weight: 800; white-space: nowrap;
}
.pill-btn.accent, .btn.primary {
  background: linear-gradient(180deg, #ff9d89, var(--accent-deep)); color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12), 0 6px 16px rgba(240, 100, 90, 0.34);
}
.pill-btn:active, .icon-btn:active, .view-btn:active { transform: scale(0.96); }

/* ---------- needs meters ---------- */
.meters {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px 12px;
  padding: 9px 14px; border-radius: var(--r);
}
.meter {
  --c: var(--ink);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "ico label value" "bar bar bar";
  align-items: center; column-gap: 6px; row-gap: 4px; min-width: 0;
}
.meter[data-need="hunger"] { --c: var(--hunger); }
.meter[data-need="energy"] { --c: var(--energy); }
.meter[data-need="hygiene"] { --c: var(--hygiene); }
.meter[data-need="mood"] { --c: var(--mood); }
.meter[data-need="curiosity"] { --c: var(--curiosity); }
.meter[data-need="bond"] { --c: var(--bond); }
.meter .ico { grid-area: ico; width: 17px; height: 17px; color: var(--c); }
.m-label { grid-area: label; font-size: 12.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-value { grid-area: value; font-size: 12.5px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink-soft); white-space: nowrap; }
.m-state { display: none; grid-area: state; font-size: 11.5px; font-weight: 700; color: var(--ink-soft); white-space: nowrap; }
.m-bar { grid-area: bar; height: 8px; border-radius: 99px; background: rgba(100, 70, 90, 0.12); overflow: hidden; }
.m-fill { display: block; height: 100%; width: var(--v, 50%); border-radius: inherit; background: var(--c); transition: width 0.6s ease; }
.meter.low .m-fill {
  background: repeating-linear-gradient(-45deg, var(--c) 0 6px, color-mix(in srgb, var(--c) 62%, white) 6px 12px);
  animation: low-pulse 1.4s ease-in-out infinite;
}
.meter.low .m-value::before {
  content: "!"; display: inline-grid; place-items: center; width: 15px; height: 15px; margin-right: 4px;
  border-radius: 50%; background: var(--c); color: #fff; font-size: 11px; vertical-align: 1px;
}
@keyframes low-pulse { 50% { opacity: 0.55; } }

/* ---------- action dock ---------- */
.dock {
  position: absolute; left: 50%; bottom: calc(var(--sb) + 10px); transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: 10px; max-width: calc(100% - 20px);
  padding: 8px 10px; border-radius: var(--r-lg); z-index: 10;
}
.dock-group { position: relative; display: flex; align-items: flex-end; gap: 6px; padding-top: 17px; }
.dock-group + .dock-group { padding-left: 10px; border-left: 1px solid var(--line); }
.dock-label {
  position: absolute; top: 0; left: 4px; font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-soft); white-space: nowrap;
}
.dock-group + .dock-group .dock-label { left: 14px; }
.next-buttons { display: flex; gap: 6px; }
.act {
  --c: var(--ink);
  position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 66px; min-height: 58px; padding: 6px 10px; border: 0; border-radius: 15px; cursor: pointer;
  background: linear-gradient(180deg, #ffffff, #fff5ee); color: var(--ink); font-size: 12.5px; font-weight: 800; white-space: nowrap;
  box-shadow: inset 0 -3px 0 rgba(120, 80, 90, 0.1), 0 2px 6px rgba(120, 80, 90, 0.12);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.act .ico { width: 24px; height: 24px; color: var(--c); }
.act:hover { transform: translateY(-2px); }
.act:active { transform: translateY(1px) scale(0.96); box-shadow: inset 0 -1px 0 rgba(120, 80, 90, 0.1), 0 1px 2px rgba(120, 80, 90, 0.12); }
.act[data-action="feed"] { --c: var(--hunger); }
.act[data-action="wash"] { --c: var(--hygiene); }
.act[data-action="rest"] { --c: var(--lav); }
.act[data-action="pet"] { --c: var(--bond); }
.act[data-action="praise"] { --c: var(--energy); }
.act[data-action="music"] { --c: #7f62ec; }
.act[data-action="draw"] { --c: #f26d98; }
.act[data-action="customize"] { --c: var(--accent-deep); }
.act .lbl-short { display: none; }
.act.soon { background: rgba(255, 255, 255, 0.55); color: var(--ink-soft); box-shadow: inset 0 0 0 1.5px rgba(143, 124, 240, 0.25); }
.act.soon .ico { color: var(--ink-soft); }
.act.soon .tag {
  position: absolute; top: 3px; right: 3px; font-size: 9px; font-weight: 800; padding: 1px 5px;
  border-radius: 99px; background: var(--lav); color: #fff; letter-spacing: 0.02em;
}
.more-btn { display: none; }
.act.busy .ico { animation: busy-bob 1.2s ease-in-out infinite; }
@keyframes busy-bob { 50% { transform: translateY(-3px); } }

/* ---------- toasts & tips ---------- */
.toasts {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: var(--toast-bottom, calc(var(--sb) + 130px));
  width: min(92vw, 460px); display: flex; flex-direction: column-reverse; align-items: center; gap: 6px;
  pointer-events: none; z-index: 20;
}
.toast {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 9px 15px; border-radius: 18px;
  background: rgba(61, 44, 62, 0.93); color: #fff; font-weight: 700; font-size: 13.5px; box-shadow: var(--shadow);
  animation: toast-in 0.28s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.toast .ico { width: 18px; height: 18px; color: #ffd27a; }
.toast.warn .ico { color: #ffb08a; }
.toast.out { animation: toast-out 0.3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }
.hover-tip {
  position: absolute; z-index: 30; pointer-events: none; padding: 6px 10px; border-radius: 10px;
  background: rgba(61, 44, 62, 0.93); color: #fff; font-size: 12.5px; font-weight: 700; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 14px));
}
.hover-tip[hidden] { display: none; }

/* ---------- sheets (customizer, coming next) ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: 0; max-width: none; max-height: none; overflow: hidden;
  color: var(--ink); background: var(--sheet-bg); box-shadow: 0 20px 60px rgba(80, 40, 60, 0.28);
}
dialog.sheet::backdrop { background: rgba(60, 40, 60, 0.14); }
dialog.customizer::backdrop { background: transparent; }
.customizer[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; height: 58vh; height: 58dvh; max-height: 600px;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.next-sheet[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; max-height: 82vh; max-height: 82dvh;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes sheet-in { from { transform: translateX(40px); opacity: 0; } }
.sheet-head, .cz-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head h2, .cz-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
#cz-title:focus { outline: none; }
.sheet-sub { margin: 3px 0 0; color: var(--ink-soft); font-size: 13px; }
.sheet-head .icon-btn, .cz-head .icon-btn { background: rgba(255, 255, 255, 0.8); box-shadow: var(--shadow-sm); flex: none; }
.cz-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px 18px 20px; display: flex; flex-direction: column; gap: 18px;
}
.cz-sec h3 { margin: 0 0 8px; font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.cz-name input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 14px; border: 2px solid var(--line);
  background: #fff; font-size: 17px; font-weight: 800; user-select: text; -webkit-user-select: text;
}
.cz-name input:focus { outline: none; border-color: var(--lav); }
.cz-color-row { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 800; font-size: 13px; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  position: relative; width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 3px solid #fff; cursor: pointer;
  background: var(--sw, #fff); box-shadow: 0 0 0 1px var(--line), var(--shadow-sm);
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--lav), var(--shadow-sm); }
.swatch.custom { background: conic-gradient(#ff8a8a, #ffd36b, #8fe39a, #7cc8ff, #b49cff, #ff8ad0, #ff8a8a); overflow: hidden; }
.swatch.custom input { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); opacity: 0; cursor: pointer; border: 0; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 14px; border-radius: 999px;
  border: 2px solid var(--line); background: #fff; font-weight: 800; font-size: 14px; cursor: pointer;
}
.chip .ico { width: 20px; height: 20px; color: var(--ink-soft); }
.chip[aria-checked="true"] { border-color: var(--lav); background: #f1edff; color: #4a37a6; }
.chip[aria-checked="true"] .ico { color: var(--lav); }
.slider-row { display: grid; grid-template-columns: 86px minmax(0, 1fr) 38px; align-items: center; gap: 10px; min-height: 38px; font-weight: 800; font-size: 13.5px; }
.slider-row output { font-variant-numeric: tabular-nums; color: var(--ink-soft); text-align: right; font-size: 12.5px; }
input[type="range"] { width: 100%; height: 30px; margin: 0; accent-color: var(--lav); cursor: pointer; }
.cz-note, .sheet-note { margin: 2px 0 0; font-size: 12px; line-height: 1.45; color: var(--ink-soft); }
.sheet-note { padding: 4px 18px calc(18px + var(--sb)); }
.cz-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 18px calc(12px + var(--sb));
  border-top: 1px solid var(--line); background: #fffdfb;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border: 0; border-radius: 14px; cursor: pointer; font-weight: 800; background: #fff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06), var(--shadow-sm);
}
.btn .ico { width: 19px; height: 19px; }
.btn:active { transform: scale(0.97); }
.grow { flex: 1; }
.next-list { list-style: none; margin: 0; padding: 12px 16px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; }
.next-item { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; align-items: start; padding: 12px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.next-item .ico-wrap { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: #f1edff; color: var(--lav); }
.next-item h3 { margin: 0 0 3px; font-size: 15px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.next-item p { margin: 0; font-size: 13px; line-height: 1.4; color: var(--ink-soft); }
.next-item .it-tag { font-size: 10.5px; font-weight: 800; color: #fff; background: var(--lav); padding: 2px 8px; border-radius: 99px; }
.next-item.focus { box-shadow: 0 0 0 3px var(--lav), var(--shadow-sm); }

/* ---------- splash, errors ---------- */
.splash {
  position: absolute; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: radial-gradient(130% 95% at 25% 0%, #fff4e6 0%, #fde6dd 42%, #eadcf5 100%);
  font-weight: 800; color: var(--ink-soft); transition: opacity 0.5s ease, visibility 0.5s ease;
}
.splash.hide { opacity: 0; visibility: hidden; }
.splash p { margin: 0; }
.splash-blob {
  position: relative; width: 74px; height: 64px; border-radius: 50% 50% 46% 46%; background: #ffb8c9;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.06); animation: bob 1.1s ease-in-out infinite;
}
.splash-blob i { position: absolute; top: 40%; width: 7px; height: 10px; border-radius: 4px; background: #2b2034; }
.splash-blob i:first-child { left: 30%; }
.splash-blob i:last-child { right: 30%; }
@keyframes bob { 50% { transform: translateY(-8px) scaleY(1.04); } }
.gl-error { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(88vw, 420px); padding: 18px 20px; border-radius: var(--r-lg); z-index: 5; }
.gl-error h2 { margin: 0 0 6px; font-size: 18px; }
.gl-error p { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.45; }
.gl-error[hidden] { display: none; }
.noscript { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-weight: 800; }

/* ---------- desktop: meters become a side panel ---------- */
@media (min-width: 1100px) {
  .meters { align-self: flex-start; width: 240px; grid-template-columns: 1fr; gap: 11px; padding: 14px 16px; border-radius: var(--r-lg); }
  .meter { grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-areas: "ico label state value" "bar bar bar bar"; }
  .m-state { display: block; }
  .m-bar { height: 9px; }
}
@media (min-width: 900px) {
  .customizer[open] {
    inset: calc(var(--st) + 12px) calc(var(--sr) + 12px) calc(var(--sb) + 12px) auto;
    width: 400px; height: auto; max-height: none; border-radius: 24px; animation-name: sheet-in;
  }
  .next-sheet[open] { inset: 0; margin: auto; width: min(480px, 92vw); height: fit-content; max-height: 86vh; border-radius: 24px; }
}

/* ---------- tablet and below ---------- */
@media (max-width: 1099px) {
  .topbar {
    grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto;
    grid-template-areas: "id status actions" "views views views";
  }
  .views { justify-self: start; }
  .dock-label { display: none; }
  .dock-group { padding-top: 0; }
  .act .lbl-long, .next-buttons { display: none; }
  .act .lbl-short { display: inline; }
  .more-btn { display: inline-flex; }
}

/* ---------- phone portrait ---------- */
@media (max-width: 599px) {
  body { font-size: 14px; }
  .top-overlay { top: calc(var(--st) + 8px); left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px); gap: 6px; }
  .topbar { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "id id actions" "status views views"; gap: 6px; }
  .tb-actions { justify-self: end; }
  .tb-id { justify-self: start; max-width: 100%; padding: 4px 10px 4px 4px; gap: 8px; }
  .avatar { width: 32px; height: 32px; }
  .pet-name { font-size: 16px; max-width: 7.5em; }
  .badge { font-size: 10.5px; padding: 2px 7px; }
  .badge:nth-child(n + 3) { display: none; }
  .status-pill { min-height: 38px; padding: 6px 11px; gap: 6px; font-size: 12.5px; }
  .status-pill .ico { width: 18px; height: 18px; }
  .status-text .s-long, .status-source { display: none; }
  .status-text .s-short { display: inline; }
  .views { justify-self: end; padding: 3px; }
  .view-btn { width: 36px; min-height: 36px; padding: 0; }
  .view-btn .vlabel { display: none; }
  .pill-btn { width: 44px; padding: 0; justify-content: center; }
  .pill-btn .label { display: none; }
  .meters { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px 12px; padding: 8px 12px; }
  .m-label, .m-value { font-size: 11.5px; }
  .m-bar { height: 7px; }
  .dock {
    left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px); bottom: calc(var(--sb) + 8px); transform: none; max-width: none;
    flex-wrap: wrap; justify-content: center; gap: 6px; padding: 8px;
  }
  .dock-group { display: contents; }
  .act { flex: 0 0 calc((100% - 24px) / 5); min-width: 0; min-height: 54px; padding: 5px 2px; font-size: 11.5px; }
  .act .ico { width: 23px; height: 23px; }
  .toasts { width: calc(100vw - 24px); }
  .toast { font-size: 12.5px; }
}

/* ---------- short landscape phones ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .top-overlay { top: calc(var(--st) + 6px); gap: 6px; }
  .topbar { grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto auto; grid-template-areas: "id status views actions"; }
  .view-btn { width: 36px; min-height: 36px; padding: 0; }
  .view-btn .vlabel, .pill-btn .label { display: none; }
  .pill-btn { width: 44px; padding: 0; justify-content: center; }
  .meters { align-self: flex-start; width: 196px; grid-template-columns: 1fr; gap: 6px; padding: 8px 10px; }
  .dock { left: 50%; right: auto; transform: translateX(-50%); flex-wrap: nowrap; padding: 6px 8px; gap: 5px; }
  .dock-group { display: flex; }
  .act { flex: none; min-width: 56px; min-height: 48px; padding: 4px 6px; font-size: 10.5px; }
}

/* =====================================================================
   Iteration 2: Teaching Workshop, Creation Feedback Bar, Creation Gallery
   ===================================================================== */
button:disabled { cursor: default; }
.btn:disabled { opacity: 0.45; }
.act[data-feature="teach"] { --c: var(--lav); }
.act[data-feature="gallery"] { --c: #f26d98; }
[data-origin="starter"] { --o-bg: #ece6dc; --o-ink: #685538; }
[data-origin="taught"] { --o-bg: #dcf2e7; --o-ink: #2d7553; }
[data-origin="attempt"] { --o-bg: #ece6ff; --o-ink: #5440b4; }

/* ---------- "More" sheet: available features open on tap ---------- */
.next-row { list-style: none; }
.next-open { width: 100%; border: 0; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.next-open .it-tag { background: var(--accent-deep); }
.next-open:hover { box-shadow: 0 0 0 2px var(--lav), var(--shadow-sm); }
.next-open:active { transform: scale(0.99); }

/* ---------- shared segmented control ---------- */
.ws-seg { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 999px; background: rgba(143, 124, 240, 0.1); }
.ws-seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 36px; padding: 0 12px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink-soft); font-weight: 800; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.ws-seg button .ico { width: 17px; height: 17px; }
.ws-seg button[aria-checked="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Teaching Workshop sheet (positioned like the Customizer) ---------- */
dialog.workshop::backdrop { background: transparent; }
.workshop[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; height: 62vh; height: 62dvh; max-height: 640px;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.ws-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.ws-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-head h2:focus { outline: none; }
.ws-head .icon-btn { flex: none; background: rgba(255, 255, 255, 0.8); box-shadow: var(--shadow-sm); }
.ws-tabs { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 999px; background: rgba(143, 124, 240, 0.12); }
.ws-tabs [role="tab"] {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-soft); font-weight: 800; font-size: 14px; cursor: pointer;
}
.ws-tabs [role="tab"] .ico { width: 19px; height: 19px; }
.ws-tabs [role="tab"][aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }
.ws-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 10px;
}
.ws-panel { display: flex; flex-direction: column; gap: 10px; }
.ws-templates { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ws-label { flex: none; font-size: 11px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft); }
.ws-chips { display: flex; flex: 1; min-width: 0; gap: 6px; padding: 2px; overflow-x: auto; scrollbar-width: none; }
.ws-chips::-webkit-scrollbar { display: none; }
.ws-chip { flex: none; min-height: 36px; padding: 0 12px; font-size: 13px; white-space: nowrap; }
.ws-chip[aria-pressed="true"] { border-color: var(--lav); background: #f1edff; color: #4a37a6; }
.ws-timeline-wrap { position: relative; }
.ws-timeline { display: block; width: 100%; height: 72px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 1.5px var(--line); cursor: pointer; touch-action: manipulation; }
.ws-count {
  position: absolute; left: 50%; top: 50%; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.6); background: var(--accent-deep); color: #fff; font-size: 28px; font-weight: 900;
  opacity: 0; pointer-events: none; transition: opacity 0.15s ease, transform 0.15s ease; box-shadow: 0 6px 16px rgba(240, 100, 90, 0.35);
}
.ws-count.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* keyboard: pentatonic bars (xylophone) or a piano layout with every key */
.ws-keys { display: flex; flex-direction: column; gap: 6px; touch-action: none; user-select: none; -webkit-user-select: none; }
.ws-key {
  position: relative; display: flex; align-items: flex-end; justify-content: center; min-width: 0; padding: 0 0 7px;
  border: 0; border-radius: 10px 10px 12px 12px; cursor: pointer; font-weight: 900; font-size: 13px; color: rgba(61, 44, 62, 0.78);
  background: linear-gradient(180deg, color-mix(in srgb, var(--tint) 42%, white), var(--tint));
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12), 0 2px 4px rgba(110, 66, 78, 0.15);
  transition: transform 0.06s ease, filter 0.06s ease;
}
.ws-key.on { transform: translateY(2px); filter: brightness(1.05) saturate(1.2); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12), 0 0 0 3px #fff, 0 0 0 5px var(--tint); }
.ws-octave.penta { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); align-items: end; gap: 4px; height: 92px; }
.ws-key.bar { height: calc(100% - var(--i) * 2.2%); }
.ws-octave.piano { display: grid; grid-template-rows: 48px 40px; height: 88px; }
.piano .ws-key:not(.black) {
  z-index: 1; margin: 0 1px; border-radius: 0 0 10px 10px; color: var(--ink-soft);
  background: linear-gradient(180deg, #fff 58%, color-mix(in srgb, var(--tint) 38%, white));
  box-shadow: inset 0 -4px 0 color-mix(in srgb, var(--tint) 75%, white), inset 0 0 0 1px rgba(110, 72, 92, 0.18);
}
.piano .ws-key.black {
  z-index: 2; margin: 0 13%; padding-bottom: 5px; border-radius: 0 0 8px 8px; font-size: 10px; color: #fff;
  background: linear-gradient(180deg, #54476a, #2e2638); box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--tint) 80%, black), 0 2px 3px rgba(0, 0, 0, 0.25);
}
.piano .ws-key.on { box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12), 0 0 0 3px var(--tint); }
.ws-pads { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; touch-action: none; user-select: none; -webkit-user-select: none; }
.ws-pad {
  min-height: 46px; border: 0; border-radius: 14px; cursor: pointer; font-weight: 900; font-size: 13.5px; color: var(--ink);
  background: color-mix(in srgb, var(--pad) 32%, white);
  box-shadow: inset 0 -4px 0 var(--pad), 0 2px 5px rgba(110, 66, 78, 0.14);
}
.ws-pad.hit { animation: pad-hit 0.22s ease; }
@keyframes pad-hit { 40% { transform: scale(0.94); background: color-mix(in srgb, var(--pad) 60%, white); } }
.ws-transport { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.ws-transport .btn, .ws-draw-actions .btn { min-width: 0; min-height: 42px; padding: 0 8px; font-size: 13.5px; white-space: nowrap; }
.ws-rec .ico { color: #e5484d; }
.ws-rec.live { background: #ffe9e7; box-shadow: inset 0 0 0 2px #e5484d; animation: rec-pulse 1s ease-in-out infinite; }
@keyframes rec-pulse { 50% { box-shadow: inset 0 0 0 2px #e5484d, 0 0 0 4px rgba(229, 72, 77, 0.18); } }
.ws-settings { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.ws-tempo { flex: 1 1 210px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; min-width: 0; font-weight: 800; font-size: 13px; }
.ws-tempo input[type="range"] { height: 36px; }
.ws-tempo output { min-width: 62px; text-align: right; font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.ws-toggle { min-height: 40px; }
.ws-toggle[aria-pressed="true"] { border-color: var(--lav); background: #f1edff; color: #4a37a6; }

/* drawing */
.ws-draw { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 10px; }
.ws-canvas-wrap { width: min(100%, 360px); aspect-ratio: 1; }
.ws-canvas { display: block; width: 100%; height: 100%; border-radius: 14px; background: #fffaf1; box-shadow: 0 0 0 1.5px var(--line), var(--shadow-sm); touch-action: none; cursor: crosshair; }
.ws-tools { width: 100%; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.ws-swatches { flex: 1 0 100%; justify-content: center; }
.ws-brushes button { width: 46px; padding: 0; }
.ws-brushes button i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: var(--brush, var(--ink)); }
.ws-draw-actions { flex: 1 0 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.ws-draw-actions .lbl-short { display: none; }
.ws-mode { margin-left: auto; }
.ws-note { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--ink-soft); }
.ws-foot { display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(10px + var(--sb)); border-top: 1px solid var(--line); background: #fffdfb; }
.ws-hint { flex: 1; min-width: 0; margin: 0; font-size: 12.5px; font-weight: 700; line-height: 1.35; color: var(--ink-soft); }
.ws-teach { flex: none; min-height: 46px; padding: 0 18px; font-size: 15px; }
.ws-teach[aria-disabled="true"] { filter: saturate(0.5); opacity: 0.75; }
.ws-teach.nudge { animation: nudge 0.4s ease; }
@keyframes nudge { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

/* ---------- Creation Feedback Bar (floats above the dock) ---------- */
.creation-bar {
  position: absolute; left: 50%; bottom: var(--dock-top, calc(var(--sb) + 120px)); transform: translateX(-50%); z-index: 11;
  width: min(1000px, calc(100% - 20px)); padding: 8px 8px 8px 10px; border-radius: 20px;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto auto; grid-template-areas: "thumb info main nudges close";
  align-items: center; gap: 8px 10px; animation: bar-in 0.3s cubic-bezier(0.2, 1.2, 0.4, 1);
}
@keyframes bar-in { from { opacity: 0; transform: translate(-50%, 12px); } }
.cb-thumb { grid-area: thumb; display: block; width: 52px; height: 52px; border-radius: 12px; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.cb-info { grid-area: info; min-width: 0; }
.cb-title { display: flex; align-items: center; gap: 6px; min-width: 0; margin: 0; font-size: 14px; font-weight: 800; }
.cb-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-origin, .gl-origin { flex: none; padding: 2px 7px; border-radius: 999px; background: var(--o-bg); color: var(--o-ink); font-size: 10.5px; font-weight: 800; white-space: nowrap; }
.cb-status { margin: 2px 0 5px; font-size: 12px; font-weight: 700; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-progress { display: block; height: 5px; border-radius: 99px; background: rgba(100, 70, 90, 0.12); overflow: hidden; }
.cb-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--lav), var(--accent)); transition: width 0.2s linear; }
.cb-main { grid-area: main; display: flex; gap: 6px; }
.cb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 13px;
  background: #fff; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06), var(--shadow-sm); font-weight: 800; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.cb-btn .ico { width: 19px; height: 19px; }
.cb-love .ico { color: var(--bond); }
.cb-love[aria-pressed="true"] { background: #ffe3e8; color: #b8274a; }
.cb-love[aria-pressed="true"] .ico { fill: currentColor; }
.cb-love:disabled[aria-pressed="true"] { opacity: 1; }
.cb-variation .ico { color: var(--lav); }
.cb-nudges { grid-area: nudges; display: flex; gap: 3px; padding: 3px; border-radius: 14px; background: rgba(143, 124, 240, 0.1); }
.cb-nudge {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; min-height: 36px; padding: 0 9px;
  border: 0; border-radius: 11px; background: transparent; color: var(--ink); font-weight: 800; font-size: 12.5px; white-space: nowrap; cursor: pointer;
}
.cb-nudge .ico { width: 16px; height: 16px; color: var(--lav); }
.cb-nudge:not(:disabled):hover { background: #fff; }
.cb-btn:disabled, .cb-nudge:disabled { opacity: 0.45; }
.cb-btn:not(:disabled):active, .cb-nudge:not(:disabled):active { transform: scale(0.96); }
.cb-close { grid-area: close; width: 38px; height: 38px; background: rgba(255, 255, 255, 0.75); }

/* ---------- Creation Gallery sheet ---------- */
dialog.gallery::backdrop { background: rgba(60, 40, 60, 0.22); }
.gallery[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; height: 88vh; height: 88dvh;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.gl-head h2:focus { outline: none; }
.gl-toolbar { display: flex; padding: 8px 14px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.gl-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 14px 16px; }
.gl-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.gl-card {
  position: relative; display: grid; grid-template-columns: 92px minmax(0, 1fr); grid-template-areas: "thumb meta" "actions actions" "link link";
  gap: 8px 12px; padding: 10px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm);
  container-type: inline-size;
}
.gl-card.selected { box-shadow: 0 0 0 3px var(--lav), var(--shadow-sm); }
.gl-thumb { grid-area: thumb; position: relative; width: 92px; height: 92px; border-radius: 12px; overflow: hidden; background: #f6efe6; box-shadow: inset 0 0 0 1px var(--line); }
.gl-thumb canvas { display: block; width: 100%; height: 100%; }
.gl-star {
  position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.9); color: var(--ink-soft); box-shadow: var(--shadow-sm); cursor: pointer;
}
.gl-star .ico { width: 18px; height: 18px; }
.gl-star[aria-pressed="true"] { color: #e0a000; }
.gl-star[aria-pressed="true"] .ico { fill: currentColor; }
.gl-pinned {
  position: absolute; left: 4px; bottom: 4px; display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px 2px 5px;
  border-radius: 99px; background: rgba(61, 44, 62, 0.86); color: #fff; font-size: 10px; font-weight: 800;
}
.gl-pinned .ico { width: 12px; height: 12px; }
.gl-meta { grid-area: meta; display: flex; flex-direction: column; justify-content: center; gap: 5px; min-width: 0; }
.gl-title { margin: 0; font-size: 14.5px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gl-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.gl-kind, .gl-tag { padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 800; white-space: nowrap; }
.gl-kind { background: #f3eee8; color: var(--ink-soft); }
.gl-tag { background: #fff1cc; color: #7a5a00; }
.gl-meta time { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
.gl-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.gl-actions .btn { min-height: 40px; padding: 0 10px; font-size: 13px; white-space: nowrap; }
.gl-perform { flex: 1.3 1 auto; }
.gl-perform .ico { color: var(--accent-deep); }
.gl-act { flex: 1 1 auto; }
/* Narrow cards: Compare and Delete become icon buttons (names stay in aria-label and title). */
@container (max-width: 440px) {
  .gl-mini .gl-lbl { display: none; }
  .gl-mini { flex: 0 0 44px; padding: 0 !important; }
}
.gl-act[aria-pressed="true"] { background: #f1edff; color: #4a37a6; box-shadow: inset 0 0 0 2px var(--lav); }
.gl-del.confirm { background: #ffe3e0; color: #b42318; box-shadow: inset 0 0 0 2px #f97066; }
.gl-link {
  grid-area: link; justify-self: start; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border: 0; border-radius: 999px; background: #f1edff; color: #4a37a6; font-weight: 800; font-size: 12.5px; cursor: pointer;
}
.gl-link .ico { width: 16px; height: 16px; }
.gl-empty { padding: 34px 12px; text-align: center; color: var(--ink-soft); line-height: 1.5; }
.gl-empty strong { color: var(--ink); }
.gl-compare-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.gl-compare-head h3 { margin: 0; font-size: 16px; }
.gl-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 780px; margin: 0 auto; }
.gl-side { position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; margin: 0; padding: 10px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.gl-side canvas { display: block; width: 100%; aspect-ratio: 1; border-radius: 12px; background: #fffaf1; }
.gl-compare[data-kind="music"] .gl-side canvas { aspect-ratio: 4 / 3; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.gl-side-tag { align-self: flex-start; padding: 3px 9px; border-radius: 99px; background: rgba(61, 44, 62, 0.86); color: #fff; font-size: 11px; font-weight: 800; }
.gl-side figcaption { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.gl-side strong { font-size: 13.5px; line-height: 1.25; overflow-wrap: anywhere; }
.gl-side time { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
.gl-sim { margin: 12px 0 10px; text-align: center; font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.gl-compare-actions { display: flex; justify-content: center; }
.gl-foot { padding: 8px 16px calc(10px + var(--sb)); border-top: 1px solid var(--line); background: #fffdfb; }
.gl-hint { margin: 0; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }

/* ---------- Iteration 2: tablet ---------- */
@media (min-width: 600px) {
  .gl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ws-templates { flex-wrap: wrap; }
  .ws-chips { flex-wrap: wrap; overflow: visible; }
}
@media (min-width: 600px) and (max-width: 899px) {
  .workshop[open] { height: 56vh; height: 56dvh; max-height: 600px; }
  .ws-draw { grid-template-columns: auto minmax(0, 1fr); align-items: start; justify-items: stretch; }
  .ws-canvas-wrap { width: min(44vw, 40dvh, 330px); }
}
@media (min-width: 600px) and (max-width: 1099px) {
  .creation-bar { width: min(740px, calc(100% - 20px)); grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-areas: "thumb info main close" "nudges nudges nudges nudges"; }
  .cb-nudge { flex: 1; }
}
/* ---------- Iteration 2: desktop ---------- */
@media (min-width: 900px) {
  .workshop[open] {
    inset: calc(var(--st) + 12px) calc(var(--sr) + 12px) calc(var(--sb) + 12px) auto;
    width: 430px; height: auto; max-height: none; border-radius: 24px; animation-name: sheet-in;
  }
  .ws-head { flex-wrap: wrap; row-gap: 10px; }
  .ws-tabs { order: 3; flex: 1 0 100%; }
  .ws-tabs [role="tab"] { flex: 1; justify-content: center; }
  .ws-timeline { height: 88px; }
  .ws-octave.penta { height: 104px; }
  .gallery[open] { inset: 0; margin: auto; width: min(1060px, 92vw); height: min(840px, 90vh); border-radius: 24px; }
}
/* Tall desktop drawer: a bigger instrument. */
@media (min-width: 900px) and (min-height: 820px) {
  .ws-timeline { height: 108px; }
  .ws-octave.penta { height: 150px; }
  .ws-octave.piano { grid-template-rows: 64px 54px; height: 118px; }
  .ws-pad { min-height: 58px; font-size: 14.5px; }
  .ws-transport .btn { min-height: 46px; }
}
@media (min-width: 1280px) {
  .gl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gallery[open] { width: min(1240px, 92vw); }
}
/* ---------- Iteration 2: phone ---------- */
@media (max-width: 599px) {
  .workshop[open] { height: 64vh; height: 64dvh; }
  .ws-chips { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); padding-right: 22px; }
  body.workshop-open .meters { display: none; }
  .ws-head { gap: 8px; padding: 10px 12px 8px; }
  .ws-head h2 { font-size: 17px; }
  .ws-head [data-ws-name] { display: none; }
  .ws-tabs [role="tab"] { padding: 0 11px; font-size: 13.5px; }
  .ws-body { padding: 8px 12px 12px; gap: 8px; }
  .ws-panel { gap: 8px; }
  .ws-label { display: none; }
  .ws-timeline { height: 62px; }
  .ws-octave.penta { height: 84px; gap: 3px; }
  .ws-key { font-size: 12px; }
  .ws-transport { grid-template-columns: 1.25fr 1.25fr 0.6fr 1fr; }
  .ws-transport [data-ws="undo-music"] span { display: none; }
  .ws-tempo { flex-basis: 100%; }
  /* The canvas takes what is left after the shapes row and one tools row, so nothing hides below the fold. */
  .ws-canvas-wrap { width: clamp(200px, calc(64dvh - 292px), 100%); }
  .ws-draw-actions { flex: 0 0 auto; grid-template-columns: repeat(3, 44px); }
  .ws-draw-actions .btn { width: 44px; padding: 0; }
  .ws-draw-actions .btn span { display: none; }
  .ws-mode button { padding: 0 10px; }
  .ws-foot { padding: 8px 12px calc(8px + var(--sb)); }
  .ws-teach { padding: 0 14px; }
  .creation-bar {
    left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px); width: auto; transform: none; padding: 8px; gap: 6px 8px; border-radius: 18px;
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "thumb info close" "main main main" "nudges nudges nudges";
    animation-name: bar-in-m;
  }
  @keyframes bar-in-m { from { opacity: 0; transform: translateY(12px); } }
  .cb-thumb { width: 40px; height: 40px; border-radius: 10px; }
  .cb-main { display: grid; grid-template-columns: 1fr 1fr; }
  .cb-nudges { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cb-nudge { padding: 0 4px; font-size: 12px; }
  .cb-close { width: 36px; height: 36px; }
  .gl-filter button { padding: 0 10px; }
}

/* =====================================================================
   Iteration 3: dock lane, Sleep Practice, Learning Inspector
   ===================================================================== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.act[data-feature="practice"] { --c: #6f63d9; }
.act[data-feature="inspector"] { --c: #2f86c4; }

/* The dock centres itself in the safe lane (--safe-left / --safe-width, set by
   layout()): a side drawer narrows the lane, so the dock moves beside it. */
@media (min-width: 600px) {
  .dock {
    left: calc(var(--safe-left, 0px) + var(--safe-width, 100vw) / 2);
    max-width: calc(var(--safe-width, 100vw) - 24px);
    transition: left 0.3s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.18s ease;
  }
  .toasts { left: calc(var(--safe-left, 0px) + var(--safe-width, 100vw) / 2); width: min(92vw, 460px, calc(var(--safe-width, 100vw) - 24px)); }
  /* Fit modes when the lane is narrow: short labels, then the compact (More) layout, then two rows. */
  .dock.fit-tight .act .lbl-long, .dock.fit-compact .act .lbl-long, .dock.fit-wrap .act .lbl-long { display: none; }
  .dock.fit-tight .act .lbl-short, .dock.fit-compact .act .lbl-short, .dock.fit-wrap .act .lbl-short { display: inline; }
  .dock.fit-compact .dock-label, .dock.fit-wrap .dock-label, .dock.fit-compact .next-buttons, .dock.fit-wrap .next-buttons { display: none; }
  .dock.fit-compact .dock-group, .dock.fit-wrap .dock-group { padding-top: 0; }
  .dock.fit-compact .more-btn, .dock.fit-wrap .more-btn { display: inline-flex; }
  .dock.fit-wrap { width: calc(var(--safe-width, 100vw) - 24px); flex-wrap: wrap; justify-content: center; gap: 6px; padding: 8px; }
  .dock.fit-wrap .dock-group { display: contents; }
  .dock.fit-wrap .act { flex: 0 0 calc((100% - 24px) / 5); min-width: 0; padding: 5px 2px; }
}
/* Centred modal sheets cover the lower screen: the dock steps out of the way instead of peeking out. */
body.modal-covered .dock { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.18s ease, visibility 0s linear 0.18s; }

/* ---------- Teaching Workshop: notes never sliced, chips never cut ---------- */
.ws-note-compact { display: none; }
.chip-short { display: none; }
.ws-body.more-below {
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(180deg, #000 calc(100% - 26px), transparent);
}
@media (max-width: 599px) {
  /* The honesty note moves into the footer as one short line, so the sticky footer can never slice it. */
  .ws-body > .ws-note { display: none; }
  .ws-foot { flex-wrap: wrap; row-gap: 3px; }
  .ws-note-compact { display: block; flex: 1 0 100%; margin: 0; font-size: 11px; font-weight: 700; line-height: 1.3; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* Chip rows fit on one line with short names: no scrolling, no fade, nothing cut off. */
  .chip-long { display: none; }
  .chip-short { display: inline; }
  .ws-chips { -webkit-mask-image: none; mask-image: none; padding: 2px 0; overflow: visible; justify-content: space-between; gap: 5px; }
  .ws-chip { flex: 1 1 auto; justify-content: center; min-width: 0; padding: 0 6px; }
  /* Drawing tab: shapes on top, the canvas beside a column of colours and brush sizes, then mode and edit tools. */
  .ws-panel[data-panel="drawing"] {
    display: grid; gap: 8px; align-items: start;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "shapes shapes shapes" "canvas canvas swatches" "canvas canvas brushes" "mode actions actions";
  }
  .ws-panel[data-panel="drawing"] .ws-templates, .ws-panel[data-panel="drawing"] .ws-draw, .ws-panel[data-panel="drawing"] .ws-tools { display: contents; }
  .ws-panel[data-panel="drawing"] .ws-chips { grid-area: shapes; }
  .ws-panel[data-panel="drawing"] .ws-mode { grid-area: mode; margin-left: 0; align-self: center; }
  .ws-panel[data-panel="drawing"] .ws-canvas-wrap { grid-area: canvas; justify-self: start; width: clamp(176px, calc(64dvh - 268px), 100%); }
  .ws-panel[data-panel="drawing"] .ws-swatches { grid-area: swatches; display: grid; grid-template-columns: repeat(2, 34px); gap: 5px; flex: none; }
  .ws-panel[data-panel="drawing"] .ws-brushes { grid-area: brushes; flex-direction: column; width: 73px; }
  .ws-panel[data-panel="drawing"] .ws-brushes button { width: 100%; min-height: 34px; }
  .ws-panel[data-panel="drawing"] .ws-draw-actions { grid-area: actions; justify-self: end; align-self: center; }
  /* Music tab: slightly tighter rows so tempo, length and All notes fit above the footer on a 844 px phone. */
  .ws-body { gap: 7px; }
  .ws-panel { gap: 7px; }
  .ws-timeline { height: 54px; }
  .ws-octave.penta { height: 74px; }
  .ws-pad { min-height: 42px; }
  .ws-transport .btn { min-height: 40px; }
  .ws-settings { gap: 6px 8px; }
  .ws-tempo input[type="range"] { height: 30px; }
  body.practice-open .meters { display: none; }
}

/* ---------- Learned badges ---------- */
.cb-learned, .gl-learned {
  flex: none; padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 800; white-space: nowrap;
  background: linear-gradient(90deg, #efe9ff, #ffe6f1); color: #5a3fb8; box-shadow: inset 0 0 0 1px rgba(143, 124, 240, 0.35);
}
.cb-learned::before, .gl-learned::before { content: "\2726  "; }

/* ---------- Sleep Practice drawer (non-modal: the sleeping pet stays visible and touchable) ---------- */
dialog.practice { z-index: 15; }
.practice[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; height: 56vh; height: 56dvh; max-height: 600px;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sp-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.sp-moon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px; color: #fff; background: linear-gradient(135deg, #7d6ae6, #c2b3ff); box-shadow: var(--shadow-sm); }
.practice[data-status="practicing"] .sp-moon { animation: dream-glow 2.6s ease-in-out infinite; }
@keyframes dream-glow { 50% { box-shadow: 0 0 0 6px rgba(143, 124, 240, 0.18), var(--shadow-sm); } }
.sp-titles { flex: 1; min-width: 0; }
.sp-titles h2 { margin: 0; font-size: 19px; font-weight: 800; }
.sp-titles h2:focus { outline: none; }
.sp-status { margin: 2px 0 0; font-size: 12.5px; font-weight: 700; line-height: 1.35; color: var(--ink-soft); }
.sp-head .icon-btn { flex: none; background: rgba(255, 255, 255, 0.8); box-shadow: var(--shadow-sm); }
.sp-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px 14px 16px; display: flex; flex-direction: column; gap: 12px;
}
.sp-empty { padding: 12px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); line-height: 1.45; }
.sp-empty p { margin: 0 0 10px; }
.sp-dream { display: grid; grid-template-columns: 132px minmax(0, 1fr); align-items: center; gap: 12px; padding: 10px; border-radius: 18px; background: linear-gradient(135deg, #f1ecff, #fff3f8); }
.sp-dream-canvas { display: block; width: 132px; height: 96px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.sp-dream-info { min-width: 0; }
.sp-kicker { margin: 0; font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: #6f63d9; }
.sp-dream-info h3 { margin: 2px 0; font-size: 16px; font-weight: 800; overflow-wrap: anywhere; }
.sp-dream-sub { margin: 0; font-size: 12px; font-weight: 700; line-height: 1.35; color: var(--ink-soft); }
.sp-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.sp-stats div { min-width: 0; padding: 8px 10px; border-radius: 14px; background: #fff; box-shadow: var(--shadow-sm); }
.sp-stats dt { font-size: 10.5px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-stats dd { margin: 2px 0 0; font-size: 16px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-chart, .in-sec .sp-chart { margin: 0; padding: 8px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.sp-chart figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 4px; font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
.sp-chart .key { display: inline-block; width: 16px; height: 0; border-top: 3px solid var(--lav); border-radius: 2px; }
.sp-chart .key.val { border-top: 3px dashed var(--accent-deep); margin-left: 6px; }
.loss-chart { display: block; width: 100%; height: 120px; }
.loss-chart .plot { fill: #fffdfb; stroke: var(--line); }
.loss-chart .line { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.loss-chart .train { stroke: var(--lav); }
.loss-chart .val { stroke: var(--accent-deep); stroke-dasharray: 6 4; }
.loss-chart .mark { stroke: rgba(110, 72, 92, 0.28); stroke-dasharray: 2 3; }
.loss-chart .mark-rollback, .loss-chart .mark-cancel { stroke: rgba(229, 72, 77, 0.55); }
.loss-chart text { font-family: var(--font); font-size: 9.5px; font-weight: 700; fill: var(--ink-soft); }
.sp-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sp-tools .btn { min-width: 0; white-space: nowrap; font-size: 13.5px; }
.sp-compare { padding: 12px; border-radius: 18px; background: linear-gradient(135deg, #fff, #f6f2ff); box-shadow: var(--shadow-sm); }
.sp-compare h3 { margin: 0; font-size: 15px; }
.sp-compare-sub { margin: 3px 0 8px; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.sp-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.sp-pair figure { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 8px; border-radius: 14px; background: #fff; box-shadow: var(--shadow-sm); }
.sp-pair canvas { display: block; width: 100%; aspect-ratio: 4 / 3; max-height: 170px; border-radius: 10px; }
.sp-pair figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; font-weight: 800; }
.sp-tag { padding: 2px 8px; border-radius: 99px; background: #ece6dc; color: #685538; font-size: 10.5px; }
.sp-tag.learned { background: linear-gradient(90deg, #efe9ff, #ffe6f1); color: #5a3fb8; }
.sp-perform { width: 100%; margin-top: 10px; min-height: 48px; white-space: normal; text-align: center; line-height: 1.2; }
.sp-note { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--ink-soft); }
.sp-foot { display: flex; gap: 8px; padding: 10px 14px calc(10px + var(--sb)); border-top: 1px solid var(--line); background: #fffdfb; }
.sp-foot .btn { flex: 1 1 auto; min-width: 0; padding: 0 10px; white-space: nowrap; }
.sp-foot .btn.primary { flex-grow: 1.4; }
@media (min-width: 600px) {
  .sp-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .practice[open] {
    inset: calc(var(--st) + 12px) calc(var(--sr) + 12px) calc(var(--sb) + 12px) auto;
    width: 420px; height: auto; max-height: none; border-radius: 24px; animation-name: sheet-in;
  }
  .sp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .loss-chart { height: 132px; }
}
@media (max-width: 599px) {
  .sp-head { padding: 10px 12px 8px; }
  .sp-body { padding: 10px 12px 14px; gap: 10px; }
  .sp-dream { grid-template-columns: 112px minmax(0, 1fr); gap: 10px; }
  .sp-dream-canvas { width: 112px; height: 84px; }
  .sp-stats dd { font-size: 15px; }
  .sp-foot { gap: 6px; padding: 8px 12px calc(8px + var(--sb)); }
  .sp-foot .btn { padding: 0 8px; font-size: 13.5px; }
  .sp-foot [data-sp="pause"] .ico, .sp-foot [data-sp="finish"] .ico { display: none; }
}

/* ---------- Learning Inspector (centred sheet on desktop, bottom sheet on phones) ---------- */
dialog.inspector::backdrop { background: rgba(60, 40, 60, 0.22); }
.inspector[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; height: 88vh; height: 88dvh;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.in-head h2:focus { outline: none; }
.in-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 16px 20px; display: flex; flex-direction: column; gap: 18px; user-select: text; -webkit-user-select: text; }
.in-msg { margin: 0; padding: 9px 12px; border-radius: 12px; background: #f1edff; color: #4a37a6; font-size: 13px; font-weight: 800; }
.in-sec h3 { margin: 0 0 8px; font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.in-nets { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; }
.in-net { padding: 12px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.in-net header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.in-net h4 { margin: 0; font-size: 15px; }
.in-mode { flex: none; padding: 2px 8px; border-radius: 99px; font-size: 10.5px; font-weight: 800; }
.in-mode[data-mode="learned"] { background: #dcf2e7; color: #2d7553; }
.in-mode[data-mode="authored"] { background: #ece6dc; color: #685538; }
.in-net dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; margin: 0; }
.in-net dt { font-size: 11px; font-weight: 700; color: var(--ink-soft); }
.in-net dd { margin: 0; font-size: 13.5px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.in-net small { color: var(--ink-soft); font-weight: 700; }
.in-total { margin: 8px 0 0; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); line-height: 1.45; }
/* position: relative keeps visually hidden headers (absolutely positioned) inside the wrap,
   so they can never extend the dialog's own scroll area and shift the whole sheet. */
.in-table-wrap { position: relative; overflow-x: auto; border-radius: 14px; background: #fff; box-shadow: var(--shadow-sm); }
.in-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.in-table th, .in-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.in-table thead th { font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.in-table tbody th { font-weight: 700; color: var(--ink-soft); }
.in-table tr:last-child td, .in-table tr:last-child th { border-bottom: 0; }
.in-table small { color: var(--ink-soft); }
.in-kind, .in-ck { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 10.5px; font-weight: 800; white-space: nowrap; background: #ece6dc; color: #685538; }
.in-kind[data-kind="learned"] { background: #dcf2e7; color: #2d7553; }
.in-kind[data-kind="memory"] { background: #dbf0fb; color: #1d6b95; }
.in-kind[data-kind="shared"] { background: #f1edff; color: #4a37a6; }
.in-ck[data-kind="latest"] { background: #dcf2e7; color: #2d7553; }
.in-ck[data-kind="pre-sleep"] { background: #f1edff; color: #4a37a6; }
.in-ck[data-kind="user"] { background: #fff1cc; color: #7a5a00; }
.in-mini { min-height: 36px; padding: 0 10px; font-size: 12.5px; white-space: nowrap; }
.in-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.in-danger.confirm { background: #ffe3e0; color: #b42318; box-shadow: inset 0 0 0 2px #f97066; }
.in-hint { margin: 0 0 8px; font-size: 12px; line-height: 1.45; color: var(--ink-soft); }
.in-sec > .btn { margin-top: 10px; }
.in-settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px 12px; }
.in-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.in-field input, .in-field select {
  min-height: 40px; padding: 0 10px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  color: var(--ink); font: inherit; font-size: 14px; font-weight: 800; user-select: text; -webkit-user-select: text;
}
.in-field input:focus, .in-field select:focus { outline: none; border-color: var(--lav); }
@media (min-width: 900px) {
  .inspector[open] { inset: 0; margin: auto; width: min(980px, 92vw); height: min(860px, 90vh); border-radius: 24px; }
}
/* Greek letters keep their case inside upper-cased headers (an upper-cased "α" reads as "A"). */
.in-sym { text-transform: none; letter-spacing: 0; }

/* =====================================================================
   Iteration 4: narrow screens turn every Inspector table row into a
   stacked card, so no column (Rollback, Learned now, ...) is ever cut off
   by the sheet edge or hidden behind a sideways scroll.
   ===================================================================== */
@media (max-width: 640px) {
  .in-stack, .in-stack > tbody, .in-stack tr, .in-stack th, .in-stack td { display: block; }
  .in-stack > thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
  .in-stack tr { display: grid; gap: 6px 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .in-stack > tbody > tr:last-child { border-bottom: 0; }
  .in-table.in-stack th, .in-table.in-stack td { min-width: 0; padding: 0; border: 0; overflow-wrap: anywhere; }
  .in-stack td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 1px;
    font-size: 11px; font-weight: 800; line-height: 1.25; color: var(--ink-soft);
  }
  /* Checkpoints: name and Rollback on top; steps, saved and loss below. */
  .in-ckpts tr { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "name name act" "steps saved val"; }
  .in-ckpts .ck-name { grid-area: name; }
  .in-ckpts .ck-act { grid-area: act; justify-self: end; }
  .in-ckpts .ck-steps { grid-area: steps; }
  .in-ckpts .ck-saved { grid-area: saved; }
  .in-ckpts .ck-val { grid-area: val; }
  /* Evidence: the lesson on top, its three closeness numbers side by side below. */
  .in-evidence tr { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: "lesson lesson lesson" "authored control learned"; }
  .in-evidence .ev-lesson { grid-area: lesson; }
  .in-evidence .ev-authored { grid-area: authored; }
  .in-evidence .ev-control { grid-area: control; }
  .in-evidence .ev-learned { grid-area: learned; }
  .in-evidence .ev-num { align-self: end; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
  .in-evidence .ev-empty { grid-column: 1 / -1; }
  /* Replay buffer: the row's name on top, music and drawing below. */
  .in-data tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .in-data th, .in-data .d-both { grid-column: 1 / -1; }
  /* Learned vs authored: part and kind chip, then how it works. */
  .in-truth tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "part kind" "how how"; }
  .in-truth .tr-part { grid-area: part; font-weight: 800; }
  .in-truth .tr-kind { grid-area: kind; }
  .in-truth .tr-how { grid-area: how; font-size: 12.5px; color: var(--ink-soft); }
}

/* =====================================================================
   Iteration 4: Visit / Jam sheet, "made together" chips, Learn From
   ===================================================================== */
.act[data-feature="visit"] { --c: #e0820f; }
dialog.visit { z-index: 15; }
.visit[open] {
  position: fixed; inset: auto 0 0 0; width: 100%; height: 58vh; height: 58dvh; max-height: 620px;
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column; animation: sheet-up 0.32s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.vs-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.vs-badge { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px; color: #fff; background: linear-gradient(135deg, #ff9f5a, #ffc46b); box-shadow: var(--shadow-sm); }
.vs-titles { flex: 1; min-width: 0; }
.vs-titles h2 { margin: 0; font-size: 19px; font-weight: 800; }
.vs-titles h2:focus { outline: none; }
.vs-status { margin: 2px 0 0; font-size: 12.5px; font-weight: 700; line-height: 1.35; color: var(--ink-soft); }
.vs-head .icon-btn { flex: none; background: rgba(255, 255, 255, 0.8); box-shadow: var(--shadow-sm); }
.vs-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px 14px 18px; display: flex; flex-direction: column; gap: 12px;
}
.vs-msg { margin: 0; padding: 9px 12px; border-radius: 12px; font-size: 13px; font-weight: 800; line-height: 1.4; background: #e6f6ee; color: #2d7553; }
.vs-msg[data-tone="warn"] { background: #fff1e6; color: #a1460f; }
.vs-visitor { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: center; padding: 12px; border-radius: 18px; background: linear-gradient(135deg, #fff4e6, #fdf0ff); box-shadow: var(--shadow-sm); }
.vs-portrait { display: block; width: 48px; height: 48px; border-radius: 50%; }
.vs-portrait-lg { width: 64px; height: 64px; }
.vs-vinfo { min-width: 0; }
.vs-kicker { margin: 0; font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: #b85a06; }
.vs-vinfo h3 { margin: 2px 0; font-size: 17px; font-weight: 800; overflow-wrap: anywhere; }
.vs-traits, .vs-prov { margin: 0; font-size: 12.5px; font-weight: 700; line-height: 1.4; color: var(--ink-soft); }
.vs-prov { margin-top: 3px; font-size: 12px; font-weight: 600; }
.vs-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.vs-actions .btn { min-width: 0; padding: 0 10px; font-size: 13.5px; }
.vs-actions .btn.primary.vs-draw { background: linear-gradient(180deg, #ffb27a, #ec7b30); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12), 0 6px 16px rgba(236, 123, 48, 0.3); }
.vs-ellip { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-sec h3 { margin: 0 0 8px; font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.vs-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.vs-friend { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px; border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.vs-friend.here { box-shadow: 0 0 0 3px #ffb46b, var(--shadow-sm); }
.vs-friend.new { box-shadow: 0 0 0 3px var(--lav), var(--shadow-sm); }
.vs-finfo { min-width: 0; }
.vs-finfo h4 { margin: 0; font-size: 15px; font-weight: 800; overflow-wrap: anywhere; }
.vs-ftraits { margin: 1px 0 0; font-size: 12px; font-weight: 800; color: #b85a06; }
.vs-fblurb { margin: 2px 0 0; font-size: 12px; line-height: 1.35; color: var(--ink-soft); }
.vs-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.vs-tag { padding: 1px 7px; border-radius: 99px; font-size: 10.5px; font-weight: 800; white-space: nowrap; background: #ece6dc; color: #685538; }
.vs-tag[data-tag="import"] { background: #dbf0fb; color: #1d6b95; }
.vs-tag[data-tag="learned"] { background: linear-gradient(90deg, #efe9ff, #ffe6f1); color: #5a3fb8; }
.vs-tag[data-tag="copy"] { background: #fff1cc; color: #7a5a00; }
.vs-tag[data-tag="new"] { background: var(--lav); color: #fff; }
.vs-fact { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.vs-invite { min-height: 40px; padding: 0 12px; font-size: 13px; white-space: nowrap; }
.vs-remove { width: 40px; height: 40px; align-self: flex-end; background: #fff; box-shadow: var(--shadow-sm); color: var(--ink-soft); }
.vs-note { margin: 0 0 8px; font-size: 12px; line-height: 1.45; color: var(--ink-soft); }
.vs-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.vs-row .btn { min-width: 0; padding: 0 10px; font-size: 13.5px; white-space: nowrap; }
.vs-paste { display: flex; flex-direction: column; gap: 6px; }
.vs-paste-label { font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.vs-paste textarea {
  width: 100%; min-height: 72px; padding: 8px 10px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--ink); resize: vertical; user-select: text; -webkit-user-select: text;
}
.vs-paste textarea:focus { outline: none; border-color: var(--lav); }
.vs-honest { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--ink-soft); }
@media (min-width: 600px) and (max-width: 899px) {
  .vs-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .visit[open] {
    inset: calc(var(--st) + 12px) calc(var(--sr) + 12px) calc(var(--sb) + 12px) auto;
    width: 420px; height: auto; max-height: none; border-radius: 24px; animation-name: sheet-in;
  }
}
@media (max-width: 599px) {
  body.visit-open .meters { display: none; }
  .vs-head { padding: 10px 12px 8px; }
  .vs-body { padding: 10px 12px 14px; gap: 10px; }
  .vs-actions .btn, .vs-row .btn { padding: 0 8px; font-size: 13px; }
}

/* Made together with a visiting friend: a "Duet with Mochi" chip; Learn From replaces the retry controls. */
.cb-social, .gl-social {
  flex: none; padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 800; white-space: nowrap;
  background: #ffe9d2; color: #a1460f; box-shadow: inset 0 0 0 1px rgba(224, 130, 15, 0.3);
}
.creation-bar.social .cb-origin, .creation-bar.social .cb-variation, .creation-bar.social .cb-nudges { display: none; }
.cb-learn { min-width: 0; }
.cb-learn .ico { color: #e0820f; }
.cb-learn[aria-pressed="true"] { background: #fff1e6; color: #a1460f; }
.cb-learn:disabled[aria-pressed="true"] { opacity: 1; }
.cb-learn-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
