:root {
    --primary: #4f46e5;
    --secondary: #10b981;
    --accent: #f59e0b;
    --bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.12);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --table-header-bg: #f59e0b;
    --table-header-text: #fff;
    --glass-blur: 20px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Iansui', 'Noto Sans TC', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.ui-stats-btn { background: rgba(255,255,255,0.05); border: 1px solid var(--card-border); padding: 0.6rem 1.2rem; border-radius: 2rem; color: var(--text-primary); cursor: pointer; transition: 0.3s; font-family: inherit; font-size: 0.9rem; }
.ui-stats-btn:hover { background: rgba(255,255,255,0.15); box-shadow: 0 0 15px rgba(255,255,255,0.1); }
.ui-lang-switch { display: flex; background: rgba(0,0,0,0.3); padding: 4px; border-radius: 2rem; border: 1px solid var(--card-border); }
.ui-lang-switch button { background: transparent; border: none; color: var(--text-secondary); padding: 0.5rem 1.2rem; border-radius: 1.5rem; cursor: pointer; font-size: 0.85rem; font-family: inherit; transition: all 0.3s; }
.ui-lang-switch button.active { background: var(--secondary) !important; color: white !important; font-weight: 700 !important; box-shadow: 0 0 20px rgba(16, 185, 129, 0.8) !important; }

/* Moving Bicycle Progress Bar */
.liantng-progress-container { width: 80%; max-width: 500px; margin: 3rem auto 2rem; }
.progress-track { position: relative; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; }
.progress-fill { position: absolute; left: 0; top: 0; height: 100%; width: 0%; background: var(--secondary); border-radius: 3px; transition: width 0.3s ease-out; box-shadow: 0 0 10px var(--secondary); }
.wheel-progress-wrapper { position: absolute; left: 0%; top: -37px; transform: translateX(-50%); transition: left 0.3s ease-out; }
.liantng-wheel { width: 60px; height: 60px; filter: drop-shadow(0 0 10px rgba(16, 185, 129, 0.4)); animation: spin-liantng 1s infinite linear; }

.glass-bg {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at 10% 10%, rgba(79, 70, 229, 0.08) 0%, transparent 40%),
                radial-gradient(circle at 90% 90%, rgba(16, 185, 129, 0.06) 0%, transparent 40%);
    z-index: -1;
}

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }

header { text-align: center; margin-bottom: 2rem; }
header h1 { font-size: clamp(1.5rem, 5vw, 2.2rem); margin-bottom: 1rem; }
header h1 span { background: linear-gradient(to right, #818cf8, #34d399); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* Stepper RWD */
.stepper { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin-top: 1rem; }
.step { padding: 0.4rem 1rem; border-radius: 2rem; background: rgba(255, 255, 255, 0.05); color: var(--text-secondary); font-size: 0.8rem; border: 1px solid var(--card-border); }
.step.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 0 15px rgba(79, 70, 229, 0.3); }

/* Card & Views */
.card {
    background: var(--card-bg); backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--card-border); border-radius: 1rem; padding: 1.5rem;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3); margin-bottom: 1rem;
}
.hidden { display: none; }

.card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.card-header h2 { font-size: 1.2rem; }

/* Form Elements */
textarea {
    width: 100%; height: 200px; background: rgba(0,0,0,0.2); border: 1px solid var(--card-border);
    border-radius: 0.8rem; padding: 1rem; color: white; font-size: 1rem; line-height: 1.6;
    margin-bottom: 1.5rem; resize: vertical;
}

.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.control-group { display: flex; flex-direction: column; gap: 0.4rem; }
.control-group label { font-size: 0.8rem; color: var(--text-secondary); }
select, input { background: rgba(0,0,0,0.3); border: 1px solid var(--card-border); border-radius: 0.6rem; padding: 0.7rem; color: white; font-size: 0.9rem; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-outline {
    padding: 0.7rem 1.2rem; border-radius: 0.6rem; cursor: pointer; font-weight: 600; border: none; transition: 0.3s;
    display: inline-flex; align-items: center; justify-content: center;
}
.full-width { width: 100%; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--card-border); color: var(--text-secondary); }
.btn-outline:hover { background: rgba(255,255,255,0.05); color: white; }

/* Report Summary */
.report-summary-box { display: flex; gap: 2rem; background: rgba(255,255,255,0.05); padding: 1rem; border-radius: 0.8rem; margin-bottom: 1.5rem; font-weight: 600; font-size: 1.1rem; }

