* {
    box-sizing: border-box;
}

:root {
    color-scheme: light;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    width: min(92vw, 520px);
    padding: clamp(24px, 6vw, 42px);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.24);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(14px);
    text-align: center;
}

.auth-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

h1 {
    margin: 16px 0 10px;
    font-size: clamp(36px, 10vw, 58px);
    line-height: 1.15;
    letter-spacing: 0.08em;
    text-shadow: 0 4px 18px rgba(0, 0, 0, 0.24);
}

h2 {
    margin: 0 0 10px;
    color: #33255f;
    font-size: 28px;
    text-align: center;
}

.auth-desc {
    margin: 0 0 24px;
    color: rgba(255, 255, 255, 0.92);
    line-height: 1.7;
}

.auth-form {
    display: grid;
    gap: 16px;
}

.auth-field {
    display: grid;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    text-align: left;
}

.auth-field span {
    padding-left: 4px;
}

.auth-modal .auth-field {
    color: #3b2a68;
}

.auth-field input {
    width: 100%;
    border: 0;
    outline: none;
    border-radius: 18px;
    padding: 16px 18px;
    font-size: 16px;
    color: #30265a;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.auth-field input::placeholder {
    color: #8b86a8;
}

.auth-note {
    margin: 16px 0 0;
    color: #fff7c7;
    font-size: 13px;
    line-height: 1.6;
    text-align: center;
}

.auth-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 14px;
}

.auth-btn {
    min-height: 52px;
    border: 0;
    border-radius: 16px;
    padding: 14px 10px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    text-align: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.auth-btn.full-width {
    width: 100%;
}

.auth-btn.compact {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 42px;
    padding: 10px 8px;
    font-size: 14px;
}

.auth-btn:hover,
.auth-btn:focus {
    transform: translateY(-2px);
}

.auth-btn:disabled {
    opacity: 0.68;
    cursor: wait;
    transform: none;
}

.auth-btn.primary {
    color: #fff;
    background: linear-gradient(135deg, #ffb347 0%, #ff7b54 100%);
    box-shadow: 0 10px 24px rgba(255, 123, 84, 0.32);
}

.auth-btn.secondary {
    color: #3b2a68;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}

.auth-btn.ghost {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
}

.auth-message {
    min-height: 28px;
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    line-height: 1.6;
    text-align: center;
}

.auth-message.success {
    background: rgba(60, 180, 120, 0.2);
}

.auth-message.error {
    background: rgba(255, 95, 95, 0.18);
}

.auth-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
}

.auth-modal.open {
    display: flex;
}

.auth-modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(18, 14, 42, 0.58);
    backdrop-filter: blur(8px);
}

.auth-modal-card {
    position: relative;
    z-index: 1;
    width: min(92vw, 460px);
    padding: 30px;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.auth-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    color: #3b2a68;
    background: #f0edff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.auth-modal-desc {
    margin: 0 0 20px;
    color: #6a5c91;
    line-height: 1.7;
    text-align: center;
}

.library-shell {
    position: relative;
    align-items: stretch;
    padding: clamp(72px, 10vh, 94px) 24px 24px;
}

.library-card {
    width: min(92vw, 880px);
    height: min(78vh, 820px);
    min-height: 540px;
    margin: 0 auto;
    padding: clamp(18px, 4vw, 30px);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.24);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.library-fixed-head {
    flex: 0 0 auto;
}

.library-title {
    margin: 10px 0 12px;
    font-size: clamp(28px, 6vw, 42px);
    letter-spacing: 0.06em;
}

.library-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.library-tab,
.level-filter-btn {
    min-height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 999px;
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.library-tab.active,
.level-filter-btn.active {
    color: #432c78;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 236, 168, 0.96) 100%);
    box-shadow: 0 10px 22px rgba(31, 24, 75, 0.18);
}

.library-tab:hover,
.library-tab:focus-visible,
.level-filter-btn:hover,
.level-filter-btn:focus-visible {
    transform: translateY(-1px);
    outline: none;
}

.level-filter {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.level-filter[hidden] {
    display: none;
}

.level-filter-btn {
    min-height: 36px;
    padding: 8px 10px;
    font-size: 13px;
}

.library-scroll {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 14px;
    padding: 0 4px 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.library-scroll::-webkit-scrollbar {
    width: 8px;
}

.library-scroll::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.34);
}

.library-load-hint {
    padding: 14px 8px 2px;
    color: rgba(255, 255, 255, 0.82);
    font-size: 13px;
    font-weight: 800;
    text-align: center;
}

.library-back-button {
    position: fixed;
    top: max(18px, env(safe-area-inset-top));
    right: max(18px, env(safe-area-inset-right));
    z-index: 20;
    width: clamp(46px, 12vw, 58px);
    height: clamp(46px, 12vw, 58px);
    border: 1px solid rgba(255, 255, 255, 0.46);
    border-radius: 50%;
    color: #4b2d83;
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.98), rgba(255, 246, 207, 0.88) 42%, rgba(255, 183, 77, 0.94) 100%);
    box-shadow: 0 14px 34px rgba(34, 20, 82, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.82);
    font-size: clamp(24px, 6vw, 32px);
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.library-back-button:hover,
.library-back-button:focus-visible {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 18px 40px rgba(34, 20, 82, 0.34), inset 0 2px 0 rgba(255, 255, 255, 0.9);
    outline: none;
}

.library-back-button span {
    transform: translateX(-1px);
}

.library-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}

