/* Sprite Matcher — phone-first, dark, chunky. */
:root {
  --bg: #0b0d2b;
  --bg-2: #17123f;
  --panel: #1b1f4d;
  --panel-2: #252a63;
  --line: #343a80;
  --text: #f4f3ff;
  --muted: #a9aad8;
  --accent: #4fd1ff;
  --ok: #46e08a;
  --danger: #ff5c7a;

  --v-regular: #8fa3bf;
  --v-fortune: #ff4d6d;
  --v-cursed: #a35cff;
  --v-golden: #ffc83d;
  --v-special: #3ddcff;

  --display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --gutter: 12px;
  --tap: 48px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(120% 60% at 50% 0%, #2a1a6b 0%, var(--bg-2) 40%, var(--bg) 100%) fixed;
  background-color: var(--bg);
  color: var(--text);
  font: 16px/1.35 var(--body);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) calc(env(safe-area-inset-bottom) + 24px);
}

/* ---------- top bar ---------- */
.brand {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: .5px;
  text-align: center;
  margin: 2px 0 10px;
  background: linear-gradient(90deg, var(--v-golden), var(--v-fortune), var(--v-cursed));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.seg > button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: .3px;
  padding: 6px 8px;
}
.seg > button[aria-selected="true"] {
  background: linear-gradient(180deg, #5b62ff, #3b3fd1);
  color: #fff;
  box-shadow: 0 2px 0 #22258c, 0 0 0 1px rgba(255,255,255,.15) inset;
}
.kid-switch > button { font-size: 22px; min-height: 56px; }
.kid-switch > button[aria-selected="true"] { background: linear-gradient(180deg, #ffd860, #f0a81c); color: #2b1a00; box-shadow: 0 3px 0 #a36b00; }
.tabs { margin-top: 8px; }

/* ---------- counter ---------- */
.counter {
  margin: 14px 0 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.counter-main { display: flex; align-items: baseline; gap: 8px; font-family: var(--display); }
.counter-main .big { font-size: 34px; line-height: 1; }
.counter-main .of { color: var(--muted); font-size: 20px; }
.counter-main .label { color: var(--muted); font-size: 16px; margin-right: 2px; }
.counter-bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.08); margin: 10px 0; overflow: hidden; }
.counter-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--v-cursed), var(--v-fortune), var(--v-golden)); border-radius: 99px; }
.mini { display: flex; flex-wrap: wrap; gap: 6px; }
.mini span {
  font-size: 13px; font-weight: 700;
  padding: 3px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--vc) 18%, transparent);
  color: var(--vc);
  border: 1px solid color-mix(in srgb, var(--vc) 45%, transparent);
}

/* ---------- variant colours ---------- */
.v-regular { --vc: var(--v-regular); }
.v-fortune { --vc: var(--v-fortune); }
.v-cursed  { --vc: var(--v-cursed); }
.v-golden  { --vc: var(--v-golden); }
.v-special { --vc: var(--v-special); }

