:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --ink: #141414;
  --ink-2: #4a4740;
  --ink-3: #8a857a;
  --line: #d9d3c5;
  --line-2: #ebe6da;
  --accent: #141414;
  --accent-ink: #fffdf8;
  --good: #2f6b3a;
  --warn: #9a5b00;
  --bad: #a3261b;
  --bezel: #262624;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 8px 24px -12px rgba(0, 0, 0, 0.18);
  --radius: 14px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151513;
    --card: #1e1d1a;
    --ink: #f1ede4;
    --ink-2: #c4beb1;
    --ink-3: #8a857a;
    --line: #34322d;
    --line-2: #29271f;
    --accent: #f1ede4;
    --accent-ink: #151513;
    --good: #7fc48a;
    --warn: #e0a64a;
    --bad: #ef7b6f;
    --bezel: #0b0b0a;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 30px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151513;
  --card: #1e1d1a;
  --ink: #f1ede4;
  --ink-2: #c4beb1;
  --ink-3: #8a857a;
  --line: #34322d;
  --line-2: #29271f;
  --accent: #f1ede4;
  --accent-ink: #151513;
  --good: #7fc48a;
  --warn: #e0a64a;
  --bad: #ef7b6f;
  --bezel: #0b0b0a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.01em; margin: 0; line-height: 1.1; }
