/* =========================================================================
   Substack Notes-inspired design system
   ========================================================================= */

:root {
    /* Light mode */
    --bg:           #ffffff;
    --bg-elev:      #fafafa;
    --bg-hover:     #f3f3f1;
    --bg-active:    #ececea;
    --border:       #e6e6e2;
    --border-soft:  #efefec;
    --text:         #1a1a1a;
    --text-muted:   #6b6b6b;
    --text-faint:   #9a9a9a;
    --accent:       #ff6719;
    --accent-hover: #e85a10;
    --accent-soft:  rgba(255,103,25,0.10);
    --accent-ring:  rgba(255,103,25,0.35);
    --verified:     #ff6719;
    --shadow-card:  0 1px 2px rgba(0,0,0,0.04);
}

.dark {
    --bg:           #0b0b0b;
    --bg-elev:      #141414;
    --bg-hover:     #1a1a1a;
    --bg-active:    #222222;
    --border:       #232323;
    --border-soft:  #1a1a1a;
    --text:         #ffffff;
    --text-muted:   #a3a3a3;
    --text-faint:   #6b6b6b;
    --accent:       #ff6719;
    --accent-hover: #ff7a35;
    --accent-soft:  rgba(255,103,25,0.16);
    --accent-ring:  rgba(255,103,25,0.45);
    --verified:     #ff6719;
    --shadow-card:  0 1px 2px rgba(0,0,0,0.6);
}

/* -------------------------------------------------------------------------
   Base
   ------------------------------------------------------------------------- */

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "ss01", "cv11";
}

.font-serif,
.title-serif {
    font-family: "Source Serif Pro", "Source Serif 4", Georgia, "Times New Roman", serif;
    letter-spacing: -0.01em;
}

/* Scrollbar */
::-webkit-scrollbar          { width: 10px; height: 10px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* -------------------------------------------------------------------------
   Layout shell — left rail pinned to viewport edge, content centered
   ------------------------------------------------------------------------- */

:root {
    --rail-left:   232px;
    --rail-right:  320px;
    --col-main:    640px;
}

.app-shell {
    min-height: 100vh;
    /* Reserve gutters for the fixed left/right rails */
    padding-left:  var(--rail-left);
    padding-right: 0;
}
@media (min-width: 1200px) {
    .app-shell { padding-right: var(--rail-right); }
}
@media (max-width: 1023px) {
    .app-shell { padding-left: 0; }
}

/* Left rail — fixed to the left viewport edge */
.left-rail {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--rail-left);
    height: 100vh;
    padding: 14px 12px 12px;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 30;
}
@media (max-width: 1023px) {
    .left-rail { display: none; }
    .left-rail.is-open {
        display: flex;
        width: 280px;
        z-index: 60;
        box-shadow: 0 0 40px rgba(0,0,0,0.4);
    }
}

/* Center column — centered within the available space between rails */
.center-col {
    width: 100%;
    max-width: var(--col-main);
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    min-height: 100vh;
    background: var(--bg);
}
@media (max-width: 1023px) {
    .center-col { border-left: none; border-right: none; padding-bottom: 70px; }
}

/* Right rail — fixed to the right viewport edge */
.right-rail {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--rail-right);
    height: 100vh;
    padding: 20px 18px;
    overflow-y: auto;
}
@media (max-width: 1199px) {
    .right-rail { display: none; }
}

/* -------------------------------------------------------------------------
   Left rail nav — Substack Notes style
   ------------------------------------------------------------------------- */

.brand-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 4px 4px 18px;
    color: var(--accent);
}
.brand-link svg { width: 28px; height: 28px; }

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-height: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 10px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 500;
    line-height: 1.2;
    transition: background 0.12s, color 0.12s;
}
.nav-item:hover         { background: var(--bg-hover); color: var(--text); }
.nav-item svg           { width: 22px; height: 22px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.75; }
.nav-item.active        { color: var(--text); font-weight: 700; }
.nav-item.active svg    { fill: currentColor; stroke-width: 0; }

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 6px;
}

.nav-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
    min-width: 18px;
    text-align: center;
}

/* Create CTA */
.btn-create {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 16px;
    padding: 12px 16px;
    border-radius: 6px;
    width: 100%;
    margin-top: 8px;
    transition: background 0.12s;
}
.btn-create:hover { background: var(--accent-hover); color: #fff; }
.btn-create svg   { width: 12px; height: 12px; fill: currentColor; }

/* "More" footer entry */
.nav-more {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 10px;
    margin-top: 12px;
    border-top: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}
.nav-more svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.nav-more:hover { color: var(--accent); }

/* User chip */
.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    margin-top: 6px;
    transition: background 0.12s;
}
.user-chip:hover     { background: var(--bg-hover); }
.user-chip .meta     { line-height: 1.2; min-width: 0; }
.user-chip .name     { font-weight: 600; font-size: 13px; color: var(--text); }
.user-chip .handle   { font-size: 12px; color: var(--text-muted); }

