:root {
  color-scheme: dark;
  --page: #120809;
  --panel: #211012;
  --field: #170b0d;
  --subtle: #32171a;
  --line: #5b3035;
  --ink: #fff5f4;
  --muted: #d7b7b9;
  --accent: #c44643;
  --accent-text: #ffc0bb;
  --selected: #4a2025;
  --gutter: clamp(10px, 2vw, 28px);
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
[hidden] { display: none !important; }
a { color: var(--accent-text); }
p { line-height: 1.5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link {
  position: fixed; z-index: 20; top: 8px; left: max(8px, env(safe-area-inset-left));
  transform: translateY(calc(-100% - 16px)); padding: 10px 14px;
  border: 2px solid var(--ink); border-radius: 6px; background: var(--panel);
  color: var(--ink); font-size: 13px; font-weight: 650;
}
.skip-link:focus-visible { transform: none; }
button svg {
  width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

.topbar { min-height: 61px; background: linear-gradient(180deg, #2b1518, var(--panel)); border-bottom: 1px solid #71383f; }
.bar-inner, .workspace { max-width: 1340px; margin: auto; padding-inline: var(--gutter); }
.bar-inner { min-height: inherit; display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; margin: 0; flex: 0 0 auto; font-weight: 740; font-size: 17px; letter-spacing: -.035em; white-space: nowrap; }
.brand img { display: block; flex: none; width: 34px; height: 34px; border-radius: 50%; box-shadow: 0 2px 9px #0005; }
.brand-wordmark > span { color: #d5b8bb; font-weight: 520; }
.bar-actions { margin-left: auto; display: flex; gap: 8px; flex: 0 0 auto; min-width: 0; }
.button, .icon-button {
  display: inline-flex; justify-content: center; align-items: center; gap: 7px;
  min-height: 36px; padding: 6px 11px; border: 1px solid var(--line);
  background: var(--subtle); color: var(--ink); border-radius: 7px; font-size: 13px; font-weight: 620; white-space: nowrap;
}
.button:hover, .icon-button:hover { background: #472126; border-color: #80444b; }
.button.primary { background: var(--accent); color: white; border-color: var(--accent); }
.button.primary:hover { background: #a92f2d; border-color: #a92f2d; }
.icon-button { width: 36px; min-height: 36px; padding: 0; }
.button svg, .icon-button svg { width: 15px; height: 15px; }

.workspace { padding-top: 18px; }
.project-button { max-width: 240px; min-width: 0; min-height: 36px; background: transparent; border-color: transparent; color: var(--muted); }
.project-button span { overflow: hidden; text-overflow: ellipsis; }
.project-dots { margin-left: 3px; color: var(--muted); }

.work-grid { display: grid; grid-template-columns: minmax(0, 2.15fr) minmax(310px, 1fr); gap: 14px; align-items: start; }
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 13px; min-width: 0; }
.segmented { display: inline-flex; gap: 2px; max-width: 100%; padding: 3px; background: var(--field); border: 1px solid var(--line); border-radius: 7px; }
.segmented button {
  color: var(--muted); background: transparent; border: 0; border-radius: 4px;
  padding: 6px 10px; min-height: 34px; font-size: 12px; font-weight: 620; white-space: nowrap;
}
.segmented button[aria-pressed=true] { background: var(--subtle); color: var(--ink); box-shadow: inset 0 -2px #ef6961; }
.segmented button:hover { color: var(--ink); }
.preview-mat { margin: 0 13px; min-height: 90px; padding: 13px 23px; display: grid; place-items: center; border: 1px solid #4e272c; border-radius: 6px; background: var(--field); }

.screen{container-type:inline-size;position:relative;width:100%;max-width:810px;aspect-ratio:960/544;overflow:hidden;background:#341217;border-radius:5px;border:1px solid #67343b;color:white;box-shadow:0 4px 14px #0006;isolation:isolate}.screen .status-bar{position:absolute;z-index:4;inset:0 0 auto;height:8.09%;display:flex;align-items:center;justify-content:space-between;padding:0 2.3%;background:#260d12;color:#fff0f0;font-size:1.62cqw;font-weight:650}.status-bar span:last-child{display:flex;align-items:center;gap:1cqw}.status-bar .battery{display:block;width:2.8cqw;height:1.3cqw;border:1px solid #ffe3e0;border-radius:.2cqw;background:linear-gradient(90deg,#f08f85 82%,transparent 82%);box-shadow:0 0 .3cqw #f3aaa3}.livearea-card{position:absolute;left:6.25%;top:8.09%;width:87.5%;height:91.91%;overflow:hidden;background:radial-gradient(ellipse at 70% 20%,#9c4b55,#59232b 55%,#2e1117);border-radius:2.4cqw 2.4cqw 0 0}.screen-image,.livearea-card>img,.frame-region img,.gate-region img{width:100%;height:100%;object-fit:fill;display:block}.screen-image{position:absolute;inset:0}.frame-region,.gate-region{position:absolute;display:grid;place-items:center}.gate-region{background:#6f3038ba;border:1px solid #f2b1b56b;border-radius:1cqw;overflow:hidden}.gate-region img{position:absolute;inset:0}.start-chip{position:absolute;left:28.57%;bottom:5.06%;width:42.86%;height:20.25%;display:grid;place-items:center;background:linear-gradient(#fff7f6,#f0d9d8);border-radius:.45cqw;color:#6a252d;box-shadow:0 1px 3px #260a10a8;font-weight:800;font-size:1.8cqw}.frame-text{position:absolute;left:2%;right:2%;bottom:5%;text-align:center;color:#fff;font-weight:700;line-height:1.1;text-shadow:0 1px 3px #000,0 0 4px #000;overflow:hidden;max-height:95%;overflow-wrap:anywhere}.frame-text[data-align=left]{text-align:left}.frame-text[data-align=right]{text-align:right}.frame-text[data-valign=top]{bottom:auto;top:5%}.frame-text[data-valign=center]{bottom:50%;transform:translateY(50%)}
.bubble-backdrop{height:100%;display:grid;place-items:center;background:radial-gradient(ellipse at 20% 100%,#9f4652,transparent 60%),linear-gradient(135deg,#321017,#8e3b46 70%,#3c1119)}.bubble-stack{display:grid;gap:1.5cqw;place-items:center;font-size:2.3cqw;font-weight:690}.bubble-icon{display:grid;place-items:center;width:13.33cqw;aspect-ratio:1;border-radius:50%;background:#a33f4b;overflow:hidden;box-shadow:0 .6cqw 1.5cqw #21070da0,inset 0 0 0 .15cqw #fff8}.bubble-icon img{width:100%;height:100%}.empty-screen{position:absolute;inset:0;display:grid;place-content:center;justify-items:center;gap:1.2cqw;color:#fff2f1;text-align:center;font-size:2.25cqw}.empty-screen span{font-size:1.7cqw;color:#e1b9bd}.livearea-card .empty-screen{inset:0 0 auto;height:20%}
/* 128px Vita home art on a 960px reference screen. These effects never alter PNG exports. */
.bubble-backdrop {
  background:
    radial-gradient(ellipse at 19% 110%, #aa4a57 0%, transparent 59%),
    radial-gradient(ellipse at 88% 10%, #db6b7460 0%, transparent 58%),
    linear-gradient(135deg, #321016, #963d49 70%, #48141c);
}
.bubble-stack {
  position: relative;
  z-index: 1;
  gap: 1.6cqw;
  max-width: calc(100% - 20px);
  text-align: center;
  font-size: clamp(11px, 2.3cqw, 24px);
  line-height: 1.2;
}
.bubble-stack > span {
  max-width: min(70cqw, 100%);
  overflow-wrap: anywhere;
  text-shadow: 0 .12cqw .45cqw #21080ed9;
}
.bubble-icon {
  position: relative;
  isolation: isolate;
  width: 13.3333cqw;
  height: 13.3333cqw;
  flex: none;
  color: #fff;
  border: .16cqw solid #ffd8d4cc;
  border-radius: 50%;
  text-shadow: 0 1px 3px #2a0910;
  background: radial-gradient(circle at 35% 24%, #f58f91, #b94753 58%, #6a1f2b 100%);
  box-shadow:
    0 1.05cqw 1.8cqw -.18cqw #250810c9,
    0 .2cqw .42cqw #19050b99,
    0 0 0 .22cqw #8c303b66,
    inset 0 -.88cqw 1.25cqw #4d111b9c,
    inset 0 .18cqw .28cqw #fff1e8a3;
  transform: translateZ(0);
}
.bubble-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.bubble-icon::before,
.bubble-icon::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.bubble-icon::before {
  z-index: 1;
  top: 2%;
  left: 7%;
  width: 86%;
  height: 55%;
  border-radius: 50% 50% 44% 44% / 58% 58% 45% 45%;
  background:
    radial-gradient(ellipse at 36% 13%, #ffffffd8 0 8%, transparent 24%),
    linear-gradient(180deg, #ffffffbd 0%, #fff0ea73 30%, #ffffff12 79%, transparent 100%);
  transform: rotate(-4deg);
  filter: blur(.01px);
}
.bubble-icon::after {
  z-index: 2;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(ellipse at 50% 116%, #4b101a8c, transparent 58%),
    radial-gradient(circle at 18% 48%, #ffffff24, transparent 24%),
    linear-gradient(90deg, #49101a4f, transparent 17% 83%, #3a0d164d);
  box-shadow: inset 0 .14cqw .28cqw #fff5ef9c, inset 0 -.92cqw .9cqw #4c111d99;
}
/* Firmware keeps the gate's dimensions and position style-defined; these are surface details only. */
.gate-region {
  background: #52222a;
  border-color: #f1c4c485;
  border-radius: .8cqw;
  box-shadow: 0 .18cqw .5cqw #220a08a6, inset 0 0 0 .12cqw #34191760;
}
.start-chip {
  border: .08cqw solid #ffffffba;
  background: linear-gradient(180deg, #fff 0%, #fff3f2 42%, #edd4d4 100%);
  color: #6c2830;
  border-radius: .45cqw;
  box-shadow: 0 .12cqw .32cqw #2a161099, inset 0 .1cqw .08cqw #fff;
  font-weight: 760;
  font-size: clamp(8px, 1.8cqw, 16px);
  letter-spacing: -.01em;
  line-height: 1;
  text-shadow: 0 .06cqw #ffffffbf;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.gate-region:has(img) {
  /* Keep the native image alpha visible over the LiveArea background. */
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.preview-foot {
  min-height: 43px; padding: 6px 13px; display: flex; align-items: center; justify-content: space-between;
  gap: 6px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums;
}
.preview-foot #view-caption { min-width: 0; overflow-wrap: anywhere; }
.text-button { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; border: 0; background: transparent; color: var(--accent-text); padding: 7px 2px; font-size: 12px; font-weight: 620; white-space: nowrap; }
.text-button:hover { text-decoration: underline; }
.text-button svg { width: 13px; height: 13px; }
.style-choice {
  border: 1px solid var(--line); background: var(--field); color: var(--muted); border-radius: 6px;
  padding: 5px 6px; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 12px; font-weight: 620; white-space: nowrap; min-height: 38px;
}
.style-choice:hover { border-color: #8f4d54; color: var(--ink); }
.style-choice[aria-pressed=true] { border-color: #a74b4e; background: var(--selected); color: var(--ink); }
.style-icon { position: relative; display: block; width: 30px; height: 18px; border: 1px solid #8b4b52; border-radius: 2px; background: #241013; flex: none; overflow: hidden; }
.style-icon i { position: absolute; border: 1px solid #98535b; background: #52262b; }
.style-icon i.gate { border-color: #c87a77; background: #643b40; }

.editor-content { padding: 13px 13px 16px; }
.asset-list { border-top: 1px solid var(--line); }
.asset-row.drag, #import-vpk.drag, .livearea-card.drag { outline: 1px solid #a74b4e; outline-offset: -1px; }
.thumb { width: 38px; height: 36px; border-radius: 5px; background: var(--field); color: var(--muted); display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.65; }
.asset-name { font-size: 13px; font-weight: 620; display: block; }
.asset-spec { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; color: var(--muted); margin-top: 2px; font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.asset-actions .icon-button { width: 34px; min-height: 36px; border-color: transparent; background: transparent; color: var(--muted); }
.asset-actions .icon-button:hover { color: var(--accent-text); background: var(--selected); }
.subsection { margin-top: 11px; border-top: 1px solid var(--line); padding-top: 10px; }
.asset-list + .subsection { border-top: 0; margin-top: 0; }
.subsection summary { font-size: 12px; font-weight: 620; cursor: pointer; }
.subsection p { color: var(--muted); font-size: 12px; margin: 7px 0; }
.field { display: grid; gap: 5px; margin: 9px 0; font-size: 12px; font-weight: 620; }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--ink);
  padding: 7px 8px; min-height: 35px; font-size: 13px;
}
.field input[type=color] { padding: 2px; width: 54px; }
.field-row { display: flex; gap: 9px; }
.field-row > .field { flex: 1; min-width: 0; }
.package-info { margin: 10px 0 0; display: grid; gap: 3px; }
.package-info div { display: flex; justify-content: space-between; gap: 6px; border-bottom: 1px solid var(--line); padding: 6px 0; font-size: 12px; }
.package-info span { color: var(--muted); }
.package-info b { text-align: right; overflow-wrap: anywhere; }
.task-intro {
  display: grid; gap: 2px; margin: 7px 0 10px; padding: 9px 10px;
  border: 1px solid #572b32; border-radius: 7px; background: #241013;
}
.task-intro strong { font-size: 13px; color: #fff4f2; }
.task-intro span { color: var(--muted); font-size: 11px; line-height: 1.4; }
.empty-task {
  display: grid; gap: 8px; margin-top: 10px; padding: 12px;
  border: 1px dashed #704049; border-radius: 8px; background: #1a0c0f;
}
.empty-task strong { font-size: 14px; }
.empty-task p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.empty-task .button { justify-self: start; }
.package-card {
  display: grid; gap: 10px; margin-top: 10px; padding: 12px;
  border: 1px solid #62323a; border-radius: 8px;
  background: linear-gradient(145deg, #30151a, #1c0d10 70%);
}
.package-main { display: grid; gap: 3px; min-width: 0; }
.package-main > span { color: var(--muted); font-size: 11px; }
.package-main > strong { font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.package-main > small { color: #ddb9bb; font-size: 11px; overflow-wrap: anywhere; }
.package-card > .button { justify-self: start; }
.package-status {
  margin: 0; padding: 7px 8px; border-radius: 6px;
  background: #432026; color: #f4d4d2; font-size: 11px; line-height: 1.4;
}
.package-advanced, .simple-advanced, .metadata-advanced { margin-top: 10px; }
.compatibility-tools { margin: 0; padding: 0; border: 0; }
.metadata-advanced {
  padding: 10px; border: 1px solid #5a2d34; border-radius: 7px;
  background: #1b0d10;
}
.metadata-advanced > summary { min-height: 34px; display: flex; align-items: center; }
.metadata-advanced:not([open]) > :not(summary) { display: none !important; }
.step-explainer {
  display: grid; gap: 2px; margin: 2px 0 8px; padding: 8px 9px;
  border-radius: 7px; background: #241013; border: 1px solid #53282f;
}
.step-explainer strong { font-size: 12px; color: #fff3f1; }
.step-explainer span { color: var(--muted); font-size: 11px; line-height: 1.35; }
.expert-settings {
  margin-top: 8px; padding: 8px 9px; border: 1px solid #51282f;
  border-radius: 7px; background: #180b0e;
}
.expert-settings > summary { min-height: 32px; display: flex; align-items: center; color: #e6c5c6; }
.expert-settings:not([open]) > :not(summary) { display: none !important; }
.advanced-card {
  margin-top: 8px; padding: 9px 10px; border: 1px solid #51282f;
  border-radius: 7px; background: #180b0e;
}
.advanced-card h3 { margin: 0 0 5px; font-size: 12px; }
.compact-advanced { display: grid; gap: 7px; }
.compact-advanced .field { margin: 0; }
.compact-advanced .button { justify-self: start; }
.compact-setting {
  grid-template-columns: minmax(72px, auto) minmax(0, 1fr);
  align-items: center; margin-top: 7px;
}
.tool-page { min-width: 0; }
.inline-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.notice { color: #f3ce9e; background: #352719; border: 1px solid #59452e; padding: 8px; border-radius: 6px; font-size: 12px; margin: 9px 0; }
.launch-tools {
  margin-top: 13px;
  padding: 12px;
  border: 1px solid #493238;
  border-radius: 8px;
  background: linear-gradient(135deg, #2c191e 0%, #20191e 54%, #1e1718 100%);
}
.launch-tools h2 { flex-wrap: wrap; line-height: 1.35; }
.launch-tools h2 small { line-height: 1.35; }
.launch-tools .asset-spec { color: #c9bfc4; line-height: 1.5; }
.launch-tools .inline-actions > .button {
  flex: 1 1 132px;
  min-width: 0;
  white-space: normal;
  text-align: center;
}
#dialog:has(#gate-art-form) { width: min(520px, calc(100% - 24px)); }
#dialog:has(#gate-art-form) .preview-mat {
  border-color: #6e4148;
  background: #181111;
}
#gate-art-canvas { box-shadow: 0 6px 20px #0007; }
#gate-art-canvas:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 3px; }
#gate-art-form { display: grid; gap: 3px; margin-top: 12px; }
#gate-art-form .field-row { flex-wrap: wrap; }
#gate-art-form .field-row > .field { flex: 1 1 145px; }
#gate-art-form input[type=number] { font-variant-numeric: tabular-nums; }
#gate-art-form input[type=range] {
  width: 100%; min-height: 44px; padding: 0; accent-color: var(--accent);
  cursor: ew-resize; touch-action: pan-y;
}
#gate-art-form .inline-actions > .button { flex: 1 1 110px; min-width: 0; }
#gate-art-form .asset-spec { line-height: 1.5; }

footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 1px 18px; color: var(--muted); font-size: 11px; }
footer .text-button { font-size: 11px; }
dialog { width: min(540px, calc(100% - 28px)); max-width: calc(100% - 24px); max-height: min(90vh, 90dvh); overflow-y: auto; overscroll-behavior: contain; padding: 0; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--panel); box-shadow: 0 16px 65px #0009; }
dialog::backdrop { background: #060202b8; }
dialog.wide { width: min(1020px, calc(100% - 30px)); }
.dialog-head { position: sticky; z-index: 5; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 13px; border-bottom: 1px solid var(--line); background: var(--panel); }
.dialog-head h2 { font-size: 16px; margin: 0; }
.dialog-content { min-width: 0; padding: 12px 13px 14px; overflow-wrap: anywhere; }
.dialog-content > p:first-child { margin-top: 0; }
.dialog-content p { font-size: 13px; color: var(--muted); }
.dialog-content .preview-mat { margin: 0; }
.dialog-content .screen { max-width: none; }
.export-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; align-items: center; padding: 9px; border: 1px solid var(--line); border-radius: 7px; margin-top: 7px; }
.export-option strong { font-size: 13px; }
.export-option p { font-size: 12px; margin: 3px 0 0; }
.export-option .button { font-size: 12px; }
.xml-view { font: 12px/1.5 Consolas, monospace; width: 100%; min-height: 230px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--ink); padding: 8px; resize: vertical; white-space: pre; }
.toast { position: fixed; z-index: 10; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); padding: 10px 14px; border: 1px solid #594a4b; border-radius: 7px; color: var(--ink); background: var(--subtle); box-shadow: 0 4px 15px #0006; font-size: 13px; max-width: calc(100% - 24px); width: max-content; overflow-wrap: anywhere; }
.toast.error { background: #4b2027; border-color: #82414b; }

@media (max-width: 940px) {
  .work-grid { gap: 10px; grid-template-columns: minmax(0, 1.7fr) minmax(290px, 1fr); }
  .preview-mat { padding: 12px 16px; }
}
@media (max-width: 720px) {
  .topbar { min-height: 54px; }
  .workspace { padding-top: 12px; }
  .work-grid { grid-template-columns: 1fr; }
  .screen { max-width: none; }
}
@media (max-width: 690px) {
  .bar-inner { flex-wrap: wrap; column-gap: 10px; row-gap: 5px; padding-block: 7px; }
  .project-button { flex: 1 1 120px; max-width: none; justify-content: flex-start; }
  .bar-actions { flex: 1 1 100%; margin-left: 0; justify-content: flex-end; }
}
@media (max-width: 480px) {
  .preview-toolbar { flex-wrap: wrap; }
  .segmented { width: 100%; justify-content: space-between; }
  .segmented button { flex: 1 1 0; min-width: 0; white-space: normal; text-align: center; }
  .preview-actions { flex: 1 1 100%; justify-content: flex-end; }
  .export-option { grid-template-columns: minmax(0, 1fr); }
  .export-option .button { justify-self: stretch; }
}
@media (max-width: 430px) {
  .bar-inner { column-gap: 7px; }
  .brand { gap: 6px; font-size: 15px; }
  .brand img { width: 28px; height: 28px; border-radius: 50%; }
  .bar-actions { gap: 6px; flex-wrap: wrap; }
  .bar-actions .button { flex: 1 1 auto; gap: 5px; padding-inline: 9px; font-size: 12px; }
  .bar-actions .button svg { width: 14px; height: 14px; }
  .project-button { font-size: 12px; padding-inline: 7px; }
  .preview-toolbar, .preview-foot { padding-inline: 9px; }
  .preview-mat { margin-inline: 9px; padding: 10px 12px; }
  .segmented button { padding-inline: 6px; font-size: 12px; }
}
.preview-actions { display: flex; align-items: center; gap: 6px; }
.preview-actions .button { min-height: 36px; font-size: 12px; }
.preview-actions .button[aria-pressed=true] { border-color: #7b4144; background: var(--selected); }
.preview-foot { margin: 0; }
.frame-art, .frame-guide { position: absolute; }
.frame-art { pointer-events: none; isolation: isolate; }
.frame-art img { width: 100%; height: 100%; object-fit: fill; display: block; }
.frame-art.is-active {
  z-index: 3;
  outline: 2px solid #fff3dd;
  outline-offset: 0;
  box-shadow: 0 0 0 4px #9d2639b8, 0 3px 11px #120d09aa;
}
.frame-art.is-active.is-empty {
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(135deg, #37202b9e 0 7px, #442e3b9e 7px 14px);
}
.frame-art-empty {
  display: block;
  max-width: calc(100% - 12px);
  max-height: calc(100% - 12px);
  padding: 3px 5px;
  overflow: hidden;
  border: 1px dashed #ffe1dcba;
  border-radius: 3px;
  background: #1d1511cc;
  color: #fff4ee;
  font-size: clamp(8px, 1.15cqw, 11px);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
  pointer-events: none;
  user-select: none;
}
.frame-art.is-active.draggable-art {
  pointer-events: auto; touch-action: none; cursor: grab;
}
.frame-art.is-active.draggable-art img { pointer-events: none; user-select: none; -webkit-user-drag: none; }
.frame-art.is-active.draggable-art.drag-in-progress { cursor: grabbing; }
.frame-drag-hint, .gate-drag-hint {
  position: absolute; z-index: 2; top: 5px; left: 5px;
  display: inline-flex; align-items: center; max-width: calc(100% - 10px);
  padding: 3px 5px; border: 1px solid #fff3e76e; border-radius: 4px;
  background: #221110de; color: #fff; font-size: clamp(9px, 1.2cqw, 11px);
  font-weight: 680; line-height: 1.15; letter-spacing: .01em;
  text-align: left; overflow-wrap: anywhere; pointer-events: none; user-select: none;
}
.frame-drag-hint {
  left: auto;
  right: 5px;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gate-region.draggable-gate {
  z-index: 2; height: 31.6%; appearance: none; padding: 0; color: inherit;
  touch-action: none; cursor: grab; font: inherit;
}
.gate-region.draggable-gate.drag-in-progress { z-index: 5; cursor: grabbing; }
.frame-art.draggable-art.drag-in-progress,
.gate-region.draggable-gate.drag-in-progress {
  box-shadow: inset 0 0 0 2px #fff6d3, 0 0 0 2px #2a151b;
}
.gate-region.draggable-gate:focus-visible,
.frame-art.draggable-art:focus-visible {
  outline: 2px solid #fff6d3; outline-offset: -3px;
  box-shadow: inset 0 0 0 2px #291a1a;
}
.frame-guide {
  z-index: 2; display: flex; align-items: flex-start; justify-content: flex-start;
  border: 1px dashed #fff4e992; background: #42302522; padding: 3px; color: #fff; border-radius: 2px;
}
.frame-guide span { display: grid; place-items: center; min-width: 18px; min-height: 18px; padding: 0 3px; background: #231b15ee; border-radius: 3px; font-size: 11px; font-weight: 650; }
.frame-guide:hover, .frame-guide[aria-pressed=true], .frame-guide.drag { background: #f7cce62a; border-color: #fff3fa; }
.frame-guide[aria-pressed=true] span { background: #a52223; }
.frame-guide:focus-visible, .style-launcher:focus-visible { outline-offset: -3px; }
.frame-guide:focus-visible { outline-color: #fff; box-shadow: inset 0 0 0 2px #1c1812; }
.resize-handle {
  position: absolute; z-index: 6; right: -4px; bottom: -4px;
  display: grid; place-items: center; width: 26px; height: 26px;
  padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: #76242f;
  pointer-events: auto; touch-action: none; cursor: nwse-resize;
}
.resize-handle::before {
  content: ""; position: absolute; right: 2px; bottom: 2px;
  width: 23px; height: 23px; border: 2px solid #291720; border-radius: 5px;
  background: linear-gradient(140deg, #fffefa, #f4c5cf);
  box-shadow: 0 2px 8px #100a07c9, 0 0 0 2px #fff3dd;
}
.resize-handle::after {
  content: ""; position: absolute; right: 9px; bottom: 9px;
  width: 9px; height: 9px;
  border-right: 3px solid currentColor; border-bottom: 3px solid currentColor;
}
.resize-handle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 3px #b12639;
}
.frame-art.is-active::after {
  position: absolute; inset: 0; border: 1px dashed #4d1d28;
  content: ""; pointer-events: none;
}
.style-launcher {
  display: grid; width: 100%; grid-template-columns: 60px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  min-height: 58px; border: 0; border-bottom: 1px solid var(--line); color: var(--ink); background: transparent; padding: 12px; text-align: left;
}
.style-launcher:hover { background: var(--subtle); }
.style-launcher .style-icon { width: 60px; height: auto; aspect-ratio: 840 / 500; }
.style-launcher small, .style-launcher strong { display: block; }
.style-launcher small { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.style-launcher strong { font-size: 14px; }
.style-launcher strong span { margin-left: 3px; font-size: 11px; font-weight: 500; color: var(--muted); }
.style-change { border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; font-size: 12px; font-weight: 620; }
.tool-section h2 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 14px; margin: 0 0 8px; }
.tool-section h2 small { font-size: 11px; color: var(--muted); font-weight: 450; }
.asset-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto 34px; align-items: center; gap: 8px; min-height: 56px; border-bottom: 1px solid var(--line); }
.asset-details { min-width: 0; }
.asset-name { overflow-wrap: anywhere; }
.asset-upload { font-size: 12px; min-height: 36px; padding: 4px 8px; }
.frame-tools { margin-top: 14px; }
.frame-list { display: flex; flex-wrap: wrap; gap: 5px; }
.frame-number { min-height: 36px; min-width: 36px; padding: 3px 6px; font-size: 12px; }
.frame-number[aria-pressed=true] { border-color: #9a4d50; background: var(--selected); }
.frame-editor { margin-top: 7px; }
.frame-editor .subsection, .more-tools { margin-top: 9px; padding-top: 8px; }
.frame-editor .frame-size-tools {
  margin-top: 12px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #8f555b;
  border-radius: 8px;
  background: linear-gradient(145deg, #332329, #25231d 60%, #221b1b);
}
.frame-editor .frame-size-tools[open] { border-color: #dc9597; }
.frame-size-tools summary {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 11px 12px;
  color: #fff4f1; font-size: 13px; font-weight: 750;
  line-height: 1.35; list-style: none; cursor: pointer;
}
.frame-size-tools summary::-webkit-details-marker { display: none; }
.frame-size-tools summary::before {
  content: ""; flex: none; width: 10px; height: 10px;
  border-right: 2px solid #ffb8b7; border-bottom: 2px solid #ffb8b7;
  transform: rotate(-45deg);
}
.frame-size-tools[open] summary::before { transform: rotate(45deg); }
.frame-size-tools summary:hover { background: #50303680; }
.frame-size-tools summary:focus-visible { outline-offset: -3px; }
.frame-size-tools > p {
  margin: 0 12px 10px;
  line-height: 1.45;
}
.frame-size-tools .field-row { padding: 0 12px; }
.frame-size-tools .inline-actions { padding: 0 12px 12px; }
.more-tools { margin-top: 15px; }
.more-tools .text-button { margin-top: 8px; }
.all-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.all-grid .style-choice {
  display: grid; align-content: start; gap: 6px; padding: 8px;
  text-align: left; white-space: normal; min-width: 0;
}
.all-grid .style-icon { width: 100%; height: auto; aspect-ratio: 840 / 500; }
.style-icon i { display: grid; place-items: center; font-size: 10px; font-style: normal; line-height: 1; color: #eee2e1; overflow: hidden; }
.style-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; color: var(--ink); }
.style-heading { flex-wrap: wrap; min-width: 0; }
.style-heading strong { font-size: 12px; overflow-wrap: anywhere; }
.style-heading > span {
  color: #f4d9d8; background: #3c2428; border: 1px solid #704249;
  padding: 2px 5px; border-radius: 3px; font-size: 11px; font-weight: 700;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.style-type-chip {
  display: inline-flex; justify-self: start; max-width: 100%;
  padding: 3px 6px; border: 1px solid #5b4b4d; border-radius: 4px;
  color: #ece1e3; background: #302325; font-size: 10px;
  font-weight: 700; letter-spacing: .025em; line-height: 1.3;
  overflow-wrap: anywhere;
}
.style-facts {
  color: #e3d7d9; font-size: 10px; font-weight: 650; line-height: 1.35;
}
.style-rules {
  margin: 9px 0; padding: 10px 11px; border: 1px solid #5b4b4d; border-radius: 7px;
  background: #271c1f; color: var(--ink); line-height: 1.45;
}
.style-rules strong { display: block; margin-bottom: 3px; font-size: 12px; }
.style-rules p { margin: 0; color: var(--muted); font-size: 11px; }
.style-filter-row {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px; min-width: 0; margin: 11px 0 8px;
}
.style-filter-row .field { min-width: 0; margin: 0; }
#style-count { margin: 6px 0 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.all-grid .style-choice:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 1px;
}
@media (hover: hover) and (pointer: fine) {
  .frame-art.draggable-art:hover, .gate-region.draggable-gate:hover {
    box-shadow: inset 0 0 0 2px #ffffffaa;
  }
}
.style-description { color: var(--muted); font-size: 11px; font-weight: 450; line-height: 1.35; }
@media (max-width: 850px) { .all-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 550px) {
  .all-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .style-filter-row { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 430px) {
  .preview-actions { gap: 4px; }
  .preview-actions .button { font-size: 12px; padding-inline: 10px; }
  .frame-drag-hint { display: none; }
  .frame-art-empty { font-size: 8px; }
}
@media (max-width: 370px) {
  .field-row { flex-wrap: wrap; }
  .field-row > .field { flex-basis: 100%; }
  .all-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (pointer: coarse) {
  /* Overlay guides retain Vita geometry; full-size frame buttons remain in the inspector. */
  button:not(.frame-guide), .field input, .field select, .field textarea { min-height: 44px; }
  .preview-actions .button { min-height: 44px; }
  .icon-button, .asset-actions .icon-button { width: 44px; min-height: 44px; }
  .asset-row { grid-template-columns: 38px minmax(0, 1fr) auto 44px; gap: 6px; min-height: 62px; }
  .frame-number { min-width: 44px; }
  .text-button { min-height: 44px; padding-block: 10px; }
  .subsection summary { min-height: 44px; padding-block: 13px; }
  /* Keep a full touch target without drawing a 44px plaque over the artwork. */
  .resize-handle { width: 44px; height: 44px; right: 0; bottom: 0; border-radius: 8px; }
  .resize-handle::before { width: 24px; height: 24px; }
}

/* R5: fixed application viewport. Only the style library is an internal scroll surface. */
html { width: 100%; height: 100%; overflow: hidden; }
body {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--page);
}
.topbar {
  flex: 0 0 auto;
  min-height: 56px;
  background: #1b0c0f;
  border-bottom: 1px solid #54282e;
}
.bar-inner { min-height: 56px; max-width: 1520px; gap: clamp(8px, 1.3vw, 18px); }
.brand { font-size: 17px; font-weight: 760; letter-spacing: -.045em; }
.brand img { width: 32px; height: 32px; border-radius: 50%; box-shadow: none; }
.brand-wordmark > span { color: #d5b5b8; font-weight: 430; }
.project-button { margin-left: 12px; color: var(--muted); }
.button, .icon-button {
  border-color: var(--line);
  background: #32171a;
  border-radius: 7px;
  font-weight: 590;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.button:hover, .icon-button:hover { background: #472126; border-color: #7d434a; }
.button.primary { background: var(--accent); border-color: #c54b47; color: #fff; }
.button.primary:hover { background: #9e302c; border-color: #b23c39; }
.workspace {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1520px;
  min-height: 0;
  padding-top: clamp(7px, 1.5vh, 14px);
  padding-bottom: 5px;
}
.work-grid {
  flex: 1 1 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1.8fr) minmax(345px, 1fr);
  gap: clamp(8px, 1vw, 14px);
  align-items: stretch;
}
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-color: #512930;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 12px 36px #00000021;
}
.preview-toolbar {
  flex: none;
  min-height: 54px;
  padding: 7px 12px;
  border-bottom: 1px solid #4b252b;
}
.segmented { gap: 2px; background: #170b0d; border-color: #512930; }
.segmented button[aria-pressed=true] { background: #3b1b20; box-shadow: inset 0 -2px #e2645e; }
.preview-mat {
  flex: 1 1 0;
  container-type: size;
  display: grid;
  min-height: 0;
  place-items: center;
  margin: 0 12px;
  padding: 12px;
  overflow: hidden;
  border-color: #482329;
  border-radius: 7px;
  background: #160a0c;
}
.preview-mat .screen {
  width: min(100%, 176.47cqh, 810px);
  max-width: 100%;
  max-height: 100%;
  height: auto;
  border-radius: 4px;
  border-color: #613139;
  box-shadow: 0 6px 22px #0005;
}
.preview-foot {
  flex: none;
  min-height: 40px;
  padding: 4px 12px;
  border-top: 1px solid #472329;
  line-height: 1.35;
}
.preview-foot #view-caption { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.style-launcher {
  flex: 0 0 auto;
  min-height: 69px;
  padding: 12px 14px;
  background: #281216;
  border-bottom-color: #572b32;
}
.style-launcher:hover { background: #39191e; }
.style-launcher .style-icon { width: 68px; border-color: #a25b61; }
.style-launcher strong { font-size: 15px; font-weight: 660; letter-spacing: -.02em; }
.style-launcher small { font-size: 10px; letter-spacing: .025em; }
.style-change { padding: 5px 9px; border-color: #744347; color: #ffd0c9; }
.editor-content {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 13px 12px;
  overflow: hidden;
  overscroll-behavior: none;
}
.editor-content .history-actions { margin: 0 0 9px; }
.editor-mode-pane:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
}
@media (min-width: 801px) {
  .editor-mode-pane:not([hidden]) {
    padding: 9px 10px;
    border: 1px solid #452128;
    border-radius: 9px;
    background: linear-gradient(180deg, #1b0d10, #15090c);
    box-shadow: inset 0 1px #ffffff08;
  }
  .editor-mode-pane:not([hidden]) > :first-child { margin-top: 0; }
}
.tool-section h2 { font-size: 13px; font-weight: 700; letter-spacing: -.012em; }
.tool-section h2 small { font-weight: 440; font-size: 10px; }
.asset-row { min-height: 48px; grid-template-columns: 34px minmax(0, 1fr) auto 34px; gap: 8px; }
.thumb { width: 34px; height: 34px; }
.asset-name { font-size: 12px; }
.asset-spec { font-size: 10px; }
.asset-upload { min-height: 34px; }
.launch-tools {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #5a2d34;
  border-left: 3px solid #9d4442;
  border-radius: 7px;
  background: #291317;
}
.launch-tools .asset-spec { color: #d2b4b7; line-height: 1.35; }
.frame-tools { margin-top: 10px; }
.frame-size-tools,
.frame-editor .frame-size-tools {
  margin-top: 8px;
  border: 1px solid #63343a;
  border-radius: 7px;
  background: #2b1519;
}
.frame-size-tools[open], .frame-editor .frame-size-tools[open] { border-color: #a36567; }
.frame-size-tools summary { min-height: 44px; padding: 8px 10px; color: var(--ink); font-weight: 650; }
.frame-size-tools summary::before { border-color: #d67d79; }
.frame-size-tools summary:hover { background: #422027; }
.frame-editor .frame-size-tools > p { margin: 0 10px 7px; }
.frame-editor .frame-size-tools .field-row { padding-inline: 10px; }
.frame-editor .frame-size-tools .inline-actions { padding: 0 10px 10px; }
.field { gap: 4px; margin: 7px 0; }
.field input, .field select, .field textarea { background: #170b0d; border-color: #603138; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #d17a75; }
.subsection { margin-top: 8px; padding-top: 8px; }
.inline-actions { margin-top: 8px; gap: 6px; }
footer {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 2px 1px;
  gap: 7px;
  font-size: 10px;
}
footer .text-button { min-height: 28px; padding-block: 3px; font-size: 10px; }
dialog[open] {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 28px);
  overflow: hidden;
  border-color: #6d3941;
  border-radius: 12px;
}
.dialog-head { flex: none; min-height: 52px; padding: 9px 15px; border-bottom-color: #542a31; }
.dialog-head h2 { font-size: 16px; font-weight: 680; letter-spacing: -.015em; }
.dialog-content { flex: 1 1 auto; min-height: 0; overflow: hidden; padding: 13px 15px 15px; }
/* Advanced editing pages need a definite block budget: without it the form
   collapses to its pager and silently clips the active fields. */
#dialog[open]:has(#advanced-variant-form) {
  height: min(740px, calc(100dvh - 28px));
}
#dialog[open]:has(#advanced-variant-form) .dialog-content {
  flex: 1 1 0;
}
/* A canvas keeps its native 280x158 backing pixels for export. Its rendered
   size must instead follow the modal's size-query preview box, which otherwise
   clips a fixed-width canvas on small screens. */
#dialog[open]:has(#gate-art-form) .dialog-content .preview-mat {
  height: min(176px, 30dvh);
  min-height: 0;
  max-height: min(176px, 30dvh);
  padding: 6px !important;
}
#dialog[open]:has(#gate-art-form) .preview-mat #gate-art-canvas {
  width: min(100%, 280px, 177cqh) !important;
  height: auto !important;
  max-height: 100%;
}
/* A size-query container needs a definite block size in the expanded dialog.
   Otherwise the modal's intrinsic height collapses and its artwork is invisible. */
#dialog:has(#expanded-screen) .dialog-content {
  display: flex;
  height: min(65vw, 580px, calc(100dvh - 110px));
}
#dialog:has(#expanded-screen) .preview-mat {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 4px;
}
/* The 19-style gallery is intentionally the sole vertically scrolling surface. */
dialog:has(#style-picker-grid) .dialog-content {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.all-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; min-width: 0; max-width: 100%; }
.all-grid .style-choice {
  grid-template-columns: minmax(0, 1fr);
  max-width: 100%;
  min-height: 0;
  align-content: start;
  padding: 10px;
  border-radius: 8px;
  border-color: #63343b;
  background: #281316;
  gap: 7px;
  line-height: 1.35;
}
.all-grid .style-choice:hover { border-color: #a15a61; background: #3b1c21; }
.all-grid .style-choice[aria-pressed=true] {
  border-color: #df7771;
  background: #492127;
  box-shadow: inset 0 0 0 1px #b85150;
}
.all-grid .style-icon { border-color: #955159; background: #1d0d10; border-radius: 4px; }
.style-heading strong { font-size: 12px; font-weight: 680; }
.style-description { font-size: 11px; line-height: 1.4; }
.style-type-chip { background: #452027; border-color: #754049; color: #f1d3d3; font-weight: 700; }
.style-heading > span { background: #3a282b; border-color: #684347; }
@media (max-width: 1100px) {
  .work-grid { grid-template-columns: minmax(0, 1.55fr) minmax(305px, .95fr); }
  .bar-inner { gap: 8px; }
}
@media (max-width: 940px) {
  .work-grid { grid-template-columns: minmax(0, 1.4fr) minmax(286px, 1fr); gap: 8px; }
  .preview-mat { margin-inline: 8px; padding: 9px; }
  .style-launcher { grid-template-columns: 48px minmax(0, 1fr) auto; padding-inline: 10px; gap: 7px; }
  .style-launcher .style-icon { width: 48px; }
}
@media (max-width: 720px) {
  .workspace { padding-top: 7px; }
  .work-grid { grid-template-columns: 1fr; grid-template-rows: minmax(0, .86fr) minmax(0, 1.14fr); gap: 8px; }
  .preview-toolbar { min-height: 48px; }
  .preview-mat { margin-inline: 9px; padding: 7px; }
  .preview-foot { min-height: 35px; }
  .style-launcher { min-height: 56px; }
  .editor-content { padding: 8px 10px 10px; }
  footer { min-height: 26px; }
}
@media (max-width: 690px) {
  .bar-inner { padding-block: 5px; }
  .project-button { margin-left: auto; }
  .bar-actions { justify-content: flex-end; }
}
@media (max-width: 480px) {
  .preview-toolbar { flex-wrap: nowrap; gap: 5px; padding: 4px 8px; }
  .segmented { width: auto; min-width: 0; flex: 1 1 0; }
  .segmented button { padding: 4px 5px; min-width: 0; font-size: 11px; line-height: 1.15; }
  .preview-actions { flex: 0 0 auto; gap: 4px; justify-content: flex-end; }
  .preview-actions .button { padding-inline: 6px; font-size: 10px; }
  .preview-mat { margin-inline: 7px; padding: 6px; }
  .preview-foot { padding-inline: 8px; font-size: 10px; }
  .all-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  dialog.wide { width: calc(100% - 16px); max-width: calc(100% - 16px); }
  .dialog-head { padding: 7px 10px; }
  .dialog-content { padding: 10px; }
  .inspector .task-intro { display: none; }
  .inspector .empty-task { margin-top: 5px; padding: 8px; gap: 5px; }
  .inspector .advanced-card { margin-top: 4px; padding: 6px 7px; gap: 4px; }
  .inspector .advanced-card .editor-hint { display: none; }
}
@media (max-width: 370px) {
  .bar-inner { column-gap: 4px; }
  .brand { font-size: 14px; }
  .project-button { flex: 1 1 95px; max-width: 150px; }
  .bar-actions { gap: 4px; }
  .bar-actions .button { min-width: 0; }
  .preview-actions #guides { max-width: 48px; font-size: 0; }
  .preview-actions #guides::after { content: "Guides"; font-size: 10px; }
  .segmented button { padding: 3px; font-size: 10px; }
  .field-row { flex-wrap: wrap; }
  /* Two tiny cards can exceed the gallery's inline size when labels localize. */
  #style-picker-grid { grid-template-columns: minmax(0, 1fr); }
  .style-description { font-size: 10px; }
  /* A wrapped frame list leaves only one short editor row on 320px devices.
     Keep the advanced action reachable without hiding its 44px touch target. */
  .frame-editor-pane[data-frame-page="advanced"] p { display: none; }
  .frame-editor-pane[data-frame-page="advanced"] .subsection { margin: 0; padding: 0; border: 0; }
  /* Once a frame has versions, Image/Text/Advanced each offer two actions.
     Keep both reachable side by side instead of clipping them below the pane. */
  .inspector .frame-editor-pane:has(> [data-action="advanced-frame"]) {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start; gap: 3px;
  }
  .inspector .frame-editor-pane:has(> [data-action="advanced-frame"]) > p { display: none; }
  .inspector .frame-editor-pane:has(> [data-action="advanced-frame"]) > button {
    width: 100%; min-width: 0; min-height: 44px;
    padding: 3px 4px; font-size: 11px; line-height: 1.15; white-space: normal;
  }
}
@media (pointer: coarse) {
  .asset-row { grid-template-columns: 34px minmax(0, 1fr) auto 44px; min-height: 50px; }
  .asset-upload { min-height: 44px; }
  .preview-toolbar .segmented button { min-height: 44px; }
  .preview-foot .text-button { min-height: 44px; }
  footer .text-button { min-height: 44px; min-width: 44px; }
}
@media (max-height: 720px) {
  .topbar, .bar-inner { min-height: 50px; }
  .workspace { padding-top: 6px; padding-bottom: 2px; }
  .preview-toolbar { min-height: 46px; }
  .preview-foot { min-height: 34px; }
  .style-launcher { min-height: 55px; }
  .style-launcher .style-icon { width: 50px; }
  .editor-content { padding-block: 7px; }
  footer { min-height: 23px; }
}
/* Landscape handsets need the same touch targets in much less vertical space.
   Put history next to the style picker instead of sacrificing a whole editor row. */
@media (max-height: 440px) and (orientation: landscape) {
  .topbar, .topbar .bar-inner { min-height: 44px; }
  .topbar .bar-inner { flex-wrap: nowrap; gap: 7px; padding-block: 0; }
  .topbar .brand { font-size: 14px; }
  .topbar .brand img { width: 26px; height: 26px; }
  .topbar .project-button {
    flex: 0 1 125px; min-width: 60px; max-width: 125px;
    margin-left: 0; padding-inline: 5px;
  }
  .topbar .bar-actions { flex: 0 0 auto; flex-wrap: nowrap; gap: 4px; margin-left: auto; }
  .topbar .bar-actions .button { min-height: 44px; padding-inline: 7px; font-size: 11px; }
  .workspace { padding-block: 3px 1px; }
  .workspace footer { min-height: 22px; padding: 0; }
  .workspace .mobile-surface-switch { margin-bottom: 3px; padding: 0; }
  .work-grid { gap: 5px; }
  .preview-toolbar { min-height: 44px; padding: 0 7px; }
  .preview-toolbar .segmented { padding: 0; border: 0; }
  .preview-mat { margin-inline: 6px; padding: 3px; }
  .preview-foot { min-height: 44px; padding: 0 7px; }
  .preview-foot #preview-guide-note { display: none; }
  .inspector { position: relative; }
  .inspector .style-launcher {
    width: calc(100% - 103px); grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 5px; min-height: 44px; padding: 3px 7px;
  }
  .inspector .style-launcher .style-icon { width: 38px; }
  .inspector .style-launcher small, .inspector .style-change { display: none; }
  .inspector .style-launcher strong { font-size: 12px; }
  .inspector .editor-content { padding: 0 7px; gap: 2px; }
  .inspector .editor-content .history-actions {
    position: absolute; top: 0; right: 4px; z-index: 2;
    display: flex; gap: 4px; margin: 0; align-items: center; min-height: 44px;
  }
  .inspector .editor-content .history-actions .button {
    min-width: 44px; min-height: 44px; padding: 2px 4px; font-size: 10px;
  }
  .inspector .editor-navigation { gap: 3px; padding: 0 6px; }
  .inspector .editor-navigation > button { min-height: 44px; padding: 2px; }
  .inspector .editor-mode-pane { gap: 2px; }
  .inspector .task-intro { margin: 2px 0 4px; padding: 5px 7px; }
  .inspector .task-intro span { display: none; }
  .step-explainer { margin: 0 0 4px; padding: 4px 6px; }
  .step-explainer span { display: none; }
  .inspector .package-card { margin-top: 4px; padding: 8px; gap: 6px; }
  .inspector .package-main > strong { font-size: 13px; }
  .inspector .editor-mode-pane .asset-row { min-height: 44px; }
  .inspector .editor-mode-pane .editor-hint { display: none; }
  .inspector .editor-mode-pane .launch-tools { padding: 5px 8px; }
  .inspector .editor-mode-pane .launch-tools > .asset-spec { display: none; }
  .inspector .editor-mode-pane .launch-tools .inline-actions { margin-top: 4px; }
  #editor-content .editor-mode-pane .frame-tools {
    display: grid; flex: 1 1 0;
    grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 44px minmax(0, 1fr);
    align-items: center; gap: 2px 8px;
  }
  .inspector .frame-tools > h2 { grid-column: 1; grid-row: 1; margin: 0; }
  .inspector .frame-tools > .frame-list { grid-column: 2; grid-row: 1; gap: 3px; }
  .inspector .frame-tools > .frame-editor { grid-column: 1 / -1; grid-row: 2; gap: 2px; }
  .inspector .frame-editor .inspector-subnav { padding: 1px; }
  .inspector .frame-editor .inspector-subnav > button { min-height: 44px; padding: 2px; }
  .inspector .frame-editor-pane[data-frame-page="advanced"] p { display: none; }
  .inspector .frame-editor-pane[data-frame-page="advanced"] .subsection {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center; gap: 4px; margin: 0; padding: 0; border: 0;
  }
  .inspector .frame-editor-pane[data-frame-page="advanced"] summary { min-height: 44px; padding: 3px; }
  .inspector .frame-editor-pane[data-frame-page="advanced"] .button { min-height: 44px; white-space: normal; }
  /* Keep the advanced picker and page navigation on one line, freeing one
     complete row for its paged fields on short landscape viewports. */
  #dialog[open]:has(#advanced-variant-form) .dialog-head { min-height: 44px; padding-block: 4px; }
  #dialog[open]:has(#advanced-variant-form) .dialog-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 3px 8px; padding: 4px 8px;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-version-chooser {
    grid-column: 1; grid-row: 1; min-width: 0;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-pager {
    grid-column: 2; grid-row: 1; align-self: end; min-width: 0; gap: 3px;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-version-chooser .field,
  #dialog[open]:has(#advanced-variant-form) .variant-pager .field { margin: 0; }
  #dialog[open]:has(#advanced-variant-form) #advanced-variant-form,
  #dialog[open]:has(#advanced-variant-form) .dialog-content > .variant-page {
    grid-column: 1 / -1; grid-row: 2; min-height: 0;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-dialog-actions {
    grid-column: 1 / -1; grid-row: 3; margin: 0; justify-content: flex-end;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-page .field {
    margin: 0; gap: 2px;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="content"],
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="audience"],
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="image-layout"] {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start; gap: 4px 7px;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="content"] > .field:first-child,
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="audience"] > .field-row {
    grid-column: 1 / -1;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"] details[open] {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start; gap: 4px 7px;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"] details > .field {
    grid-column: 1 / -1;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"] details > .field-row,
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="image-layout"] > .field-row {
    min-width: 0; gap: 4px;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-form-actions {
    margin: 3px 0 0;
  }
  /* Short landscape dialogs must budget their text and XML preview inside the
     viewport rather than silently clipping the last line or primary action. */
  #dialog[open]:not(:has(#style-picker-grid, #advanced-variant-form, #gate-art-form, #expanded-screen))
    .dialog-content > p { margin-block: 4px; line-height: 1.32; }
  #dialog[open]:has(.xml-view) .xml-view {
    min-height: 0;
    height: min(205px, calc(100dvh - 165px));
    resize: none;
  }
  #dialog:has(#gate-art-form) .dialog-head { min-height: 44px; padding-block: 4px; }
  #dialog:has(#gate-art-form) .dialog-content { padding: 5px 8px; }
  #dialog[open]:has(#gate-art-form) .dialog-content .preview-mat {
    min-height: 0; max-height: 48px; height: 48px; padding: 2px;
  }
  #dialog:has(#gate-art-form) #gate-art-form { margin-top: 2px; gap: 1px; }
  #dialog:has(#gate-art-form) #gate-art-form .field { margin: 2px 0; }
  #dialog:has(#gate-art-form) #gate-art-form .inline-actions { margin-top: 2px; }
  #dialog[open]:not(:has(#style-picker-grid, #advanced-variant-form, #gate-art-form, #expanded-screen))
    .dialog-content { padding-block: 6px; }
  /* The small Vita gate is part of a scaled screen, not a toolbar button:
     global touch min-height must not enlarge its firmware-sized visual region. */
  button.draggable-gate { min-height: 0; }
}
@media (max-height: 440px) and (orientation: landscape) and (min-width: 801px) {
  /* Wider landscape viewports are fine-pointer layouts: compact the editor
     chrome so the full text-style page stays on screen without scrolling. */
  #dialog[open]:has(#advanced-variant-form) .dialog-head { min-height: 36px; }
  #dialog[open]:has(#advanced-variant-form) .dialog-content { gap: 1px 6px; padding-block: 2px; }
  #dialog[open]:has(#advanced-variant-form) .variant-page .field {
    font-size: 10px; line-height: 1.1; gap: 1px;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"] details[open] {
    gap: 2px 6px;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"]
    .field :is(input, select) { min-height: 29px; padding-block: 3px; }
  #dialog[open]:has(#advanced-variant-form) .variant-dialog-actions { margin-top: 0; }
}
@media (max-height: 440px) and (orientation: landscape) and (max-width: 700px) {
  #dialog[open]:has(#gate-art-form) .dialog-content .preview-mat {
    height: 32px; max-height: 32px;
  }
}
@media (max-height: 440px) and (orientation: landscape) and (max-width: 800px) {
  /* The mobile advanced editor otherwise gives its two labeled pickers 64px,
     leaving a 123px page and clipping controls below the fold at 667x375. */
  #dialog[open]:has(#advanced-variant-form) {
    height: calc(100dvh - 8px);
    max-height: calc(100dvh - 8px);
  }
  #dialog[open]:has(#advanced-variant-form) .dialog-head {
    min-height: 44px;
    padding-block: 0;
  }
  #dialog[open]:has(#advanced-variant-form) .dialog-content { padding-block: 3px; }
  #dialog[open]:has(#advanced-variant-form) .variant-version-chooser .field,
  #dialog[open]:has(#advanced-variant-form) .variant-pager .field {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 4px;
    font-size: 10px;
  }
  #dialog[open]:has(#advanced-variant-form) .variant-version-chooser select,
  #dialog[open]:has(#advanced-variant-form) .variant-pager select {
    flex: 1 1 0;
    min-width: 0;
  }
  /* Keep the four text-style pairs in two rows even when details content is
     rendered in its own anonymous box by Chrome. */
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"]
    details[open] > .field-row {
    display: inline-flex;
    width: calc(50% - 5px);
    margin: 0 4px 3px 0;
    vertical-align: top;
  }
  #dialog[open]:has(#advanced-variant-form) [data-variant-panel="text-style"]
    details > .field-row .field { font-size: 10px; line-height: 1.1; }
}
@media (prefers-contrast: more) {
  :root { --line: #6a707a; --muted: #d2d5db; --accent-text: #ffc3bf; }
}
@media (forced-colors: active) {
  .bubble-backdrop { background: Canvas; }
  .bubble-icon { border: .2cqw solid CanvasText; background: ButtonFace; color: ButtonText; box-shadow: none; }
  .bubble-icon::before, .bubble-icon::after { display: none; }
  .bubble-stack > span { color: CanvasText; text-shadow: none; }
  .segmented button[aria-pressed=true], .style-choice[aria-pressed=true],
  .frame-number[aria-pressed=true], .frame-guide[aria-pressed=true] { outline: 2px solid Highlight; outline-offset: -2px; }
  .frame-art.is-active { outline: 2px solid Highlight; box-shadow: none; }
  .frame-art.is-active::after { border-color: CanvasText; }
  .resize-handle { color: ButtonText; box-shadow: none; }
  .resize-handle::before { border-color: ButtonText; background: ButtonFace; box-shadow: none; }
  .frame-size-tools[open] { border-color: Highlight; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
