:root {
  --ink: #3f362f;
  --paper: #f3efe8;
  --card: #fffcf9;
  --line: #e7ddd2;
  --muted: #8b7d72;
  --accent: #c56b4a;
  --accent-deep: #a85638;
  --accent-soft: #f8ece6;
  --danger: #b42318;
  --shadow: 0 18px 40px rgba(92, 64, 42, 0.07);
  --page: 1080px;
  color-scheme: light;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
}
button, a, input, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
.glow { display: none; }

.top, .editor-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding:
    max(14px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right), calc((100% - var(--page)) / 2))
    14px
    max(20px, env(safe-area-inset-left), calc((100% - var(--page)) / 2));
  background: rgba(243, 239, 232, 0.92);
  border-bottom: 1px solid rgba(63, 54, 47, 0.08);
  backdrop-filter: blur(16px);
}

.logo, .back {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  color: inherit;
  text-decoration: none;
}
.logo span, .back {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.logo span {
  background: var(--accent-soft);
  color: var(--accent-deep);
  border: 1px solid #f0d8cc;
}
.back {
  width: auto;
  min-width: 72px;
  padding: 0 14px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 600;
}
.back:hover { border-color: #d9c8b8; }
.logo small, .kicker, figcaption {
  color: var(--muted);
  font-size: 12px;
}
.logo strong, .editor-title strong {
  display: block;
  margin-top: 1px;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.nav a {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
}
.nav a:hover {
  color: var(--ink);
  background: var(--card);
  border-color: var(--line);
}

.piece {
  width: min(var(--page), calc(100% - 40px));
  margin: 22px auto 0;
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.piece-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.piece-head > div { min-width: 0; }
.index {
  display: block;
  padding-bottom: 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
}
.kicker { margin: 0; }
.piece-head h2 {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}
.counter {
  align-self: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 12px;
  font-weight: 700;
}
.piece-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 22px;
  align-items: start;
}
.stage { min-width: 0; }
.viewport {
  position: relative;
  height: min(48vh, 440px);
  overflow: hidden;
  border-radius: 20px;
  background:
    radial-gradient(420px 180px at 50% 42%, rgba(197, 107, 74, 0.08), transparent 70%),
    #f7f2eb;
}
.track { position: absolute; inset: 0; touch-action: pan-y; }
.slide {
  position: absolute;
  left: 50%;
  top: 50%;
  height: 86%;
  width: auto;
  max-width: 68%;
  aspect-ratio: var(--card, 5 / 4);
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 14px 32px rgba(80, 52, 32, 0.1);
  transform: translate(-50%, -50%) translateX(calc(var(--offset, 0) * 74% + var(--drag, 0px))) scale(var(--scale, 0.84));
  opacity: var(--fade, 0.4);
  transition: transform 0.45s cubic-bezier(.2,.8,.2,1), opacity 0.45s ease;
}
.track:active .slide { transition: none; }
.slide.is-active { --scale: 1; --fade: 1; z-index: 3; }
.slide.is-near { --scale: 0.84; --fade: 0.5; z-index: 2; cursor: pointer; }
.slide.is-far { --fade: 0; pointer-events: none; }
.slide img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.slide.plus {
  display: grid;
  place-items: center;
  background: #fffdfb;
  border: 1.5px dashed #e4cfc4;
  box-shadow: none;
}
.plus-btn {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--accent);
}
.plus-btn span {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 40px;
  line-height: 1;
}
.plus-btn small { display: block; color: var(--muted); letter-spacing: 0.08em; }
.arrow {
  position: absolute;
  top: 50%;
  z-index: 4;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: rgba(255, 252, 249, 0.94);
  color: var(--ink);
  font-size: 22px;
  border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(80, 52, 32, 0.08);
}
.arrow:hover { border-color: #d9c8b8; }
.arrow.prev { left: 12px; }
.arrow.next { right: 12px; }
.piece-actions, .bar-actions, .person { display: flex; flex-wrap: wrap; gap: 8px; }
.piece-actions { justify-content: center; margin-top: 14px; }
.btn {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { border-color: #d9c8b8; }
.btn.gold {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.btn.gold:hover { background: var(--accent-deep); }
.btn.ghost { background: #f7f2eb; }
.btn.ghost:hover { background: #fff; }
.btn.danger { color: var(--danger); background: #fff; }
.btn.danger:hover { background: #fff6f5; border-color: #f0c9c4; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.reference { margin: 0; }
.reference-frame {
  padding: 8px;
  border-radius: 18px;
  background: #f7f2eb;
}
.reference-frame img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
}
figcaption { margin-top: 8px; text-align: center; }
.status-line, #statusText {
  width: min(var(--page), calc(100% - 40px));
  margin: 16px auto 36px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.longpress {
  width: min(520px, 100%);
  margin: 14px auto 0;
  padding: 14px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
}
.longpress p { margin: 0 0 10px; color: var(--accent-deep); }
.longpress img { max-height: 46vh; border-radius: 12px; background: #fff; }
.longpress a { color: var(--accent-deep); }

.lightbox {
  width: min(1080px, calc(100% - 28px));
  padding: 14px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(63, 54, 47, 0.16);
}
.lightbox::backdrop { background: rgba(63, 54, 47, 0.28); }
.lightbox img {
  width: 100%;
  height: min(74vh, 760px);
  max-height: calc(100svh - 120px);
  object-fit: contain;
  background: #f7f2eb;
  border-radius: 14px;
}
.lightbox-caption { display: flex; justify-content: space-between; gap: 12px; padding: 12px 6px 4px; }
#closePreview {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
}

.editor-body { min-height: 100vh; }
.editor-bar { align-items: center; }
.editor-title { min-width: 0; flex: 1 1 auto; }
.editor-title strong { font-size: 18px; }
.editor-title strong,
.editor-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editor-title span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.bar-actions { flex: 0 0 auto; }
.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 48px;
}
.canvas-wrap {
  min-width: 0;
  padding: 8px 4px 16px;
}
.stage-view,
.board-shell { min-width: 0; width: 100%; }
.board-shell { display: flex; flex-direction: column; align-items: center; }
.board {
  margin-inline: auto;
  position: relative;
  width: min(100%, calc((100vh - 250px) * var(--ar, 1.25)));
  width: min(100%, calc((100dvh - 250px) * var(--ar, 1.25)));
  aspect-ratio: var(--ar, 1.25);
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 16px 36px rgba(80, 52, 32, 0.1);
}
body.is-record .editor-grid {
  width: min(1520px, calc(100% - 28px));
  grid-template-columns: minmax(0, 1fr) 232px;
  padding-top: 12px;
}
body.is-record .canvas-wrap { padding: 0 0 8px; }
body.is-record .board {
  width: min(100%, 960px);
}
.slot { position: absolute; overflow: visible; touch-action: none; }
.photo { position: absolute; overflow: hidden; }
.slot.is-round .photo,
.slot.is-round .empty { border-radius: 50%; }
.slot.is-round::after {
  content: "";
  position: absolute;
  left: -2%;
  top: -2%;
  width: 104%;
  height: 104%;
  border: 1px solid rgba(34, 34, 34, 0.55);
  border-radius: 50%;
  pointer-events: none;
}
.border-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 520px);
  margin: 16px auto 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
}
.border-bar[hidden] { display: none; }
.border-bar span,
.border-bar output { color: var(--muted); font-size: 13px; }
.border-track {
  position: relative;
  flex: 1;
  height: 28px;
  touch-action: none;
  cursor: ew-resize;
}
.border-track::before {
  content: "";
  position: absolute;
  left: 11px;
  right: 11px;
  top: 50%;
  height: 3px;
  border-radius: 3px;
  background: #ead9d0;
  transform: translateY(-50%);
}
.border-knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(197, 107, 74, 0.35);
  transform: translateY(-50%);
  cursor: ew-resize;
  touch-action: none;
}
.slot.is-person { z-index: 3; pointer-events: none; }
.slot.is-person img,
.slot.is-person .slot-x { pointer-events: auto; }
.slot img { position: absolute; max-width: none; user-select: none; touch-action: none; }
.empty {
  width: 100%;
  height: 100%;
  border: 0;
  background: #f6f1ea;
  color: #a89888;
}
.empty b { display: block; font-size: 26px; font-weight: 400; color: var(--accent); }
.empty span { font-size: 12px; }
.slot-x, .badge { display: none; }
body.is-record .slot.is-filled .slot-x,
body.is-music-player .slot.is-filled .slot-x {
  display: grid;
  place-items: center;
  position: absolute;
  z-index: 5;
  top: 4%;
  right: 4%;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgba(63, 54, 47, 0.82);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(80, 52, 32, 0.28);
}
body.is-record .slot.is-filled .slot-x:hover,
body.is-music-player .slot.is-filled .slot-x:hover { background: var(--danger); }
.board.is-music-player .music-player-artwork {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.board.is-music-player .slot.is-round::after { display: none; }
.board.is-music-player .empty { background: transparent; }
.board.is-music-player .empty b { font-size: clamp(14px, 2vw, 24px); }
.board.is-music-player .slot.is-selected { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
.replace-song-option { display: flex; align-items: flex-start; gap: 6px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.replace-song-option[hidden] { display: none; }
.replace-song-option input { flex: none; margin-top: 3px; }
.song-controls { display: grid; gap: 10px; min-width: 0; }
.song-controls[hidden] { display: none; }
.song-controls h3 { margin: 0; font-size: 14px; font-weight: 600; }
.song-controls label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.song-controls input,
.song-controls select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}
.song-controls input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.song-controls input:disabled { opacity: 0.55; }
.song-progress-control { display: grid; gap: 5px; }
.song-progress-inputs { display: flex; align-items: center; gap: 7px; min-width: 0; }
.song-progress-inputs input[type="range"] {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  min-height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}
.song-progress-inputs input[type="number"] { flex: 0 0 62px; width: 62px; padding-inline: 6px; }
.song-progress-inputs span,
.song-progress-control output { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.song-note { margin: 0; font-size: 11px; line-height: 1.6; color: var(--muted); }
.layout-name { display: block; margin-top: 7px; font-size: 11px; line-height: 1.4; white-space: nowrap; }
body.is-music-player .editor-side { max-height: calc(100dvh - 102px); overflow-y: auto; }
@media (min-width: 981px) {
  body.is-music-player .editor-side .reference { display: none; }
}
@media (max-width: 980px) {
  .song-controls { order: 1; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); }
  body.is-music-player .editor-side { max-height: none; overflow: visible; }
  body.is-music-player .editor-side .reference { display: none; }
}
@media (pointer: coarse) {
  body.is-record .slot.is-filled .slot-x,
  body.is-music-player .slot.is-filled .slot-x { width: 32px; height: 32px; }
}
.slot.is-filled .photo { cursor: grab; }
.slot.is-source,
.slot.is-target { z-index: 4; }
.slot.is-source { outline: 2px solid var(--accent); cursor: grabbing; }
.slot.is-target { outline: 3px solid var(--accent-deep); }
.drag-ghost {
  position: fixed;
  z-index: 30;
  width: 84px;
  height: 84px;
  margin: -42px 0 0 -42px;
  border: 2px solid #fff;
  border-radius: 10px;
  object-fit: cover;
  pointer-events: none;
  box-shadow: 0 12px 28px rgba(80, 52, 32, 0.28);
}
.zoom {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}
.zoom button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 22px;
}
.zoom button:hover { border-color: #d9c8b8; }
#statusText { margin: 16px 0 0; width: 100%; }
.upload-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 14px;
}
.upload-bar .btn { flex: 0 0 auto; }
.upload-bar #statusText { margin: 0; flex: 1 1 auto; min-width: 0; }
.cover-search {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
}
.cover-panel[hidden] { display: none; }
.cover-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cover-panel .cover-search {
  flex-direction: column;
  align-items: stretch;
  margin-top: 0;
  gap: 8px;
}
.cover-search textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  max-height: 96px;
  margin: 0;
  padding: 8px 14px;
  resize: none;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  line-height: 1.4;
}
.cover-panel .cover-search textarea,
.cover-panel .cover-search .btn {
  width: 100%;
  border-radius: 16px;
}
.cover-search textarea:focus {
  outline: none;
  border-color: #d9c8b8;
}
.cover-search .btn { flex: 0 0 auto; }
.cover-panel #statusText {
  margin: 0;
  width: auto;
  flex: none;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.editor-side {
  position: sticky;
  top: 86px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.editor-side .reference-frame img { max-height: 240px; }
.editor-tools:has(#personControls[hidden]) { display: none; }
@media (min-width: 981px) {
  .editor-side .editor-tools {
    padding-top: 16px;
    border-top: 1px solid var(--line);
  }
}
.layout-block {
  grid-column: 1 / -1;
  position: relative;
  padding: 16px 18px 20px;
  border: 1px solid #ececef;
  border-radius: 20px;
  background: #fff;
}
.layout-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.ratio-chips {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 6px;
  min-width: 0;
}
.ratio-chip {
  position: relative;
  min-width: 36px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  background: #fff;
  color: #b4b4ba;
  font-size: 12px;
  font-weight: 550;
  line-height: 1;
}
.ratio-chip.is-active {
  border-color: #2c2c2c;
  color: #2c2c2c;
}
.ratio-chip.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: #2c2c2c;
  transform: translateX(-50%);
}
.recipe-btn {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
  height: 28px;
  padding: 0 12px 0 14px;
  border: 0;
  border-radius: 999px;
  background: #f2f2f4;
  color: #3a3a3a;
  font-size: 13px;
  font-weight: 650;
}
.recipe-btn[aria-expanded="true"] { background: #e7e7ea; }
.recipe-btn i {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent currentColor;
}
.recipe-menu {
  position: absolute;
  z-index: 6;
  top: 48px;
  right: 18px;
  width: min(240px, calc(100% - 36px));
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}
.recipe-menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: 13px;
}
.recipe-menu button.is-active,
.recipe-menu button:hover { background: #f6f6f7; }
.layouts {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 22px 18px;
}
.layout {
  width: 72px;
  flex: 0 0 72px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
}
.wire {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.wire line,
.wire rect,
.wire circle,
.wire ellipse {
  fill: none;
  stroke: #c2c2c8;
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
}
.layout:hover .wire line,
.layout:hover .wire rect,
.layout:hover .wire circle,
.layout:hover .wire ellipse { stroke: #8e939b; }
.layout.is-active .wire line,
.layout.is-active .wire rect,
.layout.is-active .wire circle,
.layout.is-active .wire ellipse { stroke: #2a2a2a; }
.person { align-items: center; }
.shadow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  color: var(--muted);
  font-size: 13px;
}
.shadow input { flex: 1 1 120px; min-width: 0; accent-color: var(--accent); }

.browser-guard {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(63, 54, 47, 0.28);
}
.browser-guard-card {
  width: min(440px, 100%);
  padding: 28px 22px;
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  box-shadow: var(--shadow);
}
.browser-guard-card h1 { margin: 0 0 8px; font-weight: 650; }
.browser-guard-card code {
  display: block;
  margin: 14px 0;
  padding: 10px;
  border-radius: 10px;
  background: #f7f2eb;
  word-break: break-all;
  font-size: 12px;
}
.browser-guard-card button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

@media (max-width: 980px) {
  .top, .editor-bar {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .piece, .status-line { width: min(720px, calc(100% - 24px)); }
  .editor-grid { width: calc(100% - 24px); }
  .piece { padding: 16px; border-radius: 20px; }
  .piece-body, .editor-grid { grid-template-columns: 1fr; }
  .editor-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }
  .editor-side { display: contents; }
  .cover-panel { order: 1; }
  .reference { order: 1; }
  .canvas-wrap { order: 2; }
  .editor-tools { order: 4; }
  .layout-block { order: 3; }
  .reference,
  .canvas-wrap,
  .editor-tools {
    width: 100%;
    align-self: stretch;
  }
  .reference,
  .editor-tools {
    margin: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--card);
    box-shadow: var(--shadow);
  }
  .piece-body > .reference {
    order: -1;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  .piece-head h2, .logo strong { font-size: 18px; }
  .viewport { height: clamp(240px, 62vw, 420px); }
  .reference-frame img, .editor-side .reference-frame img { max-height: min(42vh, 280px); }
  .board {
    width: min(100%, calc((100vh - 220px) * var(--ar, 1.25)));
    width: min(100%, calc((100svh - 220px) * var(--ar, 1.25)));
  }
  .status-line { margin-left: auto; margin-right: auto; }
  .layout-bar { align-items: flex-start; margin-bottom: 16px; }
  .ratio-chips {
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 2px 10px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
  }
  .ratio-chips::-webkit-scrollbar { display: none; }
  .ratio-chip { flex: 0 0 auto; }
  .layouts {
    flex-wrap: nowrap;
    align-items: center;
    gap: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 14px 2px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
  }
  .layouts::-webkit-scrollbar { display: none; }
}

@media (max-width: 720px) {
  .top {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px;
  }
  .nav {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .editor-bar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
  }
  .bar-actions { display: none; }
  body.is-music-player .editor-bar { flex-wrap: wrap; }
  body.is-music-player .bar-actions {
    display: flex;
    flex: 1 1 100%;
    justify-content: flex-end;
  }
  body.is-music-player .bar-actions .btn { min-height: 36px; padding-inline: 12px; font-size: 12px; }
  .upload-bar { flex-wrap: wrap; }
  .upload-bar .btn { width: 100%; }
  .cover-search { flex-wrap: wrap; }
  .cover-search textarea { border-radius: 16px; }
  .cover-search .btn { width: 100%; }
  .editor-title { display: block; min-width: 0; }
  .editor-title strong { font-size: 14px; }
  .editor-title span { font-size: 11px; }
  .editor-title strong,
  .editor-title span {
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
  }
  .piece-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .piece-actions .btn { width: 100%; }
  .slide { max-width: 82%; }
  .layout-block { padding: 14px 14px 16px; }
  .layout { width: 58px; flex-basis: 58px; }
  .layouts { gap: 16px 12px; }
  .lightbox { width: calc(100% - 16px); max-height: calc(100svh - 16px); }
  .lightbox-caption { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 420px) {
  .piece, .status-line, .editor-grid { width: calc(100% - 16px); }
  .piece { padding: 14px; }
  .piece-head { gap: 8px; }
  .piece-head h2 { font-size: 17px; }
  .logo small { display: none; }
  .viewport { height: clamp(220px, 70vw, 320px); }
  .plus-btn span { width: 64px; height: 64px; font-size: 32px; }
  .arrow { width: 34px; height: 34px; }
}

@media (pointer: coarse) {
  .btn, .nav a, .zoom button, .arrow { min-height: 44px; }
  .zoom button, .arrow { width: 44px; height: 44px; }
  .slot-x, .badge { width: 32px; height: 32px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 250px);
    align-items: start;
    gap: 18px;
  }
  .editor-side {
    display: flex;
    order: 0;
    position: sticky;
    top: 72px;
    max-height: calc(100svh - 84px);
    overflow: auto;
  }
  .reference,
  .editor-tools,
  .canvas-wrap { order: 0; }
  .reference,
  .editor-tools {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  .board {
    width: min(100%, calc((100vh - 140px) * var(--ar, 1.25)));
    width: min(100%, calc((100svh - 140px) * var(--ar, 1.25)));
  }
  .viewport { height: min(58vh, 280px); }
  .editor-side .reference-frame img { max-height: 120px; }
}
