/* plan.tbe.gg — reuses the tbe.gg design system (DESIGN.md): dark-only,
   single accent #3b9eff, system font + mono, industrial/utilitarian. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }

:root {
  --bg: #0a0e14;
  --surface: #131922;
  --surface-2: #19212d;
  --border: #1e2a3a;
  --text: #d4dce8;
  --dim: #8b97a6;
  --text-muted: #aeb8c4;
  --accent: #3b9eff;
  --accent-dim: #2a6db8;
  --success: #3fb950;
  --warning: #d29922;
  --error: #f47067;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', Menlo, Consolas, monospace;

  --sp-2xs: 4px; --sp-xs: 8px; --sp-sm: 12px; --sp-md: 16px; --sp-lg: 24px; --sp-xl: 32px; --sp-2xl: 48px;
  --radius-sm: 4px; --radius-md: 6px; --radius-lg: 8px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- header / footer --- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: none; margin: 0;
  padding: var(--sp-sm) var(--sp-lg);
  border-bottom: 1px solid var(--border);
}
.brand-group { display: inline-flex; align-items: center; gap: var(--sp-xs); }
.brand { font-weight: 700; font-size: var(--fs-lg, 1rem); letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.brand b { color: var(--accent); font-weight: inherit; }
.brand:hover { color: var(--accent); }
.beta-tag {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); border: 1px solid var(--accent-dim); border-radius: 4px;
  padding: 1px 5px; line-height: 1.4; align-self: center;
}
.site-links { display: flex; align-items: center; gap: var(--sp-md); }
.site-links a { color: var(--dim); font-size: 0.78rem; text-decoration: none; white-space: nowrap; }
.site-links a:hover { color: var(--accent); }
.site-footer {
  max-width: 880px; width: 100%; margin: var(--sp-2xl) auto 0;
  padding: var(--sp-md); color: var(--dim); font-size: 0.78rem;
  border-top: 1px solid var(--border);
}
.site-footer .footer-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--sp-2xs) var(--sp-md); }
.site-footer p { margin: 0; }
.site-footer a { color: var(--dim); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

#app { max-width: 880px; width: 100%; margin: 0 auto; padding: 0 var(--sp-md) var(--sp-xl); flex: 1; }
.loading { color: var(--dim); padding: var(--sp-2xl) 0; text-align: center; }

/* --- buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2xs);
  font: inherit; font-size: 0.85rem; font-weight: 500;
  padding: var(--sp-xs) var(--sp-md); min-height: 36px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent-dim); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.btn-accent:hover { background: #5aaeff; }
.btn-ghost { background: transparent; }
.btn-danger:hover { border-color: var(--error); color: var(--error); }
.btn-sm { min-height: 30px; padding: var(--sp-2xs) var(--sp-xs); font-size: 0.8rem; }
.row-actions { display: flex; gap: var(--sp-xs); flex-wrap: wrap; }

/* --- homepage --- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-md); margin: var(--sp-md) 0 var(--sp-lg); flex-wrap: wrap; }
.page-head h1 { font-size: 1.4rem; letter-spacing: -0.02em; }
.muted { color: var(--dim); }
.empty {
  text-align: center; color: var(--dim);
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: var(--sp-2xl) var(--sp-md);
}
.empty p { margin-bottom: var(--sp-xs); }

.game-group { margin-bottom: var(--sp-lg); }
.game-group h2 {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--dim); margin-bottom: var(--sp-xs); padding-bottom: var(--sp-2xs);
  border-bottom: 1px solid var(--border);
}
.plan-card {
  display: flex; align-items: center; gap: var(--sp-md);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--sp-sm) var(--sp-md); margin-bottom: var(--sp-xs); cursor: pointer;
}
.plan-card:hover { border-color: var(--accent-dim); }
.plan-card .pc-main { flex: 1; min-width: 0; }
.plan-card .pc-title { font-weight: 500; }
.plan-card .pc-meta { color: var(--dim); font-size: 0.8rem; }
.pc-progress { width: 120px; flex-shrink: 0; }

/* --- progress bar --- */
.bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.2s; }
.bar-label { font-size: 0.75rem; color: var(--dim); font-family: var(--font-mono); margin-top: 2px; }