h1 { font-size: 34px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
.kicker { font: 500 11px/1.4 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
code, .code { font-family: var(--mono); font-size: 12.5px; background: var(--line-2); padding: 1px 6px; border-radius: 5px; word-break: break-all; }
pre.code { display: block; padding: 12px 14px; white-space: pre-wrap; margin: 8px 0 0; line-height: 1.55; position: relative; }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; }
.brand b { font: 900 22px/1 var(--serif); letter-spacing: -0.02em; }
.brand span { font: 500 11px var(--mono); color: var(--ink-3); letter-spacing: 0.1em; }
nav.tabs { display: flex; gap: 4px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; }
nav.tabs a {
  text-decoration: none; padding: 7px 12px; border-radius: 999px; color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
nav.tabs a:hover { background: var(--line-2); color: var(--ink); }
nav.tabs a.on { background: var(--ink); color: var(--paper); }
.top .spacer { flex: 1; }
main { max-width: 1240px; margin: 0 auto; padding: 28px 28px 80px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.pagehead p { margin: 6px 0 0; max-width: 640px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pad { padding: 20px; }
.grid { display: grid; gap: 18px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { opacity: 0.9; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
label.field { display: flex; flex-direction: column; gap: 6px; }
label.field > span { font-weight: 600; font-size: 13px; }
label.field small { color: var(--ink-3); font-size: 12px; line-height: 1.4; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], select, textarea {
  width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 10%, transparent); }
textarea { min-height: 90px; resize: vertical; }
textarea.code-input { font-family: var(--mono); font-size: 12.5px; min-height: 260px; line-height: 1.5; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 500; }
.switch input { display: none; }
.switch i { width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.15s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { transform: translateX(16px); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--paper); }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* ---------- e-ink previews ---------- */
.device {
  background: var(--bezel); border-radius: 22px; padding: 16px 16px 30px; box-shadow: var(--shadow);
  display: inline-flex; position: relative;
}
.device::after { content: ""; position: absolute; bottom: 11px; left: 50%; width: 34px; height: 5px; border-radius: 3px; background: #3c3b37; transform: translateX(-50%); }
.device.land { padding: 16px 30px 16px 16px; }
.device.land::after { left: auto; right: 11px; bottom: 50%; width: 5px; height: 34px; transform: translateY(50%); }
.eink { display: block; background: #fff; image-rendering: pixelated; border-radius: 2px; }
.eink.loading { opacity: 0.55; transition: opacity 0.2s; }
.thumb { aspect-ratio: 528 / 792; width: 100%; background: #fff; border-radius: 8px; border: 1px solid var(--line); overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; }
.thumb.land { aspect-ratio: 792 / 528; }
.thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }
.thumb .badge { position: absolute; top: 8px; left: 8px; }

/* ---------- slots ---------- */
.slots { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.slot { display: flex; flex-direction: column; }
.slot header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; gap: 8px; }
.slot header h3 { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.slot header h3 em { font: 500 11px var(--mono); font-style: normal; color: var(--ink-3); letter-spacing: 0.08em; }
.slot .body { padding: 0 16px; }
.slot .chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 0; }
.slot footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px 14px; margin-top: auto; }
.slot footer { flex-wrap: wrap; row-gap: 10px; }
.slot footer .status { white-space: nowrap; }
.slot footer .row { margin-left: auto; }
.slot footer select { max-width: 150px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--line-2); font-size: 13px; font-weight: 500; }
.chip.cur { background: var(--ink); color: var(--paper); }
.chip button { border: 0; background: transparent; cursor: pointer; padding: 0 4px; color: inherit; opacity: 0.6; font-size: 15px; line-height: 1; }
.chip button:hover { opacity: 1; }
.badge { display: inline-flex; align-items: center; gap: 5px; font: 500 10.5px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; padding: 5px 7px; border-radius: 6px; background: var(--ink); color: var(--paper); }
.badge.soft { background: var(--line-2); color: var(--ink-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); display: inline-block; flex: none; }
.dot.good { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent); }
.dot.warn { background: var(--warn); }
.status { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }

.banner { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius); background: var(--ink); color: var(--paper); margin-bottom: 20px; flex-wrap: wrap; }
.banner .btn { background: transparent; color: var(--paper); border-color: color-mix(in srgb, var(--paper) 35%, transparent); }

/* ---------- screens ---------- */
.screens { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.screen-card { cursor: pointer; padding: 12px; display: flex; flex-direction: column; gap: 10px; text-decoration: none; transition: transform 0.12s, box-shadow 0.12s; }
.screen-card:hover { transform: translateY(-2px); }
.screen-card .meta { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.screen-card b { font-weight: 600; line-height: 1.25; }
.gallery { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tpl { text-align: left; padding: 16px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); background: var(--card); border-radius: 12px; transition: border-color 0.12s, transform 0.12s; }
.tpl:hover { border-color: var(--ink-2); transform: translateY(-1px); }
.tpl .ic { font-size: 24px; line-height: 1; width: 34px; height: 34px; display: grid; place-items: center; background: var(--line-2); border-radius: 9px; flex: none; }
.tpl b { display: block; font-weight: 600; }
.tpl small { color: var(--ink-2); font-size: 12.5px; line-height: 1.4; display: block; margin-top: 2px; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 28px; align-items: start; }
.editor .side { position: sticky; top: 86px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.editor .eink { width: 340px; height: auto; }
.editor .land .eink { width: 480px; }
.fields { display: grid; gap: 16px; }
.imgfield { display: flex; gap: 12px; align-items: center; }
.imgfield .pv { width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper) center/cover no-repeat; flex: none; }

.section { margin-top: 34px; }
.section > h2 { margin-bottom: 12px; }
.cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.steps { counter-reset: step; display: grid; gap: 14px; }
.step { display: grid; grid-template-columns: 36px 1fr; gap: 14px; align-items: start; }
.step::before { counter-increment: step; content: counter(step); width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font: 800 15px var(--serif); }
.urlrow { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.urlrow:last-child { border-bottom: 0; }
.copy { cursor: pointer; }

/* ---------- modal + toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 10, 8, 0.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; }
.modal { width: min(920px, 100%); padding: 24px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; z-index: 60; font-weight: 500; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 30px; }
.saved { font: 500 11px var(--mono); color: var(--ink-3); letter-spacing: 0.08em; text-transform: uppercase; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

@media (max-width: 880px) {
  .editor { grid-template-columns: 1fr; }
  .editor .side { position: static; order: -1; }
  .editor .eink { width: min(300px, 70vw); }
  .editor .land .eink { width: min(420px, 82vw); }
}
@media (max-width: 640px) {
  .top { padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  nav.tabs { order: 3; width: 100%; margin-left: 0; }
  nav.tabs a { padding: 6px 10px; }
  main { padding: 20px 16px 60px; }
  h1 { font-size: 28px; }
  .urlrow { grid-template-columns: 1fr auto; }
  .urlrow > :first-child { grid-column: 1 / -1; }
}
