:root {
  --bg: #0e1014;
  --bg-2: #161a21;
  --bg-3: #1d222b;
  --border: #262c36;
  --fg: #e6e8ec;
  --fg-dim: #9aa3b2;
  --accent: #7aa2ff;
  --accent-2: #5af0c4;
  --danger: #ff7676;
  --warn: #ffc06b;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  margin: 0;
  line-height: 1.5;
}

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

.muted { color: var(--fg-dim); }
.error {
  background: #2a1416;
  border: 1px solid #5a1d22;
  color: #ffb3b3;
  padding: .6rem .8rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .8rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.topbar .brand { font-weight: 700; color: var(--fg); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav .muted { font-size: .9rem; }

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.5rem 1.2rem 4rem;
}

h1 { margin-top: 0; }
h1, h2, h3 { color: var(--fg); }

.footer {
  text-align: center;
  padding: 1rem;
  font-size: .85rem;
  border-top: 1px solid var(--border);
}

/* index grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.card {
  display: block;
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: var(--radius);
  color: var(--fg);
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card h2 { margin: 0 0 .25rem; font-size: 1.1rem; }
.card .meta { font-size: .85rem; color: var(--fg-dim); display: flex; gap: .35rem; flex-wrap: wrap; }

/* forms */
form.stack { display: flex; flex-direction: column; gap: .8rem; }
form.stack.narrow { max-width: 360px; }
form.stack label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--fg-dim); }
form.stack label.checkbox { flex-direction: row; align-items: center; gap: .4rem; }

.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row label { flex: 1 1 160px; }

input, select, textarea, button {
  font: inherit;
  color: var(--fg);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .6rem;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
textarea { font-family: var(--mono); }

button, .btn-secondary {
  cursor: pointer;
  background: var(--accent);
  color: #06121f;
  border: 1px solid var(--accent);
  font-weight: 600;
}
button:hover { filter: brightness(1.1); }
.btn-secondary {
  background: var(--bg-3);
  color: var(--fg);
  border-color: var(--border);
  display: inline-block;
  padding: .5rem .8rem;
  border-radius: var(--radius);
  text-decoration: none;
}
.btn-secondary:hover { border-color: var(--accent); }

button.linklike, .linklike {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 0;
  font-weight: 400;
  cursor: pointer;
}
button.linklike:hover { text-decoration: underline; }
.linklike.danger { color: var(--danger); }

form.inline { display: inline; margin: 0; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .8rem;
  background: var(--bg-2);
}
legend { padding: 0 .4rem; color: var(--fg-dim); font-size: .85rem; }

/* project page */
.project-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }

.markdown { background: var(--bg-2); border: 1px solid var(--border); padding: 1rem 1.2rem; border-radius: var(--radius); margin: 1rem 0 1.5rem; }
.markdown :first-child { margin-top: 0; }
.markdown :last-child { margin-bottom: 0; }
.markdown pre, .markdown code { font-family: var(--mono); }
.markdown pre { background: var(--bg-3); padding: .8rem; border-radius: var(--radius); overflow-x: auto; }
.markdown code { background: var(--bg-3); padding: .1rem .35rem; border-radius: 4px; }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: .3rem .6rem; }
.markdown img { max-width: 100%; height: auto; display: block; border-radius: var(--radius); }
.markdown pre { max-width: 100%; }

.cost-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .5rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: .8rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.cost-summary > div { display: flex; flex-direction: column; }
.cost-summary strong { font-size: 1.1rem; }

.item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  margin-bottom: .8rem;
}
.item-header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.kind {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .15rem .45rem;
  border-radius: 999px;
  margin-right: .4rem;
  border: 1px solid var(--border);
}
.kind-printed { color: var(--accent-2); border-color: #1f5a4b; background: #0f2a24; }
.kind-equipment { color: var(--warn); border-color: #5a4318; background: #2a200d; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .6rem 0 0; font-size: .92rem; }
.kv dt { color: var(--fg-dim); }
.kv dd { margin: 0; word-break: break-all; }

.notes { color: var(--fg-dim); font-style: italic; margin: .5rem 0 0; }

.alts { margin-top: .8rem; border-top: 1px solid var(--border); padding-top: .6rem; }
.alts summary { cursor: pointer; color: var(--fg-dim); font-size: .9rem; }
.alts summary:hover { color: var(--fg); }
.alt { padding: .5rem 0; border-bottom: 1px dashed var(--border); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.alt:last-of-type { border-bottom: none; }
.alt-form { margin-top: .8rem; background: var(--bg-3); padding: .8rem; border-radius: var(--radius); }

.add-item { margin-top: 1rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem 1rem; }
.add-item summary { cursor: pointer; padding: .2rem 0; font-weight: 600; }
.add-item form { margin-top: .8rem; }

/* markdown editor with live preview */
.md-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem;
}
@media (max-width: 720px) {
  .md-editor { grid-template-columns: 1fr; }
}
.md-pane { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.md-label { color: var(--fg-dim); font-size: .9rem; }
.md-editor textarea {
  min-height: 22rem;
  resize: vertical;
}
.md-preview {
  margin: 0;
  min-height: 22rem;
  overflow: auto;
}
.md-preview:empty::before {
  content: "Nothing to preview yet.";
  color: var(--fg-dim);
  font-style: italic;
}
.md-preview img { max-width: 100%; height: auto; border-radius: var(--radius); }

.md-toolbar { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.md-upload-btn {
  display: inline-block;
  padding: .3rem .6rem;
  border-radius: var(--radius);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  font-size: .85rem;
}
.md-upload-btn:hover { border-color: var(--accent); }
.md-status { color: var(--fg-dim); font-size: .85rem; }
.md-status-error { color: var(--danger); }
.md-hint { margin: .25rem 0 0; font-size: .8rem; }
#md-input.drag { outline: 2px dashed var(--accent); outline-offset: -2px; }
