/* ============================================================
   auth.css — 認證/登入/註冊/成語庫公用樣式
   設計語言：animal-island-ui warm-parchment + pill shapes + 3D shadow
   ============================================================ */

/* ---------- 設計令牌 ---------- */
:root {
    /* 暖紙張色系 */
    --ai-parchment: #f7f3df;
    --ai-parchment-deep: #e8dcc8;
    --ai-parchment-dark: #d5c7a8;

    /* 功能色 · NookPhone palette */
    --ai-app-pink: #f8a6b2;
    --ai-app-purple: #b77dee;
    --ai-app-blue: #889df0;
    --ai-app-yellow: #f7cd67;
    --ai-app-orange: #e59266;
    --ai-app-teal: #82d5bb;
    --ai-app-green: #8ac68a;
    --ai-app-red: #fc736d;
    --ai-brown: #9a835a;
    --ai-warm-peach: #e18c6f;

    /* 文字色 */
    --ai-text-primary: #5f4c3b;
    --ai-text-secondary: #8c7a64;
    --ai-text-on-color: #fff;
    --ai-text-dark: #4a3828;

    /* 3D 陰影層級 */
    --ai-shadow-sm: 0 2px 6px rgba(74, 56, 40, 0.10);
    --ai-shadow-md: 0 6px 18px rgba(74, 56, 40, 0.14);
    --ai-shadow-lg: 0 14px 36px rgba(74, 56, 40, 0.18);
    --ai-shadow-xl: 0 20px 50px rgba(74, 56, 40, 0.22);
    --ai-shadow-btn: 0 4px 0 rgba(74, 56, 40, 0.18), 0 8px 20px rgba(74, 56, 40, 0.14);
    --ai-shadow-btn-hover: 0 6px 0 rgba(74, 56, 40, 0.18), 0 12px 28px rgba(74, 56, 40, 0.18);
    --ai-shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.5);

    /* 圓角 */
    --ai-radius-pill: 999px;
    --ai-radius-card: 28px;
    --ai-radius-input: 18px;
    --ai-radius-btn: 18px;
    --ai-radius-sm: 14px;

    color-scheme: light;
}

/* ---------- 重置 & 基底 ---------- */
* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(136, 157, 240, 0.12), transparent 48%),
        radial-gradient(ellipse at 80% 100%, rgba(247, 205, 103, 0.16), transparent 48%),
        linear-gradient(175deg, #f7f3df 0%, #efe8d4 40%, #e5dcc6 100%);
    background-attachment: fixed;
    color: var(--ai-text-primary);
}

/* ---------- 外層殼 ---------- */
.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: var(--ai-radius-card);
    background:
        radial-gradient(ellipse at 0% 0%, rgba(255, 255, 255, 0.9), transparent 58%),
        linear-gradient(160deg, rgba(255, 251, 240, 0.94) 0%, rgba(247, 243, 223, 0.90) 50%, rgba(232, 220, 200, 0.88) 100%);
    border: 1px solid rgba(154, 131, 90, 0.18);
    box-shadow: var(--ai-shadow-xl), var(--ai-shadow-inset);
    text-align: center;
}

/* ---------- 徽章 ---------- */
.auth-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--ai-radius-pill);
    background: rgba(136, 157, 240, 0.18);
    color: var(--ai-text-primary);
    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;
    color: var(--ai-text-dark);
    text-shadow: 0 2px 8px rgba(74, 56, 40, 0.10);
}

h2 {
    margin: 0 0 10px;
    color: var(--ai-text-dark);
    font-size: 28px;
    text-align: center;
}

/* ---------- 描述文字 ---------- */
.auth-desc {
    margin: 0 0 24px;
    color: var(--ai-text-secondary);
    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;
    color: var(--ai-text-dark);
}

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

.auth-modal .auth-field {
    color: var(--ai-text-dark);
}

.auth-field input {
    width: 100%;
    border: 1px solid rgba(154, 131, 90, 0.18);
    outline: none;
    border-radius: var(--ai-radius-input);
    padding: 16px 18px;
    font-size: 16px;
    color: var(--ai-text-dark);
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--ai-shadow-sm), var(--ai-shadow-inset);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.auth-field input:focus {
    border-color: var(--ai-app-blue);
    box-shadow: 0 0 0 3px rgba(136, 157, 240, 0.22), var(--ai-shadow-sm);
}

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

.auth-note {
    margin: 16px 0 0;
    color: var(--ai-text-secondary);
    font-size: 13px;
    line-height: 1.6;
    text-align: center;
}

/* ---------- 按鈕 ---------- */
.auth-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 14px;
}

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

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

.auth-btn.compact {
    flex: 0 0 calc(50% - 6px);
    width: calc(50% - 6px);
    min-height: 44px;
    padding: 10px 8px;
    font-size: 14px;
    border-radius: var(--ai-radius-btn);
}

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

.auth-btn:active {
    transform: translateY(1px);
}

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

/* 主要按鈕 — 暖橘金主色 */
.auth-btn.primary {
    color: var(--ai-text-on-color);
    background: linear-gradient(135deg, #f7a854 0%, #e57e44 100%);
    box-shadow: var(--ai-shadow-btn);
}

.auth-btn.primary:hover,
.auth-btn.primary:focus {
    box-shadow: var(--ai-shadow-btn-hover);
}

/* 次要按鈕 — 米白紙張 */
.auth-btn.secondary {
    color: var(--ai-text-dark);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--ai-shadow-md);
    border: 1px solid rgba(154, 131, 90, 0.16);
}

