:root {
  --bg: #0b0c0a;
  --s1: #121410;
  --s2: #1a1d17;
  --s3: #262a21;
  --line: #2e3328;
  --text: #eef2e6;
  --dim: #a3a99a;
  --lime: #c3ff5c;
  --lime-ink: #142000;
  --lav: #b9a7ff;
  --coral: #ff8a70;
  --r: 10px;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column; overflow-x: hidden;
}
a { color: var(--lime); }
svg { width: 20px; height: 20px; flex: none; }
button, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

/* top */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px)) calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l));
  border-bottom: 1px solid var(--line); background: var(--s1);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); min-height: 44px; min-width: 0; }
.logo { width: 28px; height: 28px; }
.name { font-weight: 800; font-size: 20px; letter-spacing: .02em; }
.tag { color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--s2); cursor: pointer; font-weight: 650; white-space: nowrap;
}
.btn:hover { border-color: #4a5240; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--lime); color: var(--lime-ink); border-color: var(--lime); }
.btn.ghost { background: transparent; }
.btn.icon { width: 44px; padding: 0; flex: none; }
.btn.small { padding: 0 12px; font-size: 14px; }
.link { background: none; border: 0; color: var(--lime); text-decoration: underline; cursor: pointer; padding: 10px 2px; min-height: 44px; }

/* layout */
.app {
  flex: 1; width: 100%; max-width: 1180px; margin: 0 auto;
  padding: 14px calc(14px + var(--safe-r)) 18px calc(14px + var(--safe-l));
  display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr);
}
.stage, .panel { min-width: 0; }

.find { display: flex; gap: 8px; }
.find input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--s1); font-size: 16px;
}
.find input::placeholder { color: #80867a; }

.picks { display: flex; align-items: center; gap: 10px; margin-top: 10px; min-width: 0; }
.picks-label { color: var(--dim); font-size: 13px; flex: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px 0 4px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--s1); cursor: pointer; font-size: 13px; font-weight: 600;
}
.chip canvas { width: 34px; height: 34px; image-rendering: pixelated; border-radius: 999px; background: #000; }
.chip[aria-current="true"] { border-color: var(--lime); }
.chip.mine { border-color: #4b4470; }

.view {
  position: relative; margin: 12px auto 0; width: 100%;
  max-width: min(100%, 62dvh, 560px); aspect-ratio: 1 / 1;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background-color: #151713;
  background-image: linear-gradient(45deg, #1d201a 25%, transparent 25%, transparent 75%, #1d201a 75%), linear-gradient(45deg, #1d201a 25%, transparent 25%, transparent 75%, #1d201a 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px;
  display: flex; align-items: center; justify-content: center;
}
.view.tall { aspect-ratio: 50 / 54.4; }
#cv { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; display: block; }
.veil { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(11, 12, 10, .72); color: var(--dim); font-size: 14px; text-align: center; padding: 20px; }
.veil.err { color: var(--coral); }
.info { margin: 10px 0 0; color: var(--dim); font-size: 14px; text-align: center; min-height: 1.45em; }
.info b { color: var(--text); font-weight: 650; }

.strip { list-style: none; margin: 10px 0 0; padding: 2px 2px 6px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: thin; }
.strip li { flex: none; }
.strip button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 5px; min-width: 64px; min-height: 44px;
  background: var(--s1); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.strip canvas { width: 52px; height: 52px; image-rendering: pixelated; background: #000; border-radius: 4px; }
.strip .cap { font-size: 12px; color: var(--dim); line-height: 1.2; text-align: center; }
.strip .life { min-height: 52px; width: 52px; display: grid; place-items: center; color: var(--lime); font-weight: 800; font-size: 12px; text-align: center; background: #000; border-radius: 4px; }
.strip button.on { border-color: var(--lime); }
.strip button.on .cap { color: var(--text); }

/* panel */
.panel { background: var(--s1); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-direction: column; gap: 7px; }
.lbl { font-size: 13px; color: var(--dim); font-weight: 600; display: flex; justify-content: space-between; }
.lbl output { color: var(--text); font-variant-numeric: tabular-nums; }
.hint { margin: 0; font-size: 13px; color: var(--dim); }
.hint:empty { display: none; }
.seg { display: flex; gap: 4px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent;
  cursor: pointer; font-size: 14px; font-weight: 650; color: var(--dim);
}
.seg button[aria-checked="true"] { background: var(--s3); color: var(--text); box-shadow: inset 0 -2px 0 var(--lime); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--lime); margin: 0; }
.toggles { gap: 2px; }
.tog { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 14px; }
.tog input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tog .box { width: 24px; height: 24px; border-radius: 6px; border: 1.5px solid #59614d; display: grid; place-items: center; flex: none; }
.tog .box svg { width: 16px; height: 16px; opacity: 0; color: var(--lime-ink); }
.tog input:checked + .box { background: var(--lime); border-color: var(--lime); }
.tog input:checked + .box svg { opacity: 1; }
.tog input:focus-visible + .box { outline: 2px solid var(--lime); outline-offset: 2px; }

.export { display: flex; flex-wrap: wrap; gap: 8px; }
.export .btn { flex: 1 1 120px; }
.progress { height: 6px; border-radius: 3px; background: var(--s3); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--lime); transition: width .12s linear; }
.note { margin: 0; font-size: 13px; color: var(--dim); min-height: 1.4em; }
.note.err { color: var(--coral); }
.perk { margin: 0; font-size: 13px; color: var(--dim); border-top: 1px solid var(--line); padding-top: 10px; }
.perk span { color: var(--lav); }

body[data-mode="evolution"] .only-motion, body[data-mode="motion"] .only-evo { display: none; }

.foot {
  display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; text-align: center;
  padding: 14px calc(14px + var(--safe-r)) calc(16px + var(--safe-b)) calc(14px + var(--safe-l));
  color: var(--dim); font-size: 12px; border-top: 1px solid var(--line);
}

/* dialog */
.dlg {
  width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  background: var(--s1); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
}
.dlg::backdrop { background: rgba(0, 0, 0, .66); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg p { color: var(--dim); font-size: 14px; }
.wallets { display: flex; flex-direction: column; gap: 8px; }
.wbtn { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--s2); cursor: pointer; text-align: left; }
.wico { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--s3); flex: none; }
.wname { flex: 1; font-weight: 650; }
.wsub { color: var(--dim); font-size: 12px; }
.status { min-height: 1.4em; }

/* wider screens: preview left, settings right */
@media (min-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; gap: 22px; padding-top: 20px; }
  .panel { position: sticky; top: 16px; max-height: calc(100dvh - 32px); overflow: auto; }
  .view { max-width: min(100%, 70dvh, 640px); }
}
/* phone landscape and short screens: side by side so the preview stays visible */
@media (orientation: landscape) and (max-height: 540px) {
  .app { grid-template-columns: minmax(0, 1fr) minmax(260px, 46%); align-items: start; }
  .panel { max-height: calc(100dvh - 24px); overflow: auto; position: sticky; top: 8px; }
  .view { max-width: min(100%, calc(100dvh - 150px)); }
  .tag { display: none; }
}
@media (max-width: 359px) {
  .tag { display: none; }
  .seg button { font-size: 13px; padding: 0 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .progress span { transition: none; }
}
