.coin-editor {
  --ced-ink: #233e32;
  --ced-muted: #626b59;
  --ced-paper: #faf7ed;
  --ced-line: #dbd9c8;
  --ced-gold: #edcd83;
  box-sizing: border-box;
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: calc(100% - 12px);
  max-height: calc(100dvh - 12px);
  margin: 0;
  padding: 0;
  border: 1px solid var(--ced-line);
  border-radius: 20px 20px 0 0;
  overflow: hidden;
  color: var(--ced-ink);
  background: var(--ced-paper);
  box-shadow: 0 18px 80px #112a2370;
}

.coin-editor[open] { display: flex; flex-direction: column; }
.coin-editor::backdrop { background: #142d25ad; }
.coin-editor *, .coin-editor *::before, .coin-editor *::after { box-sizing: border-box; }
.coin-editor [hidden] { display: none !important; }
.coin-editor :is(button, input, select) { color: inherit; font: inherit; }
.coin-editor :is(button, input, select):focus-visible { outline: 2px solid #9c6522; outline-offset: 2px; }
.coin-editor button { cursor: pointer; }
.coin-editor button:disabled { cursor: default; opacity: .36; }
html:has(.coin-editor[open]) { overflow: hidden; }

.ced-head, .ced-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
}

.ced-head { border-bottom: 1px solid var(--ced-line); }
.ced-kicker, .ced-figure, .ced-count {
  font: 700 10px/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: .12em;
}

.ced-kicker { margin: 0 0 3px; color: var(--ced-muted); }
.ced-head h2 { font-size: 24px; letter-spacing: -.035em; margin: 0; }
.ced-head h2:focus { outline: none; }
.ced-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 12px 14px 16px; }

.coin-editor :is(.ced-close, .ced-add button, .ced-element-row button, .ced-foot button) {
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--ced-line);
  border-radius: 9px;
  background: #fffdf6;
  font-size: 13px;
  font-weight: 700;
}

.coin-editor button.ced-close { border-radius: 50%; font-size: 24px; font-weight: 400; }
.ced-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--ced-line);
  border-radius: 12px;
  background: #eeede1;
}

.ced-tabs button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
}

