/* ==========================================================================
   SE NOTES - ARTICLE READING PAGE (W3SCHOOLS ICONIC DESIGN)
   ========================================================================== */

:root {
    --w3-green: #04AA6D;
    --w3-green-hover: #059862;
    --w3-green-soft: #e8f5e9;
    --w3-dark-bg: #1e293b;
}

:root[data-theme="dark"] {
    --w3-green: #04AA6D;
    --w3-green-hover: #22c55e;
    --w3-green-soft: rgba(4, 170, 109, 0.15);
    --w3-dark-bg: #0d1117;
}

.reading-progress { 
    position: fixed; 
    z-index: 100; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 3px; 
    background: var(--w3-green); 
    transform: scaleX(0); 
    transform-origin: left; 
}

.article-shell { 
    width: min(100% - 32px, 1400px); 
    margin: auto; 
    padding: 24px 0 96px; 
    display: grid; 
    grid-template-columns: 240px minmax(0, 780px) 220px; 
    justify-content: center; 
    gap: 32px; 
}

.article-rail { min-width: 0; }

/* ==========================================================================
   W3SCHOOLS LEFT TUTORIAL SIDEBAR (DESKTOP)
   ========================================================================== */
.w3-sidebar {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 96px);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    overflow: hidden;
}
.w3-sidebar__title {
    padding: 12px 16px;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    font-size: .8rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}
.w3-sidebar__title i { color: #f89820; font-size: 1.1em; }

.w3-sidebar__list {
    padding: 6px 4px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.w3-lesson-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 500;
    line-height: 1.35;
    text-decoration: none !important;
    transition: all .15s ease;
}
.w3-lesson-num {
    flex-shrink: 0;
    font-family: var(--mono);
    font-size: .68rem;
    font-weight: 700;
    opacity: .7;
}
.w3-lesson-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.w3-lesson-link:hover {
    background: var(--surface-soft);
    color: var(--ink);
}
.w3-lesson-link.is-active {
    background: var(--w3-green) !important;
    color: #ffffff !important;
    font-weight: 700;
}
.w3-lesson-link.is-active .w3-lesson-num { opacity: 1; color: #ffffff; }

/* ==========================================================================
   W3SCHOOLS TOP & BOTTOM ACTION BARS (< PREV / NEXT >)
   ========================================================================== */
.w3-top-nav { margin-bottom: 18px; }
.w3-nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.w3-nav-bar--top {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}
.w3-nav-bar--bottom {
    margin: 36px 0 24px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.w3-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    min-height: 40px;
    border-radius: 6px;
    font-family: var(--sans);
    font-size: .84rem;
    font-weight: 700;
    text-decoration: none !important;
    cursor: pointer;
    transition: all .2s;
}
.w3-btn--prev {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    color: var(--ink);
}
.w3-btn--prev:hover { background: var(--line); }
.w3-btn--next {
    background: var(--w3-green);
    border: 1px solid var(--w3-green);
    color: #ffffff !important;
}
.w3-btn--next:hover {
    background: var(--w3-green-hover);
    transform: translateX(2px);
}
.w3-btn--disabled {
    background: var(--surface-soft);
    color: var(--muted);
    opacity: .5;
    cursor: not-allowed;
    border: 1px solid transparent;
}

/* ==========================================================================
   BREADCRUMB & INLINE TOC
   ========================================================================== */
.breadcrumb-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    font-size: .78rem;
    color: var(--muted);
}
.breadcrumb-nav a { color: var(--muted); }
.breadcrumb-nav a:hover { color: var(--w3-green); }
.breadcrumb-nav .divider { font-size: .6rem; opacity: .6; }
.breadcrumb-nav .current { color: var(--ink); font-weight: 600; }

.inline-toc {
    margin: 20px 0 28px;
    padding: 16px 20px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--w3-green);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
}
.inline-toc__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--ink);
    font-size: .88rem;
    font-weight: 800;
}
.inline-toc__content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.inline-toc__content a {
    color: var(--ink);
    font-size: .82rem;
    line-height: 1.45;
    text-decoration: none !important;
}
.inline-toc__content .toc-h3 {
    padding-left: 16px;
    font-size: .78rem;
    color: var(--muted);
}
.inline-toc__content a:hover {
    color: var(--w3-green);
    text-decoration: underline !important;
}

/* ==========================================================================
   RIGHT SIDEBAR (PAGE TOC)
   ========================================================================== */
