/* Mobile-first. This is meant to be used on a phone next to a running game,
   so: big tap targets, high contrast, no layout that needs a mouse. */

:root {
  color-scheme: dark;
  --bg: #141210;
  --bg-raised: #1e1b18;
  --bg-sunken: #0f0d0c;
  --line: #322d28;
  --text: #ece5da;
  --muted: #9b9086;
  --accent: #d08b3c;
  --accent-dim: #6b4a20;
  --danger: #c4553f;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main { flex: 1; }

/* ------------------------------------------------------------- chrome -- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-sunken);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand .mark { color: var(--accent); font-size: 20px; }

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--bg-sunken);
  position: sticky;
  top: 49px;
  z-index: 4;
}

.tab {
  flex: 1;
  padding: 12px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.pill {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1512;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.view { padding: 12px 16px 24px; }

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.boot {
  position: fixed;
  /* Long-hand as well as `inset`: an older browser that ignores the shorthand
     would leave this panel sitting in the flow instead of covering the page,
     which looks like a working app with dead controls. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  color: var(--muted);
  z-index: 20;
}

.boot[hidden] { display: none; }

/* -------------------------------------------------------------- search -- */

.search-bar { position: sticky; top: 95px; z-index: 3; padding: 4px 0 8px; background: var(--bg); }

#q {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
}

#q:focus { outline: 2px solid var(--accent-dim); outline-offset: 1px; }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
}

.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }

/* --------------------------------------------------------------- icons -- */

/* Fixed box so rows never reflow as lazy icons arrive, and so the 14 items
   whose file was never uploaded still line up with everything else. */
.icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-size, 32px);
  height: var(--icon-size, 32px);
  border-radius: 6px;
  background: var(--bg-raised);
  overflow: hidden;
}

.icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.icon-empty {
  border: 1px solid var(--line);
  background: var(--bg-sunken);
}

.icon-empty::after {
  content: '';
  width: 34%;
  height: 34%;
  border-radius: 2px;
  background: var(--line);
}

/* Icon plus label inside a row that also carries a right-aligned quantity. */
.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.item-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.item-head h1 { margin: 0; }

.big { font-size: 26px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }

/* Four tabs need to fit a narrow phone. */
.tab { padding: 12px 4px; font-size: 15px; }

.list { list-style: none; margin: 0; padding: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.row:active { background: var(--bg-raised); }
.row .grow { flex: 1; min-width: 0; }
.row .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { display: block; color: var(--muted); font-size: 12px; }

.tag {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

/* -------------------------------------------------------------- detail -- */

.back {
  margin-bottom: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 24px 0 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.stat {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.stat dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }

.card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  margin-bottom: 10px;
}

.card .stations { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.card ul { list-style: none; margin: 0; padding: 0; }
.card li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.card .qty { color: var(--accent); font-variant-numeric: tabular-nums; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 8px; }

.btn {
  display: inline-block;
  padding: 11px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #1a1512;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ghost {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.ghost.small { padding: 6px 10px; font-size: 13px; }

.qty-input {
  width: 76px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.actions { display: flex; gap: 8px; align-items: center; margin: 14px 0; flex-wrap: wrap; }

/* ---------------------------------------------------------- calculator -- */

.empty { padding: 40px 8px; text-align: center; color: var(--muted); }

.targets { list-style: none; margin: 0 0 10px; padding: 0; }

.targets li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.targets .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.totals { list-style: none; margin: 0; padding: 0; }

.totals li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
}

.totals .qty { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.totals .note { color: var(--muted); font-size: 12px; }

.tree { font-size: 15px; }

.node { padding-left: 14px; border-left: 1px solid var(--line); margin-left: 6px; }
.tree > .node { border-left: none; margin-left: 0; padding-left: 0; }

.node-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
  width: 100%;
  padding: 7px 4px;
  background: none;
  border: none;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.node-line:active { background: var(--bg-raised); }
.node-line .qty { color: var(--accent); font-variant-numeric: tabular-nums; flex: none; }

/* `flex: 1` would set the basis to 0, letting a long name shrink below its own
   width and spill over the flag beside it. `break-word` keeps the item name's
   min-content width intact - `anywhere` would zero it and split words like
   "Silverston/e" - so deep in the tree the flag wraps to its own line instead. */
.node-line .label { flex: 1 1 auto; min-width: 0; overflow-wrap: break-word; }

/* Secondary text: stays right, and is the part that drops to the next line. */
.node-line .flag {
  flex: 0 1 auto;
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}
.node-line.leaf .label { color: var(--muted); }
.node-line.cycle .flag { color: var(--danger); }

select.alt {
  display: block;
  max-width: 100%;
  margin: 2px 0 8px 4px;
  padding: 5px 8px;
  border: 1px dashed var(--accent-dim);
  border-radius: 6px;
  background: var(--bg-sunken);
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

@media (min-width: 720px) {
  .view { max-width: 900px; margin: 0 auto; }
  .foot { max-width: 900px; margin: 0 auto; width: 100%; }
}
