:root {
  --ink: #1c1915;
  --muted: #6e655c;
  --paper: #f3eee6;
  --card: #fffcf8;
  --line: #e4dcd0;
  --green: #1c8a4b;
  --green-deep: #146b3a;
  --amber: #a86408;
  --red: #d13328;
  --forest: #14352c;
  --forest-2: #1d4a3d;
  --ball: #ee2b2b;
  --bleed: #14110f;
  --on-dark: #f6f1ea;
  --on-dark-muted: #c4b6a6;
  --placeholder: #5c534a;
  --danger-ink: #6d1c14;
  --danger-bg: #fdeceb;
  --shadow: 0 12px 32px rgba(48, 32, 16, 0.08);
  --radius: 18px;
  --tab: 4.75rem;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  color-scheme: light only;
}
html {
  background-color: var(--paper);
  color: var(--ink);
  color-scheme: light only;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 420px at 10% -10%, #fff7ea 0%, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.45;
}
a { color: var(--forest-2); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
h1, h2, p { margin: 0 0 0.6rem; }
h1 { font-size: 1.7rem; letter-spacing: -0.03em; line-height: 1.15; }
h2 { font-size: 1.05rem; letter-spacing: -0.02em; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.9rem 1.1rem 0.2rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--forest);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -0.03em;
}
.brand-mark, .ball-face {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 18%, #1c1915 19% 28%, transparent 29%),
    linear-gradient(#fff 0 46%, #1c1915 46% 54%, var(--ball) 54% 100%);
  box-shadow: inset 0 0 0 1.5px #1c1915;
  display: inline-block;
  flex: none;
}
.is-serious .brand-mark,
.is-serious .ball-face,
.ball.is-plain .ball-face {
  background: var(--forest);
  box-shadow: none;
  border-radius: 6px;
}
.who { margin: 0; color: var(--muted); font-size: 0.82rem; }

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 0.4rem 1rem calc(var(--tab) + 1.2rem);
}
body.is-bleed { background: var(--bleed); color: var(--on-dark); }
html:has(body.is-bleed) { background-color: var(--bleed); }
body.is-bleed .app { padding: 0; max-width: none; min-height: 100dvh; }
body.is-bleed .flash { margin: 0; border-radius: 0; }

