:root {
  --blue: #0a66c2;
  --blue-dark: #084d92;
  --bg: #f3f2ef;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --text: #1d2226;
  --muted: #5e6a73;
  --border: #e2e1de;
  --ok: #1f9d55;
  --warn: #c47d00;
  --danger: #c0392b;
  --star: #e8a700;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.05);
  --maxw: 920px;
}
[data-theme="dark"] {
  --bg: #16181c;
  --surface: #20242a;
  --surface-2: #2a2f36;
  --text: #e7eaee;
  --muted: #98a2ad;
  --border: #333a42;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.hidden { display: none !important; }

/* -------- App bar -------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.appbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.brand-logo {
  background: var(--blue); color: #fff; font-weight: 800;
  width: 30px; height: 30px; border-radius: 7px;
  display: grid; place-items: center; font-size: .95rem;
}
.brand-text { font-size: 1.02rem; }
.appbar-actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent; border: 0; cursor: pointer; font-size: 1.2rem;
  width: 40px; height: 40px; border-radius: 50%; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

.tabs {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; gap: 4px; padding: 0 10px;
}
.tab {
  flex: 1; background: transparent; border: 0; cursor: pointer;
  padding: 12px 6px; font-size: .92rem; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* -------- Layout -------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 16px 14px 90px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.card-head h2 { flex: 1; }
.step {
  background: var(--blue); color: #fff; width: 24px; height: 24px;
  border-radius: 50%; display: inline-grid; place-items: center;
  font-size: .82rem; font-weight: 700;
}
.badge {
  background: var(--surface-2); color: var(--muted);
  border-radius: 20px; padding: 2px 10px; font-size: .8rem; font-weight: 600;
}

/* -------- Buttons -------- */
.btn {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 22px; padding: 9px 16px;
  font-size: .92rem; font-weight: 600; cursor: pointer; transition: .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: .84rem; }
.btn-block { width: 100%; margin-top: 12px; }
.btn-danger { color: var(--danger); border-color: transparent; }

/* -------- Forms / chips -------- */
.inline-form { display: flex; gap: 8px; margin: 12px 0; }
.inline-form input { flex: 1; }
input[type=text], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); color: var(--text);
  font-size: .95rem; font-family: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 18px; padding: 6px 12px; font-size: .86rem; cursor: pointer;
  user-select: none;
}
.chip.selected { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip .x { opacity: .6; font-weight: 700; }
.chip .x:hover { opacity: 1; }
.chips-presets .chip { background: var(--surface); }
.chips-presets .chip:hover { border-color: var(--blue); }

.toggles { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.switch { display: flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; }

/* -------- Articles -------- */
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.articles { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; }
.article {
  display: flex; gap: 10px; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); cursor: pointer;
}
.article input { margin-top: 3px; }
.article-meta { font-size: .78rem; color: var(--muted); }
.article-title { font-size: .9rem; font-weight: 600; }

/* -------- Generate bar -------- */
.generate-bar { display: flex; align-items: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.num { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); flex: 1; }
.num input[type=range] { flex: 1; accent-color: var(--blue); }
.num output { font-weight: 700; color: var(--text); min-width: 18px; text-align: center; }
.generate-bar .btn-primary { padding: 11px 22px; }

/* -------- Results / idea cards -------- */
#results, .lib-panel { display: grid; grid-template-columns: 1fr; gap: 14px; }
.idea {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.idea-head { display: flex; align-items: flex-start; gap: 8px; }
.idea-head h3 { font-size: 1rem; margin: 0 0 2px; flex: 1; }
.idea-angle { font-size: .85rem; color: var(--muted); font-style: italic; margin: 0 0 10px; }
.idea-post {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; font-size: .92rem; line-height: 1.55;
}
.idea-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.charcount { font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 12px; background: var(--surface-2); }
.charcount.ok { color: var(--ok); }
.charcount.warn { color: var(--warn); }
.src-link { font-size: .8rem; color: var(--blue); text-decoration: none; }
.src-link:hover { text-decoration: underline; }
.star-btn { background: transparent; border: 0; cursor: pointer; font-size: 1.25rem; line-height: 1; }
.star-btn.on { color: var(--star); }

.refine-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.refine-bar .btn { padding: 5px 11px; font-size: .8rem; border-radius: 14px; }
.extras { margin-top: 10px; }
.hashtags { display: flex; flex-wrap: wrap; gap: 6px; }
.hashtag { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 3px 10px; font-size: .82rem; color: var(--blue); cursor: pointer; }
.hooks { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.hooks li { font-size: .85rem; padding: 7px 10px; background: var(--surface-2); border-radius: 8px; cursor: pointer; border: 1px solid var(--border); }
.hooks li:hover { border-color: var(--blue); }
.hooks .hook-label { color: var(--muted); font-size: .75rem; display: block; }

/* -------- Library / settings -------- */
.subtabs { display: flex; gap: 8px; margin-bottom: 14px; }
.subtab { flex: 1; padding: 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; font-weight: 600; cursor: pointer; color: var(--muted); }
.subtab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.lib-panel { display: none; }
.lib-panel.active { display: grid; }
.history-entry .idea-foot { margin-top: 6px; }
.entry-date { font-size: .8rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.preset-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.preset-row { display: flex; gap: 8px; align-items: flex-start; padding: 10px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }
.preset-row .pr-body { flex: 1; }
.preset-row .pr-name { font-weight: 600; font-size: .9rem; }
.preset-row .pr-instr { font-size: .82rem; color: var(--muted); }
.preset-form { display: flex; flex-direction: column; gap: 8px; }
.rss-list { padding-left: 18px; margin: 0; }
.about { text-align: center; }

/* -------- Toasts & overlay -------- */
.toasts { position: fixed; bottom: 20px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: #1d2226; color: #fff; padding: 10px 18px; border-radius: 22px; font-size: .88rem; box-shadow: var(--shadow); animation: pop .2s ease; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 60; color: #fff; gap: 14px; backdrop-filter: blur(2px); }
.overlay p { font-weight: 600; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* -------- Responsive desktop -------- */
@media (min-width: 760px) {
  #results, .lib-panel.active { grid-template-columns: 1fr 1fr; }
  .container { padding: 22px 18px 90px; }
}
