:root {
  --bg: #14110f;
  --bg2: #1c1815;
  --card: #221d19;
  --line: #3a312a;
  --ink: #f6eee3;
  --mute: #b4a796;
  --coral: #ff8a70;
  --coral-ink: #2a0f08;
  --lav: #b9a7ff;
  --lime: #c6ff4d;
  --r: 14px;
  --pad: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font: 16px/1.4 var(--font);
  background:
    radial-gradient(120% 60% at 100% 0%, #2a1c2e 0%, transparent 55%),
    radial-gradient(90% 50% at 0% 100%, #2b1912 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
.defs { position: absolute; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 22px; height: 22px; flex: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--lav); outline-offset: 2px; }
a { color: inherit; }

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 0 max(var(--pad), env(safe-area-inset-right)) 0 max(var(--pad), env(safe-area-inset-left));
}

/* top */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 0 8px;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; border-radius: 8px; }
.mark { width: 28px; height: 28px; shape-rendering: crispEdges; }
.word { font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }
.by {
  font-size: 13px; color: var(--coral); font-weight: 700;
  padding: 3px 9px; border: 1.5px dashed #ff8a7088; border-radius: 99px;
  transform: rotate(-3deg);
}

/* layout */
.work { flex: 1; display: flex; flex-direction: column; gap: 14px; }

.stage {
  position: sticky; top: 0; z-index: 3;
  margin: 0 calc(-1 * var(--pad));
  padding: 8px var(--pad) 6px;
  background: linear-gradient(var(--bg) 85%, transparent);
}
.board {
  position: relative;
  display: grid; place-items: center;
  padding: 12px;
  border-radius: var(--r);
  background:
    repeating-conic-gradient(#1f1a17 0 25%, #191512 0 50%) 0 0 / 16px 16px;
  border: 1.5px solid var(--line);
  overflow: hidden;
}
#view {
  display: block;
  max-width: 100%;
  max-height: min(40vh, 340px);
  width: auto; height: auto;
  border-radius: 6px;
  box-shadow: 0 10px 30px #0008, 0 0 0 1px #ffffff14;
  touch-action: manipulation;
}
.board.round #view { border-radius: 50%; }
.board.picking #view { cursor: crosshair; outline: 3px dashed var(--lime); outline-offset: 3px; }
.hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  margin: 0; padding: 5px 12px; border-radius: 99px;
  background: #000c; color: var(--lime); font-size: 13px; font-weight: 700; white-space: nowrap;
  pointer-events: none;
}
.loading { position: absolute; top: 10px; right: 12px; margin: 0; display: flex; gap: 4px; }
.loading span { width: 7px; height: 7px; background: var(--coral); animation: hop 0.9s infinite steps(2); }
.loading span:nth-child(2) { animation-delay: 0.15s; background: var(--lav); }
.loading span:nth-child(3) { animation-delay: 0.3s; background: var(--lime); }
@keyframes hop { 50% { transform: translateY(-5px); } }
.size { margin: 6px 0 0; text-align: center; font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; }

.panel { display: flex; flex-direction: column; gap: 14px; padding-bottom: 8px; }

/* formats */
.formats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 5px; border-radius: 16px; background: var(--bg2); border: 1.5px solid var(--line);
}
.formats button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; padding: 6px 2px; border: 0; border-radius: 12px; background: none;
  color: var(--mute); font-size: 13px; font-weight: 700;
}
.formats button.on { background: var(--coral); color: var(--coral-ink); transform: rotate(-1.5deg); }
.formats button:hover:not(.on) { color: var(--ink); }

.group { display: flex; flex-direction: column; gap: 8px; }
.group[hidden] { display: none; }
.label { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; font-size: 13px; font-weight: 800; color: var(--mute); text-transform: lowercase; letter-spacing: .02em; }
.count { font-weight: 600; font-variant-numeric: tabular-nums; }

/* chips */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { display: flex; align-items: stretch; border-radius: 12px; background: var(--card); border: 1.5px solid var(--line); overflow: hidden; }
.chips li:first-child { border-color: var(--coral); }
.chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 4px; border: 0; background: none;
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
}
.chip canvas { width: 32px; height: 32px; image-rendering: pixelated; border-radius: 7px; background: #0003; }
.chip .n { padding-right: 2px; }
.chip .crown { width: 14px; height: 14px; color: var(--coral); }
.rm { display: grid; place-items: center; width: 34px; border: 0; background: none; color: var(--mute); }
.rm svg { width: 16px; height: 16px; }
.rm:hover { color: var(--coral); }

.add { display: flex; gap: 6px; }
.add input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg2);
  font-size: 16px; font-variant-numeric: tabular-nums;
}
.add input::placeholder, #addr::placeholder { color: #8d8172; }
.icon {
  display: grid; place-items: center; flex: none;
  width: 46px; height: 46px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card);
  transition: border-color .2s, background .2s;
}
.icon:hover { border-color: var(--lav); }
.icon[aria-pressed="true"] { background: var(--lime); color: #101; border-color: var(--lime); }
.note { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--mute); }
.note:empty { min-height: 0; }

