:root {
  --ink: #18212b;
  --muted: #687482;
  --line: #dfe5ea;
  --paper: #fff;
  --wash: #f5f7f8;
  --accent: #315cce;
  --accent2: #e9efff;
}

* { box-sizing: border-box; }
body { min-height: 100vh; margin: 0; display: flex; flex-direction: column; background: var(--wash); color: var(--ink); font: 16px/1.6 system-ui, -apple-system, Segoe UI, sans-serif; }
header, main, footer { max-width: 1120px; margin: auto; }
body > main { flex: 1; width: 100%; }
header { height: 0; padding: 0; }
main { padding: 32px 24px 80px; }
a { color: var(--accent); text-decoration: none; }
button, .button { display: inline-block; border: 0; border-radius: 8px; padding: 11px 17px; background: var(--accent); color: #fff; font: inherit; cursor: pointer; }
.button.secondary { margin: 0; background: var(--accent2); color: var(--accent); }
input, select, textarea { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; }
h1 { font-size: 2.6rem; line-height: 1.15; }
h2 { margin-top: 36px; }
.eyebrow { color: var(--accent); font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.lead, .meta, .muted { color: var(--muted); }
.card, .post-card, .form-box, .editor, .revision, .row, .empty { padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.row { display: flex; justify-content: space-between; gap: 20px; margin: 10px 0; }
.row span { display: block; color: var(--muted); }
.danger-button { padding: 9px 12px; border: 1px solid #f0bcbc; border-radius: 8px; background: #fff0f0; color: #a82828; font: inherit; cursor: pointer; }
.sort { display: flex; gap: 18px; margin: 20px 0; }
.notice { margin-bottom: 18px; padding: 13px 16px; border-radius: 8px; background: var(--accent2); }
.notice.error { background: #ffe9e9; color: #8d2525; }
.back { display: inline-block; margin-bottom: 18px; }

/* Site header and footer */
.top-strip { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 58px; padding: 10px max(24px, calc((100% - 1120px) / 2)); background: #111827; color: #fff; }
.top-brand { color: #fff; font-size: 1.15rem; font-weight: 800; white-space: nowrap; }
.top-search { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 520px; }
.top-search input { height: 38px; border: 0; }
.top-search button, .top-actions button { padding: 8px 14px; background: #fff; color: #111827; }
.top-actions { display: flex; align-items: center; gap: 18px; }
.top-actions a { color: #fff; }
.search-clear { display: inline-flex; align-items: center; justify-content: center; z-index: 1; width: 38px; height: 38px; margin-left: -46px; margin-right: 8px; border-radius: 7px; color: var(--muted); font-size: 25px; line-height: 1; }
.search-clear:hover { background: #f1f3f5; color: #111827; }
.bottom-strip { display: block; width: 100%; max-width: none; margin: 24px 0 0; padding: 18px 24px; background: #111827; color: #fff; text-align: center; font-weight: 800; letter-spacing: .04em; }

/* Homepage */
.home-layout { display: grid; grid-template-columns: 180px minmax(0, 1fr) 180px; gap: 24px; width: 100%; align-items: start; }
.news-list { width: 100%; max-width: 820px; min-width: 0; margin: 0 auto; }
.news-item { margin: 0 0 20px; padding: 28px 32px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); }
.news-item:first-child { padding-top: 28px; }
.news-item h2 { margin: 0 0 6px; font-size: 1.55rem; line-height: 1.2; }
.news-item .meta { margin: 0 0 6px; font-size: .86rem; line-height: 1.3; }
.post-author { margin: 0 0 12px; color: var(--muted); font-size: .84rem; line-height: 1.35; }
.post-card .post-author { margin-top: 10px; }
.annotation { margin: 0 0 14px; color: var(--muted); font-size: .92rem; line-height: 1.5; text-align: justify; white-space: pre-line; }
.content table { width: 100%; margin: 18px 0; border-collapse: collapse; font-size: .94rem; background: #fff; }
.content th, .content td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.content th { background: var(--paper); font-weight: 700; }
.content tr:nth-child(even) td { background: #fafafa; }
.content pre { overflow-x: auto; padding: 12px; border-radius: 8px; background: #20242a; color: #f4f4f4; }
.content code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.expanded-content { padding: 18px 0 8px; font-size: 1.05rem; }
.expanded-content.is-hidden, .expand-button.is-hidden, .news-expanded-actions.is-hidden { display: none; }
.expanded-content img { max-width: 100%; height: auto; }
.expand-button { padding: 6px 10px; border-radius: 6px; background: #111827; color: #fff; font-size: .85rem; }
.post-tags { margin: 12px 0 0; font-size: .78rem; font-style: italic; line-height: 1.35; }
.post-tags a { color: var(--muted); }
.post-tags a:hover { color: var(--accent); text-decoration: underline; }
.left-sidebar { display: flex; min-width: 0; flex-direction: column; gap: 16px; }
.date-toc, .top-posts, .tag-cloud-right { width: 100%; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.date-toc .toc-date { margin: 0 0 12px; padding-bottom: 0; }
.toc-date h3 { margin: 0 0 5px; color: var(--muted); font-size: .78rem; }
.toc-date a { display: block; margin: 5px 0; font-size: .82rem; line-height: 1.35; }
.toc-date a::before { content: '✦'; display: inline-block; width: 15px; color: var(--accent); font-size: .7rem; }
.toc-date a:last-child { margin-bottom: 0; }
.top-posts h3 { margin: 0 0 10px; color: var(--muted); font-size: .78rem; }
.top-posts a { display: block; margin: 9px 0; font-size: .82rem; line-height: 1.35; }
.top-posts a:last-of-type { margin-bottom: 0; }
.top-posts a span { display: block; }
.top-posts a small { display: block; margin-top: 2px; color: var(--muted); font-size: .74rem; }
.tag-cloud-right { min-height: 220px; }
.tag-cloud-right a { display: inline-block; margin: 3px 5px 7px 0; font-size: calc(.76rem + min(var(--tag-weight), 3) * .04rem); line-height: 1.3; }

/* Editor, forms and management */
.form-box, .editor { max-width: 680px; margin: 30px auto; }
.form-box label, .editor label { display: block; margin: 18px 0; font-weight: 650; }
.image-field { margin: 18px 0; font-weight: 650; }
.image-field .field-label { display: block; margin-bottom: 8px; }
.image-picker { display: inline-block; margin: 0; cursor: pointer; }
.image-file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.form-box input, .editor input, .editor select, .editor textarea { margin-top: 6px; }
.toolbar { display: flex; gap: 5px; margin: 7px 0; }
.toolbar button { padding: 6px 10px; background: var(--accent2); color: var(--accent); }
.rich { min-height: 260px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 400; }
.rich img { display: block; max-width: 100%; width: auto; height: auto; max-height: 420px; margin: 12px 0; border-radius: 8px; object-fit: contain; }
.news-image { margin: 16px 0; }
.news-image img { display: block; max-width: 100%; width: auto; height: auto; max-height: 420px; border-radius: 8px; object-fit: contain; }
.news-image figcaption { margin-top: 5px; color: var(--muted); font-size: .72rem; font-style: italic; line-height: 1.35; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.actions select { width: auto; }
.tag-row, .image-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag-row textarea { flex: 1 1 0; min-width: 0; resize: vertical; }
.tag-row .button { padding: 9px 12px; white-space: nowrap; }
.tag-row button:disabled, .image-actions button:disabled { opacity: .65; cursor: wait; }
.generation-status { display: block; margin-top: 7px; color: var(--muted); font-weight: 500; }
.revision { margin: 12px 0; }
.revision span { margin-left: 12px; color: var(--muted); }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.or-divider { margin: 14px 0; color: var(--muted); text-align: center; }
.admin-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-row { height: 92px; min-height: 92px; align-items: center; }
.admin-post-info { min-width: 0; flex: 1; }
.admin-post-title { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-post-info small { display: block; margin-top: 4px; color: var(--muted); }
.admin-row-actions { display: flex; min-width: 90px; flex-direction: column; align-items: flex-end; justify-content: center; gap: 4px; text-align: right; }
.admin-row-actions a { line-height: 1.3; }
.admin-row-actions form { margin: 0; }
.admin-row-actions .link-button { padding: 0; border: 0; background: transparent; font: inherit; line-height: 1.3; cursor: pointer; }
.admin-row-actions .danger-link { color: #a82828; }

/* Floating controls for an expanded article */
.news-expanded-actions { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: flex; flex-direction: row; align-items: center; gap: 8px; margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.94); box-shadow: 0 5px 18px rgba(24,33,43,.14); }
.news-expanded-actions button { padding: 7px 11px; border-radius: 6px; background: #111827; color: #fff; font-size: .85rem; white-space: nowrap; }

:focus-visible { outline: 3px solid #f3b33d; outline-offset: 2px; }

@media (max-width: 1000px) and (min-width: 701px) {
  .home-layout { grid-template-columns: 150px minmax(0, 1fr) 150px; gap: 12px; }
  .date-toc, .top-posts, .tag-cloud-right { padding: 12px; }
}

@media (max-width: 700px) {
  main { padding: 18px 16px 60px; }
  .top-strip { min-height: 58px; flex-wrap: wrap; padding: 10px 16px; }
  .top-brand { order: 1; }
  .top-actions { order: 1; margin-left: auto; }
  .top-search { order: 2; flex-basis: 100%; max-width: none; }
  .top-actions a, .top-actions button { font-size: .9rem; }
  .home-layout { display: flex; flex-direction: column; }
  .home-layout .news-list { order: 1; }
  .home-layout .left-sidebar { order: 2; width: 100%; margin: 20px 0; }
  .home-layout .tag-cloud-right { order: 3; margin: 20px 0; }
  .news-item { padding: 22px 18px; }
  .news-item:first-child { padding-top: 22px; }
  .tag-row { display: block; }
  .tag-row .button { width: 100%; margin-top: 8px; }
  .admin-toolbar { justify-content: flex-start; }
  .admin-row { height: 88px; min-height: 88px; padding: 14px; }
  .admin-row-actions { min-width: 78px; }
  .inline-form { display: block; }
  .inline-form > * { margin: 5px 0; }
  .row { display: block; }
  .row > div:last-child { margin-top: 10px; }
  .news-expanded-actions { right: 16px; left: auto; justify-content: flex-end; }
  .news-expanded-actions button { flex: 0 1 auto; }
}
