/* ==========================================================================
   FOLIUM — Design System
   A place for long-form thought. Editorial, ink-and-paper, quietly confident.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,500&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root{
  /* --- Color tokens --- */
  --paper:        #FAF6EF;
  --paper-dim:    #F1EBDD;
  --ink:          #201C1A;
  --ink-soft:     #4A433C;
  --ink-faint:    #8C8275;
  --rule:         #DED4C1;
  --oxblood:      #6E1E2B;
  --oxblood-deep: #591622;
  --oxblood-tint: #F4E4E2;
  --brass:        #B8934A;
  --brass-tint:   #F3E9D2;
  --ok:           #3C6E4F;
  --err:          #A5342A;
  --white:        #FFFFFE;

  /* --- Type --- */
  --font-display: 'Fraunces', serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'IBM Plex Mono', monospace;

  /* --- Scale --- */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(32,28,26,0.06), 0 1px 1px rgba(32,28,26,0.04);
  --shadow-md: 0 6px 20px rgba(32,28,26,0.08), 0 2px 6px rgba(32,28,26,0.05);
  --shadow-lg: 0 20px 50px rgba(32,28,26,0.16), 0 6px 16px rgba(32,28,26,0.08);

  --max-w: 1120px;
}

*, *::before, *::after{ box-sizing: border-box; }
html{ -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body{
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img{ max-width: 100%; display: block; }
a{ color: inherit; text-decoration: none; }
button{ font-family: inherit; cursor: pointer; }
input, textarea, select{ font-family: inherit; font-size: inherit; }
ul{ margin:0; padding:0; list-style:none; }

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

:focus-visible{ outline: 2px solid var(--oxblood); outline-offset: 2px; }

.container{ max-width: var(--max-w); margin: 0 auto; padding: 0 24px; }

/* ==========================================================================
   Masthead (top nav) — newspaper nameplate, not a generic navbar
   ========================================================================== */
.masthead{
  position: sticky; top: 0; z-index: 40;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.masthead__inner{
  max-width: var(--max-w); margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.brand{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: 0.2px;
  color: var(--ink);
  display: flex; align-items: baseline; gap: 6px;
}
.brand em{
  font-style: italic;
  color: var(--oxblood);
}
.masthead__search{
  flex: 1; max-width: 360px;
  display: flex; align-items: center; gap: 8px;
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 8px 16px;
}
.masthead__search input{
  border: none; outline: none; background: none; width: 100%;
  font-size: 14px; color: var(--ink);
}
.masthead__search svg{ flex-shrink:0; opacity:0.5; }
.masthead__actions{ display:flex; align-items:center; gap:10px; }

.icon-btn{
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid transparent; background: transparent;
  display:flex; align-items:center; justify-content:center;
  color: var(--ink-soft); transition: background .15s, color .15s;
}
.icon-btn:hover{ background: var(--paper-dim); color: var(--ink); }

.avatar{
  width: 36px; height: 36px; border-radius: 50%;
  object-fit: cover; border: 1px solid var(--rule);
  background: var(--brass-tint);
  display:flex; align-items:center; justify-content:center;
  font-family: var(--font-display); font-weight:600; color: var(--oxblood);
  font-size: 14px;
}
.avatar--sm{ width: 28px; height: 28px; font-size: 12px; }
.avatar--lg{ width: 96px; height: 96px; font-size: 34px; border-width: 3px; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding: 10px 20px; border-radius: 999px; font-weight: 600; font-size: 14px;
  border: 1px solid transparent; transition: transform .12s ease, background .15s, box-shadow .15s, color .15s;
  white-space: nowrap;
}
.btn:active{ transform: scale(0.97); }
.btn--primary{ background: var(--oxblood); color: var(--white); }
.btn--primary:hover{ background: var(--oxblood-deep); }
.btn--ghost{ background: transparent; color: var(--ink); border-color: var(--rule); }
.btn--ghost:hover{ background: var(--paper-dim); }
.btn--outline{ background: transparent; color: var(--oxblood); border-color: var(--oxblood); }
.btn--outline:hover{ background: var(--oxblood-tint); }
.btn--sm{ padding: 6px 14px; font-size: 13px; }
.btn--block{ width: 100%; }
.btn[disabled]{ opacity: 0.55; cursor: not-allowed; }
.btn--follow.is-following{ background: var(--paper-dim); color: var(--ink-soft); border-color: var(--rule); }

/* ==========================================================================
   Layout: two-column editorial feed
   ========================================================================== */
.layout{
  max-width: var(--max-w); margin: 0 auto; padding: 40px 24px 100px;
  display: grid; grid-template-columns: 1fr 320px; gap: 56px;
  align-items: start;
}
@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; padding-bottom: 90px; }
  .sidebar{ display:none; }
}

.tabs{
  display:flex; gap: 28px; border-bottom: 1px solid var(--rule); margin-bottom: 28px;
}
.tabs button{
  background:none; border:none; padding: 10px 2px 14px;
  font-size: 15px; font-weight: 600; color: var(--ink-faint);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active{ color: var(--ink); border-bottom-color: var(--oxblood); }

/* Story card — magazine table-of-contents feel */
.story{
  display: grid; grid-template-columns: 1fr auto; gap: 24px;
  padding: 30px 0; border-bottom: 1px solid var(--rule);
}
.story__byline{
  display:flex; align-items:center; gap:8px; margin-bottom: 10px;
  font-size: 13px; color: var(--ink-faint);
}
.story__byline b{ color: var(--ink-soft); font-weight: 600; }
.story__title{
  font-family: var(--font-display); font-weight: 600; font-size: 26px;
  line-height: 1.25; margin: 0 0 8px; color: var(--ink);
}
.story__title:hover{ color: var(--oxblood); }
.story__excerpt{
  color: var(--ink-soft); font-size: 15px; line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin: 0 0 14px;
}
.story__meta{ display:flex; align-items:center; gap: 18px; }
.story__stamp{
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--brass); border: 1px solid var(--brass); border-radius: 999px; padding: 3px 10px;
  transform: rotate(-2deg); display:inline-block;
}
.story__cover{
  width: 180px; height: 130px; border-radius: var(--radius-md); overflow:hidden;
  background: var(--paper-dim); flex-shrink:0;
}
.story__cover img{ width:100%; height:100%; object-fit:cover; }
@media (max-width: 620px){
  .story{ grid-template-columns: 1fr; }
  .story__cover{ width:100%; height: 160px; order:-1; }
}

.action-row{ display:flex; align-items:center; gap: 6px; }
.action{
  display:flex; align-items:center; gap: 6px;
  background:none; border:none; color: var(--ink-faint);
  padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight:500;
  transition: color .15s, background .15s;
}
.action:hover{ background: var(--paper-dim); color: var(--ink); }
.action.is-active{ color: var(--oxblood); }
.action.is-active svg{ fill: var(--oxblood); }
.action svg{ width:18px; height:18px; }

/* Sidebar */
.panel{
  background: var(--white); border: 1px solid var(--rule); border-radius: var(--radius-lg);
  padding: 22px; margin-bottom: 24px;
}
.panel__title{
  font-family: var(--font-mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-faint); margin: 0 0 16px;
}
.suggest-row{ display:flex; align-items:center; gap:10px; padding: 10px 0; }
.suggest-row .name{ font-weight:600; font-size: 14px; }
.suggest-row .handle{ font-size: 12px; color: var(--ink-faint); }
.suggest-row > div:nth-child(2){ flex:1; min-width:0; }

/* ==========================================================================
   Auth pages
   ========================================================================== */
.auth-wrap{
  min-height: 100vh; display:flex; align-items:center; justify-content:center;
  padding: 24px; background:
    radial-gradient(circle at 12% 8%, var(--brass-tint) 0%, transparent 45%),
    radial-gradient(circle at 88% 92%, var(--oxblood-tint) 0%, transparent 45%),
    var(--paper);
}
.auth-card{
  width: 100%; max-width: 420px; background: var(--white);
  border: 1px solid var(--rule); border-radius: var(--radius-lg);
  padding: 40px 36px; box-shadow: var(--shadow-lg);
}
.auth-card .brand{ justify-content:center; margin-bottom: 6px; }
.auth-sub{ text-align:center; color: var(--ink-faint); font-size: 14px; margin: 0 0 28px; }
.field{ margin-bottom: 18px; }
.field label{ display:block; font-size: 13px; font-weight:600; margin-bottom: 6px; color: var(--ink-soft); }
.field input, .field textarea{
  width: 100%; padding: 11px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus{
  border-color: var(--oxblood); box-shadow: 0 0 0 3px var(--oxblood-tint); outline:none;
}
.field-error{ color: var(--err); font-size: 12px; margin-top: 6px; }
.auth-switch{ text-align:center; margin-top: 20px; font-size: 14px; color: var(--ink-faint); }
.auth-switch a{ color: var(--oxblood); font-weight:600; }
.divider{ display:flex; align-items:center; gap:12px; margin: 22px 0; color: var(--ink-faint); font-size: 12px; }
.divider::before, .divider::after{ content:''; flex:1; height:1px; background: var(--rule); }

/* ==========================================================================
   Editor
   ========================================================================== */
.editor-shell{ max-width: 760px; margin: 0 auto; padding: 40px 24px 140px; }
.editor-cover{
  width:100%; height: 280px; border-radius: var(--radius-lg); background: var(--paper-dim);
  border: 1px dashed var(--rule); display:flex; align-items:center; justify-content:center;
  color: var(--ink-faint); margin-bottom: 28px; cursor:pointer; overflow:hidden; position:relative;
}
.editor-cover img{ width:100%; height:100%; object-fit:cover; }
.editor-title{
  width:100%; border:none; background:none; outline:none; resize:none;
  font-family: var(--font-display); font-weight:600; font-size: 42px; line-height:1.15;
  color: var(--ink); margin-bottom: 6px;
}
.editor-title::placeholder{ color: var(--ink-faint); }
.editor-tagline{ color: var(--ink-faint); font-size: 14px; margin-bottom: 24px; }
#editorBody{
  min-height: 400px; font-size: 18px; line-height: 1.8; color: var(--ink-soft);
  border: none; outline: none;
}
#editorBody p{ margin: 0 0 20px; }
#editorBody h2{ font-family: var(--font-display); font-size: 28px; margin: 32px 0 12px; color: var(--ink); }
#editorBody blockquote{
  border-left: 3px solid var(--oxblood); margin: 24px 0; padding: 4px 20px;
  font-family: var(--font-display); font-style: italic; font-size: 21px; color: var(--ink-soft);
}
#editorBody img{ border-radius: var(--radius-md); margin: 20px 0; }
.ql-toolbar.ql-snow{
  border: 1px solid var(--rule) !important; border-radius: var(--radius-md);
  background: var(--white); position: sticky; top: 74px; z-index: 5; margin-bottom: 20px;
}
.ql-container.ql-snow{ border:none !important; font-family: var(--font-body); }
.ql-editor{ padding: 0 !important; min-height: 380px; font-size: 18px; line-height:1.8; color:var(--ink-soft); }
.ql-editor.ql-blank::before{ font-style: normal; color: var(--ink-faint); }
.ql-editor h1, .ql-editor h2{ font-family: var(--font-display); color: var(--ink); }
.ql-editor blockquote{ border-left: 3px solid var(--oxblood); font-family: var(--font-display); font-style: italic; }

.editor-topbar{
  position: sticky; top:0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--rule);
  padding: 14px 24px; display:flex; align-items:center; justify-content: space-between;
}
.tag-input{ display:flex; flex-wrap:wrap; gap:8px; padding: 10px 14px; border:1px solid var(--rule); border-radius: var(--radius-md); background: var(--white); }
.tag-chip{ background: var(--brass-tint); color: var(--oxblood-deep); font-size: 12px; font-weight:600; padding: 4px 10px; border-radius: 999px; display:flex; align-items:center; gap:6px; }
.tag-chip button{ background:none; border:none; color: inherit; font-size: 14px; line-height:1; }
.tag-input input{ border:none; outline:none; background:none; flex:1; min-width: 120px; font-size:14px; }