.ced-tabs button[aria-selected="true"] { background: var(--ced-ink); color: #fff9e9; }
.ced-tabs button span {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #d5decf;
  color: var(--ced-ink);
  font: 700 13px/1 Georgia, serif;
}
.ced-tabs button:first-child span { background: var(--ced-gold); }

.ced-panel, .ced-controls { display: grid; min-width: 0; gap: 12px; }
.ced-controls { align-content: start; }
.ced-preview {
  min-width: 0;
  padding: 12px 12px 10px;
  border-radius: 14px;
  color: #fff8e6;
  background-color: #214537;
  background-image: radial-gradient(ellipse at center, #5d6f4780, transparent 72%), radial-gradient(#f0e6b824 1px, transparent 1px);
  background-size: auto, 14px 14px;
}

.ced-preview-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.ced-live { font-size: 12px; font-weight: 700; }
.ced-live::before { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: #cbda9d; content: ''; vertical-align: .15em; }
.ced-figure { color: #dce1c6; }
.ced-stage { position: relative; isolation: isolate; display: grid; place-items: center; padding: 8px 10px; }
.ced-stage::before {
  position: absolute;
  z-index: -1;
  width: min(90%, 280px);
  height: 58%;
  border: 1px dashed #d9e5b449;
  border-radius: 50%;
  transform: rotate(-17deg);
  content: '';
}
.ced-coin { position: relative; width: min(100%, clamp(142px, 24vh, 195px)); aspect-ratio: 1; }
.ced-art, .ced-decals { position: absolute; inset: 0; }
.ced-art { filter: drop-shadow(0 7px 6px #0d241aa0); }
.ced-art svg { display: block; width: 100%; height: 100%; }
.ced-decals { clip-path: circle(48%); pointer-events: none; }

.coin-editor .ced-decal {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  max-width: 70%;
  padding: 4px;
  border: 0;
  border-radius: 7px;
  color: #4a331b;
  font-size: 18px;
  font-weight: 750;
  line-height: 1.1;
  background: transparent;
  transform: translate(-50%, -50%) rotate(var(--ced-angle));
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.ced-decal span { min-width: 0; max-width: 100%; overflow-wrap: anywhere; pointer-events: none; }
.ced-decal span:empty::before { content: '·'; }
.coin-editor .ced-decal[aria-pressed="true"] { outline: 1px dashed #624724; outline-offset: -3px; }
.coin-editor .ced-decal:focus-visible { outline: 2px solid #382814; outline-offset: 0; }
.coin-editor .ced-decal:active { cursor: grabbing; }
.ced-caption { text-align: center; font-size: 15px; font-weight: 750; overflow-wrap: anywhere; }
.ced-hint { margin: 4px 0 0; color: #dce1c6; text-align: center; font-size: 11px; }

.ced-field { display: grid; gap: 6px; padding: 11px; border: 1px solid var(--ced-line); border-radius: 12px; background: #fffdf6; }
.ced-field > label, .ced-field-title { font-size: 14px; font-weight: 750; }
.ced-field-title { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.ced-limit, .ced-empty { color: var(--ced-muted); font-size: 12px; font-weight: 400; }
.ced-empty { margin: 3px 0 0; }

.coin-editor :is(input[type="text"], select) {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid #d5d5c4;
  border-radius: 8px;
  background: #fffefa;
  font-size: 16px;
}
.coin-editor input[aria-invalid="true"] { border-color: #ac4834; }
.ced-error { margin: 0; color: #9d392c; font-size: 12px; }

.ced-colors, .ced-add { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.coin-editor .ced-swatch {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
}
.ced-swatch::before { width: 26px; height: 26px; border: 1px solid #4739215c; border-radius: 50%; background: var(--swatch); content: ''; }
.coin-editor .ced-swatch[aria-pressed="true"] { border-color: #47604b; background: #f0f2e6; }
.ced-custom { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; font-size: 12px; cursor: pointer; }
.ced-custom input { width: 44px; height: 44px; padding: 9px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; }
.ced-custom input::-webkit-color-swatch-wrapper { padding: 0; }
.ced-custom input::-webkit-color-swatch { border: 1px solid #4739215c; border-radius: 50%; }
.ced-custom input::-moz-color-swatch { border: 1px solid #4739215c; border-radius: 50%; }
.coin-editor .ced-add [data-emoji] { padding: 0 5px; font-size: 17px; }
.ced-properties { display: grid; gap: 6px; }
.ced-element-row, .ced-text-row, .ced-rotate { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; }
.ced-count { letter-spacing: 0; color: var(--ced-muted); white-space: nowrap; }
.ced-rotate { grid-template-columns: auto minmax(0, 1fr) 4ch; font-size: 12px; }
.ced-rotate input { width: 100%; min-height: 44px; margin: 0; accent-color: #345743; }
.ced-rotate output { text-align: right; font-variant-numeric: tabular-nums; }

.ced-foot {
  flex-wrap: wrap;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--ced-line);
  background: #f5f1e4;
}
.ced-history, .ced-save-row { display: flex; gap: 4px; }
.ced-save-row { margin-left: auto; }
.coin-editor .ced-history button span { font-size: 18px; }
.coin-editor button.ced-save { border-color: var(--ced-ink); color: #fff8e9; background: var(--ced-ink); padding-inline: 10px; }
.coin-editor .ced-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 370px) {
  .ced-foot { padding-inline: 9px; }
}

@media (hover: hover) {
  .coin-editor :is(.ced-close, .ced-add button, .ced-element-row button, .ced-foot button):not(:disabled):hover { background: #e9eddf; }
  .coin-editor button.ced-save:not(:disabled):hover { background: #355745; }
  .coin-editor .ced-decal:hover { background: #fff4bf70; }
}

@media (min-width: 640px) {
  .coin-editor { inset: 0; width: min(800px, calc(100% - 48px)); max-height: calc(100dvh - 48px); margin: auto; border-radius: 20px; }
  .ced-head, .ced-foot, .ced-scroll { padding-inline: 20px; }
  .ced-head, .ced-foot { padding-block: 14px; }
  .ced-tabs { width: min(100%, 310px); }
  .ced-panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: 14px; }
  .ced-preview { display: flex; flex-direction: column; justify-content: center; padding: 14px; }
  .ced-preview-head { margin-bottom: auto; }
  .ced-stage { flex: 1; }
  .ced-coin { width: min(100%, 218px); }
}
.ced-art canvas { display:block; width:100%; height:100%; }
