/* ==========================================================================
   TCG Radar — Mini App
   Colori: quelli di Telegram (variabili --tg-theme-* impostate dallo SDK)
   con ripiego chiaro/scuro fuori da Telegram, + un accento vermiglione (朱).
   Il tema si sceglie con <html data-scheme="light|dark"> (vedi js/tg.js).
   ========================================================================== */

:root {
  --accent: #D8321F;          /* bottoni pieni (testo bianco sopra: contrasto AA) */
  --accent-ink: #C02A18;      /* accento usato come colore del testo su sfondo */
  --accent-soft: rgba(216, 50, 31, .10);
  --on-accent: #fff;

  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #121214);
  --hint: var(--tg-theme-hint-color, #6f6f78);
  --link: var(--tg-theme-link-color, #2a7de1);
  --sep: var(--tg-theme-section-separator-color, rgba(120, 120, 130, .22));
  --danger: var(--tg-theme-destructive-text-color, #d93025);

  --up: #D9730D;              /* prezzo in salita */
  --down: #178A4C;            /* prezzo in discesa */
  --gold: #C9A227;
  --wish: #E0A100;

  --surface: color-mix(in srgb, var(--text) 5%, var(--bg));
  --surface-2: color-mix(in srgb, var(--text) 9%, var(--bg));
  --skel-a: color-mix(in srgb, var(--text) 7%, var(--bg));
  --skel-b: color-mix(in srgb, var(--text) 13%, var(--bg));
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.07);
  --dim-opacity: .34;

  --r-sm: 8px; --r-md: 12px; --r-lg: 18px;
  --tabbar-h: 58px;
  --appbar-h: 52px;

  /* aree sicure: notch (browser) + Telegram fullscreen (8.0+) */
  --safe-top: calc(env(safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue",
          "Hiragino Sans", "Noto Sans JP", Arial, sans-serif;
  color-scheme: light;
}

html[data-scheme="dark"] {
  --bg: var(--tg-theme-bg-color, #111114);
  --bg2: var(--tg-theme-secondary-bg-color, #000000);
  --section: var(--tg-theme-section-bg-color, #1b1b20);
  --text: var(--tg-theme-text-color, #f4f4f6);
  --hint: var(--tg-theme-hint-color, #9a9aa6);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --sep: var(--tg-theme-section-separator-color, rgba(255, 255, 255, .12));
  --danger: var(--tg-theme-destructive-text-color, #ff6b61);
  --accent: #E23B2A;
  --accent-ink: #FF7D6E;
  --accent-soft: rgba(255, 110, 95, .14);
  --up: #FFA24D;
  --down: #4FD08A;
  --gold: #E6C35C;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  --dim-opacity: .30;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 18px; height: 18px; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  overscroll-behavior-y: none;
  font-variant-numeric: tabular-nums;
}
body.no-tabbar { padding-bottom: calc(24px + var(--safe-bottom)); }
body.has-mainbtn { padding-bottom: calc(88px + var(--safe-bottom)); }
body.sheet-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
img { display: block; max-width: 100%; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

/* ---------- barra in alto ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.appbar.scrolled { border-bottom-color: var(--sep); }
.appbar__back { border: 0; background: none; padding: 6px; margin-left: -8px; color: var(--accent-ink); display: grid; }
.appbar__back svg { width: 26px; height: 26px; stroke-width: 2.4; }
.appbar__title {
  flex: 1; margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar__actions { display: flex; gap: 4px; }
.iconbtn { border: 0; background: none; padding: 8px; border-radius: 50%; color: var(--text); display: grid; place-items: center; }
.iconbtn:active { background: var(--surface-2); }

/* wordmark in Home */
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font-weight: 900; letter-spacing: -.035em; text-transform: uppercase; }
.brand b i { font-style: normal; color: var(--accent-ink); }
.brand small { font-size: 11px; font-weight: 700; color: var(--hint); letter-spacing: .12em; }

/* ---------- area schermata ---------- */
.view { outline: none; padding: 4px 16px 16px; max-width: 720px; margin: 0 auto; }
.view.enter { animation: viewIn .18s ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section { margin: 22px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.section h2 { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--hint); }
.section a, .section button.link { font-size: 14px; font-weight: 600; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- barra in basso ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--sep);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--hint); font-size: 10.5px; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent-ink); }
.tabbar a.active svg { stroke-width: 2.3; }
body.no-tabbar .tabbar { display: none; }

/* ---------- bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r-md);
  border: 0; background: var(--surface-2); color: var(--text);
  font-weight: 700; font-size: 15px; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--ghost { background: transparent; color: var(--accent-ink); }
.btn--danger { background: transparent; color: var(--danger); }
.btn--block { width: 100%; }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.btnrow > .btn { flex: 1 1 0; }

.mainbtn-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
body:not(.no-tabbar) .mainbtn-wrap { bottom: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: 10px; }
.mainbtn-wrap .btn { min-height: 50px; font-size: 16px; box-shadow: var(--shadow); }

/* ---------- pillole / filtri ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 16px; margin: 0 -16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--sep); background: var(--bg); color: var(--text);
  height: 34px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .count { font-weight: 700; opacity: .6; font-size: 12.5px; }
.chips--wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; height: 32px; border-radius: 8px; font-weight: 650; font-size: 13.5px; color: var(--hint); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- campo di ricerca ---------- */
.searchbox { position: relative; display: flex; align-items: center; }
.searchbox svg { position: absolute; left: 12px; width: 19px; height: 19px; color: var(--hint); pointer-events: none; }
.searchbox input {
  width: 100%; height: 46px; border-radius: var(--r-md); border: 0;
  background: var(--surface-2); padding: 0 40px 0 40px; font-size: 16px; outline: none;
}
.searchbox input::placeholder { color: var(--hint); }
.searchbox input:focus { box-shadow: 0 0 0 2px var(--accent-soft), inset 0 0 0 1px var(--accent-ink); }
.searchbox .clear { position: absolute; right: 6px; border: 0; background: none; color: var(--hint); padding: 8px; }
.searchbox .clear svg { position: static; }
.stickybar { position: sticky; top: calc(var(--appbar-h) + var(--safe-top)); z-index: 10; background: var(--bg); padding: 6px 0 10px; }

/* ---------- carta (tile) ---------- */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; }
@media (min-width: 400px) { .grid--dense { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 8px; } }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } .grid--dense { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.tile { position: relative; display: block; min-width: 0; border: 0; padding: 0; background: none; text-align: left; color: inherit; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tile__img {
  position: relative; aspect-ratio: 63 / 88; border-radius: 6.5% / 4.7%;
  background: var(--skel-a); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .12s ease-out, filter .25s, opacity .25s;
}
.tile__img img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.tile__img img.loaded { opacity: 1; }
.tile__img .noimg { position: absolute; inset: 0; display: grid; place-items: center; padding: 8px; text-align: center; font-size: 11px; font-weight: 700; color: var(--hint); }
.tile:active .tile__img { transform: scale(.96); }
.tile__meta { padding: 6px 2px 0; min-width: 0; }
.tile__name { font-size: 12.5px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile__sub { font-size: 11.5px; color: var(--hint); display: flex; gap: 4px; align-items: center; white-space: nowrap; overflow: hidden; }
.tile__sub span { overflow: hidden; text-overflow: ellipsis; }

/* stato nella checklist: mancante = sbiadita */
.tile--missing .tile__img { filter: grayscale(1) contrast(.9); opacity: var(--dim-opacity); box-shadow: none; }
.tile--missing .tile__name { color: var(--hint); font-weight: 600; }
.tile--owned .tile__img { box-shadow: var(--shadow); }
.tile.pop .tile__img { animation: pop .32s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { 0% { transform: scale(.9); } 100% { transform: scale(1); } }

/* rarità alta: bordino dorato-iridescente (solo se posseduta) */
.tile--hi.tile--owned .tile__img::after, .tile--hi:not(.tile--missing) .tile__img::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--gold) 85%, transparent);
}

/* bollini sulla carta */
.badge-qty, .badge-wish, .badge-owned {
  position: absolute; z-index: 2; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; line-height: 1;
}
.badge-qty { right: 5px; bottom: 5px; min-width: 22px; height: 20px; padding: 0 5px; border-radius: 10px; background: rgba(0,0,0,.72); color: #fff; }
.badge-wish { left: 5px; top: 5px; width: 20px; height: 20px; border-radius: 50%; background: var(--wish); color: #fff; font-size: 11px; }
.badge-owned { right: 5px; top: 5px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; }
.badge-owned svg, .badge-wish svg { width: 12px; height: 12px; stroke-width: 3; }
.tile--missing .badge-wish { opacity: 1; filter: none; }
.tile__more {
  position: absolute; z-index: 3; right: 2px; top: 2px; width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: none; color: #fff; display: grid; place-items: center; padding: 0;
}
.tile__more span { width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.55); display: grid; place-items: center; font-size: 14px; font-weight: 900; letter-spacing: -1px; line-height: 1; }

.rarity { display: inline-flex; align-items: center; height: 16px; padding: 0 5px; border-radius: 4px; font-size: 10px; font-weight: 800; letter-spacing: .02em; background: var(--surface-2); color: var(--hint); flex: none; }
.rarity--hi { background: color-mix(in srgb, var(--gold) 22%, transparent); color: color-mix(in srgb, var(--gold) 70%, var(--text)); }
.trend { display: inline-flex; align-items: center; gap: 2px; height: 18px; padding: 0 6px; border-radius: 5px; font-size: 11px; font-weight: 800; flex: none; }
.trend--down { color: var(--down); background: color-mix(in srgb, var(--down) 13%, transparent); }
.trend--up { color: var(--up); background: color-mix(in srgb, var(--up) 14%, transparent); }
.trend--flat { color: var(--hint); background: var(--surface-2); }

/* ---------- scheletri di caricamento ---------- */
.skel { background: linear-gradient(90deg, var(--skel-a) 25%, var(--skel-b) 50%, var(--skel-a) 75%); background-size: 300% 100%; animation: shimmer 1.3s linear infinite; border-radius: var(--r-sm); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skel-tile { aspect-ratio: 63 / 88; border-radius: 6.5% / 4.7%; }
.skel-line { height: 11px; margin-top: 7px; border-radius: 5px; }
.skel-row { height: 72px; border-radius: var(--r-md); margin-bottom: 8px; }

/* ---------- elenchi (righe) ---------- */
.list { background: var(--section); border-radius: var(--r-lg); overflow: hidden; }
html[data-scheme="light"] .list { box-shadow: 0 0 0 1px var(--sep); }
.row { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 64px; background: var(--section); color: var(--text); width: 100%; border: 0; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 72px; right: 0; border-top: 1px solid var(--sep); }
.row__thumb { width: 44px; flex: none; aspect-ratio: 63/88; border-radius: 4px; overflow: hidden; background: var(--skel-a); }
.row__thumb img { width: 100%; height: 100%; object-fit: cover; }
.row__body { flex: 1; min-width: 0; }
.row__title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__sub { font-size: 13px; color: var(--hint); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.row__end { flex: none; display: flex; align-items: center; gap: 4px; }
.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--text); }
.pill--accent { background: var(--accent-soft); color: var(--accent-ink); }

/* righe scorrevoli (collezione / wishlist) */
.swipe { position: relative; overflow: hidden; }
.swipe__bg { position: absolute; inset: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; font-weight: 800; font-size: 13px; color: #fff; }
.swipe__bg .l, .swipe__bg .r { display: flex; align-items: center; gap: 6px; opacity: 0; transition: opacity .1s; }
.swipe[data-dir="right"] .swipe__bg { background: var(--wish); }
.swipe[data-dir="left"] .swipe__bg { background: var(--danger); justify-content: flex-end; }
.swipe[data-dir="right"] .swipe__bg .l, .swipe[data-dir="left"] .swipe__bg .r { opacity: 1; }
.swipe > .row { transition: transform .22s ease-out; touch-action: pan-y; }
.swipe.dragging > .row { transition: none; }
.swipe.leaving { animation: collapse .25s ease-in forwards; }
@keyframes collapse { to { max-height: 0; min-height: 0; opacity: 0; } }
.swipe + .swipe .row::before { content: ""; position: absolute; top: 0; left: 72px; right: 0; border-top: 1px solid var(--sep); }

.group-h { display: flex; align-items: center; gap: 10px; margin: 20px 4px 8px; }
.group-h img { height: 22px; width: auto; max-width: 90px; object-fit: contain; }
.group-h b { font-size: 15px; font-weight: 800; }
.group-h span { margin-left: auto; font-size: 13px; color: var(--hint); font-weight: 600; }

/* ---------- barre di avanzamento ---------- */
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .35s cubic-bezier(.2, .8, .2, 1); }
.progress--done > i { background: linear-gradient(90deg, var(--gold), #F2D98B, var(--gold)); }

/* ---------- Home ---------- */
.hello { margin: 8px 0 14px; }
.hello h2 { margin: 0; font-size: 26px; font-weight: 900; letter-spacing: -.03em; line-height: 1.1; }
.hello p { margin: 4px 0 0; color: var(--hint); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 4px; }
.stat { background: var(--surface); border-radius: var(--r-md); padding: 12px 10px; }
.stat b { display: block; font-size: 26px; font-weight: 900; letter-spacing: -.03em; line-height: 1; }
.stat span { font-size: 12px; color: var(--hint); font-weight: 600; }
.stat:first-child { background: var(--text); color: var(--bg); }
.stat:first-child span { color: color-mix(in srgb, var(--bg) 70%, transparent); }
.shortcuts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shortcut {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 12px; min-height: 84px; border-radius: var(--r-md); background: var(--surface); color: var(--text); border: 0; text-align: left;
}
.shortcut svg { width: 24px; height: 24px; color: var(--accent-ink); }
.shortcut b { font-size: 13.5px; font-weight: 750; line-height: 1.2; }
.shortcut .soon { position: absolute; top: 8px; right: 8px; font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); background: var(--surface-2); border-radius: 4px; padding: 2px 5px; }
.shortcut:active { background: var(--surface-2); }

.setcard { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--section); color: var(--text); border-radius: var(--r-md); border: 0; width: 100%; text-align: left; }
html[data-scheme="light"] .setcard { box-shadow: 0 0 0 1px var(--sep); }
.setcard + .setcard { margin-top: 8px; }
.setcard__logo { width: 76px; height: 40px; flex: none; display: grid; place-items: center; }
.setcard__logo img { max-width: 76px; max-height: 40px; width: auto; height: auto; object-fit: contain; }
.setcard__logo .code { font-weight: 900; font-size: 15px; letter-spacing: -.02em; padding: 6px 8px; border-radius: 6px; background: var(--text); color: var(--bg); }
.setcard__body { flex: 1; min-width: 0; }
.setcard__title { font-weight: 800; font-size: 15px; display: flex; gap: 6px; align-items: baseline; }
.setcard__title small { color: var(--hint); font-weight: 700; font-size: 12px; }
.setcard__sub { font-size: 12.5px; color: var(--hint); margin: 2px 0 7px; display: flex; justify-content: space-between; }
.setcard__sub b { color: var(--text); font-weight: 800; }

/* ---------- Checklist ---------- */
.set-hero { display: flex; align-items: center; gap: 14px; margin: 6px 0 12px; }
.set-hero__logo { width: 110px; height: 54px; flex: none; display: grid; place-items: center; }
.set-hero__logo img { max-width: 110px; max-height: 54px; width: auto; height: auto; object-fit: contain; }
.set-hero__count { margin-left: auto; text-align: right; }
.set-hero__count b { font-size: 30px; font-weight: 900; letter-spacing: -.04em; line-height: 1; }
.set-hero__count span { font-size: 16px; font-weight: 800; color: var(--hint); }
.set-hero__count small { display: block; font-size: 12px; color: var(--hint); font-weight: 600; }
.checklist-bar { position: sticky; top: calc(var(--appbar-h) + var(--safe-top)); z-index: 10; background: var(--bg); padding: 8px 0 10px; margin-bottom: 4px; }
.checklist-bar .progress { margin-bottom: 10px; }
.hint-line { font-size: 12.5px; color: var(--hint); margin: 0 0 10px; }
.sentinel { height: 1px; }

/* ---------- Scheda carta ---------- */
.card-hero { display: flex; justify-content: center; padding: 6px 0 4px; }
.card-hero .tile__img { width: min(68vw, 290px); border-radius: 4.6% / 3.3%; box-shadow: 0 10px 34px rgba(0,0,0,.25); cursor: zoom-in; }
.card-title { text-align: center; margin: 16px 0 4px; }
.card-title h2 { margin: 0; font-size: 24px; font-weight: 900; letter-spacing: -.03em; line-height: 1.15; }
.card-title p { margin: 4px 0 0; color: var(--hint); font-size: 14px; display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }
.names { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin: 10px 0 2px; }
.names span { font-size: 13px; background: var(--surface); padding: 4px 9px; border-radius: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; padding: 12px 14px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; font-weight: 650; text-align: right; }
.cm-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cm-buttons .btn { font-size: 14px; }

/* ---------- fogli dal basso (sheet) ---------- */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.42); animation: fadeIn .18s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-bottom));
  animation: sheetIn .24s cubic-bezier(.2, .9, .3, 1); max-width: 720px; margin: 0 auto;
}
.sheet.closing { animation: sheetOut .18s ease-in forwards; }
.backdrop.closing { animation: fadeOut .18s forwards; }
.sheet__grip { width: 38px; height: 5px; border-radius: 3px; background: var(--surface-2); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 2px; font-size: 19px; font-weight: 850; letter-spacing: -.02em; }
.sheet__head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.sheet__head .row__thumb { width: 52px; }
.field { margin: 14px 0; }
.field > label, .field > .label { display: block; font-size: 12.5px; font-weight: 800; color: var(--hint); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 7px; }
.stepper { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 12px; }
.stepper button { width: 46px; height: 42px; border: 0; background: none; font-size: 22px; font-weight: 600; }
.stepper output { min-width: 40px; text-align: center; font-weight: 850; font-size: 18px; }
.range { width: 100%; accent-color: var(--accent); height: 30px; }
.range-val { font-weight: 900; font-size: 20px; color: var(--accent-ink); }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheetOut { to { transform: translateY(100%); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }

/* zoom immagine */
.zoom { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 20px; animation: fadeIn .2s; cursor: zoom-out; }
.zoom img { max-width: 100%; max-height: 92vh; border-radius: 3.5% / 2.5%; animation: zoomIn .25s cubic-bezier(.2, .9, .3, 1); }
@keyframes zoomIn { from { transform: scale(.85); opacity: .4; } }

/* ---------- avvisi (snackbar) ---------- */
.snackbar-host { position: fixed; left: 12px; right: 12px; z-index: 70; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 10px); display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 560px; margin: 0 auto; }
body.no-tabbar .snackbar-host { bottom: calc(var(--safe-bottom) + 14px); }
body.has-mainbtn .snackbar-host { bottom: calc(var(--safe-bottom) + 84px); }
.snackbar { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: #1f1f24; color: #fff; box-shadow: 0 8px 26px rgba(0,0,0,.28); font-size: 14.5px; font-weight: 600; animation: snackIn .22s cubic-bezier(.2, .9, .3, 1); }
html[data-scheme="dark"] .snackbar { background: #f2f2f5; color: #111; }
.snackbar.error { background: var(--danger); color: #fff; }
.snackbar span { flex: 1; }
.snackbar button { border: 0; background: none; color: #FF8A7D; font-weight: 850; text-transform: uppercase; font-size: 13px; letter-spacing: .04em; padding: 4px 2px; }
html[data-scheme="dark"] .snackbar button { color: var(--accent); }
.snackbar.out { animation: snackOut .18s forwards; }
@keyframes snackIn { from { transform: translateY(16px); opacity: 0; } }
@keyframes snackOut { to { transform: translateY(12px); opacity: 0; } }

/* ---------- stati vuoti (retino manga) ---------- */
.empty { position: relative; text-align: center; padding: 36px 20px 30px; border-radius: var(--r-lg); margin: 12px 0; overflow: hidden; }
.empty::before {
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: .55;
  background-image: radial-gradient(color-mix(in srgb, var(--text) 16%, transparent) 1.1px, transparent 1.4px);
  background-size: 7px 7px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 20%, transparent 72%);
          mask-image: radial-gradient(ellipse at center, #000 20%, transparent 72%);
}
.empty .kanji { font-size: 44px; font-weight: 900; color: var(--accent-ink); line-height: 1; font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; }
.empty h3 { margin: 12px 0 4px; font-size: 18px; font-weight: 850; }
.empty p { margin: 0 auto 16px; color: var(--hint); max-width: 300px; }
.empty .btnrow { justify-content: center; max-width: 340px; margin: 0 auto; }

/* ---------- ricerca: "Forse cercavi…" ---------- */
.didyoumean { background: var(--accent-soft); border-radius: var(--r-md); padding: 12px 14px; margin-bottom: 14px; }
.didyoumean b { display: block; font-size: 13px; margin-bottom: 8px; color: var(--accent-ink); }
.didyoumean .chips { margin: 0; padding: 0; flex-wrap: wrap; overflow: visible; }

/* ---------- import ---------- */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 16px; border: 2px dashed var(--sep); border-radius: var(--r-lg); text-align: center; background: var(--surface); }
.dropzone svg { width: 34px; height: 34px; color: var(--accent-ink); }
.table-wrap { overflow-x: auto; border-radius: var(--r-md); box-shadow: 0 0 0 1px var(--sep); }
table.preview { border-collapse: collapse; width: 100%; font-size: 13px; }
table.preview th, table.preview td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--sep); white-space: nowrap; vertical-align: middle; }
table.preview th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--hint); background: var(--surface); }
table.preview tr:last-child td { border-bottom: 0; }
table.preview select { max-width: 190px; background: var(--surface-2); border: 0; border-radius: 8px; padding: 6px; }
.import-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.import-sum div { border-radius: var(--r-md); padding: 10px; background: var(--surface); }
.import-sum b { display: block; font-size: 22px; font-weight: 900; }
.import-sum span { font-size: 12px; color: var(--hint); font-weight: 650; word-spacing: 2px; }
.st-ok { color: var(--down); } .st-check { color: var(--up); } .st-unknown { color: var(--danger); }
pre.code { background: var(--surface); padding: 12px; border-radius: var(--r-md); font-size: 12.5px; overflow-x: auto; margin: 8px 0; }

/* ---------- impostazioni ---------- */
.setting { padding: 14px; }
.setting + .setting { border-top: 1px solid var(--sep); }
.setting__t { font-weight: 750; margin-bottom: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; }
.switch-row + .switch-row { border-top: 1px solid var(--sep); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 15px; background: var(--surface-2); transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ---------- foto ---------- */
.photo-prev { width: 100%; max-height: 50vh; object-fit: contain; border-radius: var(--r-md); background: var(--surface); }

/* ---------- banner demo ---------- */
.demo-pill { flex: none; font-size: 10px; font-weight: 900; letter-spacing: .08em; padding: 3px 6px; border-radius: 5px; background: var(--wish); color: #000; }

.error-box { text-align: center; padding: 40px 16px; }
.error-box p { color: var(--hint); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
.cm-buttons svg { width: 14px; height: 14px; opacity: .6; }
.btn svg { flex: none; }
.btn--sm svg { width: 16px; height: 16px; }

/* barra strumenti collezione: segmentato + ordinamento */
.toolbar { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.toolbar .seg { flex: 1; }
.sortwrap { display: flex; align-items: center; gap: 4px; height: 38px; padding: 0 10px; border-radius: 10px; background: var(--surface-2); color: var(--text); }
.sortwrap svg { width: 16px; height: 16px; color: var(--hint); }
.sortsel { border: 0; background: none; font-weight: 700; font-size: 13.5px; outline: none; -webkit-appearance: none; appearance: none; padding-right: 2px; }
.chips .chips { display: contents; }
.chips-sep { flex: none; width: 1px; align-self: stretch; margin: 4px 2px; background: var(--sep); }