/* --- plan view --- */
.plan-head { margin: var(--sp-md) 0 var(--sp-lg); }
.plan-title-row { display: flex; align-items: center; gap: var(--sp-sm); flex-wrap: wrap; }
.plan-title-row h1 { font-size: 1.5rem; letter-spacing: -0.02em; }
.plan-title-input { font: inherit; font-size: 1.5rem; font-weight: 700; background: var(--surface); color: var(--text); border: 1px solid var(--accent-dim); border-radius: var(--radius-sm); padding: 2px var(--sp-xs); }
.plan-sub { color: var(--dim); font-size: 0.85rem; margin-top: 2px; }
.plan-progress { margin: var(--sp-md) 0; }
.plan-toolbar { display: flex; gap: var(--sp-xs); flex-wrap: wrap; margin-top: var(--sp-sm); }

.targets-bar {
  display: flex; gap: var(--sp-xs); flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--sp-sm); margin-bottom: var(--sp-lg);
}
.target-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2xs);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: var(--sp-2xs) var(--sp-xs) var(--sp-2xs) var(--sp-sm); font-size: 0.85rem;
}
.target-chip input { width: 46px; font: inherit; font-family: var(--font-mono); font-size: 0.8rem; text-align: right; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1px 2px; }
.target-chip .x { color: var(--dim); cursor: pointer; padding: 0 2px; }
.target-chip .x:hover { color: var(--error); }

/* --- sections / checklist --- */
/* --- Plan two-column layout --------------------------------------------- */
/* Plan (+ Stations/Tech) on the left; the Gather shopping list as a sticky rail
   on the right so it stays in view while scrolling a long tree. Single column on
   narrow screens — the rail drops below the plan and un-sticks. */
.plan-body { display: grid; grid-template-columns: 1fr; gap: var(--sp-lg); }
.plan-main { min-width: 0; }
@media (min-width: 760px) {
  .plan-body { grid-template-columns: minmax(0, 1fr) minmax(240px, 340px); align-items: start; }
  .plan-side { position: sticky; top: var(--sp-md); }
  .plan-side > .section:last-child { margin-bottom: 0; }
}

.section { margin-bottom: var(--sp-lg); }
.section > h3, .section-head > h3 {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--dim); margin-bottom: var(--sp-xs);
}
.check-row {
  display: flex; align-items: flex-start; gap: var(--sp-sm);
  padding: var(--sp-xs) var(--sp-sm); border-radius: var(--radius-sm);
  min-height: 40px;
}
.check-row:hover { background: var(--surface); }
.check-row.done .cr-name { color: var(--dim); text-decoration: line-through; }
.check-row input[type=checkbox] { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.cr-body { flex: 1; min-width: 0; }
.cr-name { font-weight: 500; }
.cr-qty { font-family: var(--font-mono); color: var(--accent); font-size: 0.9rem; }
.cr-for { color: var(--dim); font-size: 0.82rem; }
.cr-note { color: var(--dim); font-size: 0.8rem; }
.cr-note a { color: var(--text-muted); }
.cr-expand { background: none; border: none; color: var(--dim); cursor: pointer; font-size: 0.8rem; padding: 0; font-family: var(--font-mono); }
.cr-expand:hover { color: var(--accent); }
.recipe-children { margin: var(--sp-2xs) 0 0; padding-left: var(--sp-md); border-left: 1px solid var(--border); }
.recipe-children li { list-style: none; font-size: 0.82rem; color: var(--text-muted); padding: 1px 0; }
.recipe-children .rc-amt { font-family: var(--font-mono); color: var(--dim); }

.chips { display: flex; flex-wrap: wrap; gap: var(--sp-xs); }
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2xs);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--sp-2xs) var(--sp-sm); font-size: 0.82rem;
}
.chip input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-md);
  background: var(--surface); border: 1px solid var(--accent-dim); border-radius: var(--radius-md);
  padding: var(--sp-sm) var(--sp-md); margin-bottom: var(--sp-lg); flex-wrap: wrap;
}
.banner.warn { border-color: var(--warning); }