/* ==========================================================================
   Single post page
   ========================================================================== */
.post-shell{ max-width: 720px; margin: 0 auto; padding: 48px 24px 100px; }
.post-kicker{ font-family: var(--font-mono); font-size: 12px; text-transform:uppercase; letter-spacing:0.08em; color: var(--brass); margin-bottom: 14px; }
.post-title{ font-family: var(--font-display); font-weight: 700; font-size: 46px; line-height:1.1; margin: 0 0 20px; }
.post-byline{ display:flex; align-items:center; gap: 12px; padding: 20px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-bottom: 32px; }
.post-byline .info{ flex:1; }
.post-byline .name{ font-weight:700; font-size:15px; }
.post-byline .date{ font-size: 13px; color: var(--ink-faint); }
.post-cover{ width:100%; border-radius: var(--radius-lg); margin-bottom: 36px; max-height: 460px; object-fit:cover; }
.post-content{ font-size: 19px; line-height: 1.85; color: var(--ink-soft); }
.post-content p{ margin: 0 0 24px; }
.post-content h2{ font-family: var(--font-display); font-size: 30px; color: var(--ink); margin: 40px 0 16px; }
.post-content blockquote{ border-left: 3px solid var(--oxblood); padding: 4px 22px; font-family: var(--font-display); font-style: italic; font-size: 22px; margin: 30px 0; }
.post-content img{ border-radius: var(--radius-md); margin: 28px 0; }
.post-content a{ color: var(--oxblood); text-decoration: underline; text-decoration-color: var(--brass); text-underline-offset: 3px; }
.post-actionbar{
  display:flex; align-items:center; justify-content: space-between; gap: 16px;
  padding: 20px 0; margin: 40px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.post-tags{ display:flex; gap: 8px; flex-wrap:wrap; margin-bottom: 40px; }
.post-tag{ background: var(--paper-dim); color: var(--ink-soft); font-size: 12px; font-weight:600; padding: 6px 12px; border-radius: 999px; }

.comments{ margin-top: 40px; }
.comments h3{ font-family: var(--font-display); font-size: 22px; margin-bottom: 24px; }
.comment-form{ display:flex; gap: 12px; margin-bottom: 32px; }
.comment-form textarea{
  flex:1; border: 1px solid var(--rule); border-radius: var(--radius-md); padding: 12px 14px;
  background: var(--white); resize: vertical; min-height: 48px; font-size:14px;
}
.comment{ display:flex; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--rule); }
.comment .bubble{ flex:1; }
.comment .name{ font-weight:700; font-size: 14px; margin-right:8px; }
.comment .time{ font-size: 12px; color: var(--ink-faint); }
.comment .text{ margin-top: 4px; font-size: 15px; color: var(--ink-soft); line-height:1.6; }

