/* ==========================================================================
   CSS Architecture for "Kekse im Iran"
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design Tokens & State Machine Variables
   -------------------------------------------------------------------------- */
:root {
    /* Core Typography */
    --font-latin: 'IBM Plex Sans', sans-serif;
    --font-arabic: 'IBM Plex Arabic', sans-serif;
    
    /* Base Font Sizing */
    --text-base: 1.125rem;
    --text-h1: 2.5rem;
    
    /* Fluid (Past) vs Restricted (Present) Properties */
    --line-height-fluid: 1.6;
    --line-height-restricted: 1.3;
    --container-max-width-fluid: 680px;
    --container-max-width-restricted: 500px;

    /* Theme: Light (Default) */
    --color-bg-light: #f7f5f0; /* Dusty, warm off-white */
    --color-text-light: #1a1a1a; /* Warm espresso-black */
    --color-accent-light: #b5651d; /* Dusty terracotta/gold */
    --color-bg-light-cold: #ffffff; /* Harsh paper-white */
    --color-text-light-cold: #000000; /* Pure digital black */

    /* Theme: Dark */
    --color-bg-dark: #1e1e1e; /* Rich charcoal */
    --color-text-dark: #f0ecd8; /* Soft cream */
    --color-accent-dark: #d4a373; /* Warm dust */
    --color-bg-dark-cold: #000000; /* Pitch black */
    --color-text-dark-cold: #ffffff; /* Glaring white */

    /* Structural / Layout */
    --margin-fluid: 2rem;
    --margin-restricted: 1rem;
    
    /* Drawer */
    --drawer-width: 350px;
    --z-index-topbar: 2500;
    --z-index-drawer: 2000;
    --z-index-overlay: 1500;
}

/* --------------------------------------------------------------------------
   2. State Machine Implementation
   -------------------------------------------------------------------------- */

/* Default: Light Theme */
body {
    --current-bg: var(--color-bg-light);
    --current-text: var(--color-text-light);
    --current-accent: var(--color-accent-light);
    --current-accent-rgb: 181, 101, 29;
    --current-margin: var(--margin-fluid);
    --current-max-width: var(--container-max-width-fluid);
    --current-line-height: var(--line-height-fluid);
    --current-text-align: justify;
    --site-easing: cubic-bezier(0.4, 0, 0.2, 1);
}

body[data-theme="dark"] {
    --current-bg: var(--color-bg-dark);
    --current-text: var(--color-text-dark);
    --current-accent: var(--color-accent-dark);
    --current-accent-rgb: 212, 163, 115;
    --current-margin: var(--margin-fluid);
    --current-max-width: var(--container-max-width-fluid);
    --current-line-height: var(--line-height-fluid);
    --current-text-align: justify;
}

.chapter {
    width: 100vw;
    margin-inline-start: calc(-50vw + 50%);
    padding: 6rem var(--current-margin);
    background-color: var(--current-bg);
    color: var(--current-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}

.chapter[data-tense="present"] {
    --current-bg: var(--color-bg-light-cold);
    --current-text: var(--color-text-light-cold);
    --current-accent: #7f8c8d; /* Dead flat gray */
    --current-margin: var(--margin-restricted);
    --current-max-width: var(--container-max-width-restricted);
    --current-line-height: var(--line-height-restricted);
    --current-text-align: left;
}

body[data-theme="dark"] .chapter[data-tense="present"] {
    --current-bg: var(--color-bg-dark-cold);
    --current-text: var(--color-text-dark-cold);
    --current-accent: #5e6b73; /* Dead flat gray */
    --current-margin: var(--margin-restricted);
    --current-max-width: var(--container-max-width-restricted);
    --current-line-height: var(--line-height-restricted);
    --current-text-align: left;
}

/* RTL Override */
html[dir="rtl"] {
    font-family: var(--font-arabic);
}

/* Mobile Typography & Spacing Optimization */
@media (max-width: 768px) {
    :root {
        --text-base: 1.0625rem; /* 17px - better for narrow columns */
        --text-h1: 1.85rem;    /* Prevents excessive wrapping of chapter titles */
        --line-height-restricted: 1.4; /* Slightly more air for mobile restricted state */
    }

    /* Disable native pinch-zoom; main.js converts pinch into font-size scaling.
       Smaller root font on mobile sets a tighter default; pinch can scale up. */
    html {
        touch-action: pan-x pan-y;
        font-size: 12px;
    }

    #manuscript-container h1 {
        margin-top: 2.5rem;
        margin-bottom: 1.5rem;
    }

    #manuscript-container p {
        margin-bottom: 1.25rem;
    }

    #manuscript-container h1,
    #manuscript-container p,
    .discuss-wrapper {
        padding: 0 1.25rem; /* Slightly less padding on mobile to give text more room */
    }
}

