/* ============================================
   字數統計工具 — 淺色簡約風格
   ============================================ */

/* === Reset & Base === */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #F5F7FA;
    --surface: #FFFFFF;
    --text: #2D3748;
    --text-secondary: #718096;
    --text-light: #A0AEC0;
    --primary: #4A90D9;
    --primary-light: #EBF4FF;
    --primary-dark: #2B6CB0;
    --accent: #38B2AC;
    --accent-light: #E6FFFA;
    --info: #805AD5;
    --info-light: #FAF5FF;
    --border: #E2E8F0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* === Container === */
.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

/* === Header === */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.header-icon {
    font-size: 1.6rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 300;
}

/* === Goal Section === */
.goal-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.goal-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.goal-label {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    color: var(--text);
}

.goal-input {
    width: 140px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.goal-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.goal-input::placeholder {
    color: var(--text-light);
}

.goal-status {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--primary);
    transition: color var(--transition);
}

.goal-status.reached {
    color: #38A169;
}

.goal-progress-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.goal-progress-bar {
    flex: 1;
    height: 10px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.goal-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 999px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.goal-percent {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 42px;
    text-align: right;
}

/* === Editor Section === */
.editor-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: box-shadow var(--transition);
}

.editor-section:focus-within {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.toolbar {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    background: #FAFBFC;
    border-bottom: 1px solid var(--border);
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 14px;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
}

.tool-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.tool-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-icon {
    font-size: 0.9rem;
}

#textInput {
    width: 100%;
    min-height: 260px;
    padding: 20px 24px;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.8;
    color: var(--text);
    background: transparent;
    border: none;
    outline: none;
    resize: vertical;
}

#textInput::placeholder {
    color: var(--text-light);
    font-weight: 300;
}

/* === Stats Section === */
.stats-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 18px 14px;
    text-align: center;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
    cursor: default;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.stat-card.primary {
    border-left: 3px solid var(--primary);
    background: var(--primary-light);
}

.stat-card.accent {
    border-left: 3px solid var(--accent);
    background: var(--accent-light);
}

.stat-card.info {
    border-left: 3px solid var(--info);
    background: var(--info-light);
}

.stat-value {
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    transition: transform 0.2s ease;
}

.stat-value.bounce {
    animation: valueBounce 0.3s ease;
}

@keyframes valueBounce {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.4;
}

.stat-sub {
    display: block;
    font-size: 0.7rem;
    color: var(--text-light);
}

/* === Word Frequency === */
.freq-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.freq-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.freq-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    transition: all var(--transition);
}

.freq-item:hover {
    background: var(--primary-light);
    transform: translateX(4px);
}

.freq-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    background: var(--primary);
    flex-shrink: 0;
}

.freq-item:nth-child(1) .freq-rank {
    background: #F6AD55;
}

.freq-item:nth-child(2) .freq-rank {
    background: #A0AEC0;
}

.freq-item:nth-child(3) .freq-rank {
    background: #C68642;
}

.freq-word {
    flex: 1;
    font-weight: 500;
    font-size: 0.92rem;
    color: var(--text);
    word-break: break-all;
}

.freq-bar-wrapper {
    flex: 2;
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.freq-bar {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width 0.5s ease;
}

.freq-count {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 36px;
    text-align: right;
}

/* === FAQ Section (SEO Content) === */
.faq-section {
    width: 100%;
}

.faq-item {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    transition: background 0.2s;
}

.faq-item:hover {
    background: #f8fafc;
}

.faq-item summary {
    padding: 1.2rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    /* Hide default arrow */
    position: relative;
    user-select: none;
    outline: none;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item summary::after {
    content: '+';
    position: absolute;
    right: 1.2rem;
    font-size: 1.2rem;
    font-weight: 300;
    color: var(--text-secondary);
    transition: transform 0.3s;
}

.faq-item[open] summary::after {
    content: '−';
    transform: rotate(180deg);
}

.faq-item p {
    padding: 0 1.2rem 1.2rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.faq-item[open] summary {
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    background: #fff;
}

/* === Footer === */
.footer {
    text-align: center;
    padding-top: 16px;
    color: var(--text-light);
    font-size: 0.82rem;
    font-weight: 300;
}

/* === Toast Notification === */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 10px 24px;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* === Responsive === */
@media (max-width: 768px) {
    .container {
        padding: 20px 14px 36px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-value {
        font-size: 1.3rem;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .goal-input {
        width: 110px;
    }

    .freq-bar-wrapper {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .header h1 {
        font-size: 1.3rem;
    }

    #textInput {
        min-height: 200px;
        padding: 16px;
    }

    .goal-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .goal-input {
        width: 100%;
    }
}