:root {
  color-scheme: light dark;
  --bg: #faf9f5;
  --panel: #ffffff;
  --fg: #17150f;
  --muted: #74705f;
  --line: #e6e3d8;
  --accent: #7a5c2e;
  --accent-fg: #fffdf7;
  --warn: #9a6408;
  --warn-bg: #fdf3e0;
  --err: #a3341f;
  --err-bg: #fbeeea;
  --ok: #3f6b46;
  --ok-bg: #e8f1ea;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131209;
    --panel: #1c1b14;
    --fg: #f3f1e6;
    --muted: #97927e;
    --line: #2e2c22;
    --accent: #cfa964;
    --accent-fg: #201a0c;
    --warn: #e0b45c;
    --warn-bg: #2a2314;
    --err: #e9917c;
    --err-bg: #2d1a15;
    --ok: #8fc09a;
    --ok-bg: #1b2a1e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
h3 { margin: 18px 0 6px; font-size: 14px; font-weight: 600; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.hint code, .plain code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 11.5px; }
ul.plain { padding-left: 18px; margin: 4px 0; }
ul.plain li { margin: 3px 0; }

.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 22px 28px 10px; flex-wrap: wrap; }
.project-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.project-bar select { min-width: 220px; }

.steps { display: flex; gap: 4px; padding: 6px 28px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.steps button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted);
  padding: 8px 12px 10px; font-weight: 600; display: flex; gap: 8px; align-items: center; cursor: pointer;
}
.steps button .n { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line); font-size: 11px; }
.steps button.active { color: var(--fg); border-bottom-color: var(--accent); }
.steps button.done .n { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.steps button.active .n { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.steps button.tool { margin-left: auto; }
.steps button:disabled { opacity: 0.45; cursor: not-allowed; }

main { padding: 16px 28px 48px; }
.cols { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .cols { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel.narrow { position: sticky; top: 14px; max-height: calc(100vh - 40px); overflow-y: auto; }
@media (max-width: 980px) { .panel.narrow { position: static; max-height: none; } }

.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
label { display: block; font-size: 12px; font-weight: 600; margin: 10px 0 5px; }
.field > label:first-child { margin-top: 0; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 13px; margin: 6px 0; }
label.check input { margin-top: 3px; }
.count { float: right; font-weight: 400; color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; line-height: 1.5; }
#iconList, #previewList, #toolNames { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 12.5px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=file] { font-size: 12px; color: var(--muted); }
details > summary { cursor: pointer; font-size: 12px; font-weight: 600; padding: 6px 0; color: var(--muted); }
details[open] > summary { color: var(--fg); }

button, .button {
  font: inherit; border-radius: 8px; border: 1px solid var(--line); padding: 8px 14px; cursor: pointer;
  background: var(--panel); color: var(--fg); text-decoration: none; display: inline-block; line-height: 1.3;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
button:disabled { opacity: 0.55; cursor: progress; }
button.ghost, .button.ghost { background: transparent; }
button.danger { color: var(--err); }
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button.linkish { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: 12px; }
.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.actions select { width: auto; }

.error { color: var(--err); background: var(--err-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 0 0 14px; }
.warn { color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.ok { color: var(--ok); background: var(--ok-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

.upload-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.upload-row select { width: auto; }
.assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 12px; }
.asset { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: start; }
.asset img { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--line); }
.asset .name { font-size: 11px; word-break: break-all; color: var(--muted); }
.asset select { font-size: 12px; padding: 3px 6px; margin-bottom: 4px; }
.asset input { font-size: 12px; padding: 3px 6px; }
.asset .rm { grid-column: 1 / -1; justify-self: end; }
.asset.logo { border-color: var(--accent); }

.results-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.results-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.results-tools input, .results-tools select { width: auto; }

.progress { margin: 14px 0 4px; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

.sheets { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.sheets img { width: 220px; height: 220px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 12px; margin-top: 14px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px 10px; text-align: center;
  background: var(--panel); cursor: pointer; position: relative; transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card .art { height: 66px; display: grid; place-items: center; }
.card .art svg, .card .art img { width: 58px; height: 58px; color: var(--fg); object-fit: contain; }
.card .name { font-size: 12px; margin-top: 8px; line-height: 1.3; }
.card .slug { font-size: 10px; color: var(--muted); font-family: ui-monospace, monospace; word-break: break-all; }
.card .flag { position: absolute; top: 6px; right: 7px; font-size: 9px; letter-spacing: 0.04em; text-transform: uppercase; padding: 1px 5px; border-radius: 99px; font-weight: 700; }
.card.is-warned .flag { background: var(--warn-bg); color: var(--warn); }
.card.is-failed { border-color: var(--err); }
.card.is-failed .flag { background: var(--err-bg); color: var(--err); }
.card.is-selected, .card.is-anchor { box-shadow: inset 0 0 0 2px var(--accent); }
.card.is-selected .flag, .card.is-anchor .flag { background: var(--accent); color: var(--accent-fg); }
.card.is-pending, .card.is-running { opacity: 0.65; }
.card .spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.card .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.logbox { margin-top: 20px; }
.logbox pre, .context {
  max-height: 260px; overflow: auto; font-size: 11.5px; line-height: 1.5; font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 6px 0 0; white-space: pre-wrap;
}
.approval { margin-top: 12px; }

.spec-editor { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px 18px; margin-top: 10px; }
.spec-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.spec-group h3 { margin: 0 0 4px; }
.spec-group .field { margin-bottom: 8px; }
.spec-group textarea { font-size: 12.5px; padding: 6px 8px; min-height: 34px; }
.spec-group input[type=text], .spec-group select { font-size: 12.5px; padding: 5px 8px; }
.spec-group label { margin: 6px 0 3px; }
.spec-group label small { font-weight: 400; color: var(--muted); display: block; font-size: 11px; line-height: 1.35; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 6px; }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--fg); padding: 0; width: min(760px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.detail-inner { display: grid; grid-template-columns: 220px 1fr; gap: 18px; padding: 20px; }
@media (max-width: 620px) { .detail-inner { grid-template-columns: 1fr; } }
.detail-preview { display: grid; place-items: center; align-content: start; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.detail-preview svg, .detail-preview img { width: 160px; height: 160px; color: var(--fg); object-fit: contain; }
.detail-preview img { background: #fff; border-radius: 8px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* accounts & admin */
.by { white-space: nowrap; }
.by a, .auth-card a { color: var(--accent); }
.account { display: flex; gap: 10px; align-items: center; font-size: 12.5px; color: var(--muted); margin-left: auto; flex-wrap: wrap; }
.account .usage { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; }
.account .usage.low { color: var(--warn); border-color: var(--warn); }
.auth-gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 20px; z-index: 20; overflow-y: auto; }
.auth-card { width: min(420px, 100%); }
.auth-card h1 { margin-bottom: 4px; }
.auth-card form { margin-top: 14px; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 8px; }
table.users th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 8px; white-space: nowrap; }
table.users td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: middle; }
table.users input[type=number] { width: 90px; padding: 3px 6px; }
table.users select { width: auto; padding: 3px 6px; }
table.users .who small { display: block; color: var(--muted); }
#inviteOut { word-break: break-all; }

/* ---- Standard / Pro views ------------------------------------------------ */
.view-standard .pro-only, .view-pro .std-only { display: none !important; }

.view-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; padding: 3px; background: var(--panel); }
.view-switch button { border: 0; border-radius: 99px; padding: 5px 14px; font-size: 12.5px; font-weight: 600; background: transparent; color: var(--muted); }
.view-switch button.active { background: var(--accent); color: var(--accent-fg); }
.view-switch button:hover:not(.active) { color: var(--fg); }

.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 12px 0 4px; }
.slot-card {
  display: grid; justify-items: center; gap: 4px; text-align: center; margin: 0; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 16px 10px; font-weight: 400;
  transition: border-color 0.15s, background 0.15s;
}
.slot-card:hover, .slot-card:focus-within { border-color: var(--accent); background: var(--bg); }
.slot-card strong { font-size: 13.5px; }
.slot-card .hint { margin: 0; }
.slot-card input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.slot-icon { font-size: 22px; color: var(--accent); line-height: 1; }
.slot-card.filled { border-style: solid; border-color: var(--ok); }

.asset .doc-tile { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: 0.04em; }
.asset.guide { border-color: var(--ok); }
.asset .kind-label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 2px; }

.spec-summary { display: grid; gap: 14px; margin: 14px 0 18px; }
.spec-summary .idea { font-size: 15px; line-height: 1.5; margin: 0; }
.spec-summary .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.spec-summary .chip { border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: 12.5px; background: var(--bg); }
.spec-summary .chip b { font-weight: 600; color: var(--muted); margin-right: 4px; }
.spec-summary .two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .spec-summary .two { grid-template-columns: 1fr; } }
.spec-summary h3 { margin: 0 0 4px; }
.spec-summary ul { margin: 0; padding-left: 18px; }
.spec-summary li { margin: 3px 0; font-size: 13.5px; }
.spec-summary .from-guide { border-left: 3px solid var(--ok); padding: 6px 12px; background: var(--ok-bg); border-radius: 0 8px 8px 0; font-size: 13.5px; white-space: pre-line; }
.spec-summary .swatch { width: 28px; height: 28px; }