.toc-card { 
    position: sticky; 
    top: 76px; 
    padding: 16px; 
    border: 1px solid var(--line); 
    border-radius: var(--radius-md);
    background: var(--surface);
}
.toc-card > span { 
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px; 
    color: var(--ink); 
    font-size: .75rem; 
    font-weight: 800; 
    text-transform: uppercase; 
}
#toc-links a { 
    color: var(--muted); 
    font-size: .75rem; 
    line-height: 1.45; 
    padding: 4px 6px;
    border-radius: 4px;
    display: block;
}
#toc-links .toc-h3 { padding-left: 12px; font-size: .7rem; }
#toc-links a:hover { color: var(--w3-green); background: var(--surface-soft); }
#toc-links a.is-active { color: var(--w3-green); font-weight: 700; background: var(--w3-green-soft); }

#copy-link { 
    margin-top: 12px; 
    width: 100%;
    padding: 6px 10px; 
    border: 1px solid var(--line); 
    border-radius: 6px;
    background: var(--surface-soft); 
    color: var(--ink); 
    font-size: .72rem; 
    font-weight: 600; 
    cursor: pointer; 
}
#copy-link:hover { border-color: var(--w3-green); color: var(--w3-green); }

/* ==========================================================================
   MOBILE QUICK BAR & DRAWER (TOUCH-OPTIMIZED)
   ========================================================================== */
.mobile-quick-bar {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}
.mobile-quick-btn {
    padding: 8px 14px;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font-size: .8rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
}
.mobile-quick-btn i { color: var(--w3-green); }

.mobile-toc { display: none; }