/* ==========================================================================
   Profile
   ========================================================================== */
.profile-header{ display:flex; align-items:flex-start; gap: 24px; padding: 44px 0 30px; border-bottom: 1px solid var(--rule); }
.profile-header .info{ flex:1; }
.profile-name{ font-family: var(--font-display); font-weight: 700; font-size: 32px; margin: 0 0 4px; }
.profile-handle{ color: var(--ink-faint); font-size: 14px; margin-bottom: 14px; }
.profile-bio{ color: var(--ink-soft); font-size: 15px; max-width: 520px; margin-bottom: 16px; }
.profile-stats{ display:flex; gap: 24px; font-size: 14px; }
.profile-stats b{ color: var(--ink); }
.profile-stats span{ color: var(--ink-faint); }

/* ==========================================================================
   Misc: empty states, toasts, modals, loaders
   ========================================================================== */
.empty-state{ text-align:center; padding: 80px 20px; color: var(--ink-faint); }
.empty-state h3{ font-family: var(--font-display); color: var(--ink); font-size: 22px; margin-bottom: 8px; }

.toast{
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 13px 22px; border-radius: 999px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.toast.show{ opacity: 1; transform: translateX(-50%) translateY(0); pointer-events:auto; }

.modal-overlay{
  position: fixed; inset: 0; background: rgba(32,28,26,0.5); z-index: 100;
  display:flex; align-items:center; justify-content:center; padding: 20px;
  opacity:0; pointer-events:none; transition: opacity .2s;
}
.modal-overlay.show{ opacity:1; pointer-events:auto; }
.modal{ background: var(--white); border-radius: var(--radius-lg); padding: 28px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.modal h3{ font-family: var(--font-display); margin: 0 0 8px; }
.modal p{ color: var(--ink-soft); font-size: 14px; margin-bottom: 22px; }
.modal-actions{ display:flex; gap: 10px; justify-content:flex-end; }

.spinner{
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--rule); border-top-color: var(--oxblood);
  animation: spin 0.8s linear infinite; margin: 60px auto;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

.skel{ background: linear-gradient(90deg, var(--paper-dim) 25%, var(--rule) 37%, var(--paper-dim) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-md); }
@keyframes shimmer{ 0%{background-position:100% 50%;} 100%{background-position:0 50%;} }

/* Mobile bottom nav (installed-app feel) */
.bottom-nav{
  display:none; position: fixed; bottom:0; left:0; right:0; z-index: 50;
  background: var(--white); border-top: 1px solid var(--rule);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  align-items:center; justify-content: space-around;
}
.bottom-nav a{ display:flex; flex-direction:column; align-items:center; gap:3px; color: var(--ink-faint); font-size: 10px; padding: 6px 10px; }
.bottom-nav a.active{ color: var(--oxblood); }
@media (max-width: 900px){ .bottom-nav{ display:flex; } }

.fab{
  position: fixed; bottom: 90px; right: 24px; width: 56px; height:56px; border-radius: 50%;
  background: var(--oxblood); color: var(--white); display:flex; align-items:center; justify-content:center;
  box-shadow: var(--shadow-lg); z-index: 45;
}
@media (min-width: 901px){ .fab{ display:none; } }

.hidden{ display: none !important; }
