/* ── Design Tokens ── */
:root {
    --red:     #B7382C;
    --red-3:   #DA5B4E;
    --ink:     #1B1410;
    --paper:   #F6EFE0;
    --serif:   "Spectral", Georgia, serif;
    --sans:    "IBM Plex Sans", system-ui, sans-serif;
    --mono:    "IBM Plex Mono", "Courier New", monospace;

    --ink-2:   rgba(27, 20, 16, 0.62);
    --ink-3:   rgba(27, 20, 16, 0.38);
    --ink-4:   rgba(27, 20, 16, 0.24);
    --paper-2: #EDE5D0;
    --paper-3: #E4DABC;
    --line:    rgba(27, 20, 16, 0.12);
}

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
        "topbar"
        "subnav"
        "main"
        "footer";
}

/* ── Container ── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ── Topbar ── */
.topbar {
    grid-area: topbar;
    background: var(--ink);
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 200;
    border-bottom: 1px solid rgba(246, 239, 224, 0.08);
}

.topbar-inner {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 0;
}

/* ── Brand ── */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 32px;
    white-space: nowrap;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--red-3);
    margin-right: 2px;
}

.brand-word {
    font-family: var(--serif);
    font-size: 1.3rem;
    line-height: 1;
    display: inline-flex;
    align-items: baseline;
    letter-spacing: -0.02em;
}

.brand-samo {
    font-style: italic;
    font-weight: 400;
    color: var(--paper);
}

.brand-lit {
    font-weight: 600;
    font-style: normal;
    letter-spacing: 0.02em;
    color: var(--red-3);
    margin-left: 1px;
}

.brand-sub {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    color: rgba(246, 239, 224, 0.55);
    text-transform: uppercase;
    padding-left: 10px;
    margin-left: 4px;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    display: none;
}

@media (min-width: 1180px) {
    .brand-sub {
        display: inline;
    }
}

/* ── Topbar Nav ── */
.topbar-nav {
    display: flex;
    align-items: stretch;
    height: 100%;
    flex: 1;
    gap: 0;
}

.topbar-nav a {
    display: flex;
    align-items: center;
    padding: 0 14px;
    font-size: 0.875rem;
    font-weight: 400;
    color: rgba(246, 239, 224, 0.7);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
}

.topbar-nav a:hover {
    color: var(--paper);
    background: rgba(246, 239, 224, 0.06);
}

.topbar-nav a.active {
    color: var(--paper);
    background: rgba(246, 239, 224, 0.08);
    border-bottom-color: var(--red);
}

/* ── Topbar Actions ── */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    background: var(--red);
    color: #fff;
    border: 1px solid var(--red);
    border-radius: 4px;
    font-family: var(--sans);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: #9e2e22;
    border-color: #9e2e22;
}

.btn.ghost {
    background: transparent;
    color: rgba(246, 239, 224, 0.8);
    border-color: rgba(246, 239, 224, 0.3);
}

.btn.ghost:hover {
    background: rgba(246, 239, 224, 0.08);
    color: var(--paper);
    border-color: rgba(246, 239, 224, 0.5);
}

.btn.sm {
    padding: 5px 12px;
    font-size: 0.8rem;
}

/* ── Hamburger ── */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: 8px;
}

.nav-hamburger span {
    display: block;
    height: 2px;
    background: var(--paper);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}

.nav-hamburger.is-open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.nav-hamburger.is-open span:nth-child(2) {
    opacity: 0;
}
.nav-hamburger.is-open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ── SubNav ── */
.subnav {
    grid-area: subnav;
    background: var(--paper-2);
    border-bottom: 1px solid var(--line);
    height: 36px;
}

.subnav-inner {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.subnav-inner::-webkit-scrollbar {
    display: none;
}

.subnav-inner a {
    font-size: 0.78rem;
    color: var(--ink-3);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s;
}

.subnav-inner a:hover {
    color: var(--ink);
}

.subnav-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--ink-4);
    flex-shrink: 0;
}

/* ── Language Switcher ── */
.lang-switcher {
    line-height: 1;
}

.lang-switcher select {
    appearance: none;
    background: transparent;
    border: 1px solid rgba(246, 239, 224, 0.25);
    border-radius: 4px;
    padding: 4px 24px 4px 8px;
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(246, 239, 224, 0.7);
    cursor: pointer;
    font-family: var(--sans);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='rgba(246,239,224,0.5)' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    transition: border-color 0.15s, color 0.15s;
}

.lang-switcher select:hover {
    border-color: var(--red-3);
    color: var(--paper);
}

.lang-switcher select option {
    background: var(--ink);
    color: var(--paper);
}

/* ── Main content area ── */
.site-main {
    grid-area: main;
}

.page-padded {
    padding-top: 32px;
    padding-bottom: 32px;
}

/* ── Cover + Book card system (shared across pages) ── */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 24px;
}

.book-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.cover-wrap {
    position: relative;
    width: 100%;
    padding-top: 150%;
    margin-bottom: 10px;
    transform-style: preserve-3d;
    transition: transform 0.2s ease;
}

.book-card:hover .cover-wrap {
    transform: perspective(800px) rotateY(-3deg);
}

.cover-front {
    position: absolute;
    inset: 0;
    background: var(--paper-3);
    overflow: hidden;
}

