* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: #fff;
  color: #000;
  font: 13px/1.5 Arial, Helvetica, sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#stage { --preview-inset: 24px; flex: 1; display: flex; align-items: center; justify-content: center; position: relative; min-height: 0; }
/* Preview dimensions are fitted by the app independently of export pixels.
   Keep the element itself at the displayed image bounds for SVG controls. */
#canvas { flex: none; max-width: calc(100% - 48px); max-height: calc(100% - 48px); cursor: crosshair; touch-action: none; border: 1px solid #e0e0e0; }
#drop { position: absolute; inset: 24px; border: 1px solid #e0e0e0; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; color: #6b6b6b; cursor: pointer; }
#drop > span:first-child { color: #333; }
#drop:hover, #drop.over { color: #000; }
#drop.over { border-color: #000; }
#drop.hidden, #canvas.hidden { display: none; }
#effectControl { position: absolute; display: none; overflow: hidden; pointer-events: none; touch-action: none; user-select: none; mix-blend-mode: difference; }
.control-visual { fill: none; stroke: #fff; vector-effect: non-scaling-stroke; }
#effectRing { stroke-width: 1; stroke-dasharray: 4 5; opacity: .8; }
#directionLine { stroke-width: 1; opacity: .9; }
#moveHit { fill: rgba(0,0,0,.001); stroke: none; pointer-events: all; cursor: move; }
.control-handle { pointer-events: all; cursor: grab; outline: none; }
.control-handle:active { cursor: grabbing; }
.control-hit { fill: rgba(0,0,0,.001); stroke: none; }
.control-dot { fill: #fff; stroke: none; }
#radiusHandle { cursor: nwse-resize; }
#radiusGrip { fill: none; stroke: #fff; stroke-width: 1.5; }
#centerCross { stroke-width: 1; }
.control-handle:focus-visible .control-dot,
.control-handle:focus-visible #radiusGrip { stroke: #fff; stroke-width: 2; }
.control-handle:focus-visible .control-hit { stroke: #fff; stroke-width: 1; }
#overlay { position: absolute; display: none; align-items: flex-end; justify-content: center; padding: 10px; background: transparent; color: #333; pointer-events: none; }
#overlay > span { max-width: min(100%, 300px); padding: 4px 9px; background: #fffffff2; border: 1px solid #dedede; border-radius: 4px; font-size: 12px; line-height: 1.4; text-align: center; }
#bar { display: flex; align-items: center; gap: 16px; padding: 12px 24px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid #e0e0e0; flex-shrink: 0; }
#bar .hint { color: #b0b0b0; visibility: hidden; }
body.loaded #bar .hint { visibility: visible; }
button { background: none; border: none; color: #000; font: inherit; padding: 0; text-decoration: underline; cursor: pointer; }
button:hover:not(:disabled) { color: #444; }
button:focus-visible, #drop:focus-visible, #canvas:focus-visible { outline: 1px solid #000; outline-offset: 3px; }
#compare { min-width: 82px; min-height: 34px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 10px; border: 1px solid #d0d0d0; border-radius: 4px; text-decoration: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; margin-left: auto; }
#compare *, #compare svg { user-select: none; -webkit-user-select: none; pointer-events: none; }
#compare svg { width: 18px; height: 18px; }
#compare:hover:not(:disabled) { border-color: #000; color: #000; }
#compare.active { background: #000; border-color: #000; color: #fff; }
#compare.active:hover:not(:disabled) { background: #333; border-color: #333; color: #fff; }
#compare:disabled { opacity: .25; cursor: default; }
#compare:focus-visible { outline: 1px solid #000; outline-offset: 2px; }
.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.toggle input { cursor: pointer; }
.toggle.busy { color: #666; pointer-events: none; }
.toggle.busy span { animation: none; }
@keyframes pulse { 50% { opacity: .4; } }
#message { position: absolute; left: 50%; top: 38px; transform: translateX(-50%); max-width: calc(100% - 64px); background: #fff; border: 1px solid #e0e0e0; padding: 10px 14px; color: #000; z-index: 2; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 600px) {
  #stage { --preview-inset: 12px; }
  #drop { inset: 12px; }
  #canvas { max-width: calc(100% - 24px); max-height: calc(100% - 24px); }
  #bar { flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  #bar .hint { flex-basis: 100%; order: 4; }
  body:not(.loaded) #bar .hint { display: none; }
  #message { top: 24px; max-width: calc(100% - 48px); width: max-content; }
}
@media (hover: none) and (pointer: coarse) { #bar .hint { display: none; } }
@media (prefers-reduced-motion: reduce) { .toggle.busy span { animation: none; } }

/* Keep the photo dominant; disclose editing tools only after intake. */
#bar { gap: 24px; }
.empty-hint { color: #6b6b6b; }
body.loaded .empty-hint { display: none; }
.editing-tools { display: none; flex: 1; align-items: center; flex-wrap: wrap; gap: 14px 20px; }
body.loaded .editing-tools { display: flex; }
.file-actions, .history-actions, .export-actions { display: flex; align-items: center; gap: 12px; }
.file-actions { gap: 14px; white-space: nowrap; }
.export-actions { margin-left: auto; flex-shrink: 0; }
#bar .hint { flex-basis: auto; order: 0; font-size: 12px; color: #6b6b6b; white-space: nowrap; }
button { transition: color 140ms ease, background-color 140ms ease, border-color 140ms ease, opacity 140ms ease; }
button:disabled { cursor: default; }
.muted-action { color: #6b6b6b; white-space: nowrap; }
.muted-action:disabled { opacity: .4; }
.history-actions { gap: 2px; }
.history-actions button { min-height: 32px; padding: 4px 7px; border-radius: 4px; text-decoration: none; }
.history-actions button:hover:not(:disabled) { background: #f1f1f1; color: #000; }
.history-actions button:disabled { opacity: .3; }
.intensity-control { width: 148px; flex-shrink: 0; }
.intensity-control label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; color: #6b6b6b; }
.intensity-control output { color: #222; font-variant-numeric: tabular-nums; }
#intensity { --amount: 100%; display: block; width: 100%; height: 22px; margin: 0; appearance: none; -webkit-appearance: none; background: transparent; cursor: ew-resize; touch-action: pan-y; }
#intensity::-webkit-slider-runnable-track { height: 2px; border-radius: 2px; background: linear-gradient(to right, #222 var(--amount), #dedede var(--amount)); }
#intensity::-moz-range-track { height: 2px; border-radius: 2px; background: #dedede; }
#intensity::-moz-range-progress { height: 2px; border-radius: 2px; background: #222; }
#intensity::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 10px; height: 10px; border-radius: 50%; background: #222; margin-top: -4px; transition: box-shadow 140ms ease; }
#intensity::-moz-range-thumb { width: 10px; height: 10px; border: 0; border-radius: 50%; background: #222; }
#intensity:hover::-webkit-slider-thumb, #intensity:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px #0000000d; }
#intensity:focus-visible { outline: 1px solid #555; outline-offset: 2px; border-radius: 2px; }
#intensity:disabled { opacity: .4; cursor: default; }
#compare { margin-left: 0; transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease; }
body:not(.loaded) #compare { display: none; }
#save { min-height: 32px; min-width: 96px; padding: 6px 14px; border: 1px solid #111; border-radius: 4px; background: #111; color: #fff; text-decoration: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
#save:hover:not(:disabled) { background: #333; border-color: #333; color: #fff; }
#save:active:not(:disabled) { transform: translateY(1px); }
#save:disabled { background: #f3f3f3; border-color: #e6e6e6; color: #aaa; }
#save.saved { background: #2b2b2b; border-color: #2b2b2b; }
#save.saved #exportLabel { animation: export-confirm 180ms ease-out; }
#guidance { position: absolute; z-index: 1; bottom: 8px; left: 50%; transform: translate(-50%, 3px); max-width: calc(100% - 32px); padding: 3px 8px; background: #ffffffed; border-radius: 3px; color: #6b6b6b; font-size: 12px; line-height: 1.4; text-align: center; pointer-events: none; opacity: 0; transition: opacity 160ms ease, transform 160ms ease; }
#guidance.visible { opacity: 1; transform: translate(-50%, 0); }
#stage.photo-enter #canvas, #stage.photo-enter #overlay { animation: photo-reveal 240ms ease-out both; }
#stage.effect-placed #effectRing { animation: ring-place 280ms ease-out; }
#stage.effect-placed .control-dot, #stage.effect-placed #radiusGrip { animation: handle-reveal 180ms ease-out both; }
@keyframes photo-reveal { from { opacity: 0; } to { opacity: 1; } }
@keyframes ring-place { from { stroke-dashoffset: 18; opacity: .2; } to { stroke-dashoffset: 0; opacity: .8; } }
@keyframes handle-reveal { from { opacity: 0; } to { opacity: 1; } }
@keyframes export-confirm { from { opacity: .4; } to { opacity: 1; } }
@media (max-width: 1200px) { #bar { gap: 18px; } #bar .hint { display: none; } .editing-tools { gap: 12px 18px; } }
@media (max-width: 760px) {
  #bar { padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); gap: 8px 16px; }
  body.loaded #bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  body.loaded .editing-tools { display: contents; }
  .file-actions { grid-column: 1; grid-row: 1; gap: 14px; }
  .history-actions { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  .intensity-control { grid-column: 1; grid-row: 2; width: 100%; }
  #resetEffect { grid-column: 2; grid-row: 2; justify-self: end; align-self: center; }
  #bgToggle { grid-column: 1; grid-row: 3; font-size: 12px; gap: 5px; }
  .export-actions { grid-column: 2; grid-row: 3; gap: 10px; }
  .history-actions button { min-height: 32px; }
  .file-actions button, #resetEffect { min-height: 32px; }
  #save { min-width: 92px; padding: 6px 11px; }
  #guidance { font-size: 11px; bottom: 6px; width: max-content; }
}
@media (hover: none) and (pointer: coarse) {
  .file-actions button, .history-actions button, #resetEffect, #save, #compare, .toggle { min-height: 44px; }
  #intensity { height: 32px; }
  #compare { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  button, #compare, #guidance, #intensity::-webkit-slider-thumb { transition: none; }
  #stage.photo-enter #canvas, #stage.photo-enter #overlay,
  #stage.effect-placed #effectRing, #stage.effect-placed .control-dot,
  #stage.effect-placed #radiusGrip, #save.saved #exportLabel { animation: none; }
}

/* Framing and output choices stay in contextual panels. */
#bar { position: relative; }
.workspace-tools { display: flex; gap: 6px; align-items: center; }
.workspace-tools button { border: 1px solid #dedede; border-radius: 4px; padding: 5px 9px; text-decoration: none; min-height: 32px; }
.workspace-tools button:hover:not(:disabled), .workspace-tools button[aria-expanded="true"] { border-color: #777; background: #f6f6f6; color: #111; }
.workspace-tools button:disabled { opacity: .35; }
.tool-panel { position: absolute; bottom: calc(100% + 12px); right: 24px; width: 350px; max-width: calc(100vw - 32px); max-height: calc(100dvh - var(--toolbar-height, 90px) - 32px); overflow: auto; overscroll-behavior: contain; z-index: 5; padding: 18px; background: #fff; border: 1px solid #ddd; border-radius: 6px; box-shadow: 0 8px 32px #00000014; }
.tool-panel[hidden], [hidden] { display: none !important; }
#framePanel { width: 280px; }
#stage.framing { padding-right: 320px; }
#stage.background-open, #stage.help-open { padding-right: 390px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.tool-panel .panel-heading { position: sticky; top: -18px; z-index: 3; padding: 4px 0; background: #fff; }
.panel-heading h2 { font-size: 15px; font-weight: 500; line-height: 1.4; }
.close-button { text-decoration: none; width: 28px; min-height: 28px; font-size: 21px; line-height: 1; color: #666; border-radius: 3px; }
.close-button:hover { background: #f4f4f4; color: #111; }
.panel-help { font-size: 12px; line-height: 1.5; color: #6b6b6b; margin: 8px 0 12px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 14px; }
.segmented button { padding: 6px 8px; border: 1px solid #ddd; border-radius: 4px; text-decoration: none; font-size: 12px; min-height: 32px; }
.segmented button[aria-pressed="true"] { color: #fff; background: #222; border-color: #222; }
.segmented button:hover:not([aria-pressed="true"]) { color: #111; border-color: #777; }
.field-label { display: flex; gap: 12px; align-items: center; justify-content: space-between; font-size: 12px; margin: 10px 0 6px; }
.field-label output { color: #666; font-variant-numeric: tabular-nums; }
.panel-range { display: block; width: 100%; height: 26px; accent-color: #222; cursor: ew-resize; }
.panel-row, .panel-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-row { margin-top: 6px; }
.panel-footer { justify-content: flex-end; margin-top: 14px; }
.tool-panel .panel-footer { position: sticky; bottom: -18px; z-index: 2; padding-top: 10px; background: #fff; border-top: 1px solid #eee; box-shadow: 0 -6px 8px #fff; }
.panel-footer > button:not(.primary-button) { padding: 7px 4px; }
.primary-button { background: #171717; border: 1px solid #171717; color: #fff; border-radius: 4px; padding: 7px 13px; min-height: 34px; text-decoration: none; white-space: nowrap; }
.primary-button:hover:not(:disabled) { background: #333; color: #fff; }
.primary-button:disabled { color: #aaa; background: #f1f1f1; border-color: #e5e5e5; }
fieldset { border: 0; padding: 0; margin-top: 14px; min-width: 0; }
fieldset legend { font-size: 12px; color: #6b6b6b; margin-bottom: 9px; }
fieldset:disabled { opacity: .4; }
.background-options { display: grid; grid-template-columns: repeat(4,1fr); gap: 7px; }
.background-options button { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11px; text-decoration: none; min-width: 0; padding: 5px 0; border: 1px solid transparent; border-radius: 4px; }
.background-options button[aria-pressed="true"] { border-color: #666; color: #000; }
.background-options button:hover:not(:disabled) { background: #f4f4f4; color: #000; }
.swatch { width: 30px; height: 30px; border: 1px solid #d2d2d2; border-radius: 50%; }
.gradient-swatch { background: linear-gradient(#fff,#ededed); }
.white-swatch { background: #fff; }
.black-swatch { background: #000; border-color: #000; }
.checkerboard, #canvas { background-color: #fff; background-image: conic-gradient(#e8e8e8 25%, transparent 0 50%, #e8e8e8 0 75%, transparent 0); background-size: 16px 16px; }
.color-field { display: flex; gap: 10px; align-items: center; justify-content: space-between; border: 1px solid #ddd; border-radius: 4px; padding: 8px; margin-top: 12px; font-size: 12px; }
.color-field.selected { border-color: #777; }
.color-field input[type="color"] { width: 32px; height: 26px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.color-field input[type="text"] { width: 80px; min-width: 0; padding: 6px; font: inherit; font-variant-numeric: tabular-nums; color: #555; border: 1px solid #ddd; border-radius: 3px; }
#cropControl { position: absolute; z-index: 2; touch-action: none; }
.crop-shade { fill: #0006; }
.crop-outline { stroke: #fff; stroke-width: 1.5; }
.crop-thirds { stroke: #ffffff80; stroke-width: 1; }
.crop-circle { stroke: #fff; stroke-width: 1; stroke-dasharray: 5 4; }
.crop-move { cursor: move; }
.crop-handle { outline: none; cursor: nwse-resize; }
.crop-handle#cropHandle-ne, .crop-handle#cropHandle-sw { cursor: nesw-resize; }
.crop-handle#cropHandle-n, .crop-handle#cropHandle-s { cursor: ns-resize; }
.crop-handle#cropHandle-e, .crop-handle#cropHandle-w { cursor: ew-resize; }
.crop-grip { fill: #fff; stroke: #333; stroke-width: 1; }
.crop-handle:focus-visible .crop-grip { stroke: #000; stroke-width: 2; }
.crop-move:focus-visible { outline: none; stroke: #fff; stroke-dasharray: 3 3; stroke-width: 2; }
#stage.avatar-preview #canvas { clip-path: circle(closest-side); }
#stage.framing #guidance { display: none; }
#exportDialog { margin: auto; width: 700px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain; padding: 22px; border: 1px solid #ddd; border-radius: 8px; background: #fff; color: #111; box-shadow: 0 12px 60px #0002; font: inherit; }
#exportDialog::backdrop { background: #0005; }
.export-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24px; align-items: start; }
.export-preview { position: relative; min-height: 240px; display: flex; align-items: center; justify-content: center; border: 1px solid #e5e5e5; border-radius: 4px; overflow: hidden; background: #f5f5f5; }
.export-preview img { display: block; max-width: 100%; max-height: 330px; object-fit: contain; border: 1px solid #e2e2e2; }
.export-preview img:not([src]) { display: none; }
.export-preview img.preparing { opacity: .4; }
#exportPreparing { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 12px; color: #666; white-space: nowrap; background: #fffffff2; padding: 5px 8px; }
.export-settings select, .dimension-fields input { display: block; width: 100%; min-width: 0; height: 40px; border: 1px solid #d5d5d5; border-radius: 4px; background: #fff; color: #111; font: inherit; line-height: 1.4; padding: 8px 12px; }
.export-settings select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m2 4 4 4 4-4' fill='none' stroke='%23444' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 12px;
  cursor: pointer;
}
.export-settings > .field-label { margin-top: 16px; }
.export-settings > .field-label:first-child { margin-top: 0; }
.dimension-fields { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: end; gap: 8px; margin-top: 16px; }
.dimension-fields label { min-width: 0; font-size: 12px; color: #666; }
.dimension-fields input { margin-top: 5px; font-variant-numeric: tabular-nums; }
.dimension-fields > span { display: grid; place-items: center; height: 40px; padding: 0; color: #777; }
.export-details { font-size: 12px; font-variant-numeric: tabular-nums; margin-top: 14px; }
.inline-error { font-size: 12px; color: #a32929; margin-top: 10px; }
.color-field input[aria-invalid="true"] { border-color: #a32929; }
#backgroundStatus { margin-top: 10px; color: #555; font-size: 13px; }
#backgroundStatus.inline-error { color: #a32929; }
#backgroundColorError { margin-top: 6px; }
#exportScaleNote { margin-top: 8px; }
#comparisonLabel { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; padding: 4px 10px; border: 1px solid #d5d5d5; border-radius: 4px; background: #fffffff2; color: #222; font-size: 13px; pointer-events: none; }
.help-diagram { display: block; width: 100%; height: auto; margin: 12px 0; border: 1px solid #e0e0e0; border-radius: 4px; }
#helpPanel ul { padding-left: 18px; }
#helpPanel li + li { margin-top: 8px; }
select:focus-visible, input[type="number"]:focus-visible, input[type="color"]:focus-visible, .color-field input[type="text"]:focus-visible { outline: 2px solid #222; outline-offset: 2px; }
@media (max-width: 760px) {
  body { font-size: 14px; }
  #stage { --preview-inset: 12px; }
  #canvas { max-width: calc(100% - 24px); max-height: calc(100% - 24px); }
  .workspace-tools { grid-column: 1; grid-row: 2; gap: 5px; }
  .workspace-tools button { font-size: 14px; padding: 5px 7px; }
  .intensity-control { grid-row: 3; }
  #resetEffect { grid-row: 3; }
  .export-actions { grid-row: 2; }
  #stage.framing, #stage.background-open, #stage.help-open { padding-right: 0; padding-bottom: calc(var(--tool-panel-height, min(350px, 42dvh)) + 8px); }
  .tool-panel, #framePanel { left: 14px; right: auto; bottom: calc(100% + 8px); width: calc(100vw - 28px); max-width: none; max-height: min(360px, 42dvh, calc(100dvh - var(--toolbar-height, 190px) - 160px)); padding: 14px; }
  .tool-panel .panel-heading { top: -14px; }
  .tool-panel .panel-footer { bottom: -14px; }
  #framePanel .segmented { grid-template-columns: repeat(4,1fr); margin-bottom: 10px; }
  #framePanel .segmented button { padding: 5px 3px; font-size: 13px; }
  .panel-help, .field-label, .dimension-fields label, fieldset legend, .color-field, .intensity-control label, .background-options button, .export-details, .inline-error, #backgroundStatus { font-size: 14px; }
  #guidance, #overlay > span { font-size: 13px; }
  .export-settings select, .dimension-fields input, .color-field input[type="text"] { font-size: 16px; }
  .color-field input[type="text"] { width: 96px; }
  #exportDialog { padding: 17px; }
  .export-layout { grid-template-columns: 1fr; gap: 10px; }
  .export-preview { min-height: 150px; max-height: 220px; }
  .export-preview img { max-height: 220px; }
}
@media (hover: none) and (pointer: coarse) {
  .workspace-tools button, .primary-button, .panel-footer > button, .segmented button, .background-options button { min-height: 44px; }
  .close-button { width: 44px; min-height: 44px; }
  .dimension-fields input, .export-settings select { height: 44px; min-height: 44px; }
  .dimension-fields > span { height: 44px; }
  .color-field input[type="text"] { min-height: 40px; }
}
@media (max-width: 760px) and (max-height: 650px) {
  #exportDialog { padding: 14px; max-height: calc(100dvh - 20px); }
  .export-preview { min-height: 96px; max-height: 136px; }
  .export-preview img { max-height: 136px; }
  .tool-panel .panel-footer, #exportDialog .panel-footer { position: sticky; bottom: -14px; z-index: 2; background: #fff; border-top: 1px solid #eee; padding-top: 10px; box-shadow: 0 -6px 8px #fff; }
  .tool-panel .panel-heading, #exportDialog .panel-heading { position: sticky; top: -14px; z-index: 3; background: #fff; padding-top: 4px; }
}
@media (forced-colors: active) { .export-settings select { appearance: auto; -webkit-appearance: auto; background-image: none; padding-right: 12px; } }
@media (max-width: 760px) and (max-height: 520px) {
  /* During framing these tools are disabled; reclaim their rows for the image. */
  #stage.framing + #bar .history-actions,
  #stage.framing + #bar .intensity-control,
  #stage.framing + #bar #resetEffect,
  #stage.framing + #bar .export-actions,
  #stage.framing + #bar #backgroundButton,
  #stage.framing + #bar #helpButton { display: none; }
  #stage.framing + #bar .workspace-tools { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  #framePanel > .panel-help:first-of-type { position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* A labelled Compare action and three tool buttons need their own rows on
   phones. Keep labels readable instead of compressing controls into each other. */
@media (max-width: 480px) {
  body.loaded #bar { column-gap: 12px; }
  .workspace-tools { grid-column: 1 / -1; grid-row: 2; }
  .export-actions { grid-column: 1 / -1; grid-row: 4; width: 100%; margin-left: 0; justify-content: space-between; }
  #compare { min-width: 90px; }
  #save { min-width: 108px; }
  #stage.framing + #bar .workspace-tools { width: auto; }
}

@media (max-height: 650px) {
  /* Sticky commit actions also cover wide phones in landscape. */
  #exportDialog .panel-footer { position: sticky; bottom: -22px; z-index: 2; background: #fff; border-top: 1px solid #eee; padding-top: 10px; box-shadow: 0 -6px 8px #fff; }
  #exportDialog .panel-heading { position: sticky; top: -22px; z-index: 3; background: #fff; padding-top: 4px; }
}
@media (max-width: 760px) and (max-height: 650px) {
  #exportDialog .panel-footer { bottom: -14px; }
  #exportDialog .panel-heading { top: -14px; }
}
@media (min-width: 761px) and (max-height: 320px) {
  /* Short desktop windows also need enough room between sticky panel actions.
     Scroll the page instead of compressing a tool into an unusable strip. */
  body { height: auto; min-height: 100dvh; overflow-y: auto; }
  #stage { flex: none; min-height: 260px; }
  #stage.framing, #stage.background-open, #stage.help-open { min-height: max(260px, calc(var(--tool-panel-height, 400px) + 32px)); }
  .tool-panel { max-height: none; }
}

@media (max-width: 760px) and (max-height: 520px) {
  /* At extreme zoom there is not room for a photo and controls together.
     Let the document scroll rather than clipping either task area. */
  body { height: auto; min-height: 100dvh; overflow-y: auto; }
  #stage { flex: none; min-height: 220px; }
  #stage.framing, #stage.background-open, #stage.help-open { min-height: calc(220px + var(--tool-panel-height, 350px) + 8px); }
  .tool-panel, #framePanel { width: calc(100% - 28px); max-width: calc(100% - 28px); max-height: none; }
}

/* Keep the basic guide readable; disclose precision shortcuts on demand. */
.help-intro { color: #555; }
.help-handles { display: grid; gap: 7px; }
.keyboard-tips { border-top: 1px solid #e0e0e0; padding-top: 6px; color: #555; }
.keyboard-tips summary { display: list-item; min-height: 32px; padding: 6px 0; cursor: pointer; color: #222; }
.keyboard-tips summary:focus-visible { outline: 2px solid #222; outline-offset: 2px; }
.keyboard-tips p { margin: 6px 0; }
@media (hover: none) and (pointer: coarse) {
  .keyboard-tips summary { min-height: 44px; padding: 11px 0; }
}