/* --------------------------------------------------------------------------
   3. Base Styles & Reset
   -------------------------------------------------------------------------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-latin);
    font-size: var(--text-base);
    line-height: var(--line-height-fluid);
    background-color: var(--current-bg);
    color: var(--current-text);
    overflow-x: hidden;
}

#hero {
    position: relative;
    width: 100vw;
    height: 100vh;
    background-image: url('Pics/1.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed; /* Parallax effect */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #fff;
}

@media (max-width: 768px) {
    #hero {
        background-attachment: scroll;
        background-image: url('Pics/mobile/1.jpg');
    }
}

#hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.hero-content {
    position: relative;
    z-index: 10;
}

#hero h1 {
    font-size: clamp(3rem, 8vw, 6rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
    text-transform: uppercase;
    color: var(--color-text-dark); /* Soft cream for both views */
}

.subtitle {
    font-size: 1.25rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    opacity: 0.9;
    color: var(--color-text-dark);
}

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.8;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

.arrow-down {
    width: 0; 
    height: 0; 
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #fff;
}

/* --------------------------------------------------------------------------
   5. Smart Top Bar
   -------------------------------------------------------------------------- */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: var(--current-bg);
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    z-index: var(--z-index-topbar);
    transition: transform 0.3s ease;
}

#top-bar.hidden {
    transform: translateY(-100%);
}

.top-bar-left, .top-bar-center, .top-bar-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.top-bar-center {
    display: none; /* Hide on smaller screens */
}

#book-title {
    font-weight: bold;
    cursor: pointer;
}

@media (min-width: 768px) {
    .top-bar-center { display: flex; }
}

#bottom-bar {
    display: none;
}

@media (max-width: 768px) {
    #bottom-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        background-color: var(--current-bg);
        border-top: 1px solid rgba(128, 128, 128, 0.2);
        justify-content: space-around;
        align-items: center;
        padding: 0 1rem;
        z-index: var(--z-index-topbar);
        transition: transform 0.3s ease;
    }

    #bottom-bar.hidden {
        transform: translateY(100%);
    }

    #main-content {
        padding-bottom: 80px; /* Space for bottom bar */
    }
}

button, .nav-link {
    background: none;
    border: none;
    color: var(--current-text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    transition: color 0.3s ease;
}

button:hover, .nav-link:hover {
    color: var(--current-accent);
}

select {
    background: transparent;
    border: 1px solid var(--current-text);
    color: var(--current-text);
    padding: 0.25rem 0.5rem;
    font-family: inherit;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   6. Manuscript Container & Typography
   -------------------------------------------------------------------------- */
#page-wrapper {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#main-content {
    display: flex;
    justify-content: center;
    padding: 0;
}

#page-wrapper.drawer-open-fullscreen {
    transform: translateX(-100vw);
}
html[dir="rtl"] #page-wrapper.drawer-open-fullscreen {
    transform: translateX(100vw);
}

#manuscript-container {
    width: 100%;
}

#manuscript-container h1, 
#manuscript-container p, 
#manuscript-container ul,
#manuscript-container .discuss-wrapper {
    width: 100%;
    max-width: var(--current-max-width);
    line-height: var(--current-line-height);
}

#manuscript-container h1 {
    font-size: var(--text-h1);
    margin-top: 4rem;
    margin-bottom: 2rem;
    font-weight: 600;
    scroll-margin-top: 80px; /* Offset for the smart top-bar */
}

