:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6a6f76;
  --line: #e1ddd3;
  --accent: #1f4b9c;
  --err: #c62828;
  --warn: #a86b00;
  --ok: #2f8a3f;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; margin: 0; }
.tagline { margin: 0; font-size: 12.5px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, .button, select {
  font: inherit;
  font-size: 13.5px;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid #cfcabf;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  display: inline-block;
}
button:hover, .button:hover, select:hover { border-color: #9d978a; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #173b7c; }
.select { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---- layout ---- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(340px, 38%) 1fr;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .editor { height: 50vh; }
}
section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.pane-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.pane-head h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); }
.hint a { color: var(--accent); }

/* ---- editor ---- */
.editor {
  flex: 1;
  display: flex;
  min-height: 200px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 20px;
  background: #fbfaf7;
}
.gutter {
  margin: 0;
  padding: 10px 8px 10px 10px;
  text-align: right;
  color: #a7a294;
  background: #f3f0e8;
  border-right: 1px solid var(--line);
  overflow: hidden;
  user-select: none;
  min-width: 42px;
  font: inherit;
}
.gutter span { display: inline-block; padding: 0 3px; border-radius: 3px; }
.gutter .err { background: var(--err); color: #fff; }
.gutter .warn { background: #f0c35a; color: #3a2a00; }
textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: transparent;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
}

.messages {
  max-height: 30%;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg {
  text-align: left;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  line-height: 1.35;
}
.msg.ok { color: var(--ok); }
.msg.error { background: #fdecec; border-color: #f2c4c4; color: #7d1717; }
.msg.warning { background: #fff6e0; border-color: #f1dca4; color: #6b4600; }

/* ---- preview ---- */
.preview {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-items: center;
  background:
    radial-gradient(circle at 1px 1px, #e4dfd3 1px, transparent 0) 0 0 / 16px 16px,
    #f8f6f1;
}
.empty { color: var(--muted); margin-top: 40px; text-align: center; }
.empty code { background: #fff; padding: 2px 5px; border-radius: 4px; border: 1px solid var(--line); }
.card { margin: 0; width: 100%; max-width: 900px; }
.card figcaption {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.card-title { font-weight: 600; }
.card-meta { color: var(--muted); flex: 1; }
.card-actions { display: flex; gap: 6px; }
.card-actions button { padding: 4px 9px; font-size: 12px; }
.card-svg svg {
  width: 100%;
  height: auto;
  display: block;
  box-shadow: 0 2px 10px rgba(60, 50, 30, .14);
  border-radius: 3px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #222;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- printing ---- */
.print-area { display: none; }
@page { size: A4; margin: 10mm; }
@media print {
  body { background: #fff; display: block; }
  .topbar, .layout, .toast { display: none !important; }
  .print-area {
    display: flex;
    flex-wrap: wrap;
    gap: 6mm;
    justify-content: center;
    align-content: flex-start;
  }
  .print-card { break-inside: avoid; page-break-inside: avoid; }
  .print-card svg { width: 100%; height: auto; display: block; }
}