.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
}
.mobile-drawer.is-open { display: block; }
.mobile-drawer__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}
.mobile-drawer__content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.25);
    animation: slideUp .25s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.mobile-drawer__header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
}
.mobile-drawer__header h3 { margin: 0; font-size: .95rem; font-weight: 800; }
.mobile-drawer__header i { color: #f89820; }
.mobile-drawer__close {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: .9rem;
    cursor: pointer;
}
.mobile-drawer__list {
    padding: 12px 14px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ==========================================================================
   PROSE & CONTENT TYPOGRAPHY
   ========================================================================== */
.prose { 
    color: var(--ink); 
    font-family: var(--sans); 
    font-size: 1rem; 
    line-height: 1.8; 
    overflow-wrap: break-word; 
}

.prose .article-kicker { 
    margin-bottom: 10px; 
    display: flex; 
    flex-wrap: wrap; 
    gap: 6px; 
}
.prose .article-kicker span {
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--w3-green-soft);
    color: var(--w3-green);
    font-size: .68rem;
    font-weight: 700;
}

.prose h1 { 
    margin: 0 0 12px; 
    font-size: clamp(1.6rem, 3.2vw, 2.2rem); 
    font-weight: 800; 
    line-height: 1.25; 
    letter-spacing: -.02em;
}
.prose .article-meta { 
    margin-bottom: 20px; 
    padding-bottom: 14px; 
    display: flex; 
    flex-wrap: wrap; 
    gap: 12px 18px; 
    border-bottom: 1px solid var(--line); 
    color: var(--muted); 
    font-size: .78rem; 
}
.prose .article-meta span { display: inline-flex; align-items: center; gap: 6px; }

.prose h2 { 
    margin: 1.8em 0 .5em; 
    font-size: 1.38rem; 
    font-weight: 800; 
    line-height: 1.35; 
    border-bottom: 1px solid var(--line);
    padding-bottom: 6px;
}
.prose h3 { 
    margin: 1.4em 0 .35em; 
    font-size: 1.12rem; 
    font-weight: 700; 
}

.prose p { margin: .9em 0; }
.prose strong { color: var(--ink); font-weight: 700; }
.prose a { color: var(--w3-green); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.prose ul, .prose ol { padding-left: 20px; margin: .9em 0; }
.prose li { margin: 5px 0; }
.prose hr { margin: 28px 0; border: 0; border-top: 1px solid var(--line); }

/* W3Schools Note & Callouts */
.prose blockquote { 
    margin: 18px 0; 
    padding: 14px 18px; 
    border-left: 4px solid var(--w3-green); 
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface-soft); 
    color: var(--ink); 
    font-size: .92rem;
    line-height: 1.6;
}
.prose blockquote p { margin: 0; }

/* Images & Diagrams */
.prose img { 
    max-width: 100%; 
    height: auto; 
    margin: 20px auto; 
    display: block; 
    border: 1px solid var(--line); 
    border-radius: var(--radius-md); 
    background: var(--surface); 
    padding: 4px;
}

/* W3Schools Code Blocks with Mobile Touch Scroll */
.prose code { 
    padding: 2px 5px; 
    border-radius: 4px; 
    background: var(--surface-soft); 
    color: #e83e8c; 
    font-family: var(--mono); 
    font-size: .86em; 
    font-weight: 600;
}
:root[data-theme="dark"] .prose code { color: #f472b6; }

.prose pre { 
    position: relative;
    margin: 18px 0; 
    padding: 16px 18px; 
    border: 1px solid rgba(255, 255, 255, 0.1) !important; 
    border-radius: var(--radius-md); 
    background: var(--w3-dark-bg) !important; 
    color: #e6edf3 !important; 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
}
.prose pre code { 
    padding: 0; 
    border-radius: 0; 
    background: transparent !important; 
    color: #e6edf3 !important; 
    font-family: var(--mono); 
    font-size: .84rem; 
    font-weight: 400;
    line-height: 1.6; 
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 3px 8px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    color: #ffffff;
    font-family: var(--sans);
    font-size: .68rem;
    font-weight: 600;
    cursor: pointer;
}
.code-copy-btn:hover { background: var(--w3-green); }

/* Mermaid Diagrams */
.prose .mermaid {
    margin: 20px 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    display: flex;
    justify-content: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tables with Touch Horizontal Scroll */
.prose table { 
    width: 100%; 
    margin: 20px 0; 
    border-collapse: collapse; 
    border: 1px solid var(--line); 
    font-size: .86rem; 
    display: table;
}
.prose th, .prose td { 
    padding: 8px 12px; 
    border: 1px solid var(--line); 
    text-align: left; 
}
.prose th { 
    background: var(--surface-soft); 
    color: var(--ink); 
    font-weight: 700;
}
.prose tr:nth-child(even) { background: color-mix(in srgb, var(--surface-soft) 50%, transparent); }

/* Author & Related Section */
.author-box { 
    margin: 32px 0; 
    padding: 18px; 
    display: grid; 
    grid-template-columns: 50px 1fr; 
    align-items: center; 
    gap: 14px; 
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-soft); 
}
.author-box img { 
    width: 50px;
    height: 50px;
    border-radius: 50%; 
    object-fit: cover; 
}
.author-label { color: var(--w3-green); font-size: .68rem; font-weight: 700; text-transform: uppercase; }
.author-box h2 { margin: 2px 0; font-size: 1rem; font-weight: 700; }
.author-box p { margin: 0; color: var(--muted); font-size: .78rem; }

.related-section { margin-top: 36px; }
.related-section > h2 { margin: 4px 0 16px; font-size: 1.25rem; font-weight: 800; }
.related-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.related-card { 
    padding: 14px 16px; 
    border: 1px solid var(--line); 
    border-radius: var(--radius-sm); 
    background: var(--surface); 
    text-decoration: none !important; 
    transition: all .15s; 
}
.related-card:hover { border-color: var(--w3-green); transform: translateY(-2px); }
.related-card > span { color: var(--w3-green); font-size: .65rem; font-weight: 700; text-transform: uppercase; }
.related-card h3 { margin: 4px 0; color: var(--ink); font-size: .88rem; font-weight: 700; }
.related-card p { margin: 0; display: -webkit-box; overflow: hidden; color: var(--muted); font-size: .75rem; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

/* ==========================================================================
   RESPONSIVE BREAKPOINTS (MOBILE FIRST UX)
   ========================================================================== */
@media (max-width: 1140px) {
    .article-shell { grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
    .article-rail--right { display: none; }
}

@media (max-width: 860px) {
    .article-shell { width: min(100% - 24px, 760px); grid-template-columns: 1fr; padding-top: 14px; }
    .article-rail--left { display: none; }
    .mobile-quick-bar { display: grid; }
    .mobile-toc { 
        display: block; 
        margin-bottom: 16px; 
        padding: 10px 14px; 
        border: 1px solid var(--line); 
        border-radius: 6px; 
        background: var(--surface); 
        font-size: .82rem; 
    }
    .mobile-toc summary { cursor: pointer; font-weight: 700; }
    #mobile-toc-links { margin-top: 8px; }
}

@media (max-width: 480px) {
    .prose { font-size: .95rem; }
    .prose h1 { font-size: 1.55rem; }
    .prose h2 { font-size: 1.25rem; }
    .w3-nav-bar { flex-direction: column; gap: 8px; }
    .w3-btn { width: 100%; justify-content: center; }
    .author-box { grid-template-columns: 1fr; text-align: center; justify-items: center; }
    .related-grid { grid-template-columns: 1fr; }
}