.card-editor {
  --editor-ink: #17314b;
  --editor-muted: #687889;
  --editor-border: #e5d5bf;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
  gap: 24px;
  align-items: start;
  margin: 24px 0 42px;
  color: var(--editor-ink);
  font-family: 'Nunito', 'Source Sans 3', sans-serif;
}

.editor-sidebar {
  display: grid;
  gap: 14px;
}

.editor-background-column,
.editor-text-column {
  display: contents;
}

.editor-sidebar > .editor-background-column > .editor-panel:first-child { grid-row: 1; }
.editor-sidebar > .editor-background-column > .editor-panel:nth-child(2) { grid-row: 3; }
.editor-sidebar > .editor-text-column > .editor-panel { grid-row: 2; }

.editor-panel,
.editor-workspace {
  border: 1px solid var(--editor-border);
  border-radius: 16px;
  /*background: rgba(255, 250, 241, 0.96);*/
  background: rgba(255, 250, 241, 0.7);
  box-shadow: 0 5px 18px rgba(62, 42, 18, 0.08);
}

.editor-panel {
  padding: 16px;
}

.editor-panel-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.editor-panel-heading h2,
.preview-heading h2 {
  margin: 0;
  color: var(--editor-ink);
  font-family: 'Merienda', 'Lora', serif;
  font-size: 1.08rem;
  font-weight: 700;
}

.editor-step {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border-radius: 50%;
  background: #ad302a;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 800;
}

.background-list,
.asset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 8px;
}

.background-carousel {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 28px;
  gap: 6px;
  align-items: center;
}

.background-viewport {
  min-width: 0;
  overflow: hidden;
}

.background-carousel .background-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.background-carousel-button {
  display: grid;
  width: 28px;
  height: 34px;
  place-items: center;
  border: 1px solid #dfcfbb;
  border-radius: 7px;
  background: #fffaf1;
  color: #17314b;
  cursor: pointer;
  font: 700 1.5rem/1 'Source Sans 3', sans-serif;
}

.background-carousel-button:hover {
  border-color: #ba8a2b;
  background: #f7e6d6;
}

.asset-choice,
.background-choice {
  position: relative;
  overflow: hidden;
  min-width: 0;
  border: 2px solid transparent;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  transition:
    border-color 0.28s ease,
    background-color 0.28s ease,
    box-shadow 0.28s ease;
}

.asset-choice:hover,
.background-choice:hover {
  border-color: #ba8a2b;
  box-shadow: 0 4px 10px rgba(173, 48, 42, 0.14);
}

.asset-choice:focus-visible,
.background-choice:focus-visible,
.background-carousel-button:focus-visible,
.editor-action:focus-visible,
.element-action:focus-visible,
.card-element-flip-handle:focus-visible,
.card-element-align-button:focus-visible,
.export-button:focus-visible,
.color-option:focus-visible,
.alignment-options button:focus-visible,
.decoration-tab:focus-visible {
  outline: 3px solid #2360a5;
  outline-offset: 2px;
}

.background-choice {
  aspect-ratio: 3 / 2;
  padding: 3px;
  background: #fffdf9;
}

.background-choice.is-selected {
  border-color: #ad302a;
  box-shadow: 0 0 0 2px rgba(173, 48, 42, 0.16);
}

.background-choice img,
.asset-choice img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.background-choice img {
  background: #f4e8d4;
}

.asset-choice {
  display: grid;
  min-height: 65px;
  place-items: center;
  padding: 5px;
  border-color: #eee3d3;
  background: #fffdf9;
}

.asset-choice img {
  max-height: 66px;
  object-fit: contain;
  pointer-events: none;
}

.separator-list {
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.separator-list .asset-choice {
  min-height: 0;
  padding: 4px 10px;
  border-color: #ddccb5;
  background: #fffaf1;
}

.separator-list .asset-choice:hover {
  border-color: #ba8a2b;
}

.separator-list .asset-choice img {
  width: 100%;
  height: auto;
  max-height: 62px;
}

.asset-choice[draggable="true"] {
  cursor: grab;
}

.asset-choice[draggable="true"]:active {
  cursor: grabbing;
}

.decoration-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}

