:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --text: #191919;
  --muted: #666666;
  --border: #e3e0da;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --li: #0a66c2;
  --li-hover: #004182;
  --ok: #057642;
  --warn: #b25e09;
  --err: #cc1016;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #1b1d21;
    --surface-2: #22252a;
    --text: #ecebe8;
    --muted: #a3a3a3;
    --border: #2e3137;
    --accent: #ff8a3d;
    --accent-soft: #2e2116;
    --li: #4c9be8;
    --li-hover: #71b2f0;
    --ok: #4cc38a;
    --warn: #f0a24c;
    --err: #ff6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #1b1d21;
  --surface-2: #22252a;
  --text: #ecebe8;
  --muted: #a3a3a3;
  --border: #2e3137;
  --accent: #ff8a3d;
  --accent-soft: #2e2116;
  --li: #4c9be8;
  --li-hover: #71b2f0;
  --ok: #4cc38a;
  --warn: #f0a24c;
  --err: #ff6b6b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, Vazirmatn, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[dir="auto"]:lang(fa), [dir="rtl"] { font-family: Vazirmatn, Inter, sans-serif; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }

.container { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Top bar */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; text-decoration: none; letter-spacing: -0.01em; }
.bolt { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); }
.pill-ok { color: var(--ok); }
.pill-warn { color: var(--warn); }
.li-dot { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 4px; background: var(--li); color: #fff; font-weight: 700; font-size: 11px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-li { background: var(--li); color: #fff; }
.btn-li:hover:not(:disabled) { background: var(--li-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Flash */
.flash { max-width: 1200px; margin: 16px auto 0; padding: 12px 16px; border-radius: 10px; font-weight: 500; }
.flash-ok { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); color: var(--ok); }
.flash-error { background: color-mix(in srgb, var(--err) 12%, var(--surface)); color: var(--err); }

/* Dashboard */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin: 8px 0 20px; }
.hero h1 { font-size: 32px; letter-spacing: -0.02em; }
.refresh-form { text-align: right; }
.refresh-form .small { margin-top: 6px; }
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--muted); }
.chip b { color: var(--text); font-weight: 600; margin-left: 2px; }
.chip-on { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip-on b { color: var(--surface); }
.day { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 28px 0 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.story { display: flex; flex-direction: column; text-decoration: none; overflow: hidden; transition: transform 0.15s, box-shadow 0.15s; }
.story:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.1); }
.story.status-skipped { opacity: 0.55; }
.thumb { position: relative; aspect-ratio: 1.91 / 1; overflow: hidden; display: grid; place-items: center; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-icon { font-size: 44px; opacity: 0.9; }
.thumb img + .thumb-icon { display: none; }
.cat-ai_coding { background: linear-gradient(135deg, #ff7a18, #af002d 85%); }
.cat-ai_models { background: linear-gradient(135deg, #6a11cb, #2575fc); }
.cat-software { background: linear-gradient(135deg, #11998e, #38ef7d); }
.cat-ai_industry { background: linear-gradient(135deg, #485563, #29323c); }
.cat-other_tech { background: linear-gradient(135deg, #8e9eab, #5d6d7e); }
.score { position: absolute; top: 10px; left: 10px; background: rgba(0, 0, 0, 0.65); color: #fff; font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 8px; border-radius: 6px; }
.thumb .badge { position: absolute; top: 10px; right: 10px; }
.badge-drafted { background: #fff3bf; color: #8a6100; }
.badge-published { background: #d3f9d8; color: #1b6e2d; }
.badge-skipped { background: #e9ecef; color: #495057; }
.story-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.cat { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.story h3 { font-size: 17px; letter-spacing: -0.01em; }
.summary { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.sources { margin-top: auto; font-size: 12px; color: var(--muted); padding-top: 8px; border-top: 1px dashed var(--border); }
.empty { text-align: center; padding: 48px 20px; margin-top: 20px; }
.empty-icon { font-size: 44px; }

/* Story page */
.back { display: inline-block; margin-bottom: 14px; color: var(--muted); text-decoration: none; }
.story-page { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px); gap: 24px; align-items: start; }
@media (max-width: 960px) { .story-page { grid-template-columns: 1fr; } }
.story-detail { overflow: hidden; }
.hero-img { aspect-ratio: 1.91 / 1; position: relative; }
.hero-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pad { padding: 20px 22px 22px; }
.meta-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.meta-row .cat { margin: 0; }
.score-inline { font-weight: 700; font-size: 13px; }
.story-detail h1 { font-size: 26px; letter-spacing: -0.02em; }
.lead { font-size: 16px; }
.facts { display: grid; gap: 12px; margin: 16px 0; }
.facts > div { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; }
.facts p { margin: 4px 0 0; }
.label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.section { font-size: 14px; margin-top: 18px; }
.links { padding-left: 18px; margin: 0 0 12px; }
.links li { margin: 4px 0; word-break: break-all; }
details summary { cursor: pointer; color: var(--muted); }
.snippets li { margin: 6px 0; font-size: 14px; }
.skip-form { margin-top: 18px; }

.post-panel { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 76px; }
@media (max-width: 960px) { .post-panel { position: static; } }
.write-cta { text-align: center; padding: 36px 24px; }
.li-badge { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 10px; background: var(--li); color: #fff; font-weight: 800; font-size: 26px; display: grid; place-items: center; }

/* LinkedIn look-alike preview */
.li-preview { padding: 0; overflow: hidden; }
.li-head { display: flex; gap: 10px; align-items: center; padding: 14px 16px 6px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.avatar-initials { display: grid; place-items: center; background: var(--li); color: #fff; font-weight: 700; font-size: 20px; }
.li-name { font-weight: 600; }
.li-text { padding: 6px 16px 12px; white-space: pre-wrap; font-size: 14px; line-height: 1.45; word-wrap: break-word; }
.li-link { color: var(--li); font-weight: 600; }
.see-more { color: var(--muted); cursor: pointer; }
.see-more:hover { color: var(--li); text-decoration: underline; }
.li-image img { width: 100%; display: block; max-height: 520px; object-fit: cover; }
.li-actions { display: flex; justify-content: space-around; padding: 10px 8px; border-top: 1px solid var(--border); font-weight: 600; }
.li-comment { padding: 8px 16px 12px; border-top: 1px solid var(--border); word-break: break-all; }
.published-box { padding: 14px 16px; color: var(--ok); font-weight: 600; }

/* Editor */
.editor { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.editor h3 { font-size: 14px; margin: 4px 0 0; }
.editor-head { display: flex; justify-content: space-between; align-items: baseline; }
textarea, input[type="text"], input[type="password"] {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
textarea { resize: vertical; line-height: 1.5; }
textarea:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--li) 40%, transparent); border-color: var(--li); }
.image-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.pick { position: relative; cursor: pointer; }
.pick input { position: absolute; opacity: 0; }
.pick img, .pick-none { display: grid; place-items: center; width: 108px; height: 60px; object-fit: cover; border-radius: 8px; border: 2px solid var(--border); font-size: 12px; color: var(--muted); background: var(--surface-2); }
.pick input:checked + img, .pick input:checked + .pick-none { border-color: var(--li); box-shadow: 0 0 0 3px color-mix(in srgb, var(--li) 25%, transparent); }
.editor-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }
.rewrite { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.rewrite input { flex: 1; }
.upload { padding: 12px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.older { padding: 12px 16px; }
.older pre { white-space: pre-wrap; font: inherit; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; }

/* Login */
.login { max-width: 360px; margin: 12vh auto; padding: 32px; display: flex; flex-direction: column; gap: 12px; text-align: center; }

@media (max-width: 600px) {
  .container { padding: 16px 16px 48px; }
  .hero h1 { font-size: 26px; }
  .refresh-form { text-align: left; }
  .grid { grid-template-columns: 1fr; }
}
#post { scroll-margin-top: 80px; }
.refresh-form .btn-sm { margin-left: 6px; }
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; font-size: 13px; }
.lang-switch a { padding: 4px 10px; color: var(--muted); text-decoration: none; }
.lang-switch a.on { background: var(--accent); color: #fff; }