.toast {
  position: fixed; left: 50%; bottom: var(--sp-lg); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--sp-sm) var(--sp-md); font-size: 0.85rem; box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  display: flex; align-items: center; gap: var(--sp-md); z-index: 50; max-width: 92vw;
}
.toast a { cursor: pointer; }
.toast[hidden] { display: none; } /* author display:flex above overrides the [hidden] UA rule; restore it */

.back-link { color: var(--dim); font-size: 0.85rem; display: inline-block; margin: var(--sp-xs) 0; }

/* "Add to which plan?" chooser */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: var(--sp-md); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-lg); width: 100%; max-width: 420px; box-shadow: 0 12px 48px rgba(0,0,0,0.5); }
.modal h2 { font-size: 1rem; font-weight: 600; margin-bottom: var(--sp-md); }
.plan-choices { display: flex; flex-direction: column; gap: var(--sp-xs); }
.choice { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; width: 100%; font: inherit; padding: var(--sp-sm) var(--sp-md); background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-md); cursor: pointer; }
.choice:hover, .choice:focus-visible { border-color: var(--accent-dim); outline: none; }
.choice.is-default { border-color: var(--accent); }
.choice-title { font-weight: 500; }
.choice-meta { color: var(--dim); font-size: 0.78rem; }
.choice-new .choice-title { color: var(--accent); }
.modal-foot { margin-top: var(--sp-md); text-align: right; }
.modal-foot .btn + .btn { margin-left: var(--sp-xs); }

/* New-plan form fields */
.field { display: flex; flex-direction: column; gap: var(--sp-2xs); margin-bottom: var(--sp-md); }
.field-label { color: var(--dim); font-size: 0.78rem; }
.field select, .field input { width: 100%; box-sizing: border-box; font: inherit; font-size: 0.95rem;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: var(--sp-xs) var(--sp-sm); }
.field select:focus, .field input:focus { outline: none; border-color: var(--accent); }

@media (max-width: 560px) {
  .pc-progress { width: 84px; }
  .plan-title-row h1 { font-size: 1.3rem; }
}

/* --- Plan ingredient tree (recursive flow view) ------------------------- */
/* --pipe / --arm drive the box-drawing connectors on nested nodes (below),
   matching the item-page Crafting Tree. --arm is the row's vertical mid-point
   (where the horizontal connector meets a row); nudge it if the elbow drifts. */
.tree { list-style: none; margin: 0; padding: 0; --pipe: var(--text-muted); --arm: 0.9em; }
.tree .tree-node { list-style: none; }
/* control sits next to the "Plan" heading */
/* match the Gather section's heading gap so the two columns' first rows align;
   the h3 itself is flush (spacing comes from the flex row) so the toggle-all
   control stays on the heading's baseline. */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-sm); margin-bottom: var(--sp-xs); }
.section-head > h3 { margin-bottom: 0; }
.btn-xs { min-height: 24px; padding: 1px var(--sp-xs); font-size: 0.72rem; }
.tree-row { display: flex; align-items: baseline; gap: var(--sp-2xs); padding: 3px 0; }
.tree-row.done .tree-name { text-decoration: line-through; color: var(--dim); }
/* covered = satisfied because a parent craft item is checked (you have it, so its
   ingredients no longer need gathering). Struck + faded, distinct from a deliberate
   .done tick by the lower opacity. */
