:root {
  --ink: #f5efe6;
  --ink-dim: #b39d77;
  --gold: #d9a441;
  --gold-hi: #eec987;
  --panel: #200604;
  --line: #5a2a1c;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #160503;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  cursor: crosshair;
}

#stage-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  pointer-events: none;
  display: block;
}

#video { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.intro {
  position: fixed;
  left: max(16px, 4vw);
  top: 50%;
  transform: translateY(-50%);
  width: min(420px, calc(100vw - 32px));
  padding: 28px 28px 22px;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.intro.gone {
  opacity: 0;
  transform: translate(-24px, -50%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 600;
}

h1 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 38px;
  line-height: 1.02;
  color: #fbeed3;
}

.lede {
  margin: 0 0 18px;
  color: var(--ink-dim);
  line-height: 1.5;
}

.howto {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  gap: 9px;
}
.howto li {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 10px;
  line-height: 1.4;
  color: var(--ink);
}
.howto .k {
  color: var(--gold-hi);
  font-weight: 600;
  font-size: 12px;
  padding-top: 1px;
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #2c0a07;
  color: var(--ink);
  font: 600 14px/1 var(--sans);
  padding: 12px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}
.btn:hover { background: #471a10; border-color: #d9a441; }
.btn:active { transform: none; }
.btn.primary {
  background: #cf3527;
  border-color: #cf3527;
  color: #ffffff;
}
.btn.primary:hover { background: #e0473a; border-color: #e0473a; }
.btn:disabled { opacity: 0.6; cursor: progress; }

.status-line {
  min-height: 1.2em;
  margin: 14px 0 0;
  color: var(--ink-dim);
  font-size: 13px;
}
.status-line.err { color: #eec987; }

.hud {
  position: fixed;
  left: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  pointer-events: none;
  transition: opacity 0.3s;
}
.hud-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}
.plant-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--gold-hi);
  font-weight: 600;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}
.plant-btn:hover {
  border-color: var(--gold-hi);
  background: #38120b;
}
.plant-btn:active {
  transform: none;
}
.hud-scene-select {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 500;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  outline: none;
  font-size: 12px;
  transition: border-color 0.2s, background 0.2s;
}
.hud-scene-select:hover {
  border-color: var(--gold-hi);
  background: #38120b;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8a7a60;
}
.pill.live .dot { background: #7ed957; }
.pill.warn .dot { background: #f2b544; }

.keys {
  margin: 0;
  color: #b9c8cc;
  font-size: 12px;
}
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin: 0 3px 0 8px;
  border: 1px solid #4a5a60;
  border-radius: 4px;
  font: 600 11px/1.4 var(--sans);
  text-align: center;
}
kbd:first-child { margin-left: 0; }

.icon-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: opacity 0.3s;
}
.icon-btn:hover { border-color: #d9a441; }
.sound-btn { right: 62px; }
.sound-btn .off,
.sound-btn[aria-pressed='true'] .on { display: none; }
.sound-btn[aria-pressed='true'] .off { display: block; }

.settings {
  position: fixed;
  top: 62px;
  right: 16px;
  width: min(290px, calc(100vw - 32px));
  padding: 16px 18px;
  display: grid;
  gap: 12px;
}
.settings h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
}
.settings label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-dim);
}
.settings label.row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.settings select,
.settings input[type='range'] {
  width: 100%;
  accent-color: var(--gold);
}
.settings select {
  background: #38120b;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  font: 13px var(--sans);
}
.settings select option { background: #200604; }
.settings input[type='checkbox'] { accent-color: var(--gold); }

#preview-box {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(240px, 38vw);
  transition: opacity 0.3s;
}
#preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #000;
}
.popout-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, border-color 0.2s;
}
#preview-box:hover .popout-btn,
.popout-btn:focus-visible { opacity: 1; }
.popout-btn:hover { border-color: #d9a441; }

.btn.small { padding: 9px 14px; font-size: 13px; }

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 8px 18px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--gold-hi);
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
body.ui-hidden .toast { opacity: 0; }

.error {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 20px 24px;
  max-width: min(480px, calc(100vw - 32px));
  line-height: 1.5;
}

body.ui-hidden .hud,
body.ui-hidden .icon-btn,
body.ui-hidden #preview-box,
body.ui-hidden .settings { opacity: 0; pointer-events: none; }

@media (max-width: 640px) {
  .intro { top: auto; bottom: 16px; transform: none; padding: 20px; }
  .intro.gone { transform: translateY(24px); }
  h1 { font-size: 30px; }
  .howto li { grid-template-columns: 96px 1fr; }
  .keys { display: none; }
}