.decoration-tab {
  padding: 5px 10px;
  border: 1px solid #e6d6c1;
  border-radius: 999px;
  background: #fffaf1;
  color: #4c5862;
  cursor: pointer;
  font: inherit;
  font-size: 0.89rem;
}

.decoration-tab[aria-selected="true"] {
  border-color: #ad302a;
  background: #ad302a;
  color: #fff;
}

.editor-action {
  width: 100%;
  min-height: 38px;
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.editor-action-primary {
  background: #ad302a;
  color: #fff;
}

.editor-action-muted {
  margin: 12px 0 0;
  border: 1px solid #8e2521;
  background: #ad302a;
  color: #fff;
  box-shadow: 0 3px 8px rgba(173, 48, 42, 0.22);
}

.editor-action:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.editor-more-button {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid #d5c0a8;
  border-radius: 8px;
  background: #fffaf1;
  color: #8d342d;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.editor-more-button:hover {
  border-color: #ad302a;
  background: #f7e6d6;
}

.editor-action-muted:disabled {
  border-color: #ddd1c2;
  background: #eee8df;
  color: #a59b90;
  box-shadow: none;
  opacity: 1;
}

.editor-field {
  display: block;
  margin: 10px 0 5px;
  color: #435568;
  font-size: 0.8rem;
  font-weight: 800;
}

.editor-field output {
  float: right;
  font-weight: 600;
}

.editor-panel textarea,
.editor-panel select {
  width: 100%;
  border: 1px solid #d9c8b3;
  border-radius: 7px;
  background: #fffdf9;
  color: #17314b;
  font: inherit;
  font-size: 0.9rem;
}

.editor-panel textarea {
  min-height: 68px;
  padding: 9px;
  resize: vertical;
}

.editor-panel select {
  min-height: 36px;
  padding: 5px 8px;
}

.editor-panel textarea:disabled,
.editor-panel select:disabled,
.editor-panel input:disabled {
  opacity: 0.55;
}

.editor-control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
  align-items: end;
}

.editor-control-grid input[type="range"] {
  width: 100%;
  margin: 12px 0;
  accent-color: #ad302a;
}

.element-size-control {
  display: block;
  width: 100%;
  margin: 10px 0 12px;
  accent-color: #ad302a;
}

.element-actions {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
}

.element-action {
  display: inline-flex;
  width: 38px;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border: 1px solid #dfd1c0;
  border-radius: 6px;
  background: #fffdf9;
  color: #17314b;
  cursor: pointer;
}

.element-action img {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
  pointer-events: none;
}

.element-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.element-action[aria-pressed="true"] {
  border-color: #ad302a;
  background: #f7e6d6;
}

