/* Chengshuo content editor. Deliberately plain: the site is the design, this
   is a tool. Colours are borrowed from DESIGN.md so it does not feel foreign. */
:root {
  --ink: #16221c; --ink-soft: #4a5a52; --line: #d9e0dc;
  --bg: #f6f7f6; --panel: #ffffff; --accent: #1f5c3d; --accent-soft: #e8f0eb;
  --warn: #8a3324; --warn-soft: #fbeceb; --warn-line: #e6bdb6;
  --bg-blur: rgba(246,247,246,.94); --shadow: rgba(0,0,0,.05);
  --backdrop: rgba(20,28,24,.4);
  --radius: 6px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light dark;
}

/* Follows the OS. The accent stays the site's green but lifted, because
   1f5c3d on a dark ground fails contrast. Icons already paint with --ink so
   they invert for free; photo thumbnails are left alone. */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6ece8; --ink-soft: #9aa8a1; --line: #2c3733;
    --bg: #121815; --panel: #1a221f; --accent: #6dbb8f; --accent-soft: #23342b;
    --warn: #f0a094; --warn-soft: #34211e; --warn-line: #5c3a34;
    --bg-blur: rgba(18,24,21,.94); --shadow: rgba(0,0,0,.4);
    --backdrop: rgba(0,0,0,.6);
  }
  /* These labels sit on --accent, which is light in dark mode. */
  .btn.primary, #login button { color: #10201a; }
  /* Photos need separation from a dark ground. */
  .grid img, .imgfield img { border: 1px solid var(--line); }
}
* { box-sizing: border-box; }
/* Setting `display` on an element defeats the UA's [hidden] rule. #app is a
   grid, so while hidden it still occupied a full viewport and pushed the
   login form below the fold. */
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

/* --- login ------------------------------------------------------------- */
#login {
  max-width: 320px; margin: 15vh auto; background: var(--panel);
  padding: 32px; border: 1px solid var(--line); border-radius: var(--radius);
}
#login h1 { margin: 0; font-size: 20px; letter-spacing: .02em; }
#login .sub { margin: 4px 0 24px; color: var(--ink-soft); }
#login label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--ink-soft); }
#login input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
#login button {
  width: 100%; padding: 10px; margin-top: 8px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--panel); font-weight: 600;
}
.err { color: var(--warn); font-size: 13px; }

/* --- shell ------------------------------------------------------------- */
#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
aside {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
aside header { border-bottom: 1px solid var(--line); }
.brand {
  display: block; padding: 16px; text-decoration: none; color: var(--ink);
  border-left: 3px solid transparent;
}
.brand:hover { background: var(--bg); }
.brand.on { background: var(--accent-soft); border-left-color: var(--accent); }
.brand b { display: block; font-size: 14px; }
.brand span { color: var(--ink-soft); font-size: 12px; }
nav { overflow-y: auto; flex: 1; padding: 8px 0; }
nav .group { padding: 12px 16px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-soft); }
nav a {
  display: block; padding: 6px 16px; color: var(--ink); text-decoration: none;
  border-left: 3px solid transparent; cursor: pointer;
}
nav a:hover { background: var(--bg); }
nav a.on { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
/* Children of a menu item, drawn with a stem so the nesting is visible
   rather than implied by indentation alone. */
nav a.child { padding-left: 34px; position: relative; }
nav a.child::before {
  content: ''; position: absolute; left: 21px; top: 0; bottom: 0;
  border-left: 1px solid var(--line);
}
nav a.child::after {
  content: ''; position: absolute; left: 21px; top: 50%; width: 7px;
  border-top: 1px solid var(--line);
}
nav a.child.last-child::before { bottom: 50%; }
nav .rule { height: 1px; background: var(--line); margin: 8px 16px; }
aside footer { border-top: 1px solid var(--line); padding: 10px 16px; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; color: var(--ink-soft); }
aside footer button { background: none; border: 0; color: var(--ink-soft); text-decoration: underline; padding: 0; }

main { padding: 0 0 96px; min-width: 0; }
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--bg-blur);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
  padding: 12px 24px; display: flex; gap: 8px; align-items: center;
}
.bar h1 { font-size: 16px; margin: 0; flex: 1; }
.bar .dirty { color: var(--warn); font-size: 12px; }
.buildstate { font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.buildstate.muted { color: var(--ink-soft); }
.buildstate.bad { color: var(--warn); }
.buildstate a { color: var(--accent); font-weight: 600; }
.btn {
  padding: 7px 13px; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius); color: var(--ink);
}
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }
.btn.primary:disabled { opacity: .45; cursor: default; }
.wrap { padding: 24px; max-width: 940px; }

