/* Atkinson Hyperlegible, for long reading text. Made by the Braille Institute so that look-alike letters differ.
   The files are in web/fonts with their license (SIL Open Font License 1.1). */
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); }

/* Dark only. Panels, tabs and motion follow the look of COMP/CON, redrawn from scratch. */
:root {
  color-scheme: dark;
  /* Colors are matched by eye from a COMP/CON screenshot, not read from its theme files. */
  --bg: #080808;
  --surface: #141112;
  --text: #f1eeee;
  --muted: #9a8f91;
  --border: #3d2227;
  --edge: #3d2227;
  --crimson: #8a1c2b;
  --crimson-dark: #52111a;
  --accent: #e5384f;
  --accent-text: #ffffff;
  --slate: #4c5762; /* the bar on top of an unselected card */
  --yellow: #f5d400;
  --tab-bg: #e9566c;
  --tab-text: #ffffff;
  --danger: #ff8a80;
  --ok: #47cd89;
  --warn: #fdb022;
  --row-hover: #2a1519;
  --radius: 2px;
  --fade: 0.25s;
  /* COMP/CON sets body text in Helvetica and numbers/stat text in Consolas. Both come from the system here. */
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --reading: "Atkinson Hyperlegible", "Segoe UI", Verdana, sans-serif; /* long text: lore and quirks */
  --mono: Consolas, "Cascadia Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { zoom: 0.8; } /* whole site 20% smaller; change this one number to adjust */

body {
  margin: 0;
  background: var(--bg) radial-gradient(circle, rgba(229, 56, 79, 0.16) 1px, transparent 1.5px) 0 0 / 28px 28px;
  color: var(--text);
  font: 14px/1.45 var(--sans);
}

h1 { font-size: 34px; line-height: 1; margin: 0; letter-spacing: 1px; text-transform: uppercase; font-weight: 900; color: #fff; }
h2 {
  display: block;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: var(--crimson);
  color: #fff;
  padding: 6px 40px 6px 14px;
  margin: -14px -14px 12px;
  clip-path: polygon(0 0, 100% 0, calc(100% - 22px) 100%, 0 100%);
}
h2::before { content: "> "; color: var(--accent); }
code { background: var(--bg); padding: 1px 5px; border-radius: var(--radius); }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 20px 24px;
  /* A crimson slab with a slanted right edge and a darker stripe behind it. */
  background: linear-gradient(110deg, var(--crimson) 0 1000px, transparent 1000px 1016px, var(--crimson-dark) 1016px 1044px, transparent 1044px);
}
@media (max-width: 900px) { .topbar { background: var(--crimson); } }

.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; padding: 4px 14px; border-radius: var(--radius); color: var(--muted);
  cursor: pointer; font: inherit; letter-spacing: 3px; text-transform: uppercase;
  transition: color var(--fade), background var(--fade);
}
.tab { color: #f0c9ce; font-weight: 700; }
.tab:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.tab.active { background: var(--tab-bg); color: var(--tab-text); }
#catalog-status { margin-left: auto; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }

#account { font-size: 12px; letter-spacing: 1px; }
#account[hidden] { display: none; }
#account button { margin-left: 8px; padding: 2px 10px; font-size: 12px; }

/* A share link: the owner's name in the top bar, and none of the controls that would change the collection.
   The server refuses those writes anyway. This keeps them off the page. */
.owner-name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 18px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: #fff;
}
.owner-name[hidden] { display: none; }
body.shared #toggle-add,
body.shared #add-panel,
body.shared #review-panel,
body.shared .tab[data-view="import"],
body.shared #tabbar [data-tab="import"],
body.shared #view-import,
body.shared #bulkbar,
body.shared .sel-cell,
body.shared .tray-save,
body.shared #account { display: none; }
/* On a shared card the material is a label shaped like the owner's material button. */
.mini-card .material-static { padding: 1px 8px; font-size: 11px; }

.login-page { display: grid; justify-items: center; align-content: start; padding: 48px 16px; }
.login-card { width: min(100%, 360px); }
.login-card h1 { margin: 0 0 16px; }
.login-switch { display: flex; margin-bottom: 4px; }
.login-switch .seg { flex: 1; margin-left: -1px; border-radius: 0; padding: 6px 14px; }
.login-switch .seg:first-child { margin-left: 0; border-radius: var(--radius) 0 0 var(--radius); }
.login-switch .seg:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.login-switch .seg[aria-pressed="true"] { background: var(--crimson); border-color: var(--accent); color: #fff; }
.login-form[hidden], .login-error[hidden] { display: none; }
.login-form button[type="submit"] { margin-top: 16px; width: 100%; }
.login-form button:disabled { opacity: 0.6; cursor: default; }
.login-form input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
}
.login-error { margin: 12px 0 0; color: var(--danger); }

@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } }
#view-collection, #view-import { animation: panel-in 0.25s ease-out; }
/* Cards are rebuilt on every change, so they must not animate in or each click would make them flash. */
.panel:not([hidden]) { animation: panel-in 0.25s ease-out both; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}

