/* app.css — base, chrome, discovery, account, shared components.
   Colour/space/type come from tokens.css. This file owns layout + components
   for the application shell and the reading-adjacent surfaces. The viewer and
   studio have their own stylesheets. */

/* ---- base ---------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
/* subtle paper grain */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}
#app { position: relative; z-index: 1; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img, svg { display: block; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
.icon { flex: none; }

.shell { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--sp-5) var(--sp-9); }
.shell.narrow { max-width: 720px; }
.page { padding-top: var(--sp-6); }
.kicker { font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); }

/* ---- topbar -------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: var(--maxw); margin: 0 auto; height: 64px;
  display: flex; align-items: center; gap: var(--sp-5); padding: 0 var(--sp-5); }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--font-display);
  font-weight: 600; font-size: 19px; color: var(--ink); }
.brand .icon { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px;
  border-radius: var(--r-md); color: var(--muted); font-weight: 500; font-size: 14.5px;
  transition: background var(--ease), color var(--ease); }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { color: var(--ink); background: var(--surface-2); }
.nav-link .icon { color: var(--accent); opacity: .85; }
.actions { display: flex; align-items: center; gap: 10px; }

/* ---- buttons ------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r-md); font-weight: 600; font-size: 14.5px;
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink);
  transition: transform .06s var(--ease), background var(--ease), border-color var(--ease), box-shadow var(--ease); }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); box-shadow: var(--shadow-1); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: #b23b2a; border-color: #b23b2a; color: #fff; }
.btn.danger:hover { background: #9c3322; }
.btn.sm { padding: 7px 12px; font-size: 13.5px; }
.btn.full { width: 100%; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.btn.icon { padding: 9px; border-radius: var(--r-md); background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.icon:hover { background: var(--surface-2); color: var(--ink); }
.btn.disabled, .btn:disabled { opacity: .45; pointer-events: none; }
.theme-toggle { color: var(--ink-soft); }

/* ---- avatar & account menu ---------------------------------------------- */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: var(--on-accent); font-weight: 700; font-family: var(--font-display);
  display: grid; place-items: center; font-size: 15px; }
.avatar.lg { width: 76px; height: 76px; font-size: 30px; }
.account { position: relative; }
.menu { position: absolute; right: 0; top: 46px; width: 220px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  padding: 7px; z-index: 60; }
.menu.hidden { display: none; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 9px 11px;
  border-radius: var(--r-sm); font-size: 14px; color: var(--ink-soft); }
.menu a:hover, .menu button:hover { background: var(--surface-2); color: var(--ink); }
.menu .sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu .who { padding: 9px 11px 4px; }
.menu .who b { font-family: var(--font-display); display: block; font-size: 15px; }
.menu .who span { color: var(--muted); font-size: 13px; }

/* ---- hero ---------------------------------------------------------------- */
.hero { border-bottom: 1px solid var(--line);
  background:
    radial-gradient(120% 120% at 12% 0%, var(--accent-soft) 0%, transparent 46%),
    radial-gradient(90% 90% at 100% 0%, var(--violet-soft) 0%, transparent 40%); }
.hero-inner { max-width: var(--maxw); margin: 0 auto; padding: var(--sp-9) var(--sp-5); }
.hero-kicker { font-size: 12.5px; font-weight: 600; letter-spacing: 0.2em; color: var(--accent); }
.hero h1 { font-size: clamp(40px, 6vw, 74px); line-height: 1.02; margin: var(--sp-3) 0;
  max-width: 16ch; letter-spacing: -0.02em; }
.hero-lede { font-family: var(--font-read); font-size: 20px; color: var(--ink-soft);
  max-width: 56ch; line-height: 1.5; }
.hero-actions { margin-top: var(--sp-6); gap: 12px; }

/* ---- searchbar & chips --------------------------------------------------- */
.searchbar { display: flex; align-items: center; gap: 12px; margin: var(--sp-6) 0 var(--sp-4);
  padding: 13px 18px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-xl); box-shadow: var(--shadow-1); }
.searchbar .icon { color: var(--muted); }
.search-input { flex: 1; border: none; background: none; outline: none; font-size: 17px;
  color: var(--ink); font-family: var(--font-ui); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: var(--sp-7); }
.chips-label { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.chip { padding: 6px 13px; border-radius: 100px; background: var(--surface-2);
  border: 1px solid var(--line); font-size: 13.5px; color: var(--ink-soft); font-weight: 500; }
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---- sections & grids ---------------------------------------------------- */
.feed-section { margin-top: var(--sp-8); }
.section-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: var(--sp-5); }
.section-head .kicker { margin-right: 2px; }
.section-head h2 { font-size: 26px; }
.section-head .count { color: var(--muted); font-size: 14px; margin-left: auto; }
.grid { display: grid; gap: var(--sp-5);
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); }
.feature-grid { grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); }
.feature-grid .feature { grid-column: span 2; grid-row: span 1; }

