@font-face { font-family: 'Bricolage Grotesque'; src: url('fonts/bricolage-grotesque.woff2') format('woff2'); font-weight: 400 800; font-display: swap; }
@font-face { font-family: 'Figtree'; src: url('fonts/figtree.woff2') format('woff2'); font-weight: 400 700; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('fonts/jetbrains-mono.woff2') format('woff2'); font-weight: 500 700; font-display: swap; }

/* Layout: phone = one column + bottom tab bar; 900px and up = left rail + content column.
   Cool baseplate-grey ground, white picture tiles (box photos have white backgrounds),
   one brick-red accent, box-print style number tags. Studs only in empty states and the icon. */
:root {
  --ground: #E8EBF0;
  --surface: #FFFFFF;
  --surface-2: #F2F4F7;
  --ink: #151922;
  --ink-2: #566073;
  --line: #D3D9E2;
  --accent: #C8341F;
  --accent-ink: #FFFFFF;
  --accent-soft: #F8E2DD;
  --wish: #D99A00;
  --photo: #FFFFFF;
  --photo-ink: #8A93A3;
  --stud: #DCE1E8;
  --shadow: 0 1px 2px rgb(21 25 34 / 6%), 0 6px 18px rgb(21 25 34 / 6%);

  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Figtree', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0E1117;
    --surface: #171B23;
    --surface-2: #1F2430;
    --ink: #ECEFF4;
    --ink-2: #9CA5B5;
    --line: #2A303C;
    --accent: #FF6B55;
    --accent-ink: #1B0904;
    --accent-soft: #3A1F1A;
    --wish: #F5B82E;
    --photo: #F1F2F4;
    --photo-ink: #7D8696;
    --stud: #232935;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.45 var(--font-body);
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; }
h1 { font-size: clamp(28px, 7vw, 40px); line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 20px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }

/* ---------- App frame ---------- */
.app { min-height: 100vh; min-height: 100dvh; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: var(--tabbar-h); padding: 6px 2px;
  color: var(--ink-2); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabs a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs a[aria-current="page"] svg { stroke-width: 2.2; }
.tabs .brand { display: none; }
.brand .brick { fill: var(--accent); stroke: none; }

.view {
  display: block;
  width: 100%; max-width: 1240px; margin: 0 auto;
  padding-top: 20px;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  outline: none;
}

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
  .tabs {
    position: sticky; top: 0; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
    padding: 22px 14px;
  }
  .tabs a { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 0; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
  .tabs a:hover { background: var(--surface-2); color: var(--ink); }
  .tabs a[aria-current="page"] { background: var(--accent-soft); }
  .tabs .brand {
    display: flex; margin-bottom: 18px; color: var(--ink);
    font-family: var(--font-display); font-weight: 800; font-size: 21px; letter-spacing: -0.02em;
  }
  .tabs .brand svg { width: 30px; height: 30px; }
  .tabs .brand:hover { background: none; }
  .view { padding: 32px 36px 56px; }
}

/* ---------- Page pieces ---------- */
.page { display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; }
.lede { color: var(--ink-2); max-width: 62ch; }

.stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.stat { padding: 12px 14px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat b { display: block; font-family: var(--font-display); font-size: clamp(22px, 6vw, 30px); font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat span { display: block; margin-top: 2px; font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.stat small { display: block; font-size: 12px; color: var(--ink-2); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .grow { flex: 1 1 auto; }

.seg {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
}
.seg button {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 13px; border-radius: 9px; min-height: 36px;
  font-weight: 650; font-size: 14px; color: var(--ink-2);
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.seg .count { font-family: var(--font-mono); font-size: 12px; opacity: 0.75; margin-left: 4px; }

.field {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; min-height: 40px; min-width: 0;
}
.field:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
select.field { padding-right: 32px; }
.field.search { width: 100%; font-size: 17px; min-height: 50px; padding-inline: 16px; border-radius: 12px; }
.field.year { width: 96px; }
.label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 650; color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 9px 16px;
  font-weight: 650; text-decoration: none; cursor: pointer;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-2); padding-inline: 8px; }
.btn.quiet:hover { color: var(--ink); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg, .icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon { display: inline-flex; }
.icon.filled svg { fill: currentColor; }

/* ---------- Cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 16px; } }

.card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: var(--ink-2); box-shadow: var(--shadow); }
.card:focus-within { border-color: var(--accent); }
.card .body { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 10px 12px 12px; flex: 1; min-width: 0; }
.card .name { font-weight: 650; font-size: 15px; line-height: 1.25; text-decoration: none; overflow-wrap: anywhere; }
.card .name::after { content: ''; position: absolute; inset: 0; z-index: 0; }
.card .name:focus-visible { outline: none; }
.card .meta { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card .add { position: relative; z-index: 1; margin-top: auto; min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.card .body > .add { margin-top: 6px; }

.photo { aspect-ratio: 1; max-width: 100%; background: var(--photo); display: grid; place-items: center; padding: 10px; }
.photo img { width: 100%; height: 100%; object-fit: contain; }
.ph {
  width: 100%; height: 100%; display: grid; place-items: center;
  background-image: radial-gradient(circle, rgb(138 147 163 / 22%) 0 7px, transparent 8px);
  background-size: 24px 24px; background-position: center;
  border-radius: 8px;
}
.ph span { background: var(--photo); color: var(--photo-ink); font: 700 12px var(--font-mono); padding: 2px 6px; border-radius: 4px; }

.tag {
  display: inline-block; max-width: 100%;
  font: 700 12px/1.5 var(--font-mono); letter-spacing: 0.02em;
  background: var(--ink); color: var(--surface);
  padding: 1px 7px; border-radius: 5px; overflow-wrap: anywhere;
}
.badge {
  position: absolute; top: 8px; right: 8px; z-index: 1; pointer-events: none;
  font: 700 12px/1 var(--font-mono); padding: 5px 8px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
}
.wish-mark { position: absolute; top: 8px; left: 8px; z-index: 1; color: var(--wish); pointer-events: none; }
.wish-mark svg { width: 20px; height: 20px; fill: currentColor; stroke: rgb(0 0 0 / 25%); stroke-width: 1; }

.count-line { color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.more { align-self: center; }

/* ---------- Empty & loading ---------- */
.empty {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  padding: 28px 22px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.empty::before {
  content: ''; position: absolute; inset: 0 0 0 auto; width: min(42%, 240px); pointer-events: none;
  background-image: radial-gradient(circle, var(--stud) 0 9px, transparent 10px);
  background-size: 30px 30px; background-position: right -6px top -6px;
  -webkit-mask-image: linear-gradient(to left, #000 35%, transparent);
  mask-image: linear-gradient(to left, #000 35%, transparent);
}
.empty > * { position: relative; }
.empty p { color: var(--ink-2); max-width: 46ch; }
.empty.small { padding: 20px; }
.empty.small::before { display: none; }

.loading { display: grid; place-items: center; align-content: center; gap: 14px; min-height: 60vh; color: var(--ink-2); text-align: center; }
.studs { display: flex; gap: 8px; }
.studs i { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); animation: stud 1s ease-in-out infinite; }
.studs i:nth-child(2) { animation-delay: .15s; }
.studs i:nth-child(3) { animation-delay: .3s; }
@keyframes stud { 0%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-8px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .studs i { animation: none; opacity: .8; } .card { transition: none; } }

/* ---------- Detail pages ---------- */
.back { align-self: flex-start; }
.detail { display: grid; gap: 20px; align-items: start; }
@media (min-width: 780px) { .detail { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 28px; } }
.hero-photo { aspect-ratio: 4 / 3; max-width: 100%; background: var(--photo); border-radius: var(--radius); padding: 18px; display: grid; place-items: center; border: 1px solid var(--line); }
.hero-photo img { width: 100%; height: 100%; object-fit: contain; }
.info { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.info h1 { overflow-wrap: anywhere; }
.info .tag { font-size: 14px; padding: 2px 9px; align-self: flex-start; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; color: var(--ink-2); font-weight: 600; }
.crumbs button { border: 0; background: none; padding: 0; color: var(--ink-2); font-weight: 650; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.crumbs button:hover { color: var(--accent); text-decoration-color: currentColor; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.fact span { display: block; font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.fact b { display: block; font-family: var(--font-display); font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.panel { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel h2 { font-size: 18px; }
.panel .row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.panel .row > .label { flex-direction: row; align-items: center; gap: 12px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 44px; height: 44px; border: 0; background: var(--surface-2); cursor: pointer; display: grid; place-items: center; }
.stepper button:hover { background: var(--line); }
.stepper button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.stepper output { min-width: 52px; text-align: center; font: 750 20px var(--font-display); font-variant-numeric: tabular-nums; }
textarea.field { width: 100%; min-height: 76px; resize: vertical; line-height: 1.4; }
.wish-btn[aria-pressed="true"] { border-color: var(--wish); }
.wish-btn[aria-pressed="true"] .icon { color: var(--wish); }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links .btn { font-size: 14px; min-height: 40px; padding: 7px 12px; }
.section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.section-head .count-line { font-size: 14px; }

/* ---------- Sync page ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; max-width: 720px; }
.panel p { color: var(--ink-2); }
.panel .actions { display: flex; flex-wrap: wrap; gap: 10px; }
textarea.code { font: 500 12px/1.5 var(--font-mono); word-break: break-all; min-height: 92px; }
.note { font-size: 14px; color: var(--ink-2); }
.note.ok { color: var(--ink); font-weight: 600; }
.note.err { color: var(--accent); font-weight: 650; }
.confirm { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); }
.confirm p { color: var(--ink); font-weight: 600; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }
.steps b { color: var(--ink); }
.fine { font-size: 13px; color: var(--ink-2); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.install-banner { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }

/* ---------- Scan ---------- */
.scan-drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 168px; padding: 24px 16px; text-align: center; cursor: pointer;
  background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius);
}
.scan-drop:hover, .scan-drop:focus-within { border-color: var(--accent); }
.scan-drop .icon svg { width: 40px; height: 40px; color: var(--accent); stroke-width: 1.6; }
.scan-drop b { font-family: var(--font-display); font-size: 20px; }
.scan-drop span { color: var(--ink-2); font-size: 14px; }
.scan-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.scan-preview { display: flex; justify-content: center; background: var(--photo); border-radius: var(--radius); border: 1px solid var(--line); padding: 10px; }
.scan-preview img { max-height: 240px; width: auto; object-fit: contain; border-radius: 8px; }
.sure { font-weight: 700; color: var(--ink); }

/* ---------- Where it's from ---------- */
.lore .panel { gap: 12px; }
.lore .lead { color: var(--ink); max-width: 68ch; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips .label { margin-right: 4px; }
.chip { font-size: 13px; font-weight: 650; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.highlight { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.works { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 6px 16px; }
.works li { display: flex; gap: 10px; align-items: baseline; min-width: 0; padding: 6px 0; border-bottom: 1px solid var(--line); }
.works .yr { flex: none; font: 700 13px var(--font-mono); color: var(--ink-2); min-width: 3.2em; font-variant-numeric: tabular-nums; }
.works .wn { min-width: 0; overflow-wrap: anywhere; }
.works small { color: var(--ink-2); }
.lore h3 { font-family: var(--font-display); font-size: 16px; margin: 0; }
.lore .story { display: flex; flex-direction: column; gap: 12px; }
.facts-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.facts-list dt { font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); padding-top: 2px; }
.facts-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: inherit; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent); text-decoration-color: currentColor; }
@media (max-width: 420px) { .facts-list { grid-template-columns: 1fr; gap: 2px; } .facts-list dd { margin-bottom: 8px; } }

/* ---------- Your own figures ---------- */
.form { max-width: 640px; }
.form .label .field { width: 100%; font-size: 16px; color: var(--ink); font-weight: 500; }
.form .label { gap: 6px; }
.own-preview img { max-height: 220px; }

/* ---------- Every version ---------- */
.version-groups { display: flex; flex-direction: column; gap: 18px; }
.version-group { display: flex; flex-direction: column; gap: 10px; }
.version-group h3 { font-family: var(--font-display); font-size: 16px; margin: 0; }
.version-group h3 .count-line { font-family: var(--font-body); font-weight: 500; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 14px;
  padding: 10px 10px 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--surface);
  font-weight: 600; font-size: 14px; box-shadow: 0 8px 28px rgb(0 0 0 / 22%);
}
.toast span { min-width: 0; overflow-wrap: anywhere; }
.toast button { flex: none; border: 0; background: transparent; color: inherit; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 8px 10px; border-radius: 8px; }
@media (min-width: 900px) { .toast { bottom: 24px; left: calc(50% + 118px); } }