.library-item {
    display: grid;
    gap: 10px;
    min-height: 142px;
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    color: #3b2a68;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
    transition: min-height 0.22s ease, box-shadow 0.18s ease;
}

.library-item.expanded {
    min-height: 190px;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
}

.library-item-header {
    display: grid;
    grid-template-columns: minmax(42px, 1fr) auto auto auto;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.library-item-title-wrap {
    display: grid;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
}

.library-item h3 {
    max-width: 100%;
    margin: 0;
    overflow: hidden;
    font-size: 20px;
    line-height: 1.25;
    letter-spacing: clamp(0, 0.5vw, 0.04em);
    white-space: nowrap;
}

.library-level-badge {
    width: fit-content;
    max-width: 100%;
    padding: 3px 7px;
    border-radius: 999px;
    color: #5f3dc4;
    background: #f0edff;
    overflow: hidden;
    font-size: 10px;
    font-weight: 900;
}

.library-count {
    flex: 0 0 auto;
    color: #8b86a8;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.library-action-btn {
    width: 5em;
    min-width: 5em;
    min-height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 6px 14px rgba(102, 126, 234, 0.22);
    font-size: 11px;
    font-weight: 900;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.library-action-btn:hover,
.library-action-btn:focus-visible {
    transform: translateY(-1px);
    outline: none;
}

.library-action-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    transform: none;
}

.library-explanation-wrap {
    position: relative;
    display: grid;
    align-items: start;
    padding-right: 28px;
}

.library-item-explanation {
    display: -webkit-box;
    min-height: 1.65em;
    margin: 6px 0 0;
    overflow: hidden;
    color: #5c567a;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.65;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
}

.library-item.expanded .library-item-explanation {
    display: block;
    overflow: visible;
    -webkit-line-clamp: unset;
}

.library-expand-btn {
    position: absolute;
    top: 7px;
    right: 0;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #ff9a8b 0%, #ff6a88 100%);
    box-shadow: 0 6px 14px rgba(255, 106, 136, 0.24);
    font-size: 18px;
    font-weight: 900;
    line-height: 20px;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.library-item.expanded .library-expand-btn {
    transform: rotate(180deg);
}

.library-expand-btn:hover,
.library-expand-btn:focus-visible {
    opacity: 0.88;
    outline: none;
}

.library-explain-modal {
    position: fixed;
    inset: 0;
    z-index: 3100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
}

.library-explain-modal.open {
    display: flex;
}

.library-explain-mask {
    position: absolute;
    inset: 0;
    background: rgba(18, 14, 42, 0.62);
    backdrop-filter: blur(8px);
}

.library-explain-card {
    position: relative;
    z-index: 1;
    width: min(90vw, 520px);
    padding: clamp(24px, 6vw, 34px);
    border-radius: 26px;
    color: #33255f;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.library-explain-card h2 {
    margin: 0 0 16px;
    color: #33255f;
    text-align: left;
}

.library-explain-card p {
    margin: 0;
    color: #5c567a;
    font-size: 17px;
    line-height: 1.8;
}

.library-explain-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    color: #3b2a68;
    background: #f0edff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

@media (max-width: 560px) {
    .auth-actions {
        flex-direction: row;
        gap: 8px;
    }

    .auth-btn.compact {
        flex-basis: 0;
        width: auto;
        min-height: 40px;
        padding: 9px 6px;
        font-size: 13px;
    }

    .library-shell {
        padding: clamp(70px, 10vh, 88px) 12px 14px;
    }

    .auth-card,
    .auth-modal-card,
    .library-card {
        border-radius: 24px;
    }

    .library-card {
        width: 100%;
        height: calc(100vh - 96px);
        min-height: 0;
        padding: 16px;
    }

    .library-title {
        font-size: clamp(26px, 8vw, 34px);
    }

    .level-filter {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .library-list {
        grid-template-columns: 1fr;
    }

    .library-item-header {
        grid-template-columns: minmax(34px, 1fr) auto auto auto;
        align-items: center;
        gap: 4px;
    }

    .library-count {
        align-self: center;
        font-size: 11px;
    }

    .library-action-btn {
        width: 5em;
        min-width: 5em;
        min-height: 26px;
        padding: 0;
        font-size: 10px;
    }
}