/* ---- work card ----------------------------------------------------------- */
.card { display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease); }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.card .cover { aspect-ratio: 16 / 11; background-size: cover; background-position: center;
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; }
.card .cover.generated { padding: var(--sp-5); }
.card.feature .cover { aspect-ratio: 16 / 9; }
.cover-type { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; color: rgba(255,255,255,.82); }
.cover-title { font-family: var(--font-display); font-weight: 600; color: #fff;
  font-size: 24px; line-height: 1.12; margin-top: 6px; text-shadow: 0 1px 14px rgba(0,0,0,.22); }
.card.feature .cover-title { font-size: 34px; }
.card .meta { padding: var(--sp-4) var(--sp-4) var(--sp-5); }
.card .meta .kicker { font-size: 11.5px; }
.card .meta h3 { font-size: 19px; margin: 5px 0 4px; line-height: 1.2; }
.card .meta .sub { color: var(--ink-soft); font-size: 14.5px; font-family: var(--font-read);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta .by { display: block; margin-top: 9px; color: var(--muted); font-size: 13px; }
.card-actions { margin-top: var(--sp-4); gap: 8px; }

/* ---- creator page -------------------------------------------------------- */
.creator-head { display: flex; gap: var(--sp-5); align-items: center; padding: var(--sp-7) 0 var(--sp-6); }
.creator-head h1 { font-size: 34px; }
.creator-head .handle { color: var(--muted); font-size: 15px; }
.creator-head .bio { color: var(--ink-soft); font-family: var(--font-read); margin-top: 8px; max-width: 60ch; }
.creator-stats { gap: 18px; margin-top: 12px; align-items: center; color: var(--ink-soft); font-size: 14px; }

/* ---- studio list head ---------------------------------------------------- */
.studio-head { display: flex; align-items: flex-end; justify-content: space-between;
  padding: var(--sp-3) 0 var(--sp-6); gap: var(--sp-4); }
.studio-head h1 { font-size: 34px; margin-top: 4px; }
.studio-grid .studio-card .cover { aspect-ratio: 16 / 11; }

/* ---- forms / panels ------------------------------------------------------ */
.center-stage { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: var(--sp-6); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: var(--sp-7); box-shadow: var(--shadow-1); width: 100%; }
.field, .insp-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field > span, .insp-field > span { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.input { width: 100%; padding: 11px 13px; border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--paper); color: var(--ink); font-size: 15px; font-family: var(--font-ui); outline: none;
  transition: border-color var(--ease), box-shadow var(--ease); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled { opacity: .6; }
textarea.input.area { min-height: 96px; resize: vertical; line-height: 1.5; }
select.input { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23999' stroke-width='1.6'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }
input.color { width: 100%; height: 40px; padding: 3px; border: 1px solid var(--line-strong);
  border-radius: var(--r-md); background: var(--paper); cursor: pointer; }
.error-note { background: color-mix(in srgb, #b23b2a 12%, transparent); color: #9c3322;
  border: 1px solid color-mix(in srgb, #b23b2a 28%, transparent); padding: 10px 13px;
  border-radius: var(--r-md); font-size: 14px; margin-bottom: var(--sp-4); }
.error-note.hidden { display: none; }

/* ---- auth ---------------------------------------------------------------- */
.auth-panel { max-width: 420px; }
.auth-brand { display: flex; align-items: center; gap: 9px; color: var(--accent);
  font-family: var(--font-display); font-size: 18px; margin-bottom: var(--sp-5); }
.auth-panel h1 { font-size: 28px; }
.auth-sub { color: var(--ink-soft); margin: 6px 0 var(--sp-6); font-family: var(--font-read); }
.auth-switch { margin-top: var(--sp-5); text-align: center; color: var(--muted); font-size: 14px; }
.auth-switch a { color: var(--accent-ink); font-weight: 600; }
.auth-note { margin-top: var(--sp-4); text-align: center; color: var(--muted); font-size: 13px; }

/* ---- toast --------------------------------------------------------------- */
#toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 9px; z-index: 200; align-items: center; }
.toast { background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 100px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(10px); transition: opacity .24s var(--ease), transform .24s var(--ease); }
.toast.in { opacity: 1; transform: translateY(0); }
.toast.error { background: #9c3322; color: #fff; }

/* ---- modal / overlay ----------------------------------------------------- */
.overlay { position: fixed; inset: 0; z-index: 150; background: color-mix(in srgb, var(--ink) 38%, transparent);
  backdrop-filter: blur(3px); display: grid; place-items: center; padding: var(--sp-5);
  opacity: 0; transition: opacity .2s var(--ease); }
.overlay.in { opacity: 1; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop); width: 100%; max-width: 460px; transform: translateY(8px) scale(.99);
  transition: transform .2s var(--ease); max-height: 88vh; overflow: auto; }
.overlay.in .modal { transform: none; }
.modal.wide { max-width: 720px; }
.modal-body { padding: var(--sp-6); }
.modal-body.wide { padding: var(--sp-6); }
.modal-body h2 { font-size: 23px; margin-bottom: var(--sp-5); }
.modal-actions { gap: 10px; justify-content: flex-end; margin-top: var(--sp-5); }
.modal-actions.between { justify-content: space-between; align-items: center; margin-top: 0; margin-bottom: var(--sp-4); }
.confirm { padding: var(--sp-6); }
.confirm p { font-size: 16px; color: var(--ink-soft); }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: var(--sp-5); }

/* ---- asset drawer -------------------------------------------------------- */
.asset-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  margin: var(--sp-4) 0; max-height: 52vh; overflow: auto; }
.asset-tile { aspect-ratio: 1; border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--surface-2) center / cover no-repeat; display: grid; place-items: center;
  color: var(--muted); font-size: 12px; padding: 6px; word-break: break-word; }
.asset-tile:hover { border-color: var(--accent); }

/* ---- helpers ------------------------------------------------------------- */
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.empty { text-align: center; padding: var(--sp-9) var(--sp-5); color: var(--ink-soft); max-width: 480px; }
.empty h2 { font-size: 26px; margin-bottom: 10px; color: var(--ink); }
.empty p { margin-bottom: var(--sp-5); }
.empty.soft { padding: var(--sp-7); }
.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- dashboard ----------------------------------------------------------- */
.stats { display: grid; gap: var(--sp-4); margin: var(--sp-5) 0;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--sp-5); }
.stat b { font-family: var(--font-display); font-size: 32px; font-weight: 600; display: block; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.table { width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.table th, .table td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: none; }
.table a { color: var(--accent-ink); font-weight: 600; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 100px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-soft); text-transform: capitalize; }
.pill.published { background: color-mix(in srgb, #2e7d32 16%, transparent); color: #2e7d32; }
.pill.draft { background: var(--surface-2); color: var(--muted); }
.pill.archived { background: var(--surface-2); color: var(--muted); }

/* ---- page attention bars ------------------------------------------------- */
.attn { display: flex; flex-direction: column; gap: 8px; margin-top: var(--sp-3); }
.attn-row { display: flex; align-items: center; gap: 12px; }
.attn-label { width: 70px; font-size: 13px; color: var(--ink-soft); }
.attn-bar { flex: 1; height: 12px; background: var(--surface-2); border-radius: 100px; overflow: hidden; }
.attn-fill { height: 100%; background: var(--accent); border-radius: 100px; }
.attn-num { width: 36px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.insp-hint { color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 760px) {
  .nav { display: none; }
  .hero h1 { font-size: 38px; }
  .feature-grid .feature { grid-column: span 1; }
  .creator-head { flex-direction: column; text-align: center; align-items: center; }
}

/* ---- Utilities added with admin/branding ---- */
.muted { color: var(--muted); }
.input.sm, select.input.sm { padding: 5px 8px; font-size: 12.5px; height: auto; }
.brand-logo { height: 30px; width: auto; display: block; }

/* Powered-by badge (toggleable by operators) */
.powered-by {
  position: fixed; right: 14px; bottom: 12px; z-index: 40;
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .04em;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 999px; box-shadow: var(--shadow-1); pointer-events: none;
}

/* ---- Admin console ---- */
.admin-page { max-width: var(--maxw); margin: 0 auto; padding: var(--sp-6) var(--sp-5) var(--sp-9); }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); align-items: start; }
.admin-grid .admin-card:last-child { grid-column: 1 / -1; }
.admin-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.admin-card-head { display: flex; align-items: center; gap: 9px; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
.admin-card-head .icon { color: var(--accent); }
.admin-card-head h2 { margin: 0; font-size: 16px; }
.admin-card-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.card-lede { color: var(--muted); margin: 0 0 var(--sp-1); font-size: 13.5px; }
.logo-preview { display: flex; align-items: center; gap: var(--sp-3); min-height: 44px; }
.logo-preview img { max-height: 44px; max-width: 180px; border-radius: var(--r-sm); background: var(--paper-2); padding: 4px; }

.user-list { display: flex; flex-direction: column; gap: 2px; }
.user-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2); border-radius: var(--r-md); }
.user-row:hover { background: var(--paper-2); }
.user-row.is-suspended { opacity: .6; }
.user-id { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.user-id b { font-size: 14px; }
.user-id .email { font-size: 11.5px; }
.user-meta { display: flex; align-items: center; gap: var(--sp-2); font-size: 12px; }
.user-controls { display: flex; align-items: center; gap: var(--sp-2); }

@media (max-width: 760px) {
  .admin-grid { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr auto; }
  .user-meta { display: none; }
}

/* Reader-focused home header (no marketing block) */
.reader-hero .hero-inner { padding: var(--sp-7) var(--sp-5) var(--sp-4); }
.reader-hero h1 { margin: 0; max-width: none; font-size: clamp(34px, 4.5vw, 56px); }
.reader-hero .hero-lede { margin-top: var(--sp-2); }