/* --- fields ------------------------------------------------------------ */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.field input[type=text], .field textarea, .field select, .field input[type=number] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel);
}
.field textarea { resize: vertical; min-height: 62px; }
.field.inline { display: flex; align-items: center; gap: 8px; }
.field.inline > label { margin: 0; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin: 0 0 14px; background: var(--panel); }
fieldset > legend { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-soft); padding: 0 6px; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.row > summary { padding: 7px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.row > summary::-webkit-details-marker { display: none; }
.row > summary::before {
  content: ''; flex: none; width: 6px; height: 6px; margin-right: 2px;
  border-right: 1.5px solid var(--ink-soft); border-bottom: 1.5px solid var(--ink-soft);
  transform: rotate(-45deg); transition: transform .15s;
}
.row[open] > summary::before { transform: rotate(45deg); }
.row > summary .grip, .sec > summary .grip {
  color: var(--line); cursor: grab; flex: none; line-height: 1;
}
.row > summary:hover .grip, .sec > summary:hover .grip { color: var(--ink-soft); }
.grip:active { cursor: grabbing; }
.row > summary .n { flex: 1; }
.row > .body { padding: 10px; border-top: 1px solid var(--line); background: var(--panel); }
.mini { border: 0; background: none; color: var(--ink-soft); padding: 2px 5px; }
.mini:hover { color: var(--warn); }

details.adv { margin-top: 6px; }
details.adv > summary {
  font-size: 12px; color: var(--ink-soft); cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before {
  content: ''; flex: none; width: 5px; height: 5px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
details.adv[open] > summary::before { transform: rotate(45deg); }
details.adv > div { padding: 10px; margin-top: 6px; border: 1px dashed var(--line);
  border-radius: var(--radius); background: var(--bg); }

/* --- sections ---------------------------------------------------------- */
.sec { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 8px; }
.sec[open] { box-shadow: 0 1px 3px var(--shadow); }
.sec > summary { padding: 11px 12px; display: flex; gap: 10px; align-items: center; cursor: pointer; }
.sec > summary::-webkit-details-marker { display: none; }
/* The grip is a drag target, not a disclosure cue. Without a caret nothing
   said these rows open at all. */
.sec > summary::before {
  content: ''; flex: none; width: 7px; height: 7px; margin-right: 2px;
  border-right: 1.5px solid var(--ink-soft); border-bottom: 1.5px solid var(--ink-soft);
  transform: rotate(-45deg); transition: transform .15s;
}
.sec[open] > summary::before { transform: rotate(45deg); }
.sec > summary:hover { background: var(--accent-soft); }
.sec > summary:hover::before { border-color: var(--accent); }
.row > summary:hover { background: var(--accent-soft); }
.sec .type { font-size: 11px; color: var(--ink-soft); background: var(--bg);
  border: 1px solid var(--line); border-radius: 3px; padding: 1px 6px; }
.sec .head { flex: 1; font-weight: 600; }
.sec .head.empty { font-weight: 400; color: var(--ink-soft); font-style: italic; }
.sec .held { color: var(--warn); font-size: 11px; background: var(--warn-soft);
  border-radius: 3px; padding: 1px 6px; }
.sec > .body { padding: 14px; border-top: 1px solid var(--line); }
.dragging { opacity: .4; }
.drop-before { border-top: 2px solid var(--accent); }

/* --- pickers ----------------------------------------------------------- */
.imgfield { display: flex; gap: 10px; align-items: center; }
.imgfield img { width: 76px; height: 52px; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--line); background: var(--bg); }
.imgfield .path { flex: 1; font-family: var(--mono); font-size: 11px; color: var(--ink-soft);
  overflow-wrap: anywhere; }

.iconfield { display: flex; gap: 8px; align-items: center; }
.iconfield .sw { width: 34px; height: 34px; border: 1px solid var(--line);
  border-radius: 4px; display: grid; place-items: center; background: var(--panel); }
.iconfield .sw svg { width: 22px; height: 22px; }
.iconfield .sw svg.traced, .grid svg.traced { fill: var(--ink); }
.iconfield .sw svg.stroked, .grid svg.stroked { stroke: var(--ink); }
.iconfield .nm { flex: 1; font-family: var(--mono); font-size: 12px; }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0;
  width: min(860px, 92vw); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: var(--backdrop); }
dialog header { padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center; }
dialog header h2 { margin: 0; font-size: 15px; flex: 1; }
dialog .body { padding: 16px 18px; max-height: 64vh; overflow-y: auto; }
dialog input[type=search] { padding: 7px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); width: 220px;
  background: var(--panel); color: var(--ink); }

.grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.grid button { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: 8px 4px; display: grid; gap: 5px; justify-items: center; }
.grid button:hover { border-color: var(--accent); background: var(--accent-soft); }
.grid button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.grid svg { width: 26px; height: 26px; }
.grid img { width: 100%; aspect-ratio: 3/2; object-fit: cover; border-radius: 3px; }
.grid .cap { font-size: 10px; color: var(--ink-soft); overflow-wrap: anywhere; line-height: 1.25; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--accent-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 12px; }
.chip button { border: 0; background: none; color: var(--ink-soft); padding: 0 2px; }

/* --- misc -------------------------------------------------------------- */
.problems { background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--warn);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; }
.problems ul { margin: 6px 0 0; padding-left: 18px; }
.problems li { font-family: var(--mono); font-size: 12px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--panel);
  padding: 10px 15px; border-radius: var(--radius); z-index: 60; font-size: 13px; }
.toast.bad { background: var(--warn); }
.muted { color: var(--ink-soft); }
.blurb { margin: 0 0 20px; padding: 11px 14px; background: var(--accent-soft);
  border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--ink); max-width: 62ch; }
.hist { font-size: 12px; }
.hist div { padding: 5px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.hist code { font-family: var(--mono); color: var(--ink-soft); }
.hist .s { flex: 1; }
