:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: 76px;
  -webkit-tap-highlight-color: transparent;
}
.muted { color: var(--muted); }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(15,23,42,.92); backdrop-filter: blur(8px);
  padding: 14px 16px calc(10px + env(safe-area-inset-top)); padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); }
.summary { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* Main */
main { padding: 14px 14px 24px; max-width: 720px; margin: 0 auto; }
h2.section { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }

/* Cards */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px;
}
.card.tap { cursor: pointer; transition: background .12s; }
.card.tap:active { background: var(--panel-2); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-title { font-weight: 650; font-size: 15.5px; line-height: 1.25; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.card-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.link {
  color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px;
}
.link:active { opacity: .7; }

/* Chips & badges */
.chip { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.st-NOT_STARTED { background: #3f3f46; color: #e4e4e7; }
.st-MODEL_FOUND { background: #1e3a5f; color: #7dd3fc; }
.st-PRINTING   { background: #78350f; color: #fcd34d; }
.st-PRINTED    { background: #14532d; color: #86efac; }
.st-INSTALLED  { background: #4c1d95; color: #d8b4fe; }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.bd-native  { background: #052e16; color: #4ade80; border: 1px solid #166534; }
.bd-fit     { background: #042f2e; color: #2dd4bf; border: 1px solid #115e59; }
.bd-adapter { background: #422006; color: #fbbf24; border: 1px solid #854d0e; }
.bd-custom  { background: #450a0a; color: #f87171; border: 1px solid #7f1d1d; }
.adapter-tag { font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.adapter-tag.done { color: #86efac; }

/* Reference card */
.ref { background: var(--panel-2); }
.ref summary { cursor: pointer; font-weight: 650; font-size: 13.5px; }
.ref a { display: block; margin: 8px 0; }
.ref .rn { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }

/* Queue board */
.queue-col h3 { font-size: 13px; margin: 0 0 6px; display: flex; justify-content: space-between; }
.queue-col h3 .n { color: var(--muted); font-weight: 600; }
.mini {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 7px; display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.mini .mt { font-size: 13.5px; font-weight: 600; }
.mini .md { font-size: 11.5px; color: var(--muted); }

/* Custom checklist */
.check-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-top: 1px solid var(--line); }
.check-row:first-of-type { border-top: none; }
.check-row label { flex: 1; font-size: 14px; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

/* Grid planner — layer/version bar */
.layer-bar { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.layer-chip {
  display: flex; align-items: center; gap: 2px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--panel); overflow: hidden;
}
.layer-chip.active { border-color: var(--lc); box-shadow: 0 0 0 1px var(--lc) inset; }
.layer-chip.off { opacity: .5; }
.layer-chip .layer-eye, .layer-chip .layer-name, .layer-chip .layer-edit {
  background: none; border: none; color: var(--text); font-size: 12.5px; font-weight: 650;
  padding: 7px 4px; cursor: pointer;
}
.layer-chip .layer-eye { padding-left: 9px; }
.layer-chip .layer-edit { padding-right: 10px; color: var(--muted); }
.layer-chip .layer-name { display: flex; align-items: center; gap: 6px; padding: 7px 2px; }
.layer-swatch { width: 11px; height: 11px; border-radius: 3px; background: var(--lc); display: inline-block; }
.layer-add {
  border: 1px dashed var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 650; cursor: pointer;
}
.gblock.active-layer { z-index: 5; }

/* Grid planner */
.wall-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.wall-tabs button {
  flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); font-weight: 650; font-size: 13px;
}
.wall-tabs button.active { background: var(--accent); color: #06283d; border-color: var(--accent); }
.grid-scroll { overflow: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
.walls-all { display: flex; gap: 26px; align-items: flex-start; width: max-content; }
.wall-wrap { width: max-content; }
.wall-name { font-size: 12px; color: var(--muted); font-weight: 650; margin-bottom: 6px; }
.wgrid { display: grid; gap: 2px; --cell: 20px; }
.gcell {
  width: var(--cell); height: var(--cell); border: 1px solid var(--line);
  border-radius: 3px; background: var(--panel); cursor: pointer;
}
.gcell:active { background: var(--panel-2); }
.gblock {
  background: #164e63; border: 1px solid #0e7490; border-radius: 4px; color: #cffafe;
  font-size: 9px; font-weight: 600; line-height: 1.05; text-align: center; padding: 2px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  z-index: 2; cursor: pointer; position: relative;
}
.gblock:active { background: #0e7490; }
/* Active-layer blocks are draggable — stop the page from scrolling under the finger. */
.gblock.active-layer { cursor: grab; touch-action: none; }
.gblock.dragging, .gblock.resizing {
  z-index: 20; cursor: grabbing; opacity: .92;
  box-shadow: 0 6px 18px rgba(0,0,0,.45); overflow: visible;
}
.gblock.clash { outline: 2px solid #f87171; outline-offset: -1px; }
/* Bottom-right resize handle */
.resize-handle {
  position: absolute; right: -4px; bottom: -4px; width: 15px; height: 15px;
  border-radius: 4px; background: #e2e8f0; border: 2px solid #0e7490;
  cursor: nwse-resize; touch-action: none; z-index: 21;
}
.resize-handle::after {
  content: ''; position: absolute; inset: 3px 3px auto auto; width: 5px; height: 5px;
  border-right: 2px solid #0e7490; border-bottom: 2px solid #0e7490;
}
.hint { font-size: 12px; color: var(--muted); margin: 10px 2px; }

/* Footprint + link editor */
.foot-row { display: flex; align-items: center; gap: 10px; }
.foot-row input { width: auto; flex: 1; }
.foot-row span { color: var(--muted); font-weight: 700; }
.link-edit {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 7px;
}
.link-edit input, .link-edit select { font-size: 13.5px; padding: 9px 10px; }
.le-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 2px; }
.le-b {
  width: auto; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; font-size: 12.5px; font-weight: 650;
}
.le-b.on { background: #052e16; color: #4ade80; border-color: #166534; }
.le-b.danger { background: #450a0a; color: #f87171; border-color: #7f1d1d; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: rgba(15,23,42,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 12px 0 14px; font-size: 12.5px; font-weight: 650;
}
.tabbar button.active { color: var(--accent); }

/* Sheet / modal */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
}
/* [hidden] must win over the display:flex above, or the backdrop eats every click. */
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--panel); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; animation: up .18s ease;
}
@keyframes up { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3 { margin: 0 0 2px; }
.field { margin-top: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
select, input[type="number"], input[type="text"], textarea, button.big {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
button.big { font-weight: 700; }
button.primary { background: var(--accent); color: #06283d; border-color: var(--accent); }
button.ghost { background: var(--panel-2); }

/* Login */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px 24px; width: 100%; max-width: 340px; text-align: center;
}
.login-logo { font-size: 40px; color: var(--accent); }
.login-card h1 { font-size: 20px; margin: 8px 0 2px; }
.login-card input { margin: 16px 0 12px; text-align: center; }
.login-card button { width: 100%; background: var(--accent); color: #06283d; border: none; border-radius: 10px; padding: 12px; font-weight: 700; font-size: 15px; }
.login-error { color: #f87171; font-size: 13px; min-height: 18px; margin: 10px 0 0; }