.panel, .sidebar, .table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 14px;
  /* Cut bottom-right corner. */
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 20px), calc(100% - 20px) 100%, 0 100%);
}
.sidebar { position: sticky; top: 16px; }
.table-wrap { padding: 0; overflow-x: auto; margin-bottom: 16px; }
.panel { margin-bottom: 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 220px; }
.toolbar select { min-width: 0; max-width: 100%; } /* long faction names must not widen the page on a phone */

input, select, textarea, button { font: inherit; color: inherit; }
input[type="search"], input[type="text"], input[type="number"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
}
textarea { width: 100%; resize: vertical; }
button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition: filter var(--fade), background var(--fade), border-color var(--fade);
}
button:hover { background: var(--row-hover); filter: brightness(1.2); }
button.primary {
  background: var(--crimson); border-color: var(--accent); color: #fff;
  letter-spacing: 2px; text-transform: uppercase; font-size: 12px;
}
button.primary:hover { background: var(--crimson); filter: brightness(1.3); }
button.icon { padding: 2px 8px; line-height: 1.2; }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.check { display: inline-flex; align-items: center; gap: 6px; }
.row { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-top: 10px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { padding-left: 14px; }
th:last-child, td:last-child { padding-right: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); user-select: none; }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--text); }
td { transition: background var(--fade); }
tbody tr:hover { background: var(--row-hover); }
td.num:nth-last-child(4) { color: var(--accent); } /* BV column */
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.tray-summary, .mini-card .card-foot, .view-controls .count, #catalog-status { font-family: var(--mono); }
button, th, .tab { font-family: var(--sans); }
button.primary, th { font-weight: 700; }
td input[type="number"] { width: 54px; text-align: right; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 2px; }
.empty { padding: 24px; text-align: center; margin: 0; }

