:root {
    --primary: #696cff;
    --primary-dark: #5558e6;
    --secondary: #8592a3;
    --success: #71dd37;
    --background: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.08);
    --gold: #fde047;
    --silver: #e2e8f0;
    --bronze: #fb923c;
}

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

body {
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    overflow-x: hidden;
    min-height: 100vh;
}

.background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 30%, rgba(105, 108, 255, 0.15) 0%, transparent 50%),
                radial-gradient(circle at 80% 70%, rgba(113, 221, 55, 0.1) 0%, transparent 50%);
    z-index: -1;
}

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

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.8s ease-out;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--primary);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.stats-bar {
    display: flex;
    justify-content: center;
    gap: 4rem;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    width: fit-content;
    margin: 0 auto;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.stat-item .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.countdown-item .value {
    color: var(--success);
}

.countdown-item .value.ended {
    color: var(--gold);
}

.deadline-note {
    margin-top: 0.15rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.data-retention-note {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 0.85rem auto 0;
    max-width: 720px;
}

.voting-ended-note {
    margin: 1rem auto 0;
    max-width: 760px;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(253, 224, 71, 0.28);
    border-radius: 8px;
    background: rgba(253, 224, 71, 0.08);
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.6;
}

/* Ranking Card */
.ranking-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    min-height: 400px;
    animation: fadeInUp 0.8s ease-out;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.8rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 0.75rem;
    color: white;
    outline: none;
    transition: all 0.3s;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(105, 108, 255, 0.2);
}

.group-select {
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 0.75rem;
    color: white;
    outline: none;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 150px;
    max-width: 220px;
    font-family: inherit;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2rem;
    padding-right: 2.5rem;
}

.group-select:focus {
    border-color: var(--primary);
}

.group-select option {
    background: #1e293b;
    color: white;
}

.refresh-button {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    border: none;
    border-radius: 0.75rem;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.refresh-button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.refresh-button:active {
    transform: translateY(0);
}

/* Table Styles */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.5rem;
}

th {
    padding: 1rem;
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr {
    background: rgba(255, 255, 255, 0.03);
    transition: all 0.3s;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: scale(1.005);
}

td {
    padding: 1.25rem 1rem;
    vertical-align: middle;
}

td:first-child {
    border-top-left-radius: 0.75rem;
    border-bottom-left-radius: 0.75rem;
}

td:last-child {
    border-top-right-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
}

/* Rank Styling */
.rank-badge {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1rem;
}

tr:nth-child(1) .rank-badge {
    background: linear-gradient(135deg, #fbbf24, #d97706);
    color: white;
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.4);
}

tr:nth-child(2) .rank-badge {
    background: linear-gradient(135deg, #94a3b8, #475569);
    color: white;
}

tr:nth-child(3) .rank-badge {
    background: linear-gradient(135deg, #ca8a04, #92400e);
    color: white;
}

/* Work Info Styling */
.work-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.work-title {
    font-weight: 700;
    color: white;
    font-size: 1rem;
}

.work-id {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--primary);
}

.group-tag {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(105, 108, 255, 0.1);
    color: var(--primary);
    border: 1px solid rgba(105, 108, 255, 0.2);
}

.vote-count {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--success);
}

.btn-detail {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-detail:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* Overlays */
.loader-overlay, .error-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    z-index: 10;
    border-radius: 1.5rem;
}

.error-overlay i {
    font-size: 3rem;
    color: #ef4444;
    margin-bottom: 1rem;
}

.spinner {
    width: 3rem;
    height: 3rem;
    border: 4px solid rgba(105, 108, 255, 0.1);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.btn-secondary {
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: white;
    border-radius: 0.5rem;
    cursor: pointer;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

footer {
    text-align: center;
    margin-top: 3rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.support-note {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    opacity: 0.65;
}

@media (max-width: 768px) {
    header h1 { font-size: 2rem; }
    .stats-bar { gap: 1.5rem; flex-wrap: wrap; }
    .card-header { flex-direction: column; align-items: stretch; }
    .group-col, .action-col { display: none; }
}

/* 新增功能樣式 */
.growth-col { width: 120px; text-align: center; }
.growth-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.growth-positive { background: rgba(113, 221, 55, 0.2); color: #71dd37; }
.growth-zero { background: rgba(148, 163, 184, 0.1); color: #94a3b8; }

/* Modal 彈出視窗樣式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    padding: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 10px;
}

.modal-body {
    height: 360px;
    position: relative;
}

.modal-body canvas {
    width: 100%;
    height: 100%;
}

.chart-status {
    position: absolute;
    left: 20px;
    right: 20px;
    bottom: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    pointer-events: none;
}

.close {
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

/* 趨勢小圖樣式 */
.trend-col { width: 100px; text-align: center; }
.sparkline {
    width: 80px;
    height: 30px;
    stroke: #696cff;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    filter: drop-shadow(0 0 2px rgba(105, 108, 255, 0.4));
}

/* 分頁與關注樣式 */
.tabs { display: flex; gap: 10px; margin-top: 20px; }
.tab-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
}
.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 15px rgba(105, 108, 255, 0.4);
}

.follow-col { width: 50px; text-align: center; }
.follow-star { cursor: pointer; color: var(--text-muted); font-size: 1.2rem; transition: color 0.2s; }
.follow-star.active { color: #ffab00; }

.chart-container-large { padding: 20px; height: 400px; width: 100%; position: relative; }
.compare-tags { display: flex; flex-wrap: wrap; gap: 8px; padding: 20px; }
.compare-tag {
    background: rgba(105, 108, 255, 0.1);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    border: 1px solid rgba(105, 108, 255, 0.3);
}

.guide-header {
    margin-bottom: 20px;
}

.guide-header h3 {
    font-size: 1.4rem;
    margin-bottom: 6px;
}

.guide-header p {
    color: var(--text-muted);
}

.vote-rule-note {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    background: rgba(105, 108, 255, 0.08);
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.6;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}

.guide-step {
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    overflow: hidden;
}

.guide-step-text {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
}

.guide-step-text span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-weight: 800;
    flex: 0 0 auto;
}

.guide-step-text p {
    font-weight: 700;
}

.guide-step img {
    display: block;
    width: 100%;
    height: auto;
    border-top: 1px solid var(--glass-border);
}

/* 學校資訊樣式 */
.work-meta { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.school-tag {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.school-tag i { font-size: 0.7rem; color: var(--primary); }

.award-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.award-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
    padding: 3px 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.award-badge img {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.award-woman { border-color: rgba(255, 112, 166, 0.35); }
.award-aboriginal { border-color: rgba(113, 221, 55, 0.35); }
.award-newtaiwan { border-color: rgba(33, 150, 243, 0.35); }

/* 組別專屬配色 */
.group-tag.group-elementary { background: rgba(76, 175, 80, 0.1); color: #4caf50; border-color: rgba(76, 175, 80, 0.3); }
.group-tag.group-middle { background: rgba(33, 150, 243, 0.1); color: #2196f3; border-color: rgba(33, 150, 243, 0.3); }
.group-tag.group-high { background: rgba(156, 39, 176, 0.1); color: #9c27b0; border-color: rgba(156, 39, 176, 0.3); }
.group-tag.group-teacher { background: rgba(255, 152, 0, 0.1); color: #ff9800; border-color: rgba(255, 152, 0, 0.3); }

/* 雙重增長排版微調 */
.growth-container { display: flex; flex-direction: column; gap: 2px; }
.growth-row { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; }
.growth-row small { color: var(--text-muted); min-width: 25px; }
