:root {
  --navy: #201f55;
  --ink: #1f2454;
  --body: #3e4761;
  --teal-deep: #1f7772;
  --teal: #4bbdb5;
  --teal-mid: #53b1a9;
  --teal-light: #d7f3f0;
  --mint: #ecfaf7;
  --gold: #f3b740;
  --pink: #f082b4;
  --border: #e8e8e1;
  --shadow: 0 14px 28px -20px rgba(9, 49, 74, 0.5);
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--body);
  background: #fff;
  line-height: 1.6;
  font-size: 17px;
}

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(118deg, #1f7772 0%, #2c9b92 34%, #53b1a9 62%, #9fdcd2 100%);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 10px rgba(9, 49, 74, 0.18);
}
.top .brand {
  font-weight: 800;
  font-size: clamp(16px, 4.5vw, 20px);
  letter-spacing: 0.2px;
  margin-right: auto;
  color: #fff;
  text-decoration: none;
}
.top .brand small { display: block; font-weight: 600; font-size: 11px; opacity: 0.85; }
.pill {
  border: none;
  cursor: pointer;
  font-family: var(--font);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.pill.solid { background: var(--teal-deep); border-color: var(--teal-deep); }
.pill.ghost { background: #fff; color: var(--teal-deep); border-color: var(--border); }
.pill:active { transform: translateY(1px); }

.wrap { max-width: 820px; margin: 0 auto; padding: 16px; }

/* Index list */
.lead { color: var(--body); margin: 4px 0 18px; }
.postlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid var(--border);
  border-top: 3px solid var(--teal);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card:hover { background: var(--mint); }
.card .num {
  font-size: 12px;
  font-weight: 800;
  color: var(--teal-deep);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.card h2 { margin: 4px 0 6px; font-size: 18px; color: var(--navy); font-weight: 700; line-height: 1.3; }
.card .meta { font-size: 13px; color: #7a8296; display: flex; gap: 14px; flex-wrap: wrap; }
.card .go { color: var(--teal-deep); font-weight: 700; }

/* Reader */
.doc { font-size: 17px; }
.doc h1 { font-size: clamp(24px, 6vw, 34px); color: var(--navy); font-weight: 800; line-height: 1.2; margin: 0 0 6px; }
.doc h2 { font-size: clamp(20px, 5vw, 26px); color: var(--navy); font-weight: 700; margin: 34px 0 10px; padding-bottom: 6px; border-bottom: 3px solid var(--teal-light); }
.doc h3 { font-size: 19px; color: var(--ink); font-weight: 700; margin: 24px 0 8px; }
.doc h4 { font-size: 16px; color: var(--teal-deep); font-weight: 700; margin: 20px 0 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.doc p { margin: 0 0 14px; }
.doc a { color: var(--teal-deep); }
.doc em { font-style: italic; }
.doc blockquote {
  margin: 18px 0;
  padding: 12px 18px;
  border-left: 4px solid var(--teal);
  background: var(--mint);
  border-radius: 0 10px 10px 0;
  color: var(--ink);
  font-weight: 600;
}
.doc ul, .doc ol { margin: 0 0 14px; padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }
.doc code { background: var(--teal-light); padding: 1px 6px; border-radius: 5px; font-size: 0.9em; }
.tbl-wrap { overflow-x: auto; margin: 0 0 18px; -webkit-overflow-scrolling: touch; }
.doc table { border-collapse: collapse; width: 100%; font-size: 15px; min-width: 460px; }
.doc th { background: var(--navy); color: #fff; text-align: left; padding: 9px 12px; font-weight: 700; }
.doc td { border-bottom: 1px solid var(--border); padding: 9px 12px; vertical-align: top; }
.doc tbody tr:nth-child(even), .doc tbody tr:nth-child(even) { background: #f7fbfa; }

/* Editor */
.edbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: #fbfdfd;
  position: sticky;
  top: 56px;
  z-index: 15;
}
.status { font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c7cdd6; }
.status.saved .dot { background: #35b37e; }
.status.saving .dot { background: var(--gold); animation: pulse 1s infinite; }
.status.dirty .dot { background: var(--gold); }
.status.error .dot { background: #e0555a; }
@keyframes pulse { 50% { opacity: 0.35; } }
.status .txt { color: var(--body); }
.spacer { margin-left: auto; }

.editor-area { display: grid; grid-template-columns: 1fr; }
textarea#raw {
  width: 100%;
  min-height: 62vh;
  border: none;
  outline: none;
  resize: vertical;
  padding: 18px 16px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: #fff;
  -webkit-text-size-adjust: 100%;
}
.previewing textarea#raw { display: none; }
#preview { display: none; }
.previewing #preview { display: block; }

/* Editor app-shell: pin the teal header + toolbar, scroll only the text.
   Scoped to editing so the list and reader still scroll the page normally. */
body.editing { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.editing .top { flex: 0 0 auto; }
body.editing #app { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
body.editing .edbar { position: static; top: auto; flex: 0 0 auto; }
body.editing .editor-area { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
body.editing textarea#raw { flex: 1 1 auto; min-height: 0; height: auto; resize: none; }
body.editing #preview { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

/* History drawer */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(360px, 88vw);
  background: #fff;
  box-shadow: -10px 0 40px -10px rgba(9, 49, 74, 0.4);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer .dhead { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.drawer .dhead b { color: var(--navy); font-size: 16px; margin-right: auto; }
.vlist { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.vitem { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.vitem .when { font-weight: 700; color: var(--ink); font-size: 14px; }
.vitem .sub { font-size: 12px; color: #7a8296; margin: 2px 0 8px; }
.vitem .tag { display: inline-block; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.4px; padding: 2px 7px; border-radius: 999px; background: var(--teal-light); color: var(--teal-deep); }
.vitem .tag.manual { background: #fff0d0; color: #a9781a; }
.vitem .tag.seed { background: #eee; color: #666; }
.vitem .tag.restored { background: #ffe1ec; color: #b03a6b; }
.vitem .row { display: flex; gap: 8px; }
.vbtn { flex: 1; border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 6px; font-size: 12.5px; font-weight: 700; cursor: pointer; font-family: var(--font); color: var(--teal-deep); }
.vbtn:active { transform: translateY(1px); }
.backdrop { position: fixed; inset: 0; background: rgba(20, 30, 45, 0.35); opacity: 0; pointer-events: none; transition: opacity 0.22s; z-index: 35; }
.backdrop.open { opacity: 1; pointer-events: auto; }

.empty { color: #7a8296; text-align: center; padding: 40px 20px; }
.loading { color: #7a8296; text-align: center; padding: 40px; }

@media (min-width: 900px) {
  textarea#raw { min-height: 70vh; }
}
