/* Same look as the other dliu.com apps (video.dliu.com, traffic.dliu.com). */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f6f7f9;
  --panel-2: #ffffff;
  --line: #dfe3e8;
  --text: #1c2024;
  --muted: #646b75;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --danger: #d1242f;
  --ok: #1a7f37;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
img, video { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

header.top {
  display: flex; align-items: center; gap: 12px; padding: 12px max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.92);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); display: flex; align-items: center; gap: 8px; flex: none; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 26px; height: 26px; flex: none; }
header.top nav { margin-left: auto; display: flex; gap: 8px; align-items: center; }
header.top nav .button { white-space: nowrap; }

main {
  width: 100%; max-width: 760px; margin: 0 auto; flex: 1;
  padding: 24px max(24px, env(safe-area-inset-right)) 24px max(24px, env(safe-area-inset-left));
}
main.wide { max-width: 1180px; }
footer.bottom { color: var(--muted); font-size: 13px; text-align: center; padding: 24px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
footer.bottom a { color: var(--muted); }

h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 24px 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }
.row h1 { margin: 0; }
.head { margin-bottom: 16px; }

button, .button {
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover, .button:hover { border-color: #b8c0ca; background: var(--panel); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.button.docs-link { display: inline-flex; align-items: center; gap: 6px; }
.button.docs-link .icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button.docs-link[aria-current="page"] { border-color: var(--accent); color: var(--accent); }
.button.sign-in { padding: 9px 18px; font-weight: 600; box-shadow: 0 1px 3px rgba(37, 99, 235, 0.35); }
button.danger, .button.danger { color: var(--danger); }
button.small, .button.small { font-size: 13px; padding: 5px 10px; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.link:hover { background: none; text-decoration: underline; }
button.link.danger { color: var(--danger); }
button:disabled { opacity: 0.55; cursor: default; }

input[type=text], input[type=search], textarea, select {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(37, 99, 235, 0.35); border-color: var(--accent); }
textarea { resize: vertical; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel + .panel { margin-top: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.empty { text-align: center; padding: 80px 20px; color: var(--muted); }
.notice { margin: 0 0 16px; padding: 10px 14px; border-radius: 8px; border: 1px solid #b7e1c1; background: #eef9f1; }
.notice.error { border-color: #f1b8bc; background: #fdf0f1; color: var(--danger); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.pill.published { background: #eef9f1; border-color: #b7e1c1; color: var(--ok); }

/* ---------- Post list (home and admin) ---------- */
.posts { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.posts li { display: flex; align-items: baseline; gap: 16px; padding: 14px 2px; border-bottom: 1px solid var(--line); }
.posts .title { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.posts .title:hover { color: var(--accent); text-decoration: none; }
.posts time, .posts .when { flex: none; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.posts.admin li { align-items: center; flex-wrap: wrap; }
.posts.admin .info { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 4px; }
.posts.admin .meta { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.posts.admin .actions { display: flex; gap: 6px; }

/* ---------- API tokens ---------- */
.lead { margin: 4px 0 18px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important; font-size: 13px !important; }
.token-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.token-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.token-form label:first-child { flex: 1; min-width: 200px; }
.token-form select { width: auto; }
.new-token { border-color: var(--accent); margin-bottom: 16px; }
.new-token h2 + .warn, .new-token .muted { margin-top: 0; }
.new-token .warn { color: var(--danger); font-weight: 600; }
.new-token textarea { margin-bottom: 8px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.copy-row input { flex: 1; min-width: 0; }
h2.section { font-size: 15px; margin: 24px 0 8px; }

/* ---------- Post page ---------- */
.back { display: inline-block; margin-bottom: 12px; font-size: 14px; }
.article h1 { font-size: 30px; line-height: 1.25; margin: 0 0 6px; overflow-wrap: anywhere; }
.article .meta { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.prose { font-size: 17px; line-height: 1.7; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose figure { margin: 0 0 1.1em; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.3; margin: 1.6em 0 .6em; }
.prose h1 { font-size: 1.6em; } .prose h2 { font-size: 1.35em; } .prose h3 { font-size: 1.15em; }
.prose img { display: block; height: auto; margin: 1.2em auto; border-radius: 8px; }
.prose blockquote { padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.prose code { font: .88em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel); padding: .1em .35em; border-radius: 4px; }
.prose pre { overflow: auto; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; line-height: 1.5; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose table { border-collapse: collapse; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 24px 0; }
.gallery img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.attachments { margin-top: 24px; }
.attachments ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.attachments a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
.attachments a:hover { border-color: var(--accent); text-decoration: none; }
.attachments .ext { flex: none; font-size: 11px; font-weight: 700; color: var(--accent); background: #eef3fe; border-radius: 4px; padding: 3px 6px; }
.attachments .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.attachments .size { flex: none; color: var(--muted); font-size: 13px; }

/* ---------- Editor ---------- */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.title-input { font-size: 22px !important; font-weight: 600; padding: 10px 12px !important; }
.permalink { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0 14px; color: var(--muted); font-size: 13px; min-height: 28px; overflow-wrap: anywhere; }
.permalink input { width: 14rem; padding: 4px 8px; font-size: 13px; }
.editor { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel-2); }
.editor-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--line); }
.tabs button { border: 0; padding: 4px 12px; font-size: 13px; border-radius: 6px; background: none; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--text); font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; }
.toolbar button { min-width: 30px; height: 30px; padding: 0 7px; border-color: transparent; background: none; font-size: 13px; }
.toolbar button:hover { border-color: var(--line); background: var(--panel-2); }
.toolbar .b { font-weight: 700; }
.toolbar .i { font-style: italic; }
#body { display: block; min-height: 460px; border: 0; border-radius: 0; padding: 14px; font: 15px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
#body:focus { outline: none; }
#body.over { outline: 2px dashed var(--accent); outline-offset: -6px; }
.editor .preview { min-height: 460px; padding: 14px 18px; }
.editor-status { display: flex; justify-content: space-between; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 12px; }
.facts { margin: 0 0 14px; font-size: 13px; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.publish-actions { display: grid; gap: 8px; }
.publish-actions .button, .publish-actions button { width: 100%; }
.publish-actions .delete { justify-self: start; width: auto; margin-top: 4px; font-size: 13px; }
.drop {
  display: block; border: 2px dashed var(--line); border-radius: 10px; padding: 18px 10px; text-align: center; cursor: pointer;
  background: var(--panel-2); color: var(--muted); font-size: 13px; margin: 0;
}
.drop.over { border-color: var(--accent); color: var(--accent); }
.files { list-style: none; margin: 10px 0 0; padding: 0; }
.files li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.files .thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--line); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; overflow: hidden; }
.files .name { overflow-wrap: anywhere; color: var(--text); }
.files .file-actions { display: flex; gap: 10px; margin-top: 2px; color: var(--muted); font-size: 12px; }
.files .file-actions button { font-size: 12px; }
.files progress { width: 100%; }
.files .failed { color: var(--danger); }

/* Phones and small tablets */
@media (max-width: 860px) {
  .editor-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  header.top { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  main { padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); }
  h1 { font-size: 21px; }
  .article h1 { font-size: 25px; }
  .prose { font-size: 16px; }
  .posts li { flex-direction: column; gap: 2px; }
  .posts.admin li { flex-direction: row; }
  #body, .editor .preview { min-height: 320px; }
  header.top nav { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  header.top nav .button { padding: 8px 10px; }
  header.top nav .hide-narrow { display: none; }
}
@media (max-width: 480px) {
  .brand .name { display: none; }
}
@media (max-width: 400px) {
  header.top nav .button { padding: 8px 9px; }
}
/* Touch screens: bigger targets, and 16px text so iOS doesn't zoom into fields */
@media (pointer: coarse) {
  button, .button { min-height: 44px; }
  .toolbar button, .tabs button, button.link { min-height: 36px; }
  input[type=text], input[type=search], textarea, select { font-size: 16px; }
}
.small { font-size: 13px; }