/* Distribution Table RWD */
.distribution-table-container { width: 100%; overflow-x: auto; margin-bottom: 2rem; border-radius: 0.8rem; }
.styled-table { width: 100%; border-collapse: collapse; min-width: 1000px; font-size: 0.85rem; background: rgba(255,255,255,0.02); }
.styled-table th { background: var(--table-header-bg); color: var(--table-header-text); padding: 12px; text-align: center; border: 1px solid rgba(0,0,0,0.1); }
.styled-table td { padding: 10px; border: 1px solid var(--card-border); text-align: center; }
.styled-table .word-list-col { text-align: left; min-width: 300px; font-family: monospace; line-height: 1.8; color: #e2e8f0; }

/* Detailed Table */
.table-container { max-height: 400px; overflow-y: auto; overflow-x: auto; border-radius: 0.8rem; }
#freqTable { width: 100%; border-collapse: collapse; min-width: 400px; }
#freqTable th { position: sticky; top: 0; background: #1e1b4b; padding: 0.8rem; text-align: left; font-size: 0.8rem; }
#freqTable td { padding: 0.8rem; border-bottom: 1px solid var(--card-border); }

/* Trigger Banner */
.ai-trigger-banner { background: rgba(16, 185, 129, 0.08); padding: 1.5rem; border-radius: 1rem; border: 1px dashed var(--secondary); text-align: center; margin: 2rem 0; }
.ai-trigger-banner p { margin-bottom: 1.5rem; color: var(--text-secondary); font-size: 1rem; }
.ai-controls { display: flex; align-items: flex-end; justify-content: center; gap: 1.5rem; flex-wrap: wrap; }
.ai-controls .control-group { text-align: left; }
.percentage-input-group { display: flex; align-items: center; gap: 0.5rem; }
.percentage-input-group input { width: 80px; text-align: center; }
.unit { font-weight: 700; color: var(--secondary); }
.est-hint { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; }

@keyframes spin-liantng {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Loading Status */
#loadingStatus { font-weight: 700; font-size: 1.5rem; transition: opacity 0.5s; background: linear-gradient(90deg, #fff, var(--secondary), #fff); background-size: 200% auto; -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: shine 2s linear infinite; }
.fade-out { opacity: 0; }
@keyframes shine { to { background-position: 200% center; } }

/* Output View */
.output-box { min-height: 300px; background: rgba(0,0,0,0.3); border-radius: 1rem; padding: 1.5rem; line-height: 1.8; font-size: 1rem; color: #e2e8f0; border: 1px solid var(--card-border); margin-bottom: 1.5rem; }

/* Badges */
.badge { padding: 0.2rem 0.5rem; border-radius: 0.4rem; font-size: 0.7rem; font-weight: 600; }
.rank-top-500 { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.rank-top-1000 { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.rank-common { background: rgba(79, 70, 229, 0.2); color: #818cf8; }
.rank-unknown { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.rank-tw { background: rgba(129, 140, 248, 0.2); color: #818cf8; }

.ui-stats-btn { margin-right: 1rem; background: rgba(255,255,255,0.05) !important; border: 1px solid var(--card-border) !important; }
.ui-stats-btn:hover { background: rgba(255,255,255,0.15) !important; }

/* Stats View */
.stats-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 1.5rem; margin-top: 1.5rem; }
.stats-card { background: rgba(0,0,0,0.2); padding: 1.5rem; border-radius: 1rem; border: 1px solid var(--card-border); }
.stats-card h3 { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 1rem; }
.stats-num { font-size: 3rem; font-weight: 800; color: var(--secondary); text-shadow: 0 0 20px rgba(16, 185, 129, 0.4); }
.history-list { max-height: 300px; overflow-y: auto; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem; border-bottom: 1px solid var(--card-border); font-size: 0.85rem; }
.history-item:last-child { border-bottom: none; }
.hist-time { color: var(--text-secondary); width: 120px; }
.hist-preview { flex: 1; margin: 0 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.hist-count { background: rgba(79, 70, 229, 0.2); color: #818cf8; padding: 0.2rem 0.6rem; border-radius: 1rem; font-size: 0.75rem; }

@media (max-width: 800px) {
    .stats-grid { grid-template-columns: 1fr; }
}

footer { margin-top: 3rem; text-align: center; color: var(--text-secondary); font-size: 0.75rem; padding-bottom: 2rem; }

/* RWD Queries */
@media (max-width: 600px) {
    .container { padding: 0.5rem; }
    .card { padding: 1rem; }
    .stepper { flex-direction: column; align-items: stretch; }
    .step { text-align: center; }
    .report-summary-box { flex-direction: column; gap: 0.5rem; }
}