/* ---------- grid ---------- */
.variant-head, .cells {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.variant-head {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(env(safe-area-inset-top) + 6px) 0 6px;
  margin: 0 calc(var(--gutter) * -1);
  padding-left: var(--gutter); padding-right: var(--gutter);
  background: linear-gradient(180deg, var(--bg-2) 80%, rgba(23,18,63,0));
}
.variant-head span {
  text-align: center;
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: .3px;
  padding: 6px 2px;
  border-radius: 10px;
  color: #10122f;
  background: var(--vc);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row { margin: 10px 0 14px; }
.row-head {
  display: flex; align-items: center; gap: 6px;
  min-height: 36px;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.row-num { font-family: var(--display); color: var(--muted); font-size: 14px; width: 24px; }
.row-name { font-family: var(--display); font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit {
  width: 44px; height: 44px; margin: -4px -6px -4px 0;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 18px;
}
.edit:active { background: var(--panel-2); }

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 44px;
  width: 100%;
  padding: 0;
  border-radius: var(--radius);
  border: 2px solid var(--vc);
  border: 2px solid color-mix(in srgb, var(--vc) 55%, transparent);
  background: #1b1f4d;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--vc) 38%, #1b1f4d) 0%, #14173c 75%);
  overflow: hidden;
  transition: transform .08s;
}
.cell:active { transform: scale(.95); }
.art { position: absolute; inset: 8% 8% 22%; display: flex; align-items: center; justify-content: center; }
.art img { width: 100%; height: 100%; object-fit: contain; }
.sil {
  width: 82%; height: 82%;
  background: var(--vc);
  -webkit-mask: url("img/silhouette.svg") center / contain no-repeat;
  mask: url("img/silhouette.svg") center / contain no-repeat;
}
.badge {
  position: absolute; left: 50%; bottom: 6%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--display);
  font-size: 15px; line-height: 1;
  padding: 4px 7px 3px;
  border-radius: 8px;
}
.cell-name {
  position: absolute; top: 4px; left: 0; right: 0;
  font-size: 11px; font-weight: 800; text-align: center; color: var(--vc);
  text-shadow: 0 1px 2px #000;
}
.s-owned .badge { background: #fff; color: #14173c; box-shadow: 0 2px 0 rgba(0,0,0,.4); }
.s-owned { box-shadow: 0 0 12px -2px color-mix(in srgb, var(--vc) 70%, transparent); }
.s-buyable { border-style: dashed; background: #14173c; }
.s-buyable .art { opacity: .38; filter: saturate(.5); }
.s-buyable .badge { background: rgba(0,0,0,.65); color: var(--v-golden); font-size: 13px; border: 1px solid rgba(255,200,61,.5); }
.s-locked { border-color: #2a2e5e; background: #101230; }
.s-locked .sil { background: #262a55; }
.s-locked .art img { filter: brightness(0) invert(.15); opacity: .9; }
.s-locked .badge { color: #4b5090; font-size: 14px; }

.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 18px 8px 0; }

/* ---------- compare ---------- */
.seg-compare { margin-top: 14px; }
.seg-compare > button { font-size: 14px; line-height: 1.1; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.seg-compare .n { font-size: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip {
  min-height: 44px; padding: 0 14px;
  border-radius: 99px;
  border: 2px solid color-mix(in srgb, var(--vc, var(--accent)) 60%, transparent);
  background: transparent;
  color: var(--vc, var(--text));
  font-weight: 800; font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--vc, var(--accent)); color: #10122f; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px 8px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--vc);
  border-radius: var(--radius);
  min-height: 64px;
}
.item.actionable { border-color: color-mix(in srgb, var(--v-golden) 60%, transparent); border-left-color: var(--vc); background: linear-gradient(90deg, var(--panel), #2b2650); }
.thumb {
  flex: none; width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--vc) 38%, #1b1f4d) 0%, #14173c 75%);
}
.thumb img { width: 90%; height: 90%; object-fit: contain; }
.thumb .sil { width: 70%; height: 70%; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-family: var(--display); font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-block; margin-top: 3px;
  font-size: 12px; font-weight: 800; letter-spacing: .3px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 99px;
  background: var(--vc); color: #10122f;
}
.note { font-size: 13px; color: var(--v-golden); font-weight: 700; margin-top: 4px; }
.lvl { flex: none; font-family: var(--display); font-size: 16px; text-align: right; color: var(--muted); }
.lvl b { font-weight: normal; }
.lvl .hi { color: var(--ok); }
.lvl .mine { color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; font-family: var(--display); font-size: 20px; }

/* ---------- bottom sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(4, 5, 20, .6); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 16px);
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  animation: up .18s ease-out;
  max-height: 90vh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet::before { content: ""; display: block; width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head .thumb { width: 64px; height: 64px; }
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: normal; font-size: 22px; line-height: 1.1; }
.sheet-head .who { color: var(--muted); font-size: 13px; margin-top: 4px; }
.close { margin-left: auto; width: 48px; height: 48px; border-radius: 14px; border: 0; background: var(--panel-2); font-size: 20px; flex: none; }
.sheet h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.state-btns, .levels { display: grid; gap: 8px; }
.state-btns { grid-template-columns: repeat(3, 1fr); }
.levels { grid-template-columns: repeat(5, 1fr); }
.big-btn {
  min-height: 56px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--panel-2);
  font-family: var(--display); font-size: 18px;
}
.big-btn[aria-pressed="true"] { border-color: #fff; background: #fff; color: #14173c; }
.big-btn.st-owned[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); }
.big-btn.st-buyable[aria-pressed="true"] { background: var(--v-golden); border-color: var(--v-golden); }
.big-btn.st-locked[aria-pressed="true"] { background: #646aa8; border-color: #646aa8; color: #fff; }
.levels .big-btn { font-size: 22px; }
.price-row { display: flex; gap: 8px; align-items: center; }
.price-row .coin { font-size: 24px; color: var(--v-golden); }
.price-row input {
  flex: 1; min-width: 0; min-height: 56px;
  border-radius: 14px; border: 2px solid var(--line); background: #10122f; color: var(--text);
  font: 22px var(--display); padding: 0 14px;
}
.done { width: 100%; margin-top: 18px; background: linear-gradient(180deg, #5b62ff, #3b3fd1); border-color: #3b3fd1; }

/* ---------- PIN pad ---------- */
.pin {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: radial-gradient(120% 60% at 50% 0%, #2a1a6b 0%, var(--bg-2) 45%, var(--bg) 100%);
  overflow-y: auto;
}
.pin-inner { width: 100%; max-width: 320px; text-align: center; }
.pin-logo { border-radius: 18px; }
.pin h1 { font-family: var(--display); font-weight: normal; margin: 8px 0 4px; font-size: 28px; }
.pin-msg { color: var(--muted); min-height: 1.4em; margin: 0 0 14px; }
.pin-msg.err { color: var(--danger); font-weight: 700; }
.pin-dots { display: flex; justify-content: center; gap: 12px; height: 22px; margin-bottom: 20px; }
.pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--v-golden); border-color: var(--v-golden); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-10px); } 50% { transform: translateX(10px); } 75% { transform: translateX(-6px); } }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-keys button {
  height: 72px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--panel-2);
  font-family: var(--display); font-size: 32px;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.pin-keys button:active { transform: translateY(2px); box-shadow: none; }
.pin-keys .key-alt { font-size: 26px; color: var(--muted); }
.pin-keys .key-ok { background: var(--ok); color: #0b2a17; border-color: var(--ok); }
.pin-keys button:disabled { opacity: .5; }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--danger); color: #fff; font-weight: 800;
  padding: 12px 18px; border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.toast.good { background: var(--ok); color: #0b2a17; }
.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 22px; color: var(--muted); }

@media (min-width: 600px) {
  .brand { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