/* -------------------------------------------------------------------------
   Center column header
   ------------------------------------------------------------------------- */

.feed-header {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
}
.feed-header h1, .feed-header h2 {
    font-size: 18px;
    font-weight: 700;
    padding: 14px 0;
    margin: 0;
}

.feed-tabs {
    display: flex;
    gap: 4px;
    padding: 4px 0 0;
}
.feed-tab {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: color 0.12s, border-color 0.12s;
}
.feed-tab:hover    { color: var(--text); }
.feed-tab.is-active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* -------------------------------------------------------------------------
   Compose / tweet box
   ------------------------------------------------------------------------- */

.compose {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.compose textarea {
    width: 100%;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 15px;
    line-height: 1.4;
    resize: vertical;
    min-height: 56px;
    transition: border-color 0.12s, background 0.12s;
}
.compose textarea::placeholder { color: var(--text-muted); }
.compose textarea:focus {
    outline: none;
    border-color: var(--accent-ring);
    background: var(--bg);
}
.compose-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}
.compose-tools {
    display: flex;
    gap: 4px;
    color: var(--accent);
}
.compose-tools label {
    cursor: pointer;
    padding: 7px;
    border-radius: 6px;
    transition: background 0.12s;
}
.compose-tools label:hover { background: var(--accent-soft); }

/* -------------------------------------------------------------------------
   Note item (replaces "tweet")
   ------------------------------------------------------------------------- */

.note-item {
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    cursor: pointer;
}
.note-item:hover           { background: var(--bg-elev); }
.note-item.is-readonly     { cursor: default; }

.note-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.note-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-active);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-weight: 700;
}
.note-avatar img { width: 100%; height: 100%; object-fit: cover; }

.note-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.3;
}
.note-meta .name {
    color: var(--text);
    font-weight: 600;
}
.note-meta .name:hover { text-decoration: underline; }
.note-meta .handle, .note-meta .time, .note-meta .country, .note-meta .desc { color: var(--text-muted); }
.note-meta .dot { color: var(--text-faint); }

.note-body {
    margin-top: 4px;
    font-size: 15.5px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}
.note-body a {
    color: var(--accent);
    text-decoration: none;
}
.note-body a:hover { text-decoration: underline; }

.note-image {
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-elev);
}
.note-image img {
    width: 100%;
    max-height: 540px;
    object-fit: cover;
    display: block;
}

/* Embedded / quoted note */
.note-embed {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    background: var(--bg);
    transition: background 0.1s;
}
.note-embed:hover { background: var(--bg-elev); }
.note-embed-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.note-embed-head .avatar { width: 18px; height: 18px; border-radius: 50%; overflow: hidden; background: var(--bg-active); }
.note-embed-head .name { color: var(--text); font-weight: 600; }
.note-embed-body { font-size: 14px; color: var(--text); line-height: 1.45; white-space: pre-wrap; word-break: break-word; }

/* Link card */
.link-card {
    display: block;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: background 0.1s;
}
.link-card:hover { background: var(--bg-elev); }
.link-card .image { width: 100%; height: 160px; overflow: hidden; background: var(--bg-elev); }
.link-card .image img { width: 100%; height: 100%; object-fit: cover; }
.link-card .body { padding: 12px 14px; }
.link-card .domain { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.link-card .title { font-size: 14.5px; font-weight: 700; color: var(--text); line-height: 1.3; margin-bottom: 4px; }
.link-card .desc { font-size: 13px; color: var(--text-muted); line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Verified / source / agg badges */
.note-badge {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}
.note-badge.verified svg { fill: var(--verified); }
.note-badge.source   svg { fill: #d97706; }
.note-badge.agg      svg { fill: #8b5cf6; }

/* Action bar */
.note-actions {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 13px;
}
.note-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.12s, color 0.12s;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: inherit;
}
.note-action svg { width: 18px; height: 18px; fill: currentColor; }
.note-action:hover            { background: var(--bg-hover); color: var(--text); }
.note-action.is-liked         { color: var(--accent); }
.note-action.is-liked:hover   { color: var(--accent-hover); background: var(--accent-soft); }
.note-action.is-retweeted     { color: #16a34a; }

.note-retweet-banner {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-left: 24px;
}
.note-retweet-banner svg { width: 14px; height: 14px; fill: currentColor; }

/* -------------------------------------------------------------------------
   Right rail
   ------------------------------------------------------------------------- */

.search-input {
    position: relative;
    margin-bottom: 18px;
}
.search-input svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    fill: var(--text-muted);
    pointer-events: none;
}
.search-input input {
    width: 100%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 9px 14px 9px 38px;
    font-size: 14px;
    transition: background 0.12s, border-color 0.12s;
}
.search-input input::placeholder { color: var(--text-muted); }
.search-input input:focus {
    outline: none;
    border-color: var(--accent-ring);
    background: var(--bg);
}

.rs-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}
.rs-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.rs-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}
.rs-card-link {
    font-size: 13px;
    color: var(--text-muted);
}
.rs-card-link:hover { color: var(--accent); }

.rs-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}
.rs-row + .rs-row { border-top: 1px solid var(--border-soft); padding-top: 12px; margin-top: 6px; }
.rs-row .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-active);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}
.rs-row .avatar img { width: 100%; height: 100%; object-fit: cover; }
.rs-row .meta { flex: 1; min-width: 0; line-height: 1.2; }
.rs-row .meta .name { font-weight: 600; font-size: 14px; color: var(--text); }
.rs-row .meta .name:hover { text-decoration: underline; }
.rs-row .meta .sub { font-size: 12px; color: var(--text-muted); }
.rs-rank {
    width: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
}