.auth-btn.secondary:hover,
.auth-btn.secondary:focus {
    box-shadow: var(--ai-shadow-lg);
}

/* 幽靈按鈕 */
.auth-btn.ghost {
    color: var(--ai-text-dark);
    background: rgba(255, 255, 255, 0.42);
    border: 1px solid rgba(154, 131, 90, 0.22);
}

.auth-btn.ghost:hover,
.auth-btn.ghost:focus {
    background: rgba(255, 255, 255, 0.68);
}

/* ---------- 訊息 ---------- */
.auth-message {
    min-height: 28px;
    margin-top: 18px;
    padding: 12px 16px;
    border-radius: var(--ai-radius-sm);
    background: rgba(255, 255, 255, 0.64);
    color: var(--ai-text-primary);
    line-height: 1.6;
    text-align: center;
    font-weight: 600;
}

.auth-message.success {
    background: rgba(138, 198, 138, 0.18);
    color: #3a6b3a;
}

.auth-message.error {
    background: rgba(252, 115, 109, 0.14);
    color: #a04030;
}

/* ---------- 模態框 ---------- */
.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(74, 56, 40, 0.38);
    backdrop-filter: blur(8px);
}

.auth-modal-card {
    position: relative;
    z-index: 1;
    width: min(92vw, 460px);
    padding: 30px;
    border-radius: var(--ai-radius-card);
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(154, 131, 90, 0.14);
    box-shadow: var(--ai-shadow-xl);
}

.auth-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    color: var(--ai-text-dark);
    background: var(--ai-parchment);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.18s ease;
}

.auth-modal-close:hover {
    background: var(--ai-parchment-deep);
}

.auth-modal-desc {
    margin: 0 0 20px;
    color: var(--ai-text-secondary);
    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: var(--ai-radius-card);
    background:
        radial-gradient(ellipse at 0% 0%, rgba(255, 255, 255, 0.9), transparent 58%),
        linear-gradient(160deg, rgba(255, 251, 240, 0.94) 0%, rgba(247, 243, 223, 0.90) 50%, rgba(232, 220, 200, 0.88) 100%);
    border: 1px solid rgba(154, 131, 90, 0.18);
    box-shadow: var(--ai-shadow-xl), var(--ai-shadow-inset);
    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;
    color: var(--ai-text-dark);
}

.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(154, 131, 90, 0.22);
    border-radius: var(--ai-radius-pill);
    color: var(--ai-text-primary);
    background: rgba(255, 255, 255, 0.56);
    font-weight: 900;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.library-tab.active,
.level-filter-btn.active {
    color: var(--ai-text-dark);
    background: linear-gradient(135deg, rgba(255, 251, 240, 0.98) 0%, rgba(247, 205, 103, 0.48) 100%);
    border-color: rgba(247, 205, 103, 0.56);
    box-shadow: var(--ai-shadow-md);
}

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

.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: var(--ai-radius-pill);
    background: rgba(154, 131, 90, 0.32);
}

.library-load-hint {
    padding: 14px 8px 2px;
    color: var(--ai-text-secondary);
    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(154, 131, 90, 0.22);
    border-radius: 50%;
    color: var(--ai-text-dark);
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.98), rgba(247, 243, 223, 0.88) 42%, rgba(247, 205, 103, 0.48) 100%);
    box-shadow: var(--ai-shadow-lg), var(--ai-shadow-inset);
    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: var(--ai-shadow-xl), var(--ai-shadow-inset);
    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: 14px;
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
    color: var(--ai-text-dark);
    border: 1px solid rgba(154, 131, 90, 0.14);
    box-shadow: var(--ai-shadow-sm);
}

.library-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

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

.library-item h3 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
}

.library-level-badge {
    width: fit-content;
    padding: 4px 9px;
    border-radius: var(--ai-radius-pill);
    color: var(--ai-text-dark);
    background: rgba(136, 157, 240, 0.18);
    font-size: 12px;
    font-weight: 900;
}

.library-count {
    flex: 0 0 auto;
    padding-top: 2px;
    color: var(--ai-text-secondary);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.library-action-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.library-action-btn {
    min-height: 38px;
    border: 0;
    border-radius: var(--ai-radius-pill);
    color: var(--ai-text-on-color);
    background: linear-gradient(135deg, #889df0 0%, #b77dee 100%);
    box-shadow: var(--ai-shadow-btn);
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

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

.library-action-btn:active {
    transform: translateY(1px);
}

.library-action-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    transform: 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(74, 56, 40, 0.42);
    backdrop-filter: blur(8px);
}

.library-explain-card {
    position: relative;
    z-index: 1;
    width: min(90vw, 520px);
    padding: clamp(24px, 6vw, 34px);
    border-radius: var(--ai-radius-card);
    color: var(--ai-text-dark);
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(154, 131, 90, 0.14);
    box-shadow: var(--ai-shadow-xl);
}

.library-explain-card h2 {
    margin: 0 0 16px;
    color: var(--ai-text-dark);
    text-align: left;
}

.library-explain-card p {
    margin: 0;
    color: var(--ai-text-secondary);
    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: var(--ai-text-dark);
    background: var(--ai-parchment);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.18s ease;
}

.library-explain-close:hover {
    background: var(--ai-parchment-deep);
}

/* ---------- 響應式 ---------- */
@media (max-width: 560px) {
    .auth-actions {
        flex-direction: row;
    }

    .auth-btn.compact {
        flex-basis: calc(50% - 6px);
        width: calc(50% - 6px);
    }

    .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-action-row {
        gap: 6px;
    }

    .library-action-btn {
        font-size: 12px;
        padding-inline: 6px;
    }
}