.tree-row.covered { opacity: .55; }
.tree-row.covered .tree-name, .tree-row.covered .tree-qty { text-decoration: line-through; color: var(--dim); }
.tree-row input[type=checkbox] { flex: none; align-self: center; }
.tree-toggle { flex: none; width: 1.2em; background: none; border: none; color: var(--dim); cursor: pointer; font-size: 0.8rem; padding: 0; font-family: var(--font-mono); align-self: center; }
.tree-toggle:hover { color: var(--accent); }
.tree-lead { flex: none; width: 1.2em; }
/* name takes the slack and WRAPS instead of overflowing the row — deep nesting +
   long item names would otherwise push qty/tag off-screen and clip. */
.tree-name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.tree-qty { flex: none; font-family: var(--font-mono); color: var(--accent); font-size: 0.9rem; }
.tree-tag { flex: none; font-size: 0.68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }
/* Nested ingredients render as a box-drawing tree (├──/└──/│) like the item-page
   Crafting Tree. Connectors are CSS borders on each child <li>: a vertical pipe
   down the left edge + a horizontal arm into the row. The last child's pipe stops
   at the arm so nothing dangles below the elbow. Only nested levels (children of a
   .tree-children) get pipes — the root targets stay flush left. */
.tree-children { list-style: none; margin: 0; padding-left: 0.6em; }
.tree-children > .tree-node { position: relative; padding-left: 1.5em; }
.tree-children > .tree-node::before {
  content: ""; position: absolute; left: 0; top: 0; height: 100%;
  border-left: 2px solid var(--pipe);
}
.tree-children > .tree-node:last-child::before { height: var(--arm); }
.tree-children > .tree-node::after {
  content: ""; position: absolute; left: 0; top: var(--arm); width: 1.05em;
  border-top: 2px solid var(--pipe);
}
@media (max-width: 480px) {
  .tree-children { padding-left: 0.3em; }
  .tree-children > .tree-node { padding-left: 1.15em; }
  .tree-children > .tree-node::after { width: 0.8em; }
}
/* craft-row = the optional "cube from" ladder under a rune (D2R): reference, not
   demand, so it's dimmed and checkbox-less, with the toggle aligned where the
   checkbox would sit. The "cube ↓" / "cube" tags read as "you could make this". */
.tree-row.craft-row { padding-left: calc(1.2em + var(--sp-2xs)); color: var(--dim); }
.tree-row.craft-row .tree-name { font-weight: 400; }
.tree-tag.cube { color: var(--accent); border-color: var(--accent); }
.tree-tag.boss { color: var(--warning); border-color: var(--warning); }
.tree-tag.muted { opacity: .7; }
/* "boss" marker in the Gather "Drops from boss X" note */
.boss-mark { color: var(--warning); font-weight: 600; text-transform: uppercase; font-size: 0.7em; letter-spacing: .04em; }
.totals { list-style: none; margin: 0; padding: 0; }
.totals li { padding: 2px 0; font-size: 0.92rem; }
/* fully covered by checked items → no longer needed; cross it off the shopping list */
.totals li.covered { opacity: .55; }
.totals li.covered a, .totals li.covered .cr-qty { text-decoration: line-through; color: var(--dim); }

/* --- Add-item search modal --------------------------------------------- */
.modal-search { width: min(440px, 92vw); }
.search-input { width: 100%; box-sizing: border-box; padding: var(--sp-xs) var(--sp-sm); font-size: 1rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: inherit; }
.search-input:focus { outline: none; border-color: var(--accent); }
.search-results { margin-top: var(--sp-xs); max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; }
.search-hit { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-sm); width: 100%;
  text-align: left; background: none; border: none; border-bottom: 1px solid var(--border); color: var(--text);
  padding: var(--sp-xs) var(--sp-2xs); cursor: pointer; font: inherit; }
.search-hit:hover, .search-hit:focus { background: var(--bg-elev, rgba(255,255,255,0.04)); }
.search-hit .hit-name { font-weight: 500; }
.search-hit .hit-type { color: var(--dim); font-size: 0.8rem; }
.search-empty { color: var(--dim); padding: var(--sp-sm) var(--sp-2xs); }