/* segmented */
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg2); border: 1.5px solid var(--line); }
.seg button {
  flex: 1; min-height: 40px; padding: 0 8px; border: 0; border-radius: 9px; background: none;
  color: var(--mute); font-weight: 700; font-size: 14px; transition: background .2s, color .2s;
}
.seg button[aria-checked="true"] { background: var(--lav); color: #17102e; }
.seg.mini { padding: 3px; text-transform: none; }
.seg.mini button { min-height: 32px; font-size: 13px; padding: 0 12px; }

/* toggle */
.toggle { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; font-size: 14px; cursor: pointer; align-self: flex-start; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.knob { position: relative; width: 46px; height: 28px; border-radius: 99px; background: var(--card); border: 1.5px solid var(--line); transition: background .2s; }
.knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: var(--mute); transition: transform .2s, background .2s; }
.toggle input:checked + .knob { background: var(--coral); border-color: var(--coral); }
.toggle input:checked + .knob::after { transform: translateX(18px); background: var(--coral-ink); }
.toggle input:focus-visible + .knob { outline: 3px solid var(--lav); outline-offset: 2px; }

/* swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw {
  width: 38px; height: 38px; padding: 0; border-radius: 11px;
  border: 2px solid #ffffff22; background: var(--c);
  transition: transform .15s;
}
.sw:hover { transform: translateY(-2px) rotate(-4deg); }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
.from { display: flex; align-items: center; gap: 8px; padding-top: 8px; border-top: 1.5px dashed var(--line); }
.from .swatches { flex: 1; }
.from .sw { width: 30px; height: 30px; border-radius: 6px; }
.slots { display: flex; gap: 8px; }
.slot { display: flex; align-items: center; gap: 6px; padding: 4px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg2); }
.slot i { display: block; width: 28px; height: 28px; border-radius: 7px; background: var(--c); border: 1.5px solid #ffffff22; }
.slot[aria-pressed="true"] { border-color: var(--ink); }
.slot::after { content: attr(data-n); font-size: 12px; font-weight: 800; color: var(--mute); padding-right: 6px; }

/* dock */
.dock {
  position: sticky; bottom: 0; z-index: 2;
  margin: 4px calc(-1 * var(--pad)) 0;
  padding: 10px var(--pad) max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.save {
  width: 100%; min-height: 54px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 16px;
  background: var(--coral); color: var(--coral-ink);
  font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 0 #b4503b;
  transition: transform .1s, box-shadow .1s;
}
.save:active { transform: translateY(3px); box-shadow: 0 1px 0 #b4503b; }
.save[disabled] { opacity: .6; cursor: progress; }

.foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 0 max(14px, env(safe-area-inset-bottom));
  font-size: 13px; color: var(--mute);
}
.foot b { color: var(--coral); }
.foot a { display: inline-block; padding: 8px 2px; color: var(--lime); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.dot { width: 4px; height: 4px; background: var(--lav); }

/* 404 */
.lost { justify-content: center; align-items: center; text-align: center; gap: 16px; }
.lost .mark.big { width: 56px; height: 56px; }
.lost p { margin: 0; font-weight: 800; font-size: 20px; }
.lost .save { width: auto; padding: 0 24px; text-decoration: none; }

/* dialog */
dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px; border-radius: 18px;
  border: 1.5px solid var(--line); background: var(--bg2); color: var(--ink);
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
#addr {
  width: 100%; height: 48px; padding: 0 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); font-size: 16px; font-family: ui-monospace, Menlo, monospace;
}
dialog .note { margin: 8px 0 14px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; }
.ghost, .primary { min-height: 44px; padding: 0 18px; border-radius: 12px; font-weight: 800; }
.ghost { background: none; border: 1.5px solid var(--line); }
.primary { background: var(--coral); color: var(--coral-ink); border: 0; }

/* larger screens and landscape */
@media (min-width: 900px) {
  .app { max-width: 1180px; margin: 0 auto; width: 100%; }
  .work { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; align-items: start; }
  .stage { top: 16px; margin: 0; padding: 0; background: none; }
  .board { height: min(72vh, 640px); padding: 28px; }
  #view { max-height: calc(min(72vh, 640px) - 60px); }
  .panel { padding-top: 0; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .top { padding-bottom: 2px; }
  .work { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 44%); gap: 16px; align-items: start; }
  .stage { top: 0; margin: 0; padding: 4px 0 0; background: none; }
  .board { height: calc(100dvh - 92px); min-height: 120px; padding: 8px; }
  #view { max-height: calc(100dvh - 112px); }
  .size { margin-top: 2px; }
  .formats button { min-height: 44px; flex-direction: row; justify-content: center; gap: 6px; }
  .formats button span { font-size: 12px; }
  .foot { padding-top: 4px; }
}
@media (orientation: landscape) and (max-height: 560px) and (max-width: 700px) {
  .formats button span { display: none; }
}
@media (max-width: 360px) {
  :root { --pad: 12px; }
  .formats button { font-size: 12px; }
  .icon { width: 44px; height: 44px; }
  .add input { height: 44px; }
  .sw { width: 34px; height: 34px; }
}
@media (max-height: 620px) and (orientation: portrait) {
  .stage { position: static; }
  #view { max-height: 34vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .formats button.on, .by { transform: none; }
}