.flash {
  margin: 0.6rem 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: #e7f6ec;
  color: var(--green-deep);
}
.flash-erreur, .flash-warn { background: #fff1d8; color: #7a4b00; }
.flash-erreur { background: var(--red); color: white; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 1fr auto 1fr 1fr;
  align-items: end;
  gap: 0.15rem;
  padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom));
  background: rgba(255, 252, 248, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 650;
  padding: 0.2rem;
}
.tab svg { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tab.is-on { color: var(--forest); }
.tab.ball { margin-top: -1.15rem; }
.ball-face { width: 3.35rem; height: 3.35rem; }
.tab.ball.is-plain .ball-face { width: 3.1rem; height: 3.1rem; border-radius: 1rem; }

.hero, .block, .card, .stats, .dex-teaser { margin-bottom: 1rem; }
.hero {
  background: linear-gradient(165deg, var(--forest) 0%, #1e5648 70%, #2c6b52 100%);
  color: #f6f3ec;
  border-radius: 28px;
  padding: 1.25rem 1.2rem 1.15rem;
  box-shadow: var(--shadow);
}
.kicker {
  margin: 0 0 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  color: #d7c4a2;
}
.hero h1 { color: white; font-size: 1.35rem; }
.hero-label { margin: 0.8rem 0 0; color: #d9efe4; font-size: 0.95rem; }
.hero-num {
  margin: 0;
  font-size: 2.7rem;
  font-weight: 750;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.hero-num small, .hero-sub, .margin, .held { font-weight: 550; }
.hero-num small { font-size: 1rem; margin-left: 0.2rem; opacity: 0.85; }
.hero-sub, .margin, .held { margin: 0.15rem 0 0; color: #e7f3ec; }
.hero-tight { padding-bottom: 1rem; }
.margin.neg, .neg { color: #ffd0c8; }
.hero .neg { color: #ffd0c8; }

.bar, .pill-bar {
  height: 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
  margin: 0.75rem 0 0.45rem;
}
.bar span, .pill-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #7ddea0;
}
.env-warn .bar span, .alert-warn { background: #f0b429; }
.env-over .bar span { background: #ff8d7a; }
.env .bar { background: #efe7dc; margin: 0.55rem 0 0; }
.held { font-size: 0.88rem; color: #d5ecdf; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  padding: 0;
  list-style: none;
}
.stats li, .card, .env, .alert, .dex-teaser, .gate .form, .cat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stats li { padding: 0.75rem 0.7rem; }
.stats span, .env-meta, .txlist small, .note, .hint, .lede { color: var(--muted); }
.stats span { display: block; font-size: 0.75rem; }
.stats strong { font-size: 1.02rem; font-variant-numeric: tabular-nums; }
.pos { color: var(--green-deep); }
.neg { color: var(--red); }
.stats .neg, .txlist .neg, .env-left.neg { color: var(--red); }
.stats .pos, .txlist .pos { color: var(--green-deep); }

.block-head, .row-actions, .month-nav, .scan-top, .shutter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.block-head a, .note a { font-weight: 650; }

.envelopes, .txlist, .alerts, .menu, .codes, .dex-grid { list-style: none; padding: 0; margin: 0; }
.env { padding: 0.8rem 0.85rem; margin-bottom: 0.55rem; }
.env-head { display: flex; gap: 0.7rem; align-items: center; }
.env-creature { width: 2.6rem; height: 2.6rem; flex: none; }
.env-name { margin: 0; font-weight: 720; }
.env-meta { margin: 0.1rem 0 0; font-size: 0.82rem; }
.env-left { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.env-ok { box-shadow: inset 3px 0 0 var(--green); }
.env-warn { box-shadow: inset 3px 0 0 #e0a106; }
.env-over { box-shadow: inset 3px 0 0 var(--red); }

.alerts { display: grid; gap: 0.45rem; margin-bottom: 1rem; }
.alert { padding: 0.65rem 0.8rem; border-radius: 14px; background: #fff6e8; }
.alert-over { background: #fdeceb; }
.alert-warn { background: #fff6e8; color: inherit; }

.txlist li { border-bottom: 1px solid var(--line); }
.txlist a, .txlist .plain {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem 0.1rem;
  text-decoration: none;
  color: inherit;
  align-items: center;
}
.txlist strong { display: block; }
.txlist small { display: block; font-size: 0.8rem; }
.txlist em { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.import-row.is-dup { background: #fff8ee; }
.import-row.is-bad { opacity: 0.55; }

.menu a {
  display: block;
  padding: 0.95rem 0.2rem;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  font-weight: 680;
  color: var(--ink);
}

.btn, .shutter {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  background: var(--forest);
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1.15rem;
  font-weight: 720;
}
.btn-ghost { background: transparent; color: var(--forest); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid #f0c2bd; }
.btn-small { padding: 0.45rem 0.8rem; font-size: 0.9rem; }
.scan-cta { margin-top: 0.4rem; }
.scan-cta .btn, .gate .btn, .form .btn { width: 100%; }

.form, .filters { display: grid; gap: 0.75rem; }
.card { padding: 1rem; }
.card + .card, .card + form, form + .card { margin-top: 0.8rem; }
label { display: grid; gap: 0.28rem; font-size: 0.86rem; font-weight: 680; color: var(--ink); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background-color: #fff;
  color: var(--ink);
  color-scheme: light only;
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  font-weight: 500;
}
input::placeholder, textarea::placeholder { color: var(--placeholder); opacity: 1; }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
  box-shadow: 0 0 0 1000px #fff inset;
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 0.55rem; font-weight: 600; }
.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 14px; margin: 0; padding: 0.6rem 0.8rem 0.8rem; }
legend { padding: 0 0.3rem; font-size: 0.82rem; color: var(--muted); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.filters { grid-template-columns: 1fr 1fr; margin-bottom: 0.8rem; }
.filters label:first-child { grid-column: 1 / -1; }
.note, .lede, .empty { font-size: 0.92rem; }
.note code, .codes code { font-family: ui-monospace, monospace; }
.facts { display: grid; gap: 0.55rem; margin: 1rem 0; }
.facts div { display: grid; grid-template-columns: 8rem 1fr; gap: 0.5rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.month-nav { margin-bottom: 0.8rem; }
.month-nav a {
  width: 2.4rem; height: 2.4rem; display: grid; place-items: center;
  border-radius: 999px; background: white; text-decoration: none; border: 1px solid var(--line); font-size: 1.2rem;
}
.month-nav h1 { margin: 0; text-align: center; font-size: 1.35rem; }
.spark-wrap { background: white; border-radius: 16px; border: 1px solid var(--line); padding: 0.4rem 0.2rem; margin-bottom: 0.8rem; }
.spark { width: 100%; height: 78px; }
.spark polyline { fill: none; stroke: var(--forest); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.dex-teaser { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.95rem 1rem; }
.dex-teaser p { margin: 0; }
.dex-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.dex-grid li {
  background: white; border: 1px solid var(--line); border-radius: 18px; padding: 0.7rem;
  display: grid; justify-items: center; text-align: center; gap: 0.15rem;
}
.dex-grid img { width: 5.2rem; height: 5.2rem; }
.dex-grid .is-missing { filter: grayscale(1); opacity: 0.55; }
.subcat { display: grid; grid-template-columns: 1fr auto auto auto; gap: 0.45rem; align-items: center; margin-top: 0.55rem; }
.cat-card { padding: 0.9rem; margin-bottom: 0.7rem; }
.codes { display: grid; gap: 0.35rem; margin: 1rem 0; }
.codes li { background: white; border-radius: 10px; padding: 0.45rem 0.7rem; border: 1px solid var(--line); }
.qr { width: min(220px, 70%); background: white; padding: 0.5rem; border-radius: 12px; }
.gate { max-width: 28rem; margin: 8vh auto 0; padding: 0 0.2rem; }
.gate h1 { font-size: 2rem; }
.brand-lockup { display: flex; align-items: center; gap: 0.45rem; font-weight: 760; color: var(--forest); }
body.is-bleed .brand-lockup { color: var(--on-dark); }
body.is-bleed .lede { color: var(--on-dark-muted); }
.gate .form { color: var(--ink); color-scheme: light only; }
.row-actions { margin: 1rem 0 0.6rem; }

/* Scanner */
.scan {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0.7rem 0.9rem calc(1rem + env(safe-area-inset-bottom));
  background:
    radial-gradient(800px 420px at 50% 18%, rgba(226, 59, 47, 0.18), transparent 60%),
    var(--bleed);
}
.scan-top { color: white; margin-bottom: 0.7rem; }
.scan-top h1 { margin: 0; font-size: 1.15rem; }
.icon-btn {
  width: 2.3rem; height: 2.3rem; display: grid; place-items: center;
  border-radius: 999px; color: white; text-decoration: none;
  background: rgba(255,255,255,0.08); font-weight: 700;
}
.budget-pill {
  align-self: center;
  width: min(100%, 26rem);
  background: white;
  color: var(--ink);
  color-scheme: light only;
  border-radius: 16px;
  padding: 0.55rem 0.8rem 0.65rem;
  margin-bottom: 0.8rem;
}
.budget-pill p { margin: 0; font-size: 0.95rem; }
.pill-bar { background: #ece7e1; height: 0.48rem; }
.pill-bar span { background: var(--green); }
.finder {
  position: relative;
  width: min(100%, 28rem);
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  border-radius: 28px;
  overflow: hidden;
  background: #2a241f center / cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
#cam, #shot { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ring {
  position: absolute;
  inset: 9% 8%;
  border-radius: 50%;
  border: 10px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    0 0 0 7px rgba(226, 43, 43, 0.95),
    0 0 0 14px rgba(255,255,255,0.35),
    inset 0 0 0 7px rgba(226, 43, 43, 0.95);
  pointer-events: none;
}
.ring-line {
  position: absolute;
  left: -10px; right: -10px; top: 50%;
  height: 4px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 0 0 4px rgba(226, 43, 43, 0.9);
}
.is-serious .ring { border-radius: 18px; box-shadow: none; border-color: rgba(255,255,255,0.8); }
.is-serious .ring-line { display: none; }
.finder-hint {
  position: absolute;
  left: 0; right: 0; bottom: 0.8rem;
  text-align: center;
  margin: 0;
  color: white;
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
  font-size: 0.85rem;
}
.creature {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 9.5rem;
  height: 9.5rem;
  transform: translate(-50%, -50%) scale(0.4);
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.35));
  animation: pop 0.55s cubic-bezier(.2,1.4,.4,1) forwards;
  z-index: 3;
}
.ball-shake {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 8, 7, 0.28);
  z-index: 4;
}
.ball-face-lg { width: 5.2rem; height: 5.2rem; animation: shake 0.45s linear infinite; }
.capture-card {
  width: min(100%, 28rem);
  margin: 0.8rem auto 0;
  background: white;
  color: var(--ink);
  color-scheme: light only;
  border-radius: 22px;
  padding: 0.85rem 1rem;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.7rem;
  align-items: center;
}
.capture-card h2 { grid-column: 2; margin: 0; font-size: 1.35rem; color: var(--red); }
.capture-kicker {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 2.6rem;
  height: 2.6rem;
  margin: 0;
  border-radius: 999px;
  background: #e5f6ea;
  color: var(--green-deep);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.78rem;
}
.capture-card.is-fled h2 { color: #5c564e; }
#capture-detail { grid-column: 2; margin: 0.1rem 0 0; color: var(--muted); font-size: 0.92rem; }
.ticket-form {
  width: min(100%, 28rem);
  margin: 0.8rem auto 0;
  background: #fffdf9;
  color: var(--ink);
  color-scheme: light only;
  border-radius: 22px;
  padding: 0.9rem;
  display: grid;
  gap: 0.65rem;
}
.ticket-lead, .warn-line { margin: 0; font-size: 0.88rem; color: var(--muted); }
.warn-line, .scan-alert {
  color: var(--danger-ink);
  background: var(--danger-bg);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  font-weight: 680;
}
.scan-alert { width: min(100%, 28rem); margin: 0.8rem auto 0; }
.scan .btn-ghost {
  color: var(--on-dark);
  border-color: rgba(246, 241, 234, 0.55);
  background: transparent;
}
.shutter-row { flex-direction: column; margin-top: auto; padding-top: 0.8rem; }
.shutter {
  width: 4.6rem; height: 4.6rem; padding: 0; border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 16%, #1c1915 17% 26%, transparent 27%),
    linear-gradient(#f7f4ef 0 46%, #1c1915 46% 54%, var(--ball) 54% 100%);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35), inset 0 0 0 3px #f7f4ef, inset 0 0 0 5px #1c1915;
}
.is-serious .shutter {
  background: white;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.text-btn {
  background: none; border: 0; color: #f0e6da; text-decoration: underline; cursor: pointer; font: inherit;
}
.after-links { display: flex; gap: 0.5rem; justify-content: center; margin-top: 0.8rem; }
.scan.is-reading .finder-hint, .scan.is-review .shutter-row, .scan.is-done .shutter-row { display: none; }
.scan.is-review .finder, .scan.is-done .finder { aspect-ratio: 1; max-height: 22rem; }

@keyframes shake {
  0%, 100% { transform: rotate(0) translateX(0); }
  20% { transform: rotate(-18deg) translateX(-6px); }
  40% { transform: rotate(16deg) translateX(6px); }
  60% { transform: rotate(-10deg) translateX(-3px); }
  80% { transform: rotate(8deg) translateX(3px); }
}
@keyframes pop {
  to { transform: translate(-50%, -62%) scale(1); }
}

@media (min-width: 920px) {
  .tabbar {
    top: 0; bottom: 0; right: auto;
    width: 7.2rem;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(5, auto);
    align-content: center;
    justify-items: center;
    border-top: 0;
    border-right: 1px solid var(--line);
    padding: 1rem 0.4rem;
  }
  .tab.ball { margin-top: 0; }
  .app { margin-left: 7.2rem; padding: 1.2rem 1.4rem 2rem; }
  body.is-bleed .app { margin-left: 0; }
  .home-grid, body[data-page="home"] .app { }
  body[data-page="home"] .app {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    column-gap: 1rem;
    align-items: start;
  }
  body[data-page="home"] .hero,
  body[data-page="home"] .stats { grid-column: 1 / -1; }
  .filters { grid-template-columns: repeat(4, 1fr); }
  .gate { margin-top: 14vh; }
}

@media (prefers-color-scheme: dark) {
  html { background-color: var(--paper); color: var(--ink); color-scheme: light only; }
  body:not(.is-bleed) { background-color: var(--paper); color: var(--ink); }
  body.is-bleed { background-color: var(--bleed); color: var(--on-dark); }
  body.is-bleed .brand-lockup { color: var(--on-dark); }
  body.is-bleed .lede { color: var(--on-dark-muted); }
  .card, .gate .form, .ticket-form, .budget-pill, .capture-card, .stats li, .env, .dex-teaser, .cat-card {
    color: var(--ink);
    color-scheme: light only;
  }
  label, input, select, textarea {
    color: var(--ink);
    color-scheme: light only;
  }
  input, select, textarea {
    background-color: #fff;
    -webkit-text-fill-color: var(--ink);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ball-face-lg, .creature { animation: none; }
  .creature { transform: translate(-50%, -62%) scale(1); }
}