/* Hashtag list */
.hashtag-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 7px 0;
    font-size: 14px;
}
.hashtag-row + .hashtag-row { border-top: 1px solid var(--border-soft); }
.hashtag-row a { font-weight: 600; color: var(--text); }
.hashtag-row a:hover { color: var(--accent); }
.hashtag-row .count { color: var(--text-muted); font-size: 13px; }

/* -------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-primary    { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ghost      { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-subscribe  {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 5px 14px;
    font-size: 13px;
    border-radius: 6px;
}
.btn-subscribe:hover { background: var(--accent); color: #fff; }
.btn-block { width: 100%; }
.btn-lg    { padding: 11px 22px; font-size: 15px; }

/* -------------------------------------------------------------------------
   Mobile header & bottom nav
   ------------------------------------------------------------------------- */

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    padding: 0 12px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 50;
    align-items: center;
    justify-content: space-between;
}
@media (max-width: 1023px) {
    .mobile-header { display: flex; }
    .app-shell    { padding-top: 52px; }
}
.mobile-header .icon-btn {
    padding: 8px;
    border-radius: 8px;
    color: var(--text);
}
.mobile-header .icon-btn:hover { background: var(--bg-hover); }

/* Mobile FAB */
.fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--accent);
    color: #fff;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: 0 6px 20px rgba(255,103,25,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
}
.fab:hover { background: var(--accent-hover); color: #fff; }
@media (min-width: 1024px) { .fab { display: none; } }

/* Mobile sidebar overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 55;
    display: none;
}
.sidebar-overlay.is-visible { display: block; }
@media (min-width: 1024px) { .sidebar-overlay { display: none !important; } }

/* -------------------------------------------------------------------------
   Forms (login / register / edit_profile)
   ------------------------------------------------------------------------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    background: var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 28px;
    box-shadow: var(--shadow-card);
}
.auth-card h1 {
    font-size: 24px;
    font-weight: 800;
    margin: 0 0 4px;
    text-align: center;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}
.field input,
.field textarea,
.field select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    transition: border-color 0.12s, background 0.12s;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent-ring);
    background: var(--bg);
}

/* Generic content / static page wrapper */
.prose-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 20px 80px;
    color: var(--text);
}
.prose-page h1 { font-size: 28px; font-weight: 800; margin: 0 0 16px; }
.prose-page h2 { font-size: 20px; font-weight: 700; margin: 28px 0 10px; }
.prose-page h3 { font-size: 16px; font-weight: 700; margin: 20px 0 6px; }
.prose-page p, .prose-page li { font-size: 15px; line-height: 1.65; color: var(--text); margin-bottom: 12px; }
.prose-page a { color: var(--accent); }
.prose-page a:hover { text-decoration: underline; }
.prose-page ul { padding-left: 22px; margin-bottom: 14px; }

/* Famous strip */
.famous-card {
    margin: 14px 18px;
    padding: 14px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.famous-card .head {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 12px;
    font-weight: 700; font-size: 14px;
    color: var(--text);
}
.famous-card .head svg { width: 16px; height: 16px; fill: var(--accent); }
.famous-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.famous-cell {
    display: flex; flex-direction: column; align-items: center;
    width: 64px; gap: 4px;
    text-align: center;
}
.famous-cell .avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-active);
    transition: box-shadow 0.12s;
}
.famous-cell:hover .avatar { box-shadow: 0 0 0 2px var(--accent); }
.famous-cell .avatar img { width: 100%; height: 100%; object-fit: cover; }
.famous-cell .label { font-size: 11px; line-height: 1.2; color: var(--text); }

/* Loading spinner */
.spinner-wrap { padding: 24px; text-align: center; }
.spinner {
    display: inline-block;
    width: 28px; height: 28px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Misc utilities */
.hidden        { display: none !important; }
.line-clamp-5  { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.show-more-btn {
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    background: none;
    border: 0;
    padding: 4px 0;
    cursor: pointer;
}
.show-more-btn:hover { text-decoration: underline; }
