* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: 'Inter Tight', sans-serif;
    min-height: 100vh;
    color: var(--theme-text, #2b2545);
    background: var(--theme-bg, #ffffff);
    transition: background 0.7s ease, color 0.7s ease;
}

/* ---- Theme gradients ---- */
body.theme-about {
    --theme-bg: linear-gradient(135deg, #ffccb3 0%, #ffc4c7 35%, #ffb3d9 70%, #ffb3e6 100%);
    --theme-text: #5E1C45ED;
    --theme-shift-from: linear-gradient(135deg, #ffd9c8 0%, #ffc8d4 40%, #ffcaef 100%);
    --theme-shift-mid: linear-gradient(135deg, #ffbba0 0%, #ffb2c4 38%, #ffa8df 100%);
}

body.theme-math {
    --theme-bg: linear-gradient(135deg, #e2d8f0 0%, #daabe0 35%, #8beffc 100%);
    --theme-text: #662a81f5;
    --theme-shift-from: linear-gradient(135deg, #d3d9ff 0%, #cfbdf2 45%, #97f8ea 100%);
    --theme-shift-mid: linear-gradient(135deg, #dce1ff 0%, #c8b2ef 42%, #83efe0 100%);
}

body.theme-trading {
    --theme-bg: linear-gradient(135deg, #f99b8a 0%, #e4b182 25%, #cfc67a 50%, #b9db72 75%, #a4f16a 100%);
    --theme-text: #0a492b;
    --theme-shift-from: linear-gradient(135deg, #ff9c8e 0%, #efb57a 30%, #d8cc70 60%, #86e086 100%);
    --theme-shift-mid: linear-gradient(135deg, #ff8e81 0%, #ecaa6b 30%, #cadc6e 60%, #73d99b 100%);
}

body.theme-random {
    --theme-bg: linear-gradient(135deg, #b3e5fc 0%, #fff9c4 100%);
    --theme-text: #06426b9f;
    --theme-shift-from: linear-gradient(135deg, #9ed9ff 0%, #ffe7a8 100%);
    --theme-shift-mid: linear-gradient(135deg, #8fd4ff 0%, #ffde92 100%);
}

body.theme-shift {
    animation: themeShift 1.15s ease both;
}

@keyframes themeShift {
    0% {
        background: var(--theme-shift-from, var(--theme-bg));
    }
    55% {
        background: var(--theme-shift-mid, var(--theme-bg));
    }
    100% {
        background: var(--theme-bg);
    }
}

/* ---- Layout ---- */
.page {
    max-width: 1040px;
    margin: 0 auto;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 32px;
}

.brand {
    font-family: 'Fraunces', serif;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* ---- Tabs ---- */
.tabs {
    position: relative;
    display: flex;
    gap: 0;
    padding: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.tab {
    position: relative;
    z-index: 2;
    border: none;
    cursor: pointer;
    background: transparent;
    font-family: 'Inter Tight', sans-serif;
    font-size: 15px;
    font-weight: 500;
    padding: 8px 24px;
    border-radius: 999px;
    color: rgba(40, 40, 50, 0.6);
    transition: color 0.3s ease;
}

.tab.is-active { color: #5b3fa8; }
body.theme-trading .tab.is-active { color: #1a6b46; }
body.theme-about .tab.is-active { color: #b5642f; }
body.theme-random .tab.is-active { color: #5d8d9c; }

/* Sliding white pill behind the active tab */
.tab-pill {
    position: absolute;
    z-index: 1;
    top: 5px;
    left: 5px;
    height: calc(100% - 10px);
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1), width 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}

/* ---- Main content ---- */
.main {
    padding: 28px 32px 84px;
    transition: opacity 0.32s ease, transform 0.32s ease;
}

.section-content {
    display: none;
}

.section-content.is-active {
    display: block;
}

.main.is-leaving {
    opacity: 0;
    transform: translateY(14px);
}

.main.is-entering {
    opacity: 0;
    transform: translateY(14px);
}

.kicker {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.55;
    margin-bottom: 14px;
}

.headline {
    font-family: 'Fraunces', serif;
    font-size: clamp(40px, 8vw, 76px);
    font-weight: 500;
    line-height: 1.04;
    letter-spacing: -0.02em;
    margin: 0 0 16px;
    max-width: 16ch;
}

.blurb {
    font-size: 19px;
    line-height: 1.6;
    max-width: 72ch;
    opacity: 0.8;
    margin: 0 0 32px;
}

.detail-list {
    margin: 0 0 32px;
    padding-left: 24px;
}

.detail-item {
    font-size: 19px;
    line-height: 1.6;
    opacity: 0.8;
    margin-bottom: 8px;
}

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

.card {
    position: relative;
    padding: 22px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(10px);
    min-height: 136px;
    display: flex;
    flex-direction: column;
    /* staggered entrance */
    animation: cardIn 0.5s ease both;
    /* link reset + interactivity */
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

article.card {
    cursor: default;
}

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

.definition-card {
    min-height: 0;
    padding: 20px 20px 18px;
}

.definition-card .card-title {
    font-size: 21px;
    margin-bottom: 10px;
}

.definition-card .card-body {
    font-size: 16px;
    line-height: 1.55;
    opacity: 0.76;
}

.definition-card .card-arrow {
    display: none;
}

.definition-card-alt {
    background: rgba(255, 255, 255, 0.52);
}

.card:hover {
    transform: translateY(-4px);
    background: rgba(255, 255, 255, 0.6);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.1);
}

.card-arrow {
    position: absolute;
    right: 22px;
    bottom: 22px;
    font-size: 18px;
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.card:hover .card-arrow {
    opacity: 0.7;
    transform: translateX(0);
}

.card-tag {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.5;
    margin-bottom: 10px;
}

.card-title {
    font-family: 'Fraunces', serif;
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 8px;
}

.card-body {
    font-size: 15px;
    line-height: 1.5;
    opacity: 0.7;
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Detail pages ---- */
.detail {
    padding: 14px 32px 72px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    color: inherit;
    opacity: 0.7;
    padding: 7px 14px 7px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.back-link:hover {
    opacity: 1;
    transform: translateX(-3px);
}

.detail-body {
    max-width: 84ch;
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.year-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
}

.year-row.full-width {
    grid-template-columns: 1fr;
}

.season-section h3 {
    font-family: 'Fraunces', serif;
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.01em;
    margin: 0 0 10px;
}

.season-section ul {
    margin: 0 0 14px;
    padding-left: 22px;
}

.season-section li {
    font-size: 18px;
    line-height: 1.7;
    opacity: 0.78;
    margin-bottom: 8px;
}

.detail-body h2 {
    font-family: 'Fraunces', serif;
    font-size: 24px;
    font-weight: 500;
    letter-spacing: -0.01em;
    margin: 24px 0 8px;
}

.detail-body p {
    font-size: 18px;
    line-height: 1.7;
    opacity: 0.78;
    margin: 0 0 12px;
}

.detail-body ul {
    margin: 0 0 12px;
    padding-left: 22px;
}

.detail-body li {
    font-size: 18px;
    line-height: 1.7;
    opacity: 0.78;
    margin-bottom: 6px;
}

@media (max-width: 560px) {
    .header { flex-direction: column; gap: 18px; padding: 24px; }
    .main { padding: 24px 24px 80px; }
    .detail { padding: 16px 24px 90px; }
}

/* ---- Rudin chapter accordion ---- */
.chapter-wrap {
    max-width: 980px;
    margin: 0 auto;
    padding: 8px 32px 84px;
}

.chapter-intro {
    margin: 0 0 26px;
    font-size: 18px;
    line-height: 1.7;
    opacity: 0.82;
    max-width: 76ch;
}

.theorem-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.theorem-card {
    width: 100%;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(10px);
    overflow: hidden;
    transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.theorem-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.09);
}

.theorem-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border: none;
    background: transparent;
    color: inherit;
    text-align: left;
    padding: 18px 20px;
    cursor: pointer;
    font: inherit;
}

.theorem-toggle-title {
    font-family: 'Fraunces', serif;
    font-size: 24px;
    line-height: 1.2;
    margin: 0;
}

.theorem-toggle-subtitle {
    margin: 6px 0 0;
    font-size: 17px;
    line-height: 1.6;
    opacity: 0.82;
}

.theorem-chevron {
    flex: 0 0 auto;
    font-size: 20px;
    opacity: 0.65;
    transform: rotate(0deg);
    transition: transform 0.25s ease;
}

.theorem-card.is-open .theorem-chevron {
    transform: rotate(90deg);
}

.theorem-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
    background: rgba(255, 255, 255, 0.28);
}

.theorem-panel-inner {
    padding: 4px 20px 18px;
}

.theorem-block {
    border-radius: 12px;
    padding: 14px 14px 12px;
}

.theorem-block + .theorem-block {
    margin-top: 10px;
}

.theorem-block-statement {
    border-left: 4px solid rgba(102, 42, 129, 0.55);
    background: rgba(255, 255, 255, 0.58);
}

.theorem-block-proof {
    border: none;
    background: transparent;
    border-radius: 0;
    padding: 0;
}

.theorem-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 0 0 10px;
}

.theorem-block-statement .theorem-label {
    opacity: 0.75;
}

.theorem-block-proof .theorem-label {
    opacity: 0.55;
}

.theorem-text {
    margin: 0;
    font-size: 16px;
    line-height: 1.65;
    opacity: 0.9;
}

.theorem-proof p {
    margin: 0 0 12px;
    font-size: 17px;
    line-height: 1.65;
    opacity: 0.86;
}

.theorem-proof p:last-child {
    margin-bottom: 0;
}

.theorem-proof p:last-child::after {
    content: '\25A0';
    float: right;
    font-size: 1.35em;
    line-height: 1;
    margin-left: 10px;
    opacity: 0.95;
}

@media (max-width: 560px) {
    .chapter-wrap {
        padding: 8px 20px 72px;
    }

    .theorem-toggle {
        padding: 16px;
        gap: 14px;
    }

    .theorem-toggle-title {
        font-size: 22px;
    }

    .theorem-toggle-subtitle {
        margin-top: 6px;
        font-size: 16px;
    }

    .theorem-panel-inner {
        padding: 2px 18px 18px;
    }

    .theorem-block {
        padding: 14px;
    }
}