#manuscript-container h1:first-child {
    margin-top: 0;
}

#manuscript-container p {
    margin-bottom: 1.5rem;
    text-align: var(--current-text-align);
    hyphens: auto;
    -webkit-hyphens: auto;
}

@media (max-width: 768px) {
    #manuscript-container p {
        text-align: start;
    }
}

#manuscript-container ul {
    margin-bottom: 1.5rem;
    padding-inline-start: 1.5rem;
}

#manuscript-container li {
    margin-bottom: 0.5rem;
}

.airlock {
    width: 100vw;
    height: 100vh;
    margin-inline-start: calc(-50vw + 50%);
    background-image: var(--bg-desktop);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    cursor: zoom-in;
    transition: opacity 0.5s ease;
}

@media (max-width: 768px) {
    .airlock {
        background-image: var(--bg-mobile);
        background-size: contain;
        background-repeat: no-repeat;
        background-color: var(--current-bg);
        background-attachment: scroll;
    }
}

.airlock-portrait {
    background-size: contain;
    background-repeat: no-repeat;
    background-color: var(--current-bg); 
}

/* --------------------------------------------------------------------------
   8. Lightbox for Photos
   -------------------------------------------------------------------------- */
#lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: zoom-out;
}

#lightbox.visible {
    display: flex;
    opacity: 1;
}

#lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
}

#lightbox-close {
    position: absolute;
    top: 2rem;
    right: 2rem;
    color: #fff;
    font-size: 3rem;
    line-height: 1;
    cursor: pointer;
    background: none;
    border: none;
}

.discuss-wrapper {
    margin-top: 3rem;
    margin-bottom: 1rem;
    text-align: end;
}

.discuss-btn {
    border: none;
    padding: 0.5rem 0;
    font-size: 0.8rem;
    color: var(--current-text);
    opacity: 0.4;
    transition: opacity 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.discuss-btn:hover {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   7. Mechanical Drawers
   -------------------------------------------------------------------------- */
.drawer {
    position: fixed;
    top: 0;
    padding-top: 60px; /* Offset for top-bar */
    /* Logical property: right for LTR, left for RTL */
    inset-inline-end: calc(-1 * var(--drawer-width));
    width: var(--drawer-width);
    height: 100dvh;
    background-color: var(--current-bg);
    border-inline-start: 1px solid rgba(128, 128, 128, 0.2);
    z-index: var(--z-index-drawer);
    transition: inset-inline-end 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.drawer.fullscreen {
    width: 100vw;
    inset-inline-end: -100vw;
}

.drawer.open {
    inset-inline-end: 0;
}

#drawer-book {
    inset-inline-end: auto;
    inset-inline-start: calc(-1 * var(--drawer-width));
    border-inline-start: none;
    border-inline-end: 1px solid rgba(128, 128, 128, 0.2);
    transition: inset-inline-start 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#drawer-book.open {
    inset-inline-start: 0;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.drawer-content {
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    flex-grow: 1;
}

#drawer-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: var(--z-index-overlay);
    opacity: 0;
    pointer-events: none;
}

#drawer-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Chapter Index Links */
.chapter-link {
    display: block;
    padding: 0.75rem 0;
    color: var(--current-text);
    text-decoration: none;
    border-bottom: 1px solid rgba(128, 128, 128, 0.1);
    transition: color 0.3s ease;
}
.chapter-link:hover {
    color: var(--current-accent);
}

/* --------------------------------------------------------------------------
   9. Progress Indicator
   -------------------------------------------------------------------------- */
#progress-indicator {
    position: fixed;
    z-index: 2800; /* Above topbar but below drawers */
    display: flex;
    gap: 2px;
}

body.drawer-open-fullscreen #progress-indicator {
    display: none;
}

