:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --sunk: #ecebe6;
  --text: #1f1f1c;
  --muted: #696862;
  --line: #dddbd3;
  --accent: #2c6b5a;
  --accent-text: #ffffff;
  --accent-soft: #e2efe9;
  --warn: #9a5b12;
  --warn-soft: #fbf0df;
  --bad: #a43b2a;
  --bad-soft: #f8e5e1;
  --viewer-bg: #e9e8e3;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615; --card: #21211f; --sunk: #1b1b1a; --text: #ebeae5; --muted: #a09f98; --line: #383833;
    --accent: #5fae96; --accent-text: #0e1c17; --accent-soft: #1f3530; --warn: #e0a85c; --warn-soft: #362a19;
    --bad: #e3806f; --bad-soft: #3a211c; --viewer-bg: #1d1d1b; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161615; --card: #21211f; --sunk: #1b1b1a; --text: #ebeae5; --muted: #a09f98; --line: #383833;
  --accent: #5fae96; --accent-text: #0e1c17; --accent-soft: #1f3530; --warn: #e0a85c; --warn-soft: #362a19;
  --bad: #e3806f; --bad-soft: #3a211c; --viewer-bg: #1d1d1b; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

header.top {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--card); position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
header.top .brand { font-weight: 650; font-size: 17px; text-decoration: none; color: var(--text); }
header.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
header.top nav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 6px; }
header.top nav a.on { color: var(--text); background: var(--sunk); }
header.top .spacer { flex: 1; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }

button, .button {
  font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.link { border: none; background: none; color: var(--accent); padding: 0; min-height: 0; }
button:disabled { opacity: .55; cursor: default; }

input[type=text], input[type=password], input[type=search], input[type=number], textarea, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--sunk); color: var(--muted); }
.pill.current { background: var(--accent-soft); color: var(--accent); }
.pill.idea { background: var(--warn-soft); color: var(--warn); }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--warn-soft); color: var(--text); border: 1px solid transparent; }
.notice.bad { background: var(--bad-soft); }
.notice.good { background: var(--accent-soft); }
.error { color: var(--bad); }

/* library */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input[type=search] { max-width: 340px; }
.folder { margin-bottom: 28px; }
.folder-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.design-card { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.design-card:hover { border-color: var(--muted); }
.design-card .thumb { aspect-ratio: 4 / 3; background: var(--viewer-bg); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.design-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.design-card .body { padding: 10px 12px; }
.design-card .name { font-weight: 600; }
.empty { padding: 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }

/* design */
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.design-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.viewer-wrap { background: var(--viewer-bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: relative; }
.viewer { width: 100%; aspect-ratio: 4 / 3; display: block; }
.viewer-bar { display: flex; gap: 6px; padding: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); background: var(--card); align-items: center; }
.viewer-bar button { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.viewer-bar button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.viewer-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--muted); }
.dims { margin-left: auto; font-size: 13px; color: var(--muted); }

.print-panel h2 { margin-bottom: 10px; }
.download-main { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 6px; background: var(--accent-soft); margin-bottom: 14px; }
.download-main .button { justify-content: center; }
.settings-text { white-space: pre-wrap; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--sunk); padding: 12px; border-radius: 6px; margin: 0; overflow-x: auto; }
.files { list-style: none; padding: 0; margin: 0; }
.files li { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.files li:first-child { border-top: none; }
.files .fname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.section { margin-top: 18px; }
.section > h2 { margin-bottom: 8px; }
details > summary { cursor: pointer; padding: 6px 0; }
pre.source { white-space: pre; overflow: auto; max-height: 520px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--sunk); padding: 12px; border-radius: 6px; margin: 8px 0 0; }
.versions { list-style: none; padding: 0; margin: 0; }
.versions li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.versions li:first-child { border-top: none; }
.versions li.shown { font-weight: 600; }
.versions .vnum { min-width: 82px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 14px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); color: var(--accent); }

/* lessons */
.lesson { padding: 12px 0; border-top: 1px solid var(--line); }
.lesson:first-child { border-top: none; }
.lesson .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { min-height: 30px; padding: 2px 10px; font-size: 13px; border-radius: 99px; }
.chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* settings form */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }
.part-block { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-top: 10px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 20px; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.login { max-width: 380px; margin: 12vh auto; }
code.copyable { background: var(--sunk); padding: 6px 8px; border-radius: 6px; overflow-wrap: anywhere; display: block; }
table.activity { width: 100%; border-collapse: collapse; font-size: 13px; }
table.activity td { padding: 5px 6px; border-top: 1px solid var(--line); vertical-align: top; }
