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

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
  color: #1f2428;
  background: #e8e6e1;
}

#topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid #cfccc5;
}
#logo { display: block; flex: none; margin: 6px 0; }
#tagline { flex: 1; margin: 0; padding: 4px 0; font-size: 16px; line-height: 1.35; color: #3d5a1e; }
.phone-only, .touch, #projectMenu { display: none; }

#toolbar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 22px;
  padding: 8px 16px 10px;
  background: #f6f5f1;
  border-bottom: 1px solid #cfccc5;
}
fieldset { border: 0; margin: 0; padding: 0; display: flex; align-items: center; gap: 6px; }
fieldset > label { min-height: 30px; display: flex; align-items: center; gap: 4px; }
.options { column-gap: 16px; }
legend { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6b6f73; padding: 0 0 2px; }

button, select, input { font: inherit; color: inherit; }
button, select, input[type="number"] {
  height: 30px;
  border: 1px solid #b9b5ad;
  border-radius: 5px;
  background: #fff;
}
button { padding: 0 11px; cursor: pointer; }
button:hover:not(:disabled) { background: #f1efea; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #1d5c63; border-color: #1d5c63; color: #fff; }
button.primary:hover:not(:disabled) { background: #16474d; }
input[type="number"] { width: 72px; padding: 0 6px; }

.segmented { display: flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 5px 0 0 5px; }
.segmented button:last-child { border-radius: 0 5px 5px 0; }
.segmented button + button { border-left: 0; }
.segmented button[aria-pressed="true"] { background: #1d5c63; border-color: #1d5c63; color: #fff; }

#workspace { flex: 1; display: flex; flex-direction: column; }

/* Tips or the selected art's controls on the left, undo and redo on the right. */
#designHeader {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 60px;
  padding: 10px 16px 0;
}
#designInfo { flex: 1; min-width: 0; }
#history { display: flex; gap: 6px; }
#history button { display: flex; align-items: center; gap: 6px; }
.arrow { display: inline-block; font-size: 20px; line-height: 1; }
.arrow.undo { transform: rotate(-90deg); }
.arrow.redo { transform: rotate(90deg); }
#ribbonHint { color: #55595d; }
#ribbonHint p { margin: 0 0 2px; }
#ribbonHint .keys { font-size: 12px; }
#ribbonControls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.asset-head { display: contents; }
/* Where the controls wrap to two rows, reserve both so the cards stay put. */
@media (min-width: 701px) and (max-width: 1750px) {
  #designHeader { min-height: 90px; }
}
#assetName { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#assetStatus { font-size: 13px; }
#ribbonControls:not(.is-text) .text-only, #ribbonControls.is-text .image-only,
#ribbonControls:not(.is-pane) .pane-only,
#ribbonControls.is-pane > :not(.pane-only, .asset-head) { display: none; }
#paneEyedropper { display: flex; align-items: center; gap: 6px; }
#paneEyedropper svg { order: -1; }
#paneEyedropper[aria-pressed="true"] { background: #1d5c63; border-color: #1d5c63; color: #fff; }
#paneColorName { min-width: 72px; font-size: 13px; }
#pickHint { font-size: 13px; color: #55595d; }
/* Large screens: Done closes the pane's properties. Phones always show it. */
@media (min-width: 701px) {
  #ribbonControls.is-pane #done { display: block; order: 1; }
  #pickHint { order: 2; }
}
#ribbonControls .segmented button { min-width: 34px; }
#textValue {
  width: 260px;
  max-width: 100%;
  resize: vertical;
  padding: 3px 6px;
  border: 1px solid #b9b5ad;
  border-radius: 5px;
  background: #fff;
  font: inherit;
  color: inherit;
}
input[type="color"] {
  width: 40px;
  height: 30px;
  padding: 2px;
  vertical-align: middle;
  border: 1px solid #b9b5ad;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}
input[type="range"] { width: 90px; vertical-align: middle; }
#textBgCustom { display: flex; align-items: center; gap: 8px; }
#assetStatus span { display: inline-block; margin-right: 8px; padding: 2px 8px; border-radius: 10px; background: #e4e9e6; }
#assetStatus span.warn { background: #ffe3b3; }
#assetStatus span.bad { background: #ffd0cb; }

#stage {
  flex: 1;
  min-height: 260px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: safe center;
  gap: 56px;
  padding: 8px 44px 32px;
}

/* Chosen by editor.js when one side above the other draws the card larger. */
#stage.stacked { flex-direction: column; align-items: safe center; justify-content: flex-start; gap: 28px; }
#stage.stacked figure { flex: none; }

figure { margin: 0; }
.zoom-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.zoom-bar .step { min-width: 34px; font-size: 20px; line-height: 1; }
.zoom-bar span { min-width: 150px; }
.zoom-bar .primary { margin-left: 8px; font-weight: normal; }
figcaption { margin-bottom: 10px; text-align: center; font-weight: 600; }

.sheet { position: relative; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, .18); }