/* Mobile: Vertical line of segments on the start side */
@media (max-width: 768px) {
    #progress-indicator {
        top: 100px; /* Fixed distance to avoid sliding on scroll */
        inset-inline-start: 10px;
        transform: none;
        flex-direction: column;
        gap: 3px;
    }
    
    .progress-segment {
        width: 4px;
        height: 15px;
        background-color: rgba(128, 128, 128, 0.2);
        cursor: pointer;
        transition: background-color 0.3s, height 0.3s;
        border-radius: 2px;
        position: relative;
    }
    
    /* Increase tap target area for mobile */
    .progress-segment::after {
        content: '';
        position: absolute;
        top: -4px;
        bottom: -4px;
        left: -15px;
        right: -15px;
    }
    
    .progress-segment.active {
        background-color: var(--current-accent);
        height: 22px;
    }
    
    .progress-segment.passed {
        background-color: var(--current-accent);
        opacity: 0.6;
    }
    
    body[data-state="present"] .progress-segment.active, 
    body[data-state="present"] .progress-segment.passed {
        background-color: #7f8c8d; /* Match present light accent */
    }
    
    body[data-theme="dark"][data-state="present"] .progress-segment.active, 
    body[data-theme="dark"][data-state="present"] .progress-segment.passed {
        background-color: #5e6b73; /* Match present dark accent */
    }
    
    /* Tooltip for mobile on press */
    .progress-segment::before {
        content: attr(data-title);
        position: absolute;
        inset-inline-start: 35px; /* Moved further right to clear the finger */
        top: 50%;
        transform: translateY(-50%) scale(0.9);
        background-color: var(--current-bg);
        color: var(--current-text);
        padding: 6px 10px;
        border-radius: 4px;
        font-size: 0.85rem;
        font-weight: 600;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.05s ease-out, transform 0.05s ease-out; /* Much faster appearance */
        border: 1px solid rgba(128, 128, 128, 0.2);
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
        z-index: 2900;
    }
    
    .progress-segment:active::before,
    .progress-segment.touch-active::before {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

/* Desktop: Vertical line of segments on the end side */
@media (min-width: 769px) {
    #progress-indicator {
        top: 50%;
        inset-inline-end: 20px;
        transform: translateY(-50%);
        flex-direction: column;
        gap: 6px;
    }

    .progress-segment {
        width: 6px;
        height: 22px;
        background-color: rgba(128, 128, 128, 0.3);
        cursor: pointer;
        transition: all 0.3s ease;
        border-radius: 3px;
        position: relative;
    }

    .progress-segment:hover {
        background-color: var(--current-accent);
        width: 10px;
    }

    .progress-segment.active {
        background-color: var(--current-accent);
        height: 34px;
    }
    
    .progress-segment.passed {
        background-color: var(--current-accent);
        opacity: 0.6;
    }
    
    body[data-state="present"] .progress-segment.active,
    body[data-state="present"] .progress-segment.passed {
        background-color: #7f8c8d; /* Match present light accent */
    }
    
    body[data-theme="dark"][data-state="present"] .progress-segment.active,
    body[data-theme="dark"][data-state="present"] .progress-segment.passed {
        background-color: #5e6b73; /* Match present dark accent */
    }
    
    body[data-state="present"] .progress-segment:hover {
        background-color: #7f8c8d;
    }
    
    body[data-theme="dark"][data-state="present"] .progress-segment:hover {
        background-color: #5e6b73;
    }
    
    /* Tooltip for desktop */
    .progress-segment::before {
        content: attr(data-title);
        position: absolute;
        inset-inline-end: 15px; /* Distance from the segment */
        top: 50%;
        transform: translateY(-50%);
        background-color: var(--current-bg);
        color: var(--current-text);
        padding: 6px 10px;
        border-radius: 4px;
        font-size: 0.9rem;
        font-weight: 600;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s, transform 0.3s;
        border: 1px solid rgba(128, 128, 128, 0.2);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    
    .progress-segment:hover::before {
        opacity: 1;
    }
}

/* --------------------------------------------------------------------------
   N. Comments UI (drawer-comments content)
   -------------------------------------------------------------------------- */
/* Comments: density + polish.
   The single most impactful rule is `.comments-root { font-size: 0.9rem }` —
   the subtree uses em-based sizes, so shrinking the root cascades everywhere. */
.comments-root {
    font-size: 0.9rem;
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    max-width: 720px;
    margin-inline: auto;
}

.comments-switcher {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.comments-switcher .chapter-select-label {
    font-weight: 600;
    opacity: 0.85;
}
.comments-switcher .chapter-select {
    flex: 1;
    min-width: 0;
    padding: 0.35rem 0.55rem;
    background: var(--current-bg);
    color: var(--current-text);
    border: 1px solid rgba(128, 128, 128, 0.3);
    border-radius: 6px;
    font: inherit;
    transition: border-color 0.2s var(--site-easing),
                background-color 0.2s var(--site-easing),
                box-shadow 0.2s var(--site-easing);
}

.comments-identity[hidden] { display: none; }
.comments-identity {
    padding: 0.45rem 0.65rem;
    background: rgba(128, 128, 128, 0.08);
    border-radius: 6px;
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}
.comments-identity .identity-name { font-weight: 600; }

.verified-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1em;
    height: 1em;
    padding: 0 0.25em;
    border-radius: 999px;
    background: var(--current-accent);
    color: var(--current-bg);
    font-size: 0.7em;
    font-weight: 700;
    line-height: 1;
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.comments-loading, .comments-empty, .comments-error {
    padding: 1rem;
    text-align: center;
    opacity: 0.7;
}
.comments-empty {
    padding: 1.2rem 1rem;
    opacity: 0.65;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.comments-empty-icon {
    opacity: 0.5;
    color: var(--current-accent);
}
.comments-error { color: #b00; opacity: 1; }

.comment-group {
    padding-block: 0.2rem 0.35rem;
}
.comment-group + .comment-group {
    border-top: 1px solid rgba(128, 128, 128, 0.1);
    margin-top: 0.55rem;
    padding-top: 0.55rem;
}

.comment {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.65rem;
    row-gap: 0.1rem;
    align-items: start;
    padding: 0.3rem 0.45rem 0.3rem 0.7rem;
    border-inline-start: 2px solid var(--current-accent);
    border-radius: 0 4px 4px 0;
    transition: background-color 0.2s var(--site-easing);
}
.comment:hover { background: rgba(128, 128, 128, 0.04); }
.comment + .comment { margin-top: 0.35rem; }
.comment.comment-reply {
    margin-inline-start: 1.1rem;
    border-inline-start: 1px solid rgba(128, 128, 128, 0.22);
    padding-inline-start: 0.65rem;
}

.comment-avatar {
    grid-row: 1 / span 2;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: 600 0.82rem / 1 'IBM Plex Sans', sans-serif;
    background-color: var(--current-accent);
    background-image: linear-gradient(
        135deg,
        hsl(var(--avatar-hue, 30), 38%, 65%),
        hsl(calc(var(--avatar-hue, 30) + 30), 48%, 52%)
    );
    color: var(--current-bg);
    user-select: none;
    flex: 0 0 auto;
    position: relative;
    overflow: hidden;
}
.comment-avatar[data-color="none"] {
    background: rgba(128, 128, 128, 0.12);
    color: rgba(128, 128, 128, 0.5);
    box-shadow: inset 0 0 0 1.5px rgba(128, 128, 128, 0.3);
}

.comment-reply .comment-avatar {
    width: 1.6rem;
    height: 1.6rem;
    font-size: 0.72rem;
}

.comment-head {
    grid-column: 2;
    display: flex;
    gap: 0.4rem;
    align-items: baseline;
    flex-wrap: wrap;
}
.comment-author { font-weight: 600; }
.comment-time {
    opacity: 0.55;
    font-size: 0.78em;
}

.comment-body {
    grid-column: 2;
    margin: 0.2rem 0 0.15rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 1.5;
}
.comment-body a {
    color: var(--current-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.comment-actions {
    grid-column: 2;
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
    margin-top: 0.05rem;
    margin-inline-start: -0.3rem; /* offset the button's small padding so the row left-aligns to body */
}
.comment-actions button {
    background: transparent;
    border: 0;
    color: inherit;
    padding: 0.05rem 0.3rem;
    font: inherit;
    font-size: 0.78em; /* match .comment-time — these are metadata, not controls */
    cursor: pointer;
    opacity: 0.5;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    transition: background-color 0.2s var(--site-easing),
                opacity 0.2s var(--site-easing);
}
.comment-actions button:hover {
    opacity: 1;
    background: rgba(128, 128, 128, 0.1);
}

/* Form */
.comments-root input:focus-visible,
.comments-root textarea:focus-visible,
.comments-root select:focus-visible,
.comment-actions button:focus-visible,
.comments-verify-modal input:focus-visible {
    outline: 2px solid var(--current-accent);
    outline-offset: 1px;
}

.form-field input:not([type="checkbox"]):focus-visible,
.form-field textarea:focus-visible,
.verify-code-input:focus-visible {
    outline: none;
    border-color: var(--current-accent);
    box-shadow: 0 0 0 3px rgba(var(--current-accent-rgb, 181, 101, 29), 0.18);
}

.comment-form {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid rgba(128, 128, 128, 0.2);
    border-radius: 8px;
    background: rgba(128, 128, 128, 0.04);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03),
                0 6px 18px -10px rgba(0, 0, 0, 0.06);
}
body[data-theme="dark"] .comment-form { background: rgba(128, 128, 128, 0.06); }
.comment-form .hp {
    position: absolute;
    inset-inline-start: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}
.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.form-field > span { font-weight: 600; opacity: 0.85; font-size: 0.88em; }
.form-field input:not([type="checkbox"]),
.form-field textarea,
.verify-code-input {
    padding: 0.45rem 0.55rem;
    border: 1px solid rgba(128, 128, 128, 0.3);
    border-radius: 6px;
    background: var(--current-bg);
    color: var(--current-text);
    font: inherit;
    width: 100%;
    transition: border-color 0.2s var(--site-easing),
                background-color 0.2s var(--site-easing),
                box-shadow 0.2s var(--site-easing);
}
.form-field textarea { resize: vertical; min-height: 3.75rem; line-height: 1.5; }
.form-field-checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.form-field-checkbox input[type="checkbox"] {
    width: 1.05rem;
    height: 1.05rem;
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--current-accent);
    cursor: pointer;
}
.form-field-checkbox > span { font-weight: 400; flex: 1; min-width: 0; }
.form-hint {
    opacity: 0.7;
    font-size: 0.82em;
    line-height: 1.4;
}
.form-reply-indicator[hidden] { display: none; }
.form-reply-indicator {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.35rem 0.55rem;
    background: rgba(var(--current-accent-rgb, 181, 101, 29), 0.08);
    border-inline-start: 2px solid var(--current-accent);
    border-radius: 4px;
    font-size: 0.88em;
}
.form-reply-indicator button {
    background: transparent;
    border: 1px solid rgba(128, 128, 128, 0.35);
    color: inherit;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font: inherit;
    font-size: 0.82em;
    cursor: pointer;
    margin-inline-start: auto;
    opacity: 0.75;
    transition: background-color 0.2s var(--site-easing),
                opacity 0.2s var(--site-easing);
}
.form-reply-indicator button:hover {
    opacity: 1;
    background: rgba(128, 128, 128, 0.1);
}
.form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.comment-form button[type="submit"],
.verify-submit {
    background: var(--current-accent);
    color: var(--current-bg);
    border: none;
    padding: 0.45rem 0.95rem;
    border-radius: 6px;
    font: inherit;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    transition: transform 0.15s var(--site-easing),
                box-shadow 0.2s var(--site-easing),
                opacity 0.2s var(--site-easing);
}
.comment-form button[type="submit"]:hover:not(:disabled),
.verify-submit:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(var(--current-accent-rgb, 181, 101, 29), 0.25);
}
.comment-form button[type="submit"]:active:not(:disabled),
.verify-submit:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.comment-form button[type="submit"]:disabled,
.verify-submit:disabled { opacity: 0.5; cursor: wait; }
.verify-cancel {
    background: transparent;
    border: 1px solid rgba(128, 128, 128, 0.35);
    color: inherit;
    padding: 0.45rem 0.85rem;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
    transition: background-color 0.2s var(--site-easing);
}
.verify-cancel:hover { background: rgba(128, 128, 128, 0.1); }
.form-status, .verify-status {
    font-size: 0.82em;
    opacity: 0.8;
    min-height: 1.1em;
}
.form-status.error, .verify-status.error {
    color: #b00;
    opacity: 1;
}
.form-footer { font-size: 0.82em; opacity: 0.7; }
.form-footer a { color: inherit; text-decoration: underline; }

/* Verify modal */
.comments-verify-modal[hidden] { display: none; }
.comments-verify-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.comments-verify-box {
    background: var(--current-bg);
    color: var(--current-text);
    border-radius: 10px;
    padding: 1.05rem 1.05rem 0.85rem;
    max-width: 380px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.verify-code-input {
    font-size: 1.25rem;
    letter-spacing: 0.4em;
    text-align: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    box-shadow: inset 0 -2px 0 rgba(var(--current-accent-rgb, 181, 101, 29), 0.25);
}

/* Comment skeleton (loading state) */
.comment-skeleton {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.65rem;
    row-gap: 0.35rem;
    align-items: start;
    padding: 0.3rem 0.45rem 0.3rem 0.7rem;
    border-inline-start: 2px solid rgba(128, 128, 128, 0.2);
    border-radius: 0 4px 4px 0;
}
.comment-skeleton + .comment-skeleton { margin-top: 0.35rem; }
.comment-skeleton-avatar {
    grid-row: 1 / span 2;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 999px;
    background: rgba(128, 128, 128, 0.18);
}
.comment-skeleton-line {
    grid-column: 2;
    height: 0.7rem;
    border-radius: 4px;
    background: rgba(128, 128, 128, 0.15);
}
.comment-skeleton-line.short { width: 35%; }
.comment-skeleton-line.long { width: 80%; height: 0.85rem; }

/* Motion: kept lean and gated behind prefers-reduced-motion. */
@media (prefers-reduced-motion: no-preference) {
    @keyframes commentFadeIn {
        from { opacity: 0; transform: translateY(4px); }
        to { opacity: 1; transform: translateY(0); }
    }
    @keyframes modalBackdropFade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    @keyframes modalBoxIn {
        from { opacity: 0; transform: scale(0.96); }
        to { opacity: 1; transform: scale(1); }
    }
    @keyframes replyIndicatorIn {
        from { opacity: 0; transform: translateY(-4px); }
        to { opacity: 1; transform: translateY(0); }
    }
    @keyframes skeletonShimmer {
        0% { background-position: -200px 0; }
        100% { background-position: calc(200px + 100%) 0; }
    }

    .comment.is-new {
        animation: commentFadeIn 0.28s var(--site-easing) both;
    }
    /* Light cascade for initial load: stagger up to 5 comments so they fan in. */
    .comment.is-new:nth-child(1) { animation-delay: 0ms; }
    .comment.is-new:nth-child(2) { animation-delay: 40ms; }
    .comment.is-new:nth-child(3) { animation-delay: 80ms; }
    .comment.is-new:nth-child(4) { animation-delay: 120ms; }
    .comment.is-new:nth-child(5) { animation-delay: 160ms; }

    .comments-verify-modal:not([hidden]) {
        animation: modalBackdropFade 0.22s var(--site-easing) both;
    }
    .comments-verify-modal:not([hidden]) .comments-verify-box {
        animation: modalBoxIn 0.24s var(--site-easing) both;
    }

    .form-reply-indicator:not([hidden]) {
        animation: replyIndicatorIn 0.2s var(--site-easing) both;
    }

    .comment-skeleton-avatar,
    .comment-skeleton-line {
        background: linear-gradient(
            90deg,
            rgba(128, 128, 128, 0.12) 0%,
            rgba(128, 128, 128, 0.22) 50%,
            rgba(128, 128, 128, 0.12) 100%
        );
        background-size: 200px 100%;
        background-repeat: no-repeat;
        animation: skeletonShimmer 1.6s var(--site-easing) infinite;
    }
}
