/* ========== Shared Sub-page Styles ==========
   Include in sub-pages via: <link rel="stylesheet" href="../assets/common.css">
   Set theme via: <body data-theme="primary|math|physics|senior-math|senior-physics|senior-chemistry">
   Override per-page styles in the page's own <style> block if needed.
*/

/* ===== Theme Tokens ===== */
[data-theme="primary"] {
    --c-main: #84cc16;
    --c-main-dark: #65a30d;
    --c-main-darker: #4d7c0f;
    --c-main-light: #bef264;
    --c-bg: #f7fee7;
    --c-rgba: 132,204,22;
}
[data-theme="math"] {
    --c-main: #22c55e;
    --c-main-dark: #16a34a;
    --c-main-darker: #15803d;
    --c-main-darkest: #166534;
    --c-main-light: #86efac;
    --c-bg: #f0fdf4;
    --c-bg2: #dcfce7;
    --c-rgba: 34,197,94;
}
[data-theme="physics"] {
    --c-main: #0ea5e9;
    --c-main-dark: #0284c7;
    --c-main-darker: #0369a1;
    --c-main-darkest: #075985;
    --c-main-light: #7dd3fc;
    --c-bg: #f0f9ff;
    --c-bg2: #e0f2fe;
    --c-rgba: 20,184,166;
}
[data-theme="science"] {
    --c-main: #3b82f6;
    --c-main-dark: #2563eb;
    --c-main-darker: #1d4ed8;
    --c-main-darkest: #1e40af;
    --c-main-light: #93c5fd;
    --c-bg: #eff6ff;
    --c-bg2: #dbeafe;
    --c-rgba: 59,130,246;
}
[data-theme="chemistry"] {
    --c-main: #f59e0b;
    --c-main-dark: #d97706;
    --c-main-darker: #b45309;
    --c-main-darkest: #92400e;
    --c-main-light: #fcd34d;
    --c-bg: #fffbeb;
    --c-bg2: #fef3c7;
    --c-rgba: 245,158,11;
}
[data-theme="senior-math"] {
    --c-main: #f97316;
    --c-main-dark: #ea580c;
    --c-main-darker: #c2410c;
    --c-main-darkest: #9a3412;
    --c-main-light: #fdba74;
    --c-bg: #fff7ed;
    --c-bg2: #ffedd5;
    --c-rgba: 249,115,22;
}
[data-theme="senior-physics"] {
    --c-main: #0891b2;
    --c-main-dark: #0e7490;
    --c-main-darker: #155e75;
    --c-main-darkest: #164e63;
    --c-main-light: #67e8f9;
    --c-bg: #ecfeff;
    --c-bg2: #cffafe;
    --c-rgba: 8,145,178;
}
[data-theme="senior-chemistry"] {
    --c-main: #16a34a;
    --c-main-dark: #15803d;
    --c-main-darker: #166534;
    --c-main-darkest: #14532d;
    --c-main-light: #86efac;
    --c-bg: #f0fdf4;
    --c-bg2: #dcfce7;
    --c-rgba: 22,163,74;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--c-bg);
    color: #1a2e22;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
    padding-top: 56px;
    -webkit-font-smoothing: antialiased;
}

/* ===== Back Button ===== */
.back-btn {
    position: fixed;
    top: 14px;
    left: 14px;
    padding: 8px 18px;
    border-radius: 8px;
    background: var(--c-main);
    color: #fff;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(var(--c-rgba), 0.35);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.back-btn:hover {
    background: var(--c-main-dark);
    transform: translateX(-3px);
}

.back-btn:focus-visible {
    outline: 2px solid var(--c-main);
    outline-offset: 2px;
}

/* ===== Title ===== */
h1 {
    color: var(--c-main-darker);
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}