.pane { position: absolute; overflow: hidden; }
/* Important: a pane's own background color is set on the element. */
.pane.dragover { background: #d8ecee !important; }
.pane.dragover .item { opacity: .5; }
.pane img, .pane canvas.item {
  position: absolute;
  max-width: none;
  user-select: none;
  touch-action: none;
  cursor: move;
}

.pane-label {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .85);
  color: #6b6f73;
  pointer-events: none;
}
.pane-empty {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #55595d;
}
.pane-empty:hover:not(:disabled) { background: #f4f8f8; }
.pane-empty.front { background: #edf5f5; box-shadow: inset 0 0 0 3px #1d5c63; }
.pane-empty.front:hover:not(:disabled) { background: #e2f0f1; }
.pane.dragover .pane-empty { background: transparent; }
/* With text or overlays but no main art: only the small prompt can be clicked. */
.pane-empty.quiet { pointer-events: none; align-items: flex-end; padding-bottom: 14%; }
.pane-empty.quiet .cta { pointer-events: auto; border: 1px solid #b9b5ad; font-size: 12px; }
.pane-empty.quiet .hint-art, .pane-empty.quiet small { display: none; }
/* A background color shows through the invitation, without the stand-ins. */
.pane.colored .pane-empty, .pane.colored .pane-empty:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
}
.pane.colored .hint-art { display: none; }
.pane.colored .cta { color: #55595d; }
.cta {
  position: relative;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .85);
  line-height: 1.3;
}
.cta small { display: block; font-size: 11px; }
.badge {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 3px 10px;
  border-radius: 12px;
  background: #1d5c63;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
/* Faded stand-ins. Multiply lets any white in the image disappear. */
.pane .hint-art {
  position: absolute;
  object-fit: contain;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.front .hint-art { left: 10%; top: 14%; width: 80%; height: 76%; opacity: .22; }
.back .hint-art { left: 33%; bottom: 14%; width: 34%; height: 28%; object-position: bottom; opacity: .35; }

.pane .slug { position: absolute; pointer-events: none; }

/* Faint until wanted, so the panel still looks like the card. */
.pane-tools {
  position: absolute;
  left: 50%;
  top: 40px;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  gap: 6px;
}
.pane-tools button, .pane-zoom {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  color: #1d5c63;
  opacity: .7;
}
.pane-zoom { position: absolute; right: 12px; bottom: 12px; z-index: 4; }
.pane-tools button:hover, .pane-tools button:focus-visible,
.pane-zoom:hover, .pane-zoom:focus-visible { opacity: 1; }
.pane-tools button[aria-pressed="true"] {
  background: #1d5c63;
  border-color: #1d5c63;
  color: #fff;
  opacity: 1;
}

/* Eyedropper: a layer that takes the clicks, and a magnifier. */
.picker { position: absolute; inset: 0; z-index: 8; cursor: crosshair; touch-action: none; }
.loupe {
  position: fixed;
  z-index: 40;
  width: 111px;
  height: 111px;
  overflow: hidden;
  border: 6px solid;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000, 0 4px 14px rgba(0, 0, 0, .35);
  pointer-events: none;
}
/* The white ring sets the picked color apart from the view inside it. */
.loupe canvas { display: block; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }

/*
 * With a mouse, a pane with something on it fades its buttons until pointed at.
 * Empty panes, and screens without hover, always show them.
 */
@media (hover: hover) and (pointer: fine) {
  .pane-tools button, .pane-zoom { transition: opacity .15s; }
  .pane.filled:not(:hover) .pane-tools button:not([aria-pressed="true"]):not(:focus-visible),
  .pane.filled:not(:hover) .pane-zoom:not(:focus-visible) { opacity: .12; }
}

.pane.short .pane-tools { top: 30px; }
.pane.short .pane-zoom { right: 4px; bottom: 4px; }
.pane.short .pane-empty { align-items: flex-end; padding-bottom: 8px; }
.pane.short .pane-empty.back { padding-bottom: 22px; } /* above the Pix-y link */
.pane.short .pane-empty .cta { font-size: 11px; }
.pane.short .cta small, .pane.short .hint-art { display: none; }

.guide { position: absolute; border: 1px dashed #3aa6b0; pointer-events: none; }

.fold { position: absolute; border: 0 dashed #8a8e92; pointer-events: none; }
.fold.vertical { top: -14px; bottom: -14px; left: 50%; border-left-width: 1px; }
.fold.horizontal { left: -14px; right: -14px; top: 50%; border-top-width: 1px; }

.selection { position: absolute; border: 1.5px solid #e0662b; pointer-events: none; z-index: 5; }
.handle {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: #fff;
  border: 1.5px solid #e0662b;
  border-radius: 2px;
  pointer-events: auto;
  touch-action: none;
}
.handle.rotate { top: -28px; left: 50%; border-radius: 50%; cursor: grab; }
.stem { position: absolute; left: 50%; top: -22px; height: 22px; border-left: 1.5px solid #e0662b; }
.selection.small::before {
  content: "";
  position: absolute;
  inset: -4px;
  pointer-events: auto;
  touch-action: none;
  cursor: move;
}
.selection.small .handle.edge { display: none; }
/* Text takes its height from its content, so only the sides and corners pull. */
.selection.small.text .handle.edge[data-hy="0"] { display: block; }
.selection.text .handle.edge[data-hx="0"] { display: none; }
.selection.small .handle:not(.rotate) {
  transform: translate(calc(var(--hx) * 9px), calc(var(--hy) * 9px));
}

#message {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  margin-top: 4px;
  font-weight: 600;
  color: #1d5c63;
}
#messageText { min-width: 0; overflow-wrap: anywhere; }
#messageClose { flex: none; width: 26px; height: 26px; padding: 0; }
#message.error { color: #b3261e; }
kbd { border: 1px solid #b9b5ad; border-radius: 3px; padding: 0 4px; }

/* Helpful info: a small "i" button that opens a dialog. */
button.info-button {
  position: relative;
  width: 15px;
  height: 15px;
  padding: 0;
  margin-right: 2px;
  vertical-align: top;
  border: 1px solid #1d5c63;
  border-radius: 50%;
  color: #1d5c63;
  font: italic bold 11px/1 Georgia, serif;
  text-transform: none;
}
button.info-button::after { content: ""; position: absolute; inset: -6px; }
.help {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid #b9b5ad;
  border-radius: 10px;
  color: inherit;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.help::backdrop { background: rgba(0, 0, 0, .35); }
.help-body { padding: 16px 18px; }
.help form { float: right; margin-left: 10px; }
.help h2 { margin: 0 0 12px; font-size: 18px; }
.help table { width: 100%; border-collapse: collapse; text-align: left; }
.help th, .help td { padding: 0 8px 0 0; vertical-align: top; text-align: left; }
.help thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6b6f73; }
.help tbody { border-top: 1px solid #e1ded7; }
.help tbody tr:first-child > * { padding-top: 8px; }
.help th { white-space: nowrap; }
.help th small { font-weight: normal; }
.help small { display: block; font-size: 12px; color: #6b6f73; }
.help .blurb td { padding: 2px 0 8px; font-size: 13px; color: #55595d; }
.help p { margin: 10px 0 0; }
.help p.note { font-size: 12px; color: #6b6f73; }
.help ul { margin: 10px 0 0; padding-left: 20px; }
.help li { margin-top: 6px; }
.help section:not([hidden]) ~ section { margin-top: 18px; padding-top: 14px; border-top: 1px solid #e1ded7; }
#projectMenu .info-button { align-self: center; }

/* Short or narrow screens: let the page scroll. Keep in step with editor.js. */
@media (max-width: 700px), (max-height: 560px) {
  body { display: block; height: auto; }
  fieldset { flex-wrap: wrap; min-width: 0; }
  #stage { flex-wrap: wrap; gap: 28px; min-height: 0; padding: 12px 20px 32px; }
}

/* Phones: settings behind buttons, export along the bottom, art controls in a sheet. */
@media (max-width: 700px) {
  body { padding-bottom: 72px; }
  body.has-selection { padding-bottom: 60vh; }
  button.phone-only { display: block; }
  #tagline { font-size: 13px; line-height: 1.3; }
  #menuToggle, #settingsToggle { flex: none; min-width: 42px; font-size: 20px; }

  #toolbar { gap: 8px; padding: 8px 12px; }
  #toolbar legend { display: none; }
  #settingsToggle { order: 1; margin-left: auto; }
  .options { order: 2; width: 100%; }
  .settings { order: 3; }
  fieldset.settings, button.desktop-only { display: none; }
  .show-settings fieldset.settings { display: flex; width: 100%; }
  .show-settings #toolbar .settings legend { display: block; }
  .show-settings #settingsToggle { background: #dcebec; }
  .show-project #projectMenu {
    display: flex;
    gap: 6px;
    position: absolute;
    top: 72px;
    right: 8px;
    z-index: 30;
    padding: 10px;
    background: #fff;
    border: 1px solid #b9b5ad;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  }

  fieldset.export {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    flex-wrap: nowrap;
    gap: 5px;
    padding: 12px 8px;
    background: #fff;
    border-top: 1px solid #cfccc5;
  }
  .export select { flex: 1; min-width: 0; }
  /* With both menus showing, the format takes only the room it needs. */
  .export #exportFormat:has(+ #exportSides:not([hidden])) { flex: none; }
  #toolbar .export .info-button, #projectMenu .info-button {
    flex: none;
    align-self: center;
    width: 26px;
    height: 26px;
    margin: 0;
    font-size: 16px;
  }
  #download { margin-left: auto; padding: 0 9px; }

  #designHeader { min-height: 0; padding: 10px 12px 0; align-items: center; }

  #ribbonControls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    max-height: 55vh;
    overflow-y: auto;
    gap: 8px 10px;
    padding: 10px 12px 14px;
    background: #fff;
    border-top: 3px solid #e0662b;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 20px rgba(0, 0, 0, .18);
    animation: slide-up .22s ease-out;
  }
  .asset-head { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; }
  #assetName { max-width: none; min-width: 0; }
  #textValue { width: 100%; }
  #textFont { max-width: 100%; }
  #ribbonControls input[type="number"] { width: 62px; }
  #ribbonControls button { padding: 0 10px; }

  /* Status messages float just above the export bar. */
  #message {
    width: auto;
    justify-content: space-between;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 76px;
    z-index: 15;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #cfccc5;
    border-radius: 8px;
  }
}
@keyframes slide-up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  #ribbonControls { animation: none !important; }
}

/* Fingers need bigger targets, and have no keyboard. */
@media (pointer: coarse) {
  button, select, input[type="number"] { height: 40px; font-size: 16px; }
  input[type="checkbox"] { width: 20px; height: 20px; vertical-align: middle; }
  #messageClose { width: 40px; }
  #textValue { font-size: 16px; }
  input[type="color"] { width: 48px; height: 40px; }
  .pane-tools button, .pane-zoom { width: 36px; height: 36px; }
  .pane-zoom { right: 8px; bottom: 28px; } /* clear of the Pix-y link */
  .pane.short .pane-tools { top: 28px; }
  .pane.short .pane-zoom { right: 3px; bottom: 3px; }
  button.info-button { width: 22px; height: 22px; margin-right: 4px; vertical-align: middle; font-size: 14px; }
  button.info-button::after { inset: -9px; }
  button.pane-empty { height: 100%; font-size: 14px; }
  /* Modest to look at, with a larger invisible touch area. */
  .handle { width: 16px; height: 16px; margin: -8px 0 0 -8px; }
  .handle::after { content: ""; position: absolute; inset: -10px; }
  .handle.rotate { top: -36px; }
  .selection.small .handle:not(.rotate) {
    transform: translate(calc(var(--hx) * 14px), calc(var(--hy) * 14px));
  }
  .selection.small .handle::after { inset: -6px; }
  .stem { top: -30px; height: 30px; }
  #ribbonHint .keys, .mouse, #ribbonHint .mouse { display: none; }
  .touch, #ribbonHint .touch { display: block; }
}