.color-options,
.alignment-options {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-option {
  width: 23px;
  height: 23px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px #b8aa98;
  cursor: pointer;
}

.color-option[data-color="#172b42"] { --swatch: #172b42; }
.color-option[data-color="#2360a5"] { --swatch: #2360a5; }
.color-option[data-color="#bd302c"] { --swatch: #bd302c; }
.color-option[data-color="#bd8b2f"] { --swatch: #bd8b2f; }
.color-option[data-color="#80502d"] { --swatch: #80502d; }
.color-option[data-color="#2f7047"] { --swatch: #2f7047; }

.color-option.is-selected {
  box-shadow: 0 0 0 2px #ad302a;
}

.alignment-options button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 32px;
  border: 1px solid #dfd1c0;
  border-radius: 6px;
  background: #fffdf9;
  color: #17314b;
  cursor: pointer;
}

.alignment-options button img {
  display: block;
  width: 18px;
  height: 18px;
  object-fit: contain;
  pointer-events: none;
}

.alignment-options button[data-align="left"] { text-align: left; }
.alignment-options button[data-align="center"] { text-align: center; }
.alignment-options button[data-align="right"] { text-align: right; }
.alignment-options button.is-selected { border-color: #ad302a; background: #f7e6d6; }

.editor-right-column {
  display: grid;
  min-width: 0;
  gap: 18px;
}

.editor-workspace {
  min-width: 0;
  padding: clamp(16px, 3vw, 28px);
}

.preview-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.preview-eyebrow {
  margin: 0 0 3px;
  color: #9c6c31;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.preview-hint {
  max-width: 270px;
  margin: 0;
  color: var(--editor-muted);
  font-size: 0.8rem;
  text-align: right;
}

.card-preview {
  position: relative;
  overflow: hidden;
  container-type: inline-size;
  width: 100%;
  max-width: none;
  aspect-ratio: 3 / 2;
  margin: 0;
  border: 7px solid #fffaf1;
  border-radius: 10px;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  box-shadow: 0 8px 28px rgba(27, 35, 40, 0.2);
  touch-action: none;
}

.preview-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(80%, 320px);
  margin: 0;
  color: #687889;
  font-family: 'Merienda', cursive;
  font-size: clamp(1rem, 3vw, 1.45rem);
  text-align: center;
  transform: translate(-50%, -50%);
}

.card-elements {
  position: absolute;
  inset: 0;
}

.card-element {
  position: absolute;
  z-index: 1;
  min-width: 26px;
  min-height: 20px;
  border: 1px dashed transparent;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.card-element.is-selected {
  z-index: 2;
  border-color: #2360a5;
  outline: 1px solid rgba(255, 255, 255, 0.9);
}

.card-element-resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  z-index: 3;
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 3px;
  background: #2360a5;
  box-shadow: 0 1px 4px rgba(23, 49, 75, 0.35);
  cursor: nwse-resize;
  touch-action: none;
}

.card-element-flip-handle {
  position: absolute;
  top: -7px;
  right: -7px;
  z-index: 3;
  display: none;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  padding: 3px;
  border: 1px solid #dfd1c0;
  border-radius: 4px;
  background: #fffdf9;
  cursor: pointer;
}

.card-element-flip-handle img {
  display: block;
  width: 14px;
  height: 14px;
  object-fit: contain;
  pointer-events: none;
}

.card-element.is-selected .card-element-flip-handle {
  display: flex;
}

.card-element-flip-handle[aria-pressed="true"] {
  border-color: #ad302a;
  background: #f7e6d6;
}

.card-element-align-handles {
  position: absolute;
  top: -7px;
  right: -7px;
  z-index: 3;
  display: none;
  gap: 2px;
}

.card-element.is-selected .card-element-align-handles {
  display: flex;
}

.card-element-align-button {
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border: 1px solid #dfd1c0;
  border-radius: 4px;
  background: #fffdf9;
  cursor: pointer;
}

.card-element-align-button img {
  display: block;
  width: 14px;
  height: 14px;
  object-fit: contain;
  pointer-events: none;
}

.card-element-align-button.is-selected {
  border-color: #ad302a;
  background: #f7e6d6;
}

.card-element.is-selected .card-element-resize-handle {
  display: block;
}

.card-element img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

.card-element.is-flipped-y > img {
  transform: scaleX(-1);
}

.card-element-text {
  min-width: 20%;
  min-height: 1.2em;
  padding: 3px 5px;
  font-size: calc(var(--text-size, 28) * 1px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.card-element.is-exporting,
.card-element.is-exporting * {
  border-color: transparent !important;
  outline-color: transparent !important;
}

.card-element.is-exporting .card-element-resize-handle {
  display: none;
}

.card-element.is-exporting .card-element-flip-handle {
  display: none;
}

.card-element.is-exporting .card-element-align-handles {
  display: none;
}

.card-preview.is-exporting {
  border-color: transparent;
  border-radius: 0;
  box-shadow: none;
}

.card-export-watermark {
  position: absolute;
  right: 12px;
  bottom: 10px;
  z-index: 3;
  padding: 3px 7px;
  border-radius: 4px;
  background: rgba(255, 250, 241, 0.68);
  color: rgba(23, 49, 75, 0.72);
  font: 600 clamp(8px, 1vw, 12px) / 1.2 'Source Sans 3', sans-serif;
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
}

.decoration-panel {
  min-width: 0;
}

.preview-empty[hidden] {
  display: none;
}

.export-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 22px 0 8px;
}

.export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  box-shadow: 0 4px 11px rgba(40, 30, 20, 0.13);
}

.export-button-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.export-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.export-image { background: #2E6B3F; }
.export-pdf { background: #a42d27; }
.export-share { background: #003151; }

.share-button-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.share-info-tooltip {
  position: relative;
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border: 1px solid #003151;
  border-radius: 50%;
  color: #003151;
  cursor: help;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 800;
  line-height: 1;
}

.share-info-tooltip-text {
  position: absolute;
  z-index: 3;
  right: -8px;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: min(280px, calc(100vw - 32px));
  padding: 8px 10px;
  border-radius: 6px;
  background: #003151;
  color: #fff;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 600;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  visibility: hidden;
}

.share-info-tooltip-text::after {
  position: absolute;
  top: 100%;
  right: 10px;
  border: 5px solid transparent;
  border-top-color: #003151;
  content: '';
}

.share-info-tooltip:hover .share-info-tooltip-text,
.share-info-tooltip:focus .share-info-tooltip-text {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

.export-status {
  min-height: 1.5em;
  margin: 0;
  color: var(--editor-muted);
  font-size: 0.85rem;
  text-align: center;
}

.shared-card-page {
  max-width: 1600px;
  margin: 80px auto 42px;
  padding: 0 20px;
}

.shared-card-panel {
  width: 100%;
  padding: clamp(16px, 3vw, 32px);
  border: 1px solid var(--editor-border);
  border-radius: 16px;
  background: rgba(255, 250, 241, 0.96);
  box-shadow: 0 5px 18px rgba(62, 42, 18, 0.08);
}

.shared-card-panel h1 {
  margin: 0 0 20px;
  color: var(--editor-ink);
  font-family: 'Merienda', 'Lora', serif;
  font-size: clamp(1.25rem, 2.5vw, 1.8rem);
  text-align: center;
}

.shared-card-preview {
  position: relative;
  overflow: hidden;
  container-type: inline-size;
  width: 100%;
  margin-inline: auto;
  aspect-ratio: 3 / 2;
  border: 7px solid #fffaf1;
  border-radius: 10px;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  box-shadow: 0 8px 28px rgba(27, 35, 40, 0.2);
}

@media (min-width: 1101px) {
  .shared-card-preview {
    width: 85%;
  }
}

.shared-card-element {
  position: absolute;
  z-index: 1;
  min-width: 26px;
  min-height: 20px;
}

.shared-card-element img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.shared-card-element-text {
  min-height: 1.2em;
  padding: 3px 5px;
  font-size: calc(var(--text-size, 28) * 1px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.shared-card-error {
  margin: 0;
  color: #a42d27;
  text-align: center;
}

@supports (font-size: 1cqw) {
  .card-element-text,
  .shared-card-element-text {
    font-size: calc(var(--text-size, 28) * 100cqw / 700);
  }
}

@media (max-width: 850px) {
  .card-editor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .editor-sidebar,
  .editor-right-column {
    display: contents;
  }

  .editor-workspace {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .editor-sidebar {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .editor-background-column,
  .editor-text-column {
    display: grid;
    gap: 14px;
    align-content: start;
  }

  .editor-sidebar > .editor-background-column > .editor-panel:first-child,
  .editor-sidebar > .editor-background-column > .editor-panel:nth-child(2),
  .editor-sidebar > .editor-text-column > .editor-panel {
    grid-row: auto;
  }

  .editor-background-column {
    grid-column: 1;
    grid-row: 1;
  }

  .editor-text-column {
    grid-column: 2;
    grid-row: 1;
  }

  .decoration-panel {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .separator-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
}

@media (max-width: 560px) {
  .card-editor {
    grid-template-columns: minmax(0, 1fr);
  }

  .editor-sidebar {
    grid-template-columns: minmax(0, 1fr);
  }

  .editor-background-column {
    grid-column: 1;
    grid-row: 1;
  }

  .editor-text-column {
    grid-column: 1;
    grid-row: 2;
  }

  .decoration-panel {
    grid-column: 1;
    grid-row: 3;
  }

  .editor-workspace {
    padding: 14px;
  }

  .preview-heading {
    align-items: start;
    flex-direction: column;
  }

  .preview-hint {
    text-align: left;
  }

  .card-preview {
    border-width: 4px;
  }
}