.subtitle {
    color: var(--c-text-muted, #94a3b8);
    font-size: 0.85rem;
    margin-bottom: 14px;
    text-align: center;
}

/* ===== Container Card ===== */
.container {
    width: 740px;
    max-width: 100%;
    background: #fff;
    border-radius: 16px;
    padding: 22px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

/* ===== Equation Box ===== */
.equation-box {
    background: var(--c-bg, var(--c-bg2, #f0fdf4));
    color: var(--c-main-darker);
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 1px;
    min-width: 260px;
}

/* ===== Canvas ===== */
canvas {
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #fff;
    max-width: 100%;
    height: auto;
    box-shadow: 0 2px 12px rgba(var(--c-rgba), 0.1);
    display: block;
    touch-action: none;
}

canvas[style*="grab"] {
    cursor: grab;
}

canvas:active {
    cursor: grabbing;
}

/* ===== Info Cards ===== */
.info-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.info-card {
    background: var(--c-bg);
    border-radius: 10px;
    padding: 8px 16px;
    min-width: 90px;
    text-align: center;
    border: 1px solid var(--c-bg2, var(--c-main-light));
}

.info-card .value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--c-main);
}

.info-card .label {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 2px;
}

/* ===== Sliders ===== */
.sliders {
    display: flex;
    gap: 14px 24px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.slider-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8faf9;
    border-radius: 8px;
    padding: 8px 14px;
    min-width: 200px;
}

.slider-group label {
    font-size: 0.92rem;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

.slider-group input[type=range] {
    flex: 1;
    accent-color: var(--c-main);
    cursor: pointer;
    min-width: 80px;
}

.slider-group .val {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--c-main);
    min-width: 36px;
    text-align: right;
}

/* ===== Buttons ===== */
.controls-row,
.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-top: 4px;
}

button {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    background: var(--c-main);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

button:hover {
    background: var(--c-main-dark);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button.secondary {
    background: var(--c-bg2, #dcfce7);
    color: var(--c-main-darker);
}

button.secondary:hover {
    background: var(--c-main-light);
}

/* ===== Tab Buttons (in-page) ===== */
.tab-row,
.view-tabs,
.item-select {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.tab-btn,
.view-tab,
.item-btn,
.num-btn {
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

/* ===== Hint ===== */
.hint {
    color: #94a3b8;
    font-size: 0.78rem;
    text-align: center;
    line-height: 1.6;
    margin-top: 8px;
}

/* ===== Knowledge & Example Section ===== */
.knowledge {
    width: 740px;
    max-width: 100%;
    margin: 18px auto 8px;
    background: #fff;
    border-radius: 16px;
    padding: 22px 24px 24px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border-top: 4px solid var(--c-main);
    text-align: left;
}

.knowledge h2 {
    color: var(--c-main-darker);
    font-size: 1.05rem;
    font-weight: 700;
    margin: 20px 0 10px;
    padding-left: 12px;
    border-left: 4px solid var(--c-main);
}

.knowledge h2:first-child {
    margin-top: 0;
}

.knowledge ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.knowledge ul li {
    position: relative;
    padding: 7px 0 7px 24px;
    font-size: 0.9rem;
    line-height: 1.75;
    color: #334155;
    border-bottom: 1px dashed #eef2f7;
}

.knowledge ul li:last-child {
    border-bottom: none;
}

.knowledge ul li::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 15px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-bg, #fff);
    border: 2px solid var(--c-main);
}

.knowledge .kf {
    display: inline-block;
    background: var(--c-bg, #f8fafc);
    border: 1px solid var(--c-bg2, var(--c-main-light));
    border-radius: 6px;
    padding: 1px 9px;
    font-weight: 700;
    color: var(--c-main-darker);
    font-family: "Cambria Math", "Times New Roman", Georgia, serif;
    font-size: 0.98em;
    white-space: nowrap;
}

.knowledge .example {
    background: var(--c-bg, #f8fafc);
    border-radius: 12px;
    padding: 14px 16px;
    margin-top: 4px;
}

.knowledge .example + .example {
    margin-top: 12px;
}

.knowledge .ex-q {
    font-size: 0.92rem;
    line-height: 1.75;
    color: #1e293b;
    font-weight: 600;
    margin-bottom: 8px;
}

.knowledge .ex-q::before {
    content: '例题 ';
    color: var(--c-main-darker);
    font-weight: 700;
}

.knowledge .ex-sol {
    font-size: 0.88rem;
    line-height: 1.85;
    color: #475569;
}

.knowledge .ex-sol strong {
    color: var(--c-main-darker);
}

.knowledge .ex-ans {
    margin-top: 10px;
    font-weight: 700;
    color: var(--c-main-darker);
    background: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    border: 1px solid var(--c-bg2, var(--c-main-light));
    font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    body {
        padding: 8px;
        padding-top: 48px;
    }

    h1 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    .container {
        width: 100% !important;
        padding: 14px 10px;
        gap: 10px;
    }

    .equation-box {
        font-size: 1rem;
        padding: 8px 14px;
        min-width: auto;
        width: 100%;
    }

    .info-row {
        gap: 6px;
    }

    .info-card {
        min-width: 64px;
        padding: 6px 8px;
    }

    .info-card .value {
        font-size: 0.92rem;
    }

    .sliders {
        gap: 8px;
    }

    .slider-group {
        min-width: 100%;
    }

    .back-btn {
        top: 8px;
        left: 8px;
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    button {
        padding: 7px 14px;
        font-size: 0.82rem;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
