:root {
  --bg: var(--tg-theme-bg-color, #0b0d11);
  --surface: var(--tg-theme-secondary-bg-color, #141820);
  --surface-2: #1b2029;
  --text: var(--tg-theme-text-color, #f5f7fb);
  --muted: var(--tg-theme-hint-color, #8993a4);
  --accent: var(--tg-theme-button-color, #4c8dff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #ff5e6c;
  --border: rgba(255,255,255,.075);
  --shadow: 0 18px 50px rgba(0,0,0,.28);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom)); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px; max-width: 760px; margin: 0 auto;
}
.topbar h1, .section-head h2, .sheet-head h2 { margin: 0; letter-spacing: -.03em; }
.eyebrow { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }

main { max-width: 760px; margin: 0 auto; padding: 0 14px 28px; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from {opacity:.35; transform: translateY(4px)} to {opacity:1; transform:none} }

.hero-card {
  background:
    radial-gradient(circle at 92% 12%, rgba(76,141,255,.24), transparent 34%),
    linear-gradient(145deg, #171c25, #10141b);
  border: 1px solid var(--border); border-radius: 26px; min-height: 176px;
  padding: 22px; display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: var(--shadow); margin: 8px 0 14px;
}
.hero-card h2 { font-size: 24px; line-height: 1.12; margin: 14px 0 8px; max-width: 620px; }
.pill { display: inline-flex; background: rgba(76,141,255,.14); color: #83afff; border: 1px solid rgba(76,141,255,.22); border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); margin: 0; }

.primary-btn, .secondary-btn, .danger-btn, .primary-small {
  border: 0; border-radius: 15px; padding: 14px 17px; font-weight: 750;
}
.primary-btn, .primary-small { background: var(--accent); color: var(--accent-text); }
.secondary-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.danger-btn { background: rgba(255,94,108,.12); color: #ff8a95; border: 1px solid rgba(255,94,108,.22); }
.primary-small { padding: 9px 13px; border-radius: 12px; }
.full { width: 100%; }
.text-btn { background: none; border: none; color: #7ba8ff; font-weight: 700; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 20px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 2px 12px; gap: 12px; }
.section-head h3 { margin: 0; font-size: 18px; }
.sticky-head { margin-top: 8px; }

.week-list, .plan-list, .posts-list, .settings-list { display: grid; gap: 10px; }
.week-item, .plan-item, .post-item, .setting-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 15px;
}
.week-item { display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center; }
.day-badge { width: 44px; height: 44px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; }
.item-title { font-weight: 750; line-height: 1.25; }
.item-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.item-arrow { color: var(--muted); font-size: 22px; }

.stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; margin-top: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 17px; padding: 14px; }
.stat-card strong { display: block; font-size: 24px; }
.stat-card span { font-size: 12px; color: var(--muted); }

.plan-item { display: grid; gap: 10px; }
.plan-top { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.plan-date { font-size:13px; color:var(--muted); }
.plan-topic { font-weight:750; font-size:16px; line-height:1.3; }
.plan-rubric { color:#8cb5ff; font-size:13px; font-weight:700; }

.segmented { display: flex; padding: 4px; background: var(--surface); border-radius: 14px; margin: 6px 0 14px; border:1px solid var(--border); }
.segment { flex: 1; border: 0; padding: 9px 8px; border-radius: 10px; background: transparent; color: var(--muted); }
.segment.active { background: var(--surface-2); color: var(--text); font-weight: 700; }

.post-item { display:grid; gap:8px; }
.post-status { display:inline-flex; width:max-content; border-radius:999px; padding:4px 8px; font-size:11px; font-weight:750; background:rgba(255,255,255,.06); color:var(--muted); }
.post-status.draft { color:#ffd17c; background:rgba(255,193,86,.09); }
.post-status.published { color:#7de4aa; background:rgba(71,205,135,.09); }

.bottom-nav {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); bottom: 0;
  width: min(100%, 760px); display: grid; grid-template-columns: repeat(4,1fr);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(18px); border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.nav-item { border:0; background:none; color:var(--muted); display:grid; gap:2px; place-items:center; padding:4px; }
.nav-item span { font-size:21px; line-height:1; }
.nav-item small { font-size:10px; }
.nav-item.active { color:var(--accent); }

.modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.58); z-index:40; backdrop-filter:blur(3px); }
.sheet {
  position: fixed; left:50%; transform:translateX(-50%); bottom:0; z-index:50;
  width:min(100%,760px); max-height:92vh; overflow:auto; background:#12161d;
  border:1px solid var(--border); border-radius:28px 28px 0 0;
  padding:12px 16px calc(20px + env(safe-area-inset-bottom)); box-shadow:0 -30px 80px rgba(0,0,0,.45);
}
.full-sheet { height:92vh; }
.sheet-handle { width:42px; height:5px; border-radius:5px; background:#424955; margin:0 auto 14px; }
.sheet-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
label { display:grid; gap:7px; color:var(--muted); font-size:13px; margin:13px 0; font-weight:650; }
input, textarea, select {
  width:100%; border:1px solid var(--border); background:#0d1117; color:var(--text);
  border-radius:14px; padding:13px 14px; outline:none; resize:vertical;
}
input:focus, textarea:focus, select:focus { border-color:rgba(76,141,255,.55); box-shadow:0 0 0 3px rgba(76,141,255,.1); }

.cover-wrap { position:relative; border-radius:20px; overflow:hidden; margin-bottom:15px; background:#090b0e; border:1px solid var(--border); }
.cover-wrap img { display:block; width:100%; aspect-ratio:3/2; object-fit:cover; }
.overlay-btn { position:absolute; right:10px; bottom:10px; border:1px solid rgba(255,255,255,.15); background:rgba(8,10,14,.78); color:#fff; backdrop-filter:blur(10px); border-radius:12px; padding:9px 11px; }
.post-preview { background:var(--surface); border:1px solid var(--border); border-radius:18px; padding:17px; line-height:1.5; overflow-wrap:anywhere; }
.post-preview pre { white-space:pre-wrap; background:#090c10; padding:12px; border-radius:12px; overflow:auto; }
.post-preview code { background:#090c10; padding:2px 5px; border-radius:6px; }
.quick-actions { display:grid; grid-template-columns:repeat(2,1fr); gap:8px; margin:12px 0; }
.quick-actions button { background:var(--surface-2); border:1px solid var(--border); color:var(--text); border-radius:13px; padding:11px; }
.publish-btn { margin-top:10px; }

.dev-banner { margin:5px 0 10px; border-radius:12px; padding:9px 11px; font-size:12px; color:#ffd17c; background:rgba(255,193,86,.09); border:1px solid rgba(255,193,86,.14); }

.toast { position:fixed; z-index:90; left:50%; transform:translateX(-50%); bottom:100px; max-width:90%; background:#242a34; color:#fff; padding:11px 15px; border-radius:13px; box-shadow:var(--shadow); }
.loader-overlay { position:fixed; inset:0; z-index:100; background:rgba(0,0,0,.62); display:grid; place-items:center; backdrop-filter:blur(5px); }
.loader-card { background:#171b22; border:1px solid var(--border); border-radius:20px; padding:22px 28px; display:flex; gap:13px; align-items:center; box-shadow:var(--shadow); }
.spinner { width:23px; height:23px; border:3px solid rgba(255,255,255,.15); border-top-color:var(--accent); border-radius:50%; animation:spin .8s linear infinite; }
@keyframes spin { to {transform:rotate(360deg)} }

.setting-row { display:flex; justify-content:space-between; gap:16px; padding:9px 0; border-bottom:1px solid var(--border); }
.setting-row:last-child { border-bottom:0; }
.setting-row span:last-child { color:var(--muted); text-align:right; }

@media (min-width:650px) {
  body { padding-top:10px; }
  .sheet { bottom:28px; border-radius:28px; max-height:88vh; }
  .full-sheet { height:auto; max-height:88vh; }
}

/* v3.1 creator additions */
.usage-card{margin-top:12px;background:linear-gradient(145deg,#121720,#0e1218);border:1px solid var(--border);border-radius:18px;padding:15px;display:grid;grid-template-columns:1fr 1fr;gap:12px}.usage-card div{display:grid;gap:4px}.usage-card strong{font-size:20px}
.mode-tabs{display:grid;grid-template-columns:1fr 1fr;gap:6px;background:#0d1117;border:1px solid var(--border);padding:5px;border-radius:14px}.mode-tab{border:0;background:transparent;color:var(--muted);padding:10px;border-radius:10px;font-weight:700}.mode-tab.active{background:var(--surface-2);color:var(--text)}
.analysis-card{margin:12px 0;background:rgba(76,141,255,.08);border:1px solid rgba(76,141,255,.18);border-radius:16px;padding:14px;line-height:1.45}.analysis-card strong{display:block;margin-bottom:6px}.analysis-card .row{margin:5px 0}.analysis-card .label{color:var(--muted);font-size:12px;text-transform:uppercase;letter-spacing:.08em}
.image-empty{border:1px dashed rgba(255,255,255,.13);border-radius:18px;min-height:150px;display:grid;place-items:center;color:var(--muted);background:#0c0f14;margin-bottom:12px}.image-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:12px}.image-actions .secondary-btn{padding:11px 12px}.prompt-box,.publication-box,.source-box,.draft-usage{background:var(--surface);border:1px solid var(--border);border-radius:17px;padding:14px;margin:12px 0}.prompt-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:8px;font-size:13px;font-weight:750}.prompt-box textarea{margin:0;color:#c9d2df;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px;line-height:1.45}.publication-box{display:grid;gap:8px}.radio-row{display:flex;align-items:flex-start;gap:9px;margin:0;color:var(--text);font-weight:600}.radio-row input{width:auto;margin:2px 0 0}.warning{padding:10px 12px;border-radius:12px;background:rgba(255,193,86,.08);border:1px solid rgba(255,193,86,.16);color:#ffd17c;font-size:13px}.warning .text-btn{padding:0}.source-box a{display:block;color:#87b1ff;word-break:break-all;margin:6px 0}.draft-usage{font-size:12px;color:var(--muted);display:flex;justify-content:space-between;gap:10px}.draft-usage strong{color:var(--text)}
.plan-item,.week-item,.post-item{width:100%;text-align:left;color:inherit}
@media(max-width:430px){.image-actions{grid-template-columns:1fr}.usage-card{grid-template-columns:1fr 1fr}.prompt-head{align-items:flex-start}.stats-grid{gap:6px}.stat-card{padding:12px 9px}.stat-card strong{font-size:21px}}