#add-panel input[type="search"] { width: 100%; }
.toolbar input.box-filter { flex: 0 1 170px; min-width: 120px; }
td input.box-input { width: 100%; min-width: 190px; }
.suggest {
  position: fixed;
  z-index: 60; /* above the bulk bar, whose box field uses it too */
  max-width: min(640px, 95vw);
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 4px;
}
.suggest-item { display: flex; justify-content: space-between; gap: 16px; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.suggest-item:hover, .suggest-item.active { background: var(--row-hover); }
.suggest-item.active { outline: 1px solid var(--accent); }
.field { display: grid; gap: 4px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.field input { font-size: 14px; color: var(--text); }
.suggest-empty { padding: 6px 8px; }
.review-row { display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(200px, 1.4fr) minmax(160px, 1fr); gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.review-row select, .review-row input { width: 100%; }
td select { max-width: 320px; }
@media (max-width: 900px) { .review-row { grid-template-columns: 1fr; } }

.tray-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.tray-controls label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.tray-controls input[type="text"] { min-width: 250px; }
.tray-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.tray-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.qty-ctl { display: inline-flex; align-items: center; gap: 6px; }
.tray-summary { margin-top: 12px; font-size: 15px; font-weight: 600; }
#tray::after {
  content: ""; display: block; height: 6px; margin-top: 14px;
  background: repeating-linear-gradient(45deg, rgba(255, 196, 0, 0.25) 0 10px, rgba(0, 0, 0, 0.25) 10px 20px);
}
.tray-summary .gap { font-weight: 400; margin-left: 8px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.over { color: var(--danger); }
.tray-save { display: flex; gap: 8px; margin-top: 12px; }
.tray-save input { flex: 1; }

.forces-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.force-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; cursor: pointer; transition: background var(--fade), border-color var(--fade); }
.force-item:hover { background: var(--row-hover); }
.force-item.active { border-color: var(--accent); }
.force-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.force-actions button { padding: 3px 9px; font-size: 12px; }
.force-item .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; max-width: 420px;
  background: var(--surface); color: var(--text); border: 5px double var(--edge);
  padding: 10px 14px; border-radius: var(--radius);
  z-index: 10;
  animation: panel-in 0.2s ease-out;
}
.toast.error { border-color: var(--danger); color: var(--danger); }

.import-group { margin-top: 12px; }
.import-group h3 { font-size: 13px; margin: 0 0 4px; }
.import-group ul { margin: 0; padding-left: 18px; }

/* View switcher */
.view-controls { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; margin: 0 0 12px; }
.view-controls .group { display: inline-flex; align-items: center; }
.view-controls .group[hidden] { display: none; }
.view-controls .label { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-right: 10px; }
.view-controls button.seg { margin-left: -1px; border-radius: 0; padding: 6px 14px; }
.view-controls button.seg:first-of-type { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.view-controls button.seg:last-of-type { border-radius: 0 var(--radius) var(--radius) 0; }
.view-controls button.seg[aria-pressed="true"] { background: var(--crimson); border-color: var(--accent); color: #fff; }
.view-controls .label::before { content: "> "; }
.view-controls .count { margin-left: auto; font-size: 12px; color: var(--muted); }

/* Grouped. The field dropdown sits after the Off/On switch and dims while grouping is off. */
#group-by { margin-left: 8px; }
#group-by.is-off { opacity: 0.45; }
tr.group-row td { background: var(--row-hover); padding: 0; border-top: 1px solid var(--border); }
.group-toggle { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 14px; font: inherit; color: inherit; cursor: pointer; border-radius: 0; }
.group-toggle:hover { background: rgba(127, 127, 127, 0.12); }
.group-toggle .chev { display: inline-block; width: 18px; color: var(--muted); }
.group-toggle strong { margin-right: 14px; font-size: 14px; }
.group-toggle .group-meta { color: var(--muted); font-size: 12px; margin-right: 14px; }
.group-toggle .bar { display: inline-block; width: 90px; height: 7px; background: rgba(127, 127, 127, 0.3); vertical-align: middle; margin-right: 8px; }
.group-toggle .bar i { display: block; height: 100%; background: var(--ok); }
/* The group header already names the box, so the Box column would only repeat it. */
body.group-by-box #roster th:nth-child(4), body.group-by-box #roster td:nth-child(4) { display: none; }
/* Grouped cards: each group is a header bar over its own grid. */
/* Company banner: the group header when grouped by company. It takes the company's strip color. */
.company-head { background: var(--strip, var(--crimson)); color: var(--strip-text, #fff); }
.company-head .group-toggle.company-banner {
  display: grid; grid-template-columns: 18px 56px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 12px 14px; color: inherit;
}
/* No hover filter here. A filter makes the button its own layer, and the logo's multiply blend then can't
   reach the banner color behind it, which brings back a JPEG logo's white background. */
.company-head .group-toggle.company-banner:hover { background: rgba(0, 0, 0, 0.14); filter: none; }
.company-head .group-toggle .chev { color: inherit; opacity: 0.8; }
.banner-logo-slot { width: 56px; height: 56px; display: grid; place-items: center; }
.banner-logo-slot img { width: 56px; height: 56px; object-fit: contain; margin: 0; padding: 0; background: none; filter: none; }
.banner-logo-slot img.opaque { border-radius: 4px; }
.banner-names { display: grid; gap: 3px; min-width: 0; }
.company-head .group-toggle .banner-names strong { margin: 0; font-size: 22px; letter-spacing: 0.03em; text-transform: uppercase; line-height: 1.15; overflow-wrap: anywhere; }
.banner-faction { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.85; }
.banner-stats { display: grid; gap: 6px; justify-items: end; text-align: right; }
.company-head .group-toggle .banner-count { margin: 0; font-size: 16px; font-weight: 700; color: inherit; }
.company-head .group-toggle .banner-painted { margin: 0; font-size: 13px; color: inherit; opacity: 0.85; }
.company-head .group-toggle .bar { width: 160px; margin: 0; background: rgba(0, 0, 0, 0.28); border-radius: 4px; overflow: hidden; }
.company-head .group-toggle .bar i { background: var(--strip-text, #fff); opacity: 0.9; }
.company-head .banner-tray { margin: 0 14px 0 6px; }
@media (max-width: 720px) {
  .company-head .group-toggle.company-banner { grid-template-columns: 18px 40px minmax(0, 1fr); }
  .banner-logo-slot, .banner-logo-slot img { width: 40px; height: 40px; }
  .banner-stats { grid-column: 1 / -1; justify-items: start; text-align: left; }
}
.card-group-head { background: var(--row-hover); border: 1px solid var(--border); margin-bottom: 12px; }
.card-groups .card-grid { margin-bottom: 20px; }

/* Compact density */
body.compact td, body.compact th { padding-top: 2px; padding-bottom: 2px; font-size: 13px; }
body.compact td input[type="number"] { padding: 1px 4px; width: 46px; font-size: 12px; }
body.compact td input.box-input { padding: 1px 6px; font-size: 12px; }
body.compact td button.icon { padding: 0 7px; font-size: 11px; line-height: 1.5; }
body.compact .group-toggle { padding: 5px 14px; }

/* Cards */
body.view-cards .table-wrap { display: none; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card-grid .empty { grid-column: 1 / -1; }
.mini-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: border-color var(--fade), transform var(--fade); }
.mini-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mini-card .photo {
  aspect-ratio: 1 / 1; display: grid; place-items: center; color: var(--muted); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(135deg, rgba(127, 127, 127, 0.12) 0 10px, rgba(127, 127, 127, 0.04) 10px 20px);
}
/* The artwork is black line art on white. Inverting it and blending with "screen" drops the white
   and leaves light lines on the card, so there is no white box around the portrait. */
.mini-card .photo.has-art { background: var(--surface); position: relative; overflow: hidden; }
.mini-card .photo.has-art img, .detail .photo.has-art img { filter: invert(1); mix-blend-mode: screen; }
.mini-card .photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 8px; box-sizing: border-box; }
/* A mini's own photo: no filter, and no padding. The crop sets its size and position (see cropGeometry in app.js). */
.photo.has-photo { background: var(--surface); position: relative; overflow: hidden; }
.photo.has-photo img.mini-photo { inset: auto; max-width: none; padding: 0; object-fit: fill; filter: none; mix-blend-mode: normal; user-select: none; }
.mini-card .photo.drop-target { outline: 2px dashed var(--accent); outline-offset: -4px; }
/* minmax(0, 1fr) keeps the one column as wide as the card. Without it a wide child, like the variant
   picker, stretches the column past the card and gets clipped. */
.mini-card .card-body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.mini-card .card-body > * { min-width: 0; }
.mini-card .card-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.mini-card .card-meta { color: var(--muted); font-size: 12px; }
.mini-card .card-foot { display: flex; justify-content: space-between; font-size: 12px; margin-top: 4px; }
.mini-card .card-box { font-size: 11px; color: var(--muted); border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 5px; }
/* Buttons keep their labels on one line and wrap as whole buttons, so a named card's four actions stay compact. */
/* margin-top: auto pins the buttons to the bottom, so they line up across a row of cards whatever the text above them. */
.mini-card .card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 8px; align-items: center; }
.mini-card .card-actions button { white-space: nowrap; padding: 3px 9px; font-size: 12px; }
.mini-card .card-actions .paint-toggle { display: inline-grid; place-items: center; padding: 3px 7px; }
.paint-toggle.on { background: var(--ok); border-color: var(--ok); color: #0b1f14; }
/* The photo and the strip keep their size whatever the body holds. */
.mini-card .photo, .mini-card .copy-strip { flex: none; }
.mini-card .photo { position: relative; }
.paint-badge {
  position: absolute; top: 6px; right: 6px; z-index: 1; width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 50%; background: var(--ok); color: #0b1f14; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); pointer-events: none;
}
.mini-card select { width: 100%; max-width: 100%; font-size: 12px; text-overflow: ellipsis; }

@media (max-width: 520px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .topbar { flex-wrap: wrap; gap: 8px 16px; }
  #catalog-status { margin-left: 0; flex-basis: 100%; }
}

/* Narrower windows: drop the least useful table columns before the table has to scroll sideways. */
@media (max-width: 1250px) {
  #roster th:nth-child(3), #roster td:nth-child(3) { display: none; } /* Type */
  td input.box-input { min-width: 160px; }
}
@media (max-width: 1000px) {
  #roster th:nth-child(5), #roster td:nth-child(5) { display: none; } /* Tons */
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; }
}

/* In-page confirm dialog */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.72);
  animation: fade-in 0.15s ease-out;
}
.modal {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 20px;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 20px), calc(100% - 20px) 100%, 0 100%);
  border-top: 6px solid var(--crimson);
  animation: panel-in 0.2s ease-out;
}
.modal-text { margin: 0 0 18px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
button.danger-fill { background: var(--accent); border-color: var(--accent); }

/* Owner's share link dialog */
.share-link { display: flex; gap: 10px; margin-bottom: 10px; }
.share-link input { flex: 1; min-width: 0; }
.share-note { margin: 0 0 18px; font-size: 13px; }
.modal.share .modal-actions { flex-wrap: wrap; }

/* Unit names open the detail panel */
button.unit-link {
  background: none; border: 0; padding: 0; text-align: left; color: inherit; font: inherit; font-weight: inherit;
  cursor: pointer; transition: color var(--fade);
}
button.unit-link:hover { background: none; filter: none; color: var(--accent); text-decoration: underline; }

/* Unit detail panel */
.modal-backdrop:has(.detail) { padding: 12px; place-items: stretch; }
.modal.detail { width: 100%; height: 100%; max-height: none; overflow-y: auto; padding: 24px 28px; }
.mini-card .photo.clickable { cursor: pointer; }
.detail-head { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.detail .muted { color: #cdc2c5; }
.detail .small { font-size: 15px; }
/* The panel is a bigger version of the card on the left, with the full stats and text beside it. */
.detail-layout { display: grid; grid-template-columns: minmax(300px, 440px) minmax(0, 1fr); gap: 32px; align-items: start; }
.detail-main { min-width: 0; }
.detail-main > .detail-section:first-child { margin-top: 0; }
.detail-card { position: sticky; top: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.detail .photo {
  aspect-ratio: 1 / 1; display: grid; place-items: center; position: relative; overflow: hidden;
  color: var(--muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; border-bottom: 1px solid var(--border);
}
.detail .photo.has-art { background: var(--surface); }
.detail .photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 8px; box-sizing: border-box; }
/* The strip and name at card proportions, scaled up. */
.detail-card .copy-strip { padding: 12px 18px; gap: 5px; }
.detail-card .copy-strip .strip-line { font-size: 18px; min-height: 28px; gap: 12px; }
.detail-card .copy-strip .strip-line.sub { font-size: 14px; }
.detail-card .copy-strip .faction-icon, .detail-card .copy-strip .faction-icon.company-logo { width: 28px; height: 28px; }
.detail-card-body { padding: 16px 18px 18px; display: grid; gap: 6px; }
.detail-card-body h2 { margin: 0; background: none; clip-path: none; padding: 0; font-size: 30px; line-height: 1.15; letter-spacing: 0; text-transform: none; color: #fff; }
.detail-card-body h2::before { content: none; }
.detail-card-meta { color: var(--muted); font-size: 16px; }
.detail-card-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.detail-card-pills .tag-pill, .detail-card-pills .material-static { font-size: 13px; padding: 2px 10px; }
.material-static { display: inline-block; border: 1px solid var(--warn); border-radius: 10px; color: var(--warn); }
.detail-card .copy-note-line { font-size: 15px; margin-top: 4px; }
.stats { display: grid; gap: 4px; }
.stat { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.stat .k { color: #cdc2c5; font-size: 15px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; align-self: center; }
.stat .v { font-family: var(--mono); font-size: 19px; }
.detail-section { margin-top: 24px; }
.detail-section h3 { margin: 0 0 12px; font-size: 16px; letter-spacing: 3px; text-transform: uppercase; color: #ff6b80; }
/* Lore sections fold up. Closed, a section is one line: its title and a short line about what it covers. */
.lore-blurb { min-width: 0; font-family: var(--reading); font-size: 17px; color: var(--muted); }
details.lore { margin-top: 0; border-top: 1px solid var(--border); }
details.lore:last-of-type { border-bottom: 1px solid var(--border); }
details.lore > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 16px; padding: 14px 0; }
details.lore > summary::-webkit-details-marker { display: none; }
details.lore > summary::before { content: "▸"; flex: none; width: 1em; color: #ff6b80; font-size: 16px; transition: transform var(--fade); }
details.lore[open] > summary::before { transform: rotate(90deg); }
details.lore > summary:hover .lore-title { color: #fff; }
details.lore > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lore-title { flex: none; font-size: 16px; letter-spacing: 3px; text-transform: uppercase; color: #ff6b80; }
details.lore > p { padding-left: calc(1em + 16px); }
.detail-section p strong.lead { font-weight: 700; color: #fff; }
/* Long text is easier to follow in a readable face, a bit larger, with lines about 60 characters wide and
   air between paragraphs. The screen is zoomed to 80%, so 22px reads at about 17px. */
.detail-section p { margin: 0 0 1.1em; font-family: var(--reading); font-size: 22px; line-height: 1.75; max-width: 62ch; color: #ebe6e7; text-wrap: pretty; hyphens: none; }
table.weapons { width: 100%; font-family: var(--mono); font-size: 18px; }
table.weapons th { font-size: 15px; color: #cdc2c5; }
table.weapons th, table.weapons td { padding: 6px 8px; }
table.weapons th:first-child, table.weapons td:first-child { padding-left: 0; }
.detail .credit { margin-top: 14px; }

/* Minis with a note, faction or company */
tr.copy-line td.sel-cell { border-left: 2px solid var(--accent); }
tr.all-named { opacity: 0.6; }
/* A named mini on its card: a crimson strip under the photo, then the note and tag. */
.copy-strip { background: var(--strip, var(--crimson)); color: var(--strip-text, #fff); padding: 6px 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; line-height: 1.35; overflow-wrap: anywhere; }
/* Every strip is the same height: the company (or faction) on a bold line, the faction under it. A name too
   long for its line is cut off with an ellipsis and shows in full on hover. Each line is an icon slot beside
   its text, so the company and faction icons share one size and line up with each other. */
.mini-card .copy-strip { box-sizing: border-box; height: 72px; display: flex; flex-direction: column; justify-content: center; gap: 3px; overflow: hidden; }
.copy-strip .strip-line { display: flex; align-items: center; gap: 8px; min-height: 18px; font-size: 13px; }
.copy-strip .strip-line.sub { font-size: 11px; font-weight: 400; letter-spacing: 0.08em; opacity: 0.85; }
/* The big line wraps to two lines before it is cut off. The faction line stays on one. */
.copy-strip .strip-text { min-width: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; line-height: 1.3; overflow-wrap: anywhere; }
.copy-strip .strip-line.sub .strip-text { display: block; text-overflow: ellipsis; white-space: nowrap; -webkit-line-clamp: unset; line-clamp: unset; }
/* The mech's name, first line under the photo or strip. */
.mini-card .card-title { margin-bottom: 1px; }
.mini-card .card-title .unit-link { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; font-size: 16px; font-weight: 700; background: none; border: 0; padding: 0; cursor: pointer; }
.mini-card .card-title .unit-link:hover { text-decoration: underline; filter: none; background: none; color: var(--accent); }
.copy-strip .faction-icon, .copy-strip .faction-icon.company-logo { flex: none; width: 18px; height: 18px; margin: 0; vertical-align: baseline; }
/* No backing box. A thin light halo keeps dark logos readable on the crimson strip and on the dark table. */
.faction-icon { width: 16px; height: 16px; object-fit: contain; vertical-align: -3px; margin-right: 6px; filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.9)); }
/* A logo you saved for a company. The page cuts the white out of a logo on a white background (see cleanLogo
   in app.js). A logo still on a solid color after that is shown as it is, with softened corners (.opaque). */
.faction-icon.company-logo { width: 20px; height: 20px; vertical-align: -5px; }
.faction-icon.company-logo.opaque { filter: none; border-radius: 3px; }
.logo-find { align-self: end; justify-self: start; }
.logo-picker { max-width: 560px; }
.logo-picker h3 { margin: 0 0 12px; }
.logo-current { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.logo-card { margin: 0; display: grid; gap: 8px; justify-items: center; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); text-align: center; font-size: 12px; }
/* The photo dialog: a square window onto the photo that you drag, with the zoom below it. */
.photo-dialog { max-width: 420px; }
.photo-dialog h3 { margin: 0 0 12px; }
.crop-view { position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden; border: 1px solid var(--border); cursor: grab; touch-action: none; user-select: none;
  background: repeating-linear-gradient(135deg, rgba(127, 127, 127, 0.12) 0 10px, rgba(127, 127, 127, 0.04) 10px 20px); }
.crop-view.dragging { cursor: grabbing; }
.crop-view:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.crop-img { position: absolute; max-width: none; pointer-events: none; object-fit: fill; }
.crop-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center; color: var(--muted); cursor: default; }
.zoom-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 14px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; }
.zoom-row input { flex: 1; min-width: 0; }
.photo-actions { flex-wrap: wrap; }
.photo-actions .danger { margin-right: auto; }
.color-section { display: grid; gap: 10px; margin: 4px 0 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.color-section h4 { margin: 0; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.color-preview { min-height: 36px; display: flex; flex-direction: column; justify-content: center; border-radius: 2px; transition: background var(--fade), color var(--fade); }
.swatches { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; }
.swatch { aspect-ratio: 1 / 1; padding: 0; border: 2px solid transparent; border-radius: 2px; cursor: pointer; }
.swatch[aria-pressed="true"] { border-color: #fff; }
.faction-palette > summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 2px 0; }
.faction-palette > summary:hover { color: #fff; }
.palette-body { display: grid; gap: 12px; margin-top: 10px; }
.palette-group h5 { margin: 0 0 6px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.logo-picker { max-height: 92vh; overflow-y: auto; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-input { width: 40px; height: 30px; padding: 0; border: 1px solid var(--border); background: none; border-radius: 2px; cursor: pointer; }
.hex-input { flex: 1; min-width: 0; font-family: var(--mono); text-transform: uppercase; }
.logo-thumb { width: 120px; height: 120px; object-fit: contain; background: #fff; border-radius: 2px; }
.logo-current .logo-thumb { width: 48px; height: 48px; }
.copy-note-line { font-style: italic; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.tag-pill { display: inline-block; padding: 1px 8px; font-size: 11px; border: 1px solid var(--accent); border-radius: 10px; color: var(--accent); }
.material-control { margin: 4px 0; }
.material-select { width: 100%; font-size: 12px; padding: 3px 6px; }
button.add-material { font-size: 11px; border-style: dashed; color: var(--muted); }
button.material-pill { display: inline-block; padding: 1px 8px; font: inherit; font-size: 11px; background: none; cursor: pointer; border: 1px solid var(--warn); border-radius: 10px; color: var(--warn); }
.copy-label { font-size: 12px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
/* The boxes that open when you press the pencil. */
.copy-editor { display: grid; gap: 6px; margin: 6px 0; }
.copy-editor .fld { display: grid; gap: 2px; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.copy-editor input { width: 100%; font-size: 13px; text-transform: none; letter-spacing: 0; }
.fld.inline { display: flex; align-items: center; gap: 6px; }
.copy-editor .fld.inline input { width: auto; flex: 0 0 auto; }
tr.copy-line .copy-editor { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

/* Selecting minis for a bulk change. */
input.sel-input {
  appearance: none; -webkit-appearance: none; width: 22px; height: 22px; min-width: 22px; margin: 0; padding: 0; flex: none;
  border: 2px solid #fff; border-radius: 5px; background: transparent; cursor: pointer; vertical-align: middle;
}
input.sel-input:checked, .sel-input.is-on {
  background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23b3243a' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><path d='M3 8.5l3.2 3.2L13 4.5'/></svg>") center / 15px no-repeat;
}
input.sel-input:indeterminate {
  background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M4 8h8' stroke='%23b3243a' stroke-width='2.6' stroke-linecap='round'/></svg>") center / 15px no-repeat;
}
input.sel-input:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
span.sel-input { display: inline-block; width: 22px; height: 22px; border: 2px solid #fff; border-radius: 5px; vertical-align: middle; }
/* In the table and group headers the boxes sit on the dark background, so they are a little smaller and softer. */
td.sel-cell, th.sel-cell { width: 34px; padding-right: 0; }
td.sel-cell input.sel-input, th.sel-cell input.sel-input, .group-head-row input.sel-input { width: 18px; height: 18px; min-width: 18px; border-color: var(--muted); }
tr.is-selected td { background: rgba(229, 56, 79, 0.14); }
tr.is-selected td.sel-cell { box-shadow: inset 3px 0 0 var(--accent); }
.group-head-row { display: flex; align-items: center; }
.group-head-row > input.sel-input { margin-left: 14px; }
.group-head-row .group-toggle { flex: 1; width: auto; min-width: 0; }

/* The bar on top of a card: select box, the chassis name in italics, and a round button that removes the mini. */
.mini-card .sel-bar { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; background: var(--slate); color: #fff; flex: none; transition: background var(--fade); }
.mini-card .sel-title { flex: 1; min-width: 0; text-align: center; }
.mini-card .sel-title .unit-link { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; font-style: italic; font-weight: 600; font-size: 14px; background: none; border: 0; padding: 0; cursor: pointer; }
.mini-card .sel-title .unit-link:hover { text-decoration: underline; filter: none; background: none; }
.mini-card .sel-x { flex: none; width: 24px; height: 24px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: #fff; opacity: 0.9; }
.mini-card .sel-x:hover { color: var(--accent-text); background: rgba(0, 0, 0, 0.28); opacity: 1; filter: none; }
.mini-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 6px 22px rgba(229, 56, 79, 0.28); }
.mini-card.is-selected .sel-bar { background: #b3243a; }
.card-variant-slot:empty { display: none; }

/* The bar that appears at the bottom while minis are selected. */
body.has-bulkbar { padding-bottom: 84px; }
.bulkbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 12px 22px; background: #1b1517; border-top: 2px solid var(--accent); box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.55);
}
.bulkbar[hidden] { display: none; }
.bulkbar .spacer { flex: 1; }
.bulk-count { display: flex; align-items: center; gap: 10px; margin-right: 6px; }
.bulk-count small { font-weight: 400; color: var(--muted); }
.bulkbar button.hot { border-color: var(--accent); background: #3a1a21; }
.bulk-field { display: flex; gap: 6px; padding: 4px 8px 8px; }
.bulk-input { flex: 1; min-width: 200px; }
.bulk-menu { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 51; min-width: 200px; padding: 4px; display: grid; background: #231a1d; border: 1px solid var(--accent); border-radius: 3px; box-shadow: 0 8px 26px rgba(0, 0, 0, 0.6); }
.bulk-menu[hidden] { display: none; }
.bulk-menu-head { padding: 6px 12px 4px; color: var(--muted); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }
.bulk-menu-item { text-align: left; border: 0; border-radius: 2px; background: none; padding: 8px 12px; font-size: 13px; }
.bulk-menu-item:hover, .bulk-menu-item:focus-visible { background: var(--crimson); filter: none; outline: none; }
@media (max-width: 860px) { .detail-layout { grid-template-columns: minmax(0, 1fr); } .detail-card { position: static; max-width: 440px; } }
@media (max-width: 520px) { .modal.detail { padding: 16px; } }
@keyframes fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Phone layout. Everything for narrow screens lives in this one block, last, so it wins over the
   older breakpoints above. The bottom tab bar is hidden on wider screens. */
:root {
  --tap: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
.tabbar { display: none; }

/* The filter sheet. Above 640px the wrapper adds no box, so the filters stay in the toolbar row.
   An id rule beats the browser's [hidden] rule, which is why the sheet shows here even with the attribute. */
#filter-sheet, .sheet-body { display: contents; }
.open-filters, .sheet-head, .sheet-view, .sheet-backdrop { display: none; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px;
  background: var(--crimson); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
.badge[hidden] { display: none; }

@media (max-width: 640px) {
  /* The 0.8 zoom is a desktop choice. On a phone it would shrink text and tap targets below usable size. */
  html { zoom: 1; }
  body { padding-bottom: calc(var(--tap) + var(--safe-bottom) + 16px); }

  .topbar {
    flex-wrap: nowrap;
    gap: 8px;
    padding: calc(8px + var(--safe-top)) 12px 8px;
  }
  .topbar h1 { font-size: 22px; letter-spacing: 1px; }
  .topbar .owner-name { font-size: 14px; letter-spacing: 1px; }
  .topbar .tabs { display: none; }
  #account { margin-left: auto; display: flex; align-items: center; gap: 4px; min-width: 0; }
  #account[hidden] { display: none; }
  #account .account-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #account button { flex: none; margin-left: 4px; min-height: var(--tap); padding: 4px 12px; }

  #catalog-status {
    display: block;
    margin: 0 0 8px;
    flex-basis: auto;
    font-size: 11px;
    letter-spacing: 1px;
  }

  .layout { padding: 12px; gap: 12px; }

  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40; /* above page content, below the bulk bar and the dialogs (50) */
    height: calc(var(--tap) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 2px solid var(--crimson);
  }
  .tabbar button {
    flex: 1;
    min-width: 0;
    height: var(--tap);
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
  }
  .tabbar button[aria-selected="true"] { background: var(--crimson); color: #fff; }

  /* Keep the selection bar and the toast above the tab bar. */
  .bulkbar { bottom: calc(var(--tap) + var(--safe-bottom)); }
  body.has-bulkbar { padding-bottom: calc(var(--tap) + var(--safe-bottom) + 100px); }
  .toast { right: 12px; left: 12px; max-width: none; bottom: calc(var(--tap) + var(--safe-bottom) + 12px); }

  /* One tab at a time. The tray sits inside the collection section and the saved forces outside main. */
  body[data-tab="collection"] #tray,
  body[data-tab="collection"] #forces,
  body[data-tab="import"] #forces,
  body[data-tab="forces"] #view-collection > :not(#tray) { display: none; }

  /* Toolbar row: search, Filters, Add units. The rest of the filters live in the sheet. */
  .toolbar { flex-wrap: nowrap; }
  .toolbar > input[type="search"] { flex: 1 1 0; min-width: 0; min-height: var(--tap); font-size: 16px; }
  .toolbar > button { flex: none; min-height: var(--tap); }
  .open-filters { display: inline-flex; align-items: center; }

  .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, 0.55); animation: fade-in var(--fade); }
  .sheet-backdrop[hidden] { display: none; }
  #filter-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45; /* over the tab bar (40) and the sheet backdrop (44), under dialogs (50) */
    max-height: 85vh;
    max-height: 85dvh;
    background: var(--surface);
    border-top: 2px solid var(--crimson);
    box-shadow: 0 -8px 26px rgba(0, 0, 0, 0.6);
    animation: sheet-up 0.2s ease-out;
  }
  #filter-sheet[hidden] { display: none; }
  .sheet-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
  }
  .sheet-head h2 { margin: 0 auto 0 0; font-size: 18px; letter-spacing: 1px; text-transform: uppercase; }
  .sheet-head button { min-height: var(--tap); padding: 4px 16px; }
  .sheet-body {
    display: grid;
    gap: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 12px calc(12px + var(--safe-bottom));
  }
  #filter-sheet input[type="search"], #filter-sheet select {
    width: 100%;
    min-width: 0;
    min-height: var(--tap);
    font-size: 16px;
    flex: none;
  }
  #filter-sheet .check { min-height: var(--tap); gap: 10px; }
  #filter-sheet .check input { width: 22px; height: 22px; }
  .sheet-view { display: grid; gap: 10px; padding-top: 6px; border-top: 1px solid var(--border); }
  .sheet-view h3 { margin: 0; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
  .sheet-view .group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .sheet-view .group[hidden] { display: none; }
  .sheet-view .label { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); min-width: 64px; }
  .sheet-view button.seg { min-height: var(--tap); padding: 6px 14px; }
  .sheet-view button.seg[aria-pressed="true"] { background: var(--crimson); border-color: var(--accent); color: #fff; }
  #filter-sheet .sheet-view select { flex: 1 1 140px; width: auto; }

  /* Cards are the phone's collection view, so the table and density controls have nothing to do. */
  #view-controls > .group[aria-label="View"], #density-group { display: none; }
  #view-controls { gap: 8px; }
  #view-controls .count { margin-left: auto; font-size: 13px; }

  /* Card layout: two columns, one on the narrowest phones. */
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .mini-card:hover { transform: none; }
  .mini-card .sel-bar { height: calc(var(--tap) + 8px); padding: 0 4px 0 2px; }
  .mini-card .card-body { padding: 10px 12px 12px; gap: 6px; }
  .mini-card .card-name { font-size: 14px; }
  .mini-card .card-meta { font-size: 14px; }
  .mini-card .card-box { font-size: 13px; }
  .mini-card .copy-note-line { font-size: 14px; }

  /* Touch targets: the box, the remove button, the name and every action are at least 44px. The checkbox
     keeps its 22px look inside a 44px hit area (a transparent border, with the drawn box inset). */
  .mini-card input.sel-input, .group-head-row input.sel-input {
    width: var(--tap); height: var(--tap); min-width: var(--tap);
    border: 11px solid transparent; border-radius: 16px; background-clip: padding-box; box-shadow: inset 0 0 0 2px #fff;
  }
  .group-head-row input.sel-input { box-shadow: inset 0 0 0 2px var(--muted); margin-left: 4px; }
  .mini-card .sel-x { width: var(--tap); height: var(--tap); }
  .mini-card .sel-x svg { width: 28px; height: 28px; }
  .mini-card .card-title .unit-link { display: block; width: 100%; min-height: var(--tap); line-height: var(--tap); text-align: left; font-size: 17px; }
  .mini-card button.add-material, .mini-card button.material-pill { min-height: var(--tap); padding: 4px 12px; font-size: 14px; }
  .mini-card select, .mini-card .card-body input[type="text"], .mini-card .card-body input:not([type]) { min-height: var(--tap); font-size: 16px; }
  .mini-card .card-actions { gap: 8px; padding-top: 10px; }
  .mini-card .card-actions button { flex: 1 1 auto; min-height: var(--tap); min-width: var(--tap); padding: 6px 12px; font-size: 14px; }
  .mini-card .card-actions .paint-toggle { flex: 0 0 var(--tap); padding: 6px; }
  .mini-card .card-actions > button:first-child { flex: 1 1 100%; } /* "+ tray" gets a full-width row */

  /* A card being edited takes the whole row, so its boxes are wide enough to type in. */
  .mini-card.is-editing { grid-column: 1 / -1; }
  .mini-card .copy-editor { gap: 8px; }
  .mini-card .copy-editor .fld { font-size: 12px; }
  .mini-card .copy-editor button { min-height: var(--tap); padding: 6px 14px; font-size: 14px; }
  .mini-card .copy-editor .fld.inline { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
  .mini-card .copy-editor .fld.inline input { width: 24px; height: 24px; }

  /* The unit detail panel fills the screen. Its Close button is a full touch target, and the card and the
     text stack in one column. Text sizes inside it are unchanged. */
  .modal.detail { padding: 12px; }
  .detail-head { position: sticky; top: -12px; z-index: 1; margin: -12px -12px 12px; padding: 8px 12px; background: var(--surface); }
  .detail-close { min-height: var(--tap); min-width: var(--tap); padding: 6px 18px; }
  .detail-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .detail-card { position: static; }

  /* Group headers and company banners are easy to hit. */
  .group-toggle { min-height: var(--tap); padding: 8px 12px; }
  .group-head-row .group-toggle { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; }
}

@media (max-width: 360px) {
  .card-grid { grid-template-columns: minmax(0, 1fr); }
}

@keyframes sheet-up { from { transform: translateY(100%); } }