.cover-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cover-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--paper-3) 0%, var(--paper-2) 100%);
}

.cover-spine {
    position: absolute;
    right: -6px;
    top: 2px;
    bottom: 2px;
    width: 6px;
    background: rgba(27, 20, 16, 0.15);
    transform: rotateY(90deg) translateZ(-3px);
    transform-origin: left center;
}

.card-title {
    font-family: var(--serif);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--ink);
}

.card-author {
    font-size: 0.78rem;
    color: var(--ink-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.card-price {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink);
}

.card-price.free {
    color: var(--red);
}

.book-grid__more {
    display: flex;
    justify-content: center;
    margin-top: 32px;
}

/* ── Auth pages ── */
.auth-content {
    grid-area: main;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 24px;
}

.auth-card {
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.auth-card h1 {
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 28px;
    color: var(--ink);
}

.auth-card form > div {
    margin-bottom: 18px;
}

.auth-card label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 6px;
}

.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-size: 0.9rem;
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    transition: border-color 0.15s;
}

.auth-card input[type="email"]:focus,
.auth-card input[type="password"]:focus,
.auth-card input[type="text"]:focus {
    outline: none;
    border-color: var(--ink-3);
    background: #fff;
}

.auth-card input[type="email"].is-invalid,
.auth-card input[type="password"].is-invalid,
.auth-card input[type="text"].is-invalid {
    border-color: var(--red);
}

.auth-card span {
    display: block;
    font-size: 0.8rem;
    color: var(--red);
    margin-top: 4px;
}

.auth-card form a {
    font-size: 0.8rem;
    color: var(--ink-2);
    text-decoration: none;
}

.auth-card form a:hover {
    color: var(--ink);
    text-decoration: underline;
}

.auth-card .remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-card .remember-row label {
    margin-bottom: 0;
    font-weight: 400;
    color: var(--ink-2);
    cursor: pointer;
}

.auth-card button[type="submit"] {
    width: 100%;
    padding: 10px;
    background: var(--red);
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--sans);
    cursor: pointer;
    transition: background 0.15s;
}

.auth-card button[type="submit"]:hover {
    background: #9e2e22;
}

.auth-card > p {
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--ink-3);
    text-align: center;
}

.auth-card > p a {
    color: var(--ink);
    font-weight: 500;
}

/* ── Footer ── */
.site-footer {
    grid-area: footer;
    background: var(--ink);
    color: var(--paper);
    padding: 72px 0 24px;
}

.footer-grid {
    display: grid;
    grid-template-columns: 1.6fr repeat(4, 1fr);
    gap: 48px;
    margin-bottom: 56px;
}

.footer-brand-col .brand {
    margin-right: 0;
    margin-bottom: 16px;
    display: inline-flex;
}

.footer-brand-col .brand-word {
    font-size: 2.75rem;
}

.footer-brand-col .brand-mark svg {
    width: 48px;
    height: 37px;
}

.footer-about {
    color: rgba(246, 239, 224, 0.55);
    font-size: 14px;
    max-width: 38ch;
    line-height: 1.6;
}

.footer-heading {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(246, 239, 224, 0.55);
    font-weight: 500;
    margin-bottom: 16px;
}

.footer-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.footer-links a {
    color: rgba(246, 239, 224, 0.55);
    font-size: 14px;
    text-decoration: none;
}

.footer-links a:hover {
    color: var(--paper);
}

.footer-legal {
    display: flex;
    gap: 16px;
}

.footer-legal a {
    color: rgba(246, 239, 224, 0.4);
    text-decoration: none;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.footer-legal a:hover {
    color: rgba(246, 239, 224, 0.7);
}

.footer-bottom {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    color: rgba(246, 239, 224, 0.4);
    text-transform: uppercase;
}

@media (max-width: 900px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 32px;
    }

    .footer-brand-col {
        grid-column: 1 / -1;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
}

/* ── Profile Icon Button ── */
.topbar-profile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1.5px solid rgba(246, 239, 224, 0.28);
    color: rgba(246, 239, 224, 0.55);
    text-decoration: none;
    background: transparent;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.topbar-profile-btn:hover {
    border-color: rgba(246, 239, 224, 0.62);
    color: var(--paper);
    background: rgba(246, 239, 224, 0.07);
}

.topbar-profile-btn.active {
    border-color: var(--red-3);
    color: var(--paper);
    background: rgba(183, 56, 44, 0.15);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .topbar-inner {
        position: relative;
    }

    .nav-hamburger {
        display: flex;
    }

    .topbar-actions {
        gap: 6px;
    }

    .topbar-nav {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--ink);
        border-bottom: 1px solid rgba(246, 239, 224, 0.1);
        z-index: 100;
        flex-direction: column;
        height: auto;
        padding: 8px 0;
    }

    .topbar-nav.is-open {
        display: flex;
    }

    .topbar-nav a {
        padding: 10px 24px;
        border-bottom: none;
        border-left: 2px solid transparent;
    }

    .topbar-nav a.active {
        background: rgba(246, 239, 224, 0.06);
        border-left-color: var(--red);
        border-bottom: none;
    }

    .site-main {
        padding: 24px 0;
    }

    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 16px;
    }
}

@media (max-width: 480px) {
    .book-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}
