:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --text: #15171c;
  --muted: #646b78;
  --border: #d9dce3;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --ok-bg: #e3f6ea;
  --ok-text: #136c35;
  --warn-bg: #fdf1dc;
  --warn-text: #8a5300;
  --danger: #c92a2a;
  --ns: #e4002b;
  --ps: #0070d1;
  --steam: #1b2838;
  --book: #b8621b;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1b1e25;
    --surface-2: #252932;
    --text: #eef0f4;
    --muted: #9aa1ad;
    --border: #323745;
    --accent: #6b8cff;
    --accent-text: #0b0d12;
    --ok-bg: #133222;
    --ok-text: #7ee2a3;
    --warn-bg: #3a2a10;
    --warn-text: #ffc66d;
    --danger: #ff6b6b;
    --steam: #66c0f4;
    --book: #f0a35e;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.danger { color: var(--danger); }
button.big { width: 100%; padding: 14px; font-size: 18px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
}
/* 16px+ inputs stop iPhone from zooming in on focus */
input, textarea { font-size: 16px; }
label { display: block; margin: 12px 0 4px; font-weight: 500; }
label > input, label > textarea { margin-top: 4px; font-weight: 400; }
.muted { color: var(--muted); }
.msg { min-height: 1.4em; color: var(--danger); margin: 8px 0 0; }

/* Lock screen */
.lock { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px; }
.lock-card { width: 100%; max-width: 360px; text-align: center; }
.lock-card h1 { margin: 0; font-size: 28px; }
.lock-card .muted { margin: 4px 0 28px; }
.setup { margin-top: 28px; text-align: left; }
.setup summary { color: var(--muted); cursor: pointer; text-align: center; }
.setup form button { width: 100%; margin-top: 16px; }