.studio-toggle { position: fixed; top: 16px; left: 16px; border-radius: 6px; background: #2c0a07; color: #f8f2e4; border-color: #673626; }
body.ui-hidden .studio-toggle { opacity: 0; pointer-events: none; }
.settings { max-height: calc(100dvh - 80px); overflow-y: auto; }
.settings { z-index: 5; width: min(370px, calc(100vw - 32px)); background: #200604; border-color: #673626; color: #f5efe6; border-radius: 8px; }
.settings-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.settings .btn { border-radius: 5px; color: #f5efe6; border-color: #673626; }
.settings label { color: #e3d3b8; }
.settings select, .settings select option { background: #2c0a07; color: #f5efe6; }
#quick-assets { border: 0; padding: 0; margin: 0; min-width: 0; display: grid; gap: 12px; }
#quick-assets legend { padding: 8px 0 12px; font-weight: 600; font-size: 13px; color: #eec987; }
.quick-asset { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 10px; align-items: center; }
.quick-asset img { width: 46px; height: 56px; object-fit: contain; background: #38120b; border-radius: 4px; }
.quick-asset select { min-width: 0; }
#quick-assets-status { margin: 0; font-size: 12px; line-height: 1.4; color: #b39d77; overflow-wrap: anywhere; }
#quick-assets-status[data-error='true'] { color: #f2d492; }
#studio { width: min(1140px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid #673626; border-radius: 8px; color: #f5efe6; background: #200604; overflow: auto; }
#studio::backdrop { background: #120302bb; }
#studio .btn { border-radius: 5px; color: #edf3f3; background: #38120b; border-color: #673626; line-height: 1.3; padding: 10px 12px; }
#studio .btn.primary { background: #cf3527; color: #ffffff; border-color: #cf3527; }
#studio .btn:hover { background: #2b4550; }
#studio button:focus-visible, #studio input:focus-visible, #studio select:focus-visible { outline: 2px solid #eec987; outline-offset: 3px; }
.studio-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; position: sticky; top: 0; z-index: 2; background: #200604; }
.studio-header h2 { margin: 0; font-size: 20px; }
.studio-tabs { display: flex; padding: 0 20px; border-bottom: 1px solid #5a2a1c; gap: 24px; }
.studio-tabs button { padding: 12px 0; color: #cbb593; border: 0; border-bottom: 3px solid transparent; background: none; font: 600 14px var(--sans); cursor: pointer; }
.studio-tabs button[aria-pressed='true'] { border-bottom-color: #eec987; color: #eec987; }
#studio-fields { min-width: 0; border: 0; padding: 0; margin: 0; }
.studio-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; }
.studio-workspace { min-width: 0; padding: 20px; background: #101c21; }
.checker { background-color: #38120b; background-image: conic-gradient(#4e2015 25%, transparent 0 50%, #4e2015 0 75%, transparent 0); background-size: 20px 20px; }
.cut-preview { height: 440px; position: relative; display: grid; place-items: center; border: 1px solid #673626; border-radius: 4px; overflow: hidden; }
#cut-canvas { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; touch-action: none; cursor: crosshair; }
#cut-empty { position: absolute; color: #c8d4d9; pointer-events: none; }
.part-previews { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 14px; }
.part-previews figure { margin: 0; min-width: 0; }
.part-previews img { width: 100%; height: 86px; object-fit: contain; background-color: #38120b; border: 1px solid #673626; border-radius: 4px; padding: 4px; }
.part-previews figcaption { font-size: 10px; color: #cbb593; margin-top: 4px; overflow-wrap: anywhere; }
.studio-controls { display: flex; flex-direction: column; gap: 14px; padding: 20px; border-left: 1px solid #5a2a1c; }
.studio-controls label { display: grid; gap: 7px; font-size: 12px; color: #e3d3b8; }
.studio-controls select, .studio-controls input[type='number'], .studio-controls input[type='text'], .library-picker select { width: 100%; min-width: 0; background: #2c0a07; color: #f5efe6; border: 1px solid #673626; border-radius: 4px; padding: 8px; font: 13px var(--sans); }
.asset-library { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 14px; align-items: center; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid #5a2a1c; }
.asset-library > img { width: 90px; height: 100px; object-fit: contain; background: #38120b; border-radius: 4px; }
.library-picker { display: grid; gap: 8px; min-width: 0; }
.library-picker label { font-size: 13px; font-weight: 600; }
.library-picker .asset-name { margin: 0; }
.library-picker button { justify-self: start; max-width: 100%; }
.studio-controls input[type='range'] { width: 100%; margin: 0; accent-color: #eec987; }
.studio-controls input[type='color'] { border: 1px solid #673626; background: transparent; width: 48px; height: 32px; padding: 2px; }
.studio-controls input[type='file'] { width: 100%; min-width: 0; font-size: 11px; }
.studio-controls input::file-selector-button { font: 600 12px var(--sans); padding: 7px; margin-right: 6px; background: #471a10; color: #f5efe6; border: 1px solid #673626; border-radius: 4px; cursor: pointer; }
.studio-controls .check-row { display: flex; align-items: center; }
.check-row input { accent-color: #eec987; }
.asset-name { font-size: 12px; color: #eec987; margin: -6px 0 0; overflow-wrap: anywhere; }
.studio-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.joint-coordinates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.kit-controls { border-top: 1px solid #5a2a1c; padding-top: 14px; display: grid; gap: 12px; }
.studio-footer { padding: 12px 20px; border-top: 1px solid #5a2a1c; position: sticky; bottom: 0; z-index: 2; background: #200604; }
.studio-footer p { margin: 0; font-size: 12px; color: #b39d77; line-height: 1.5; overflow-wrap: anywhere; }
.studio-footer p[data-error='true'] { color: #f2d492; }
.background-preview { aspect-ratio: 16 / 9; width: 100%; border: 1px solid #673626; }
.background-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
@media (max-width: 740px) {
  #studio { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .studio-layout { grid-template-columns: minmax(0, 1fr); }
  .studio-controls { border-left: 0; border-top: 1px solid #5a2a1c; }
  .studio-workspace { padding: 12px; }
  .cut-preview { height: 300px; }
  .part-previews { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .part-previews img { height: 65px; }
}

/* === GALLERY & MANAGEMENT UI === */
.studio-header-title { display: flex; flex-direction: column; gap: 2px; }
.studio-subtitle { font-size: 12px; color: #b39d77; font-weight: normal; }
.studio-section { padding: 20px; }

.gallery-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid #5a2a1c;
}
.gallery-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 200px;
  min-width: 180px;
}
.search-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  color: #7d939c;
  pointer-events: none;
}
.gallery-search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: #2c0a07;
  border: 1px solid #673626;
  border-radius: 6px;
  color: #f5efe6;
  font: 13px var(--sans);
}
.filter-pills { display: flex; gap: 6px; }
.pill-btn {
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid #673626;
  background: #2c0a07;
  color: #d9c9a8;
  font: 500 12px var(--sans);
  cursor: pointer;
  transition: all 0.2s;
}
.pill-btn:hover { background: #471a10; color: #fff; }
.pill-btn.active {
  background: #cf3527;
  color: #ffffff;
  border-color: #cf3527;
  font-weight: 600;
}

.puppet-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
  margin-top: 20px;
}
.puppet-card {
  background: #260805;
  border: 1px solid #5a2a1c;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s;
}
.puppet-card:hover {
  border-color: #d9a441;
}
.puppet-card.is-active-puppet {
  border-color: #eec987;
}

.puppet-card-thumb {
  height: 200px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 8px;
  border-bottom: 1px solid #5a2a1c;
}
.puppet-card-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.puppet-card-info {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.puppet-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #f8f2e4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.puppet-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-armless { background: #3d1712; color: #eec987; border: 1px solid #23614c; }
.badge-jointed { background: #332612; color: #f5cd79; border: 1px solid #5a421b; }
.badge-active { background: #221c3b; color: #cbb4f3; border: 1px solid #4a3875; }
.badge-default { background: #243237; color: #cbb593; border: 1px solid #5a2a1c; }
.badge-acc-count { background: #273740; color: #eec987; border: 1px solid #3d5563; }

.puppet-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid #5a2a1c;
}
.puppet-card-actions .btn {
  font-size: 12px;
  padding: 6px 10px;
}
.btn-try-select {
  flex: 1 1 100%;
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}
.btn-try-select select {
  flex: 1;
  background: #38120b;
  border: 1px solid #673626;
  border-radius: 4px;
  color: #f5efe6;
  font-size: 12px;
  padding: 5px;
}
.btn-danger {
  background: #57211f !important;
  color: #ffb8b8 !important;
  border-color: #7c3431 !important;
}
.btn-danger:hover {
  background: #6b2a27 !important;
}

/* Background Gallery Grid */
.background-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.bg-card {
  background: #260805;
  border: 1px solid #5a2a1c;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.bg-card.is-active-bg { border-color: #eec987; }
.bg-card-thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  object-fit: cover;
  background: #000;
}
.bg-card-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bg-card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #f5efe6;
}
.bg-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

/* === ACCESSORY MODAL STYLING === */
.accessory-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid #673626;
  border-radius: 8px;
  color: #f5efe6;
  background: #200604;
  overflow: auto;
}
.accessory-dialog::backdrop { background: #120302bb; }
.accessory-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: #260805;
  border-bottom: 1px solid #5a2a1c;
  position: sticky;
  top: 0;
  z-index: 2;
}
.accessory-dialog-header h3 { margin: 0; font-size: 18px; }
.dialog-subtitle { margin: 2px 0 0; font-size: 12px; color: #b39d77; }
.accessory-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  padding: 20px;
  gap: 20px;
}
.accessory-preview-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.acc-canvas-container {
  height: 420px;
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid #5a2a1c;
  border-radius: 8px;
  overflow: hidden;
}
#acc-preview-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.acc-preview-hint { margin: 0; font-size: 12px; color: #8ba0a8; text-align: center; }

.accessory-controls-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.acc-form-group {
  border: 1px solid #5a2a1c;
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #260805;
}
.acc-form-group legend {
  font-size: 12px;
  font-weight: 600;
  color: #eec987;
  padding: 0 6px;
}
.acc-form-group label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: #e3d3b8;
}
.acc-form-group select, .acc-form-group input[type='text'], .acc-form-group input[type='range'] {
  background: #2c0a07;
  color: #f5efe6;
  border: 1px solid #673626;
  border-radius: 4px;
  padding: 6px 8px;
  font: 12px var(--sans);
}
.acc-slider-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.acc-attached-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow-y: auto;
}
.acc-attached-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: #2c0a07;
  border-radius: 6px;
  border: 1px solid #5a2a1c;
  font-size: 12px;
}
.acc-attached-item-info { display: flex; align-items: center; gap: 6px; }
.empty-hint { margin: 0; font-size: 12px; color: #768b94; font-style: italic; }

.accessory-footer {
  padding: 12px 20px;
  background: #260805;
  border-top: 1px solid #5a2a1c;
  display: flex;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  z-index: 2;
}

@media (max-width: 820px) {
  .accessory-body { grid-template-columns: minmax(0, 1fr); }
  .acc-canvas-container { height: 280px; }
}


/* ==== mobile polish: proportional media & touch layout ==== */
@media (max-width: 640px) {
  .studio-toggle { top: 10px; left: 10px; padding: 9px 12px; font-size: 12.5px; max-width: calc(100vw - 118px); }
  .icon-btn { top: 10px; right: 10px; width: 36px; height: 36px; }
  .sound-btn { right: 54px; }
  .settings { top: 56px; right: 8px; left: 8px; width: auto; max-height: calc(100dvh - 64px); padding: 14px; }
  #preview-box { width: min(168px, 42vw); right: 10px; bottom: 88px; }
  .hud { left: 10px; bottom: 10px; gap: 8px; max-width: calc(100vw - 20px); }
  .pill { font-size: 11px; padding: 6px 9px; }
  .plant-btn { padding: 8px 12px; }
  .toast { font-size: 13px; white-space: normal; width: calc(100vw - 24px); text-align: center; }
  .studio-header { padding: 12px 14px; }
  .studio-header h2 { font-size: 18px; }
  .studio-tabs { overflow-x: auto; gap: 18px; padding: 0 14px; scrollbar-width: none; }
  .studio-tabs::-webkit-scrollbar { display: none; }
  .studio-tabs button { white-space: nowrap; }
  .studio-section { padding: 14px; }
  .studio-controls { padding: 14px; }
  .studio-workspace { padding: 10px; }
  .studio-footer { padding: 10px 14px; }
  .gallery-search-wrap { flex: 1 1 100%; }
  .filter-pills { flex-wrap: wrap; }
  .pill-btn { padding: 9px 12px; }
  .puppet-cards-grid { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
  .puppet-card-thumb { height: 150px; }
  .puppet-card-actions .btn { padding: 8px 10px; }
  .background-cards-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .accessory-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .accessory-body { padding: 14px; }
  .part-previews figcaption { font-size: 9.5px; }
}
@media (max-width: 400px) {
  .part-previews { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .joint-coordinates { grid-template-columns: 1fr 1fr; }
}
