/* Loaded after the shared brand styles, only on sheet editing pages. */
.workspace.sheet-editor {
  --editor-top: calc(var(--editor-header-height, 72px) + 16px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 332px;
  gap: 20px;
  align-items: start;
}

.sheet-editor [hidden] {
  display: none !important;
}

.sheet-editor .editor-heading {
  grid-column: 1 / -1;
  min-width: 0;
}

.sheet-editor .editor-kicker {
  margin: 0 0 5px;
  color: var(--brand-ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sheet-editor .editor-heading h1 {
  margin: 0;
  font-size: clamp(28px, 3.4vw, 42px);
  line-height: 1.12;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.sheet-editor .editor-description {
  max-width: 62ch;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  text-wrap: pretty;
}

.sheet-editor .editor-heading > p:has(.badge) {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 10px 0 0;
}

.sheet-editor .editor-main {
  position: sticky;
  top: var(--editor-top);
  min-width: 0;
}

.sheet-editor .editor-stage {
  overflow: hidden;
  border: 1px solid #d8e7ef;
  border-radius: var(--r-lg);
  background: #edf5fa;
  box-shadow: 0 12px 30px -24px rgba(8, 22, 56, 0.35);
}

.sheet-editor .editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid #d8e7ef;
  background: var(--paper);
}

.sheet-editor .editor-toolbar button {
  gap: 5px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}

.sheet-editor .editor-toolbar button:hover:not(:disabled) {
  border-color: #c4e0f0;
  background: var(--brand-softer);
}

.sheet-editor .editor-toolbar button[aria-pressed="true"] {
  border-color: #9ecfe9;
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.sheet-editor .editor-toolbar button[data-editor-action="compare"] {
  margin-left: auto;
}

/* Auto margins center a fitted sheet but become zero when zoomed. Unlike
   centered grid alignment, this keeps the oversize sheet's top/left scrollable. */
.sheet-editor .editor-viewport {
  display: flex;
  align-items: flex-start;
  width: 100%;
  /* Leave room for the heading and the stage's toolbar/footer on first load,
     before the page has scrolled far enough to engage the sticky position. */
  height: clamp(240px, calc(100vh - 392px), 640px);
  height: clamp(240px, calc(100svh - var(--editor-header-height, 72px) - 320px), 640px);
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 24px;
  overscroll-behavior: contain;
  scrollbar-color: #a6bdca #edf5fa;
  scrollbar-width: thin;
  background-image: radial-gradient(rgba(8, 22, 56, 0.075) 0.7px, transparent 0.7px);
  background-size: 12px 12px;
}

/* JS supplies --paper-width in pixels and --paper-ratio as width / height.
   Margin properties are scaled pixel lengths after initialization. The PHP
   percentage fallback is correct while the no-JS paper fills the viewport.
   Keep the page border-box and its SVG shrinkable so intrinsic SVG dimensions
   cannot enlarge it. There are deliberately no paper, SVG, or filter animations. */
.sheet-editor .editor-paper.sheet-art {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 0 0 auto;
  width: var(--paper-width, 100%);
  height: auto;
  min-width: 0;
  min-height: 0;
  max-width: none;
  aspect-ratio: var(--paper-ratio, 210 / 297);
  margin: auto;
  padding: var(--paper-padding-top, 5.714285714%)
    var(--paper-padding-right, 5.714285714%)
    var(--paper-padding-bottom, 5.714285714%)
    var(--paper-padding-left, 5.714285714%);
  overflow: hidden;
  border: 0;
  border-radius: 1px;
  background: #fff;
  outline: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 5px rgba(8, 22, 56, 0.08), 0 12px 28px -12px rgba(8, 22, 56, 0.24);
}

.sheet-editor .editor-paper > svg {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
}

.sheet-editor .editor-preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 60px;
  padding: 8px 14px;
  border-top: 1px solid #d8e7ef;
  background: var(--paper);
}

.sheet-editor .editor-paper-label {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.sheet-editor .editor-zoom {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sheet-editor .editor-zoom select {
  width: 108px;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.sheet-editor .controls.editor-controls {
  position: static;
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 24px -20px rgba(8, 22, 56, 0.28);
}

.sheet-editor .editor-controls #customize-form {
  display: grid;
  gap: 22px;
}

.sheet-editor .editor-section h2 {
  margin: 0 0 14px;
  font-size: 20px;
  line-height: 1.2;
}

.sheet-editor .editor-section + .editor-section {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.sheet-editor .editor-presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 22px;
}

.sheet-editor .editor-preset {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 76px;
  padding: 10px 5px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--paper);
  text-align: center;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}

.sheet-editor .editor-preset strong {
  color: var(--navy);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.1;
}

.sheet-editor .editor-preset small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 550;
  line-height: 1.4;
  text-wrap: balance;
}

.sheet-editor .editor-preset:hover:not(:disabled) {
  border-color: #aacfe4;
  background: var(--brand-softer);
}

.sheet-editor .editor-preset[aria-pressed="true"] {
  border-color: var(--brand-ink);
  background: var(--brand-soft);
  box-shadow: 0 0 0 1px var(--brand-ink);
}

.sheet-editor .editor-preset[aria-pressed="true"] strong {
  color: var(--brand-ink);
}

.sheet-editor .editor-range + .editor-range {
  margin-top: 22px;
}

.sheet-editor .editor-range-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.sheet-editor .editor-range-heading output {
  min-width: 50px;
  padding: 3px 7px;
  border-radius: 7px;
  background: var(--brand-softer);
  color: var(--brand-ink);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.sheet-editor .editor-range input[type="range"] {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0;
}

.sheet-editor .editor-range input[type="range"]::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -9px;
  transition: none;
}

.sheet-editor .editor-range input[type="range"]::-webkit-slider-thumb:hover {
  transform: none;
}

.sheet-editor .editor-range input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
}

.sheet-editor .editor-range-hints {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.sheet-editor .editor-controls .editor-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-wrap: pretty;
}

.sheet-editor .editor-paper-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sheet-editor .editor-paper-options label {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.sheet-editor .editor-paper-options select {
  min-width: 0;
  height: 44px;
  color: var(--ink);
  font-size: 12px;
}

.sheet-editor .editor-save-row {
  display: grid;
  gap: 8px;
}

.sheet-editor .editor-save-row button {
  width: 100%;
  min-height: 46px;
}

.sheet-editor .editor-controls .editor-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  overflow-wrap: anywhere;
}

.sheet-editor .editor-status[data-state="error"] {
  color: var(--danger);
}

.sheet-editor .editor-status[data-state="saved"] {
  color: var(--accent);
}

.sheet-editor .editor-export {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.sheet-editor .editor-export > * {
  min-width: 0;
  min-height: 44px;
  padding-inline: 10px;
  font-size: 12px;
  text-align: center;
  white-space: normal;
}

.sheet-editor .editor-export > :last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.sheet-editor .editor-extras {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.sheet-editor .editor-extras > summary {
  display: list-item;
  min-height: 44px;
  padding: 10px 0;
  color: var(--brand-ink);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.sheet-editor .editor-extras .mini-panel:first-of-type {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 0;
}

.sheet-editor .button:hover {
  transform: none;
}

.sheet-editor button:active:not(:disabled),
.sheet-editor a.button:active,
.sheet-editor a.secondary-button:active {
  transform: scale(0.96);
}

.sheet-editor button,
.sheet-editor .secondary-button,
.sheet-editor .editor-extras button {
  min-height: 44px;
}

.sheet-editor :is(button, a, select, input, summary, .editor-viewport):focus-visible {
  outline: 3px solid var(--brand-ink);
  outline-offset: 3px;
}

.sheet-editor .editor-viewport:focus-visible {
  outline-offset: -4px;
}

@media (max-width: 820px) {
  /* Block flow gives the sticky preview the entire editor as its containing
     block, including the controls below it. The mobile site header is static;
     JS may set --editor-header-height if a sticky header is introduced. */
  .workspace.sheet-editor {
    --editor-top: calc(var(--editor-header-height, 0px) + 8px);
    --editor-preview-height: min(32vh, 280px);
    --editor-preview-height: min(32svh, 280px);
    display: block;
  }

  html:has(.sheet-editor) {
    scroll-padding-top: 12px;
    scroll-padding-bottom: 20px;
  }

  /* Focus scrolling must account for the artwork that remains above a control.
     Include the 114px toolbar/footer/borders and comfortable separation. */
  .sheet-editor .editor-controls :is(button, a, select, input, summary) {
    scroll-margin-top: calc(var(--editor-top) + var(--editor-preview-height) + 130px);
    scroll-margin-bottom: 20px;
  }

  .sheet-editor .editor-heading {
    margin-bottom: 18px;
  }

  .sheet-editor .editor-heading h1 {
    font-size: clamp(27px, 7vw, 36px);
  }

  .sheet-editor .editor-description {
    font-size: 13px;
  }

  .sheet-editor .editor-main {
    z-index: 2;
    margin-bottom: 18px;
  }

  .sheet-editor .editor-stage {
    border-radius: 16px;
    box-shadow: 0 8px 20px -12px rgba(8, 22, 56, 0.3);
  }

  .sheet-editor .editor-toolbar {
    flex-wrap: nowrap;
    gap: 3px;
    padding: 6px;
  }

  .sheet-editor .editor-toolbar button {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: 5px;
    font-size: 12px;
  }

  .sheet-editor .editor-toolbar button[data-editor-action="compare"] {
    margin-left: 0;
  }

  .sheet-editor .editor-viewport {
    height: var(--editor-preview-height);
    padding: 14px;
  }

  .sheet-editor .editor-preview-footer {
    min-height: 54px;
    gap: 6px;
    padding: 5px 10px;
  }

  .sheet-editor .editor-zoom {
    gap: 5px;
  }

  .sheet-editor .editor-zoom select {
    width: 100px;
  }

  .sheet-editor .controls.editor-controls {
    padding: 20px;
  }

  .sheet-editor .editor-preset small {
    font-size: 11px;
  }

  .sheet-editor .editor-paper-options select,
  .sheet-editor .editor-export > * {
    font-size: 13px;
  }
}

@media (max-width: 820px) and (max-height: 740px) {
  .workspace.sheet-editor {
    --editor-preview-height: min(24vh, 180px);
    --editor-preview-height: min(24svh, 180px);
  }

  .sheet-editor .editor-viewport {
    padding: 10px;
  }
}

@media (max-height: 500px) {
  /* Landscape phones and short windows need room for controls more than a
     persistent preview. Keep ordinary document scrolling in this case. */
  .sheet-editor .editor-main {
    position: static;
  }

  .sheet-editor .editor-viewport {
    height: clamp(180px, 50vh, 240px);
    height: clamp(180px, 50svh, 240px);
  }

  .sheet-editor .editor-controls :is(button, a, select, input, summary) {
    scroll-margin-top: calc(var(--editor-header-height, 0px) + 16px);
    scroll-margin-bottom: 16px;
  }
}

@media (max-width: 360px) {
  .sheet-editor .controls.editor-controls {
    padding: 16px;
  }

  .sheet-editor .editor-preset small {
    font-size: 10px;
  }

  .sheet-editor .editor-paper-label,
  .sheet-editor .editor-zoom {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sheet-editor button,
  .sheet-editor a.button,
  .sheet-editor a.secondary-button {
    animation: none;
    transition: none;
    transform: none !important;
  }
}