/* App */
.app { max-width: 640px; margin: 0 auto; padding: 0 16px 40px; }
.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 0 8px;
  background: var(--bg);
}
.top input { flex: 1; font-size: 18px; padding: 12px 14px; }
.top button { white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin: 4px 0 12px; overflow-x: auto; }
.tabs button { border: none; background: none; color: var(--muted); padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.card h3 { margin: 0 0 6px; font-size: 17px; overflow-wrap: anywhere; }
.sub { font-size: 13px; margin-bottom: 6px; overflow-wrap: anywhere; }
.verdict { display: inline-block; font-size: 13px; font-weight: 600; padding: 3px 8px; border-radius: 6px; margin-bottom: 8px; }
.verdict.portable, .verdict.owned { background: var(--ok-bg); color: var(--ok-text); }
.verdict.home { background: var(--warn-bg); color: var(--warn-text); }
.copies { display: flex; flex-wrap: wrap; gap: 6px; }
.copy {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; padding: 5px 9px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid transparent;
}
.copy:hover { border-color: var(--border); }
.copy small { color: var(--muted); }

/* Platform logos on their brand colours (the logos the user gave, cut by tools/logos.mjs) */
.badge {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  height: 20px; padding: 0 6px; border-radius: 5px;
  color: #fff; background: #555;
}
.badge img { display: block; height: 12px; width: auto; }
.badge b { font: 700 10.5px/1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: 0.03em; }
.badge svg { width: 14px; height: 14px; }
.badge.steam { background: #000; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.14); }
.badge.steam img { height: 14px; }
.badge.ps5, .badge.ps4 { background: #1355e0; }
.badge.ps5 img { height: 10px; }
.badge.switch2, .badge.switch { background: #e70012; }
.badge.artbook { background: var(--book); }
.copy .badge { margin: -2px 0; }

.icon-btn { display: grid; place-items: center; width: 46px; padding: 0; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }

/* Covers view: boxes stand on a shelf. Each tile is 3 rows (box, title, chips) shared with its
   neighbours through subgrid, so boxes, titles and chips line up across a row whatever their size. */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); column-gap: 10px; }
.tile { min-width: 0; display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 0; padding-bottom: 18px; }
.tile .box { align-self: end; }
.tile h3 {
  align-self: start; margin: 7px 0 4px; font-size: 13px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile .copies { align-self: start; }
.tile .copies { gap: 4px; }
.tile .copy { padding: 3px 5px; gap: 4px; }
.tile .copy small { font-size: 11px; }

/* A cover, the same for every platform: our own banner on top (same height everywhere, brand
   colour, logo in the middle), then the picture in one portrait shape (2:3, Steam's library size).
   Sizes are in cqw (% of the cover's own width), so it looks the same at any size; cqw only works
   inside the cover, never on the cover's own padding or margins. */
.box {
  position: relative; container-type: inline-size; overflow: hidden;
  border-radius: 3px; background: #1b1e25;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.35), 0 0 0 1px rgb(0 0 0 / 0.08);
}
.box-head {
  height: 14cqw; display: flex; align-items: center; justify-content: center; gap: 2.4cqw;
  color: #fff; background: #555;
}
.box-head img { display: block; }
.box-head b { font: 800 5.2cqw/1 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: 0.08em; }
.box-head svg { width: 7cqw; height: 7cqw; }
.box-art { position: relative; aspect-ratio: 2 / 3; overflow: hidden; display: grid; place-items: center; background: #1b1e25; }
.box-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.placeholder {
  padding: 8cqw; text-align: center; font-weight: 600; font-size: max(9px, 9cqw); line-height: 1.25;
  color: #cfd3db; overflow-wrap: anywhere;
}
/* A box photo has its banner printed on it: it takes the whole cover (banner + picture) */
.box.photo .box-art { aspect-ratio: 100 / 164; }

/* The banners */
.box.switch2 .box-head { background: #e60012; }
.box.switch2 .box-head img { height: 11cqw; }
.box.switch .box-head { background: #e60012; }
.box.switch .box-head .mark { height: 8cqw; }
.box.switch .box-head .words { height: 5.2cqw; }
.box.ps5 .box-head { background: #fff; box-shadow: inset 0 -0.4cqw #e2e2e2; }
.box.ps5 .box-head img { height: 6.4cqw; filter: brightness(0); }
.box.ps4 .box-head { background: #003791; }
.box.ps4 .box-head img { height: 7.4cqw; }
.box.steam .box-head { background: #171a21; }
.box.steam .box-head .mark { height: 8cqw; }
.box.steam .box-head .words { height: 4.4cqw; }
.box.artbook .box-head { background: #b8621b; }

.empty { text-align: center; padding: 32px 8px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.empty button { margin-top: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 24px; }
.stat .badge { margin-top: 4px; }
.stat span { color: var(--muted); font-size: 14px; }
.foot { margin-top: 24px; display: flex; justify-content: center; }

/* Add / edit sheet */
.sheet {
  border: none; padding: 0; margin: auto auto 0;
  width: 100%; max-width: 640px;
  background: var(--surface); color: var(--text);
  border-radius: 16px 16px 0 0;
  max-height: 92dvh;
}
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 16px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet form { padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.chips { border: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips legend { font-weight: 500; margin-bottom: 6px; padding: 0; }
.chips label { margin: 0; font-weight: 400; }
.chips input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chips label {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer;
}
.chips label:has(input:checked) { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chips label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Platform choice as logos: the chosen one gets a ring, the others fade */
.chips.logos label { padding: 5px; border-radius: 9px; background: none; }
.chips.logos .badge { height: 28px; padding: 0 9px; border-radius: 6px; }
.chips.logos .badge img { height: 15px; }
.chips.logos .badge.steam img { height: 18px; }
.chips.logos .badge.ps5 img { height: 12px; }
.chips.logos label:not(:has(input:checked)) .badge { opacity: 0.45; }
.chips.logos label:has(input:checked) { background: none; outline: 2px solid var(--accent); outline-offset: 0; }

/* Cover picker in the sheet */
.cover-field { display: flex; gap: 12px; align-items: flex-start; margin-top: 14px; }
.cover-preview { width: 76px; flex: none; }
.cover-actions { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.cover-actions input[type="url"] { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 400; }
.check input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.field-name { font-weight: 500; }
.cover-results { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 2px; }
.cover-results:empty { display: none; }
.cover-results p { margin: 0; color: var(--muted); }
.cover-results { align-items: flex-end; }
.cover-results button {
  flex: none; width: 80px; padding: 3px; border: 2px solid transparent; border-radius: 8px;
  background: none; text-align: left;
}
.cover-results button[aria-pressed="true"] { border-color: var(--accent); }
.cover-results small {
  display: block; padding: 3px 4px; font-size: 10px; line-height: 1.2; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.segmented { flex-wrap: nowrap; gap: 0; margin-top: 14px; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented label { flex: 1; text-align: center; border: none; background: none; border-radius: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.grow { flex: 1; }
