/* ========================================
   組件樣式 - 手機優先
   ======================================== */

/* ========================================
   開獎倒數（在玉安宮區塊內）
   ======================================== */
.countdown__date {
    text-align: center;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: var(--space-md);
}

.countdown__date span {
    font-weight: 600;
    margin-left: var(--space-xs);
    color: var(--color-white);
}

.countdown__timer {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
}

.countdown__unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-xs);
    backdrop-filter: blur(4px);
}

.countdown__num {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--color-white);
    line-height: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.countdown__label {
    font-size: 0.625rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

/* ========================================
   開獎記錄
   ======================================== */
.history__loading {
    text-align: center;
    padding: var(--space-xl);
    color: var(--color-text-light);
}

/* ========================================
   歷史記錄控制區
   ======================================== */
.history-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-bg-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin-bottom: var(--space-md);
    align-items: center;
}

.history-controls__option {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    cursor: pointer;
    user-select: none;
}

.history-controls__option input[type="radio"] {
    cursor: pointer;
    margin: 0;
}

.history-controls__option span {
    font-size: 0.875rem;
    color: var(--color-text);
}

.history-controls__option input[type="number"] {
    width: 60px;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--color-bg);
    color: var(--color-text);
    text-align: center;
}

.history-controls__option input[type="number"]:disabled {
    background-color: var(--color-bg-alt);
    color: var(--color-text-light);
    cursor: not-allowed;
    opacity: 0.6;
}

.history-controls__option input[type="number"]:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

/* 手機版：垂直排列 */
@media (max-width: 640px) {
    .history-controls {
        flex-direction: column;
        align-items: flex-start;
    }
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.history-item {
    padding: var(--space-md);
    background: var(--color-bg-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.history-date {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text);
}

.history-period {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.history-numbers {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.history-numbers .ball {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--color-white);
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.875rem;
}

/* 選中號碼高亮 - 黃底紅字，符合WCAG AA標準 */
.history-numbers .ball--selected {
    background: #ffd700 !important; /* 金黃色背景 */
    color: #cc0000 !important; /* 深紅色文字 */
    border: 2px solid #cc0000;
    font-weight: 900;
}

/* 動作按鈕樣式（全選/清除） */
.selection-message {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: var(--color-bg-alt);
    border-radius: var(--radius-md);
    margin: var(--space-md) 0;
}

.selection-message .action-btn {
    background: var(--color-primary);
    border: none;
    color: var(--color-white);
    cursor: pointer;
    font-size: 0.875rem;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    min-width: 60px;
}

.selection-message .action-btn:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
}

/* 歷史記錄控制區域樣式 */
.history-controls__row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.history-controls__row:last-child {
    margin-bottom: 0;
}

.adjustment-selector {
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.875rem;
    min-width: 80px;
}

.adjustment-selector:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

/* 內嵌數字輸入框樣式 */
.inline-number-input {
    width: 50px;
    padding: 2px 6px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.875rem;
    text-align: center;
    margin: 0 4px;
}

.inline-number-input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.inline-number-input:disabled {
    background: var(--color-bg-alt);
    color: var(--color-text-light);
    cursor: not-allowed;
}

/* ========================================
   號碼統計
   ======================================== */
.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    gap: var(--space-md);
    flex-wrap: wrap;
}

.stats-tabs {
    display: flex;
    gap: var(--space-xs);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-lg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-button {
    background: none;
    border: none;
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text-light);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    min-height: 44px;
}

.tab-button.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: var(--space-sm);
}

.number-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-md) var(--space-sm);
    background: var(--color-bg-alt);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.number-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

.number-card.heat-very-hot {
    border-color: var(--color-number-hot);
    background: var(--color-error-bg);
}

.number-card.heat-hot {
    border-color: var(--color-number-warm);
    background: var(--color-warning-bg);
}

.number-card.heat-cool {
    border-color: var(--color-hover);
    background: var(--color-info-bg);
}

.number-card.heat-cold {
    border-color: var(--color-number-cold);
    background: var(--color-bg-secondary);
}

.number-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
    margin-bottom: var(--space-xs);
}

.number-stats {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
}

.number-stats .count {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.number-stats .percentage {
    font-size: 0.625rem;
    color: var(--color-text-light);
}

.number-stats .rank {
    font-size: 0.625rem;
    color: var(--color-text-light);
    font-weight: 500;
}

.period-selector {
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    color: var(--color-text);
    min-width: 120px;
    cursor: pointer;
    min-height: 44px;
}

.period-selector:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ========================================
   生日算牌
   ======================================== */
.birthday-fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.birthday-fieldset legend {
    font-weight: 600;
    color: var(--color-text);
    padding: 0 var(--space-sm);
}

.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--space-xs);
    font-size: 0.875rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 1rem;
    min-height: 44px;
}

.form-input:focus,
.form-select:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.form-row {
    display: grid;
    gap: var(--space-md);
}

.calculate-btn {
    width: 100%;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
}

.calculate-btn:hover {
    background: var(--color-primary-dark);
}

.lucky-numbers {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    background: var(--color-bg-alt);
    border-radius: var(--radius-md);
}

.lucky-numbers h3 {
    text-align: center;
    color: var(--color-primary);
    margin-bottom: var(--space-md);
}

.numbers-display {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.lucky-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--color-white);
    border-radius: 50%;
    font-size: 1.25rem;
    font-weight: 700;
}

.calculation-method {
    margin-top: var(--space-md);
}

.calculation-method details {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
}

.calculation-method summary {
    font-weight: 500;
    color: var(--color-primary);
    cursor: pointer;
    padding: var(--space-sm);
}

.method-content {
    padding: var(--space-md);
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-sm);
    color: var(--color-text-light);
    font-size: 0.875rem;
}

/* ========================================
   平板 (768px+)
   ======================================== */
@media (min-width: 768px) {
    .countdown__timer {
        gap: var(--space-md);
    }

    .countdown__unit {
        padding: var(--space-lg) var(--space-sm);
    }

    .countdown__num {
        font-size: 2rem;
    }

    .countdown__label {
        font-size: 0.75rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: var(--space-md);
    }

    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .calculate-btn {
        width: auto;
        padding: var(--space-md) var(--space-xl);
    }
}

/* ========================================
   桌面 (1024px+)
   ======================================== */
@media (min-width: 1024px) {
    .countdown__num {
        font-size: 2.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: var(--space-lg);
    }

    .number-card {
        padding: var(--space-lg) var(--space-md);
    }

    .number-value {
        font-size: 2rem;
    }

    .lucky-number {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
}

/* ========================================
   減少動畫
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .number-card:hover {
        transform: none;
    }
}

/* ========================================
   標題列控制項
   ======================================== */
.header__controls {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* ========================================
   更新狀態指示器
   ======================================== */
.update-status {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--color-text-light);
    cursor: default;
    transition: all 0.2s ease;
    min-height: 44px;
}

.update-status__icon {
    font-size: 1.25rem;
    transition: transform 0.5s ease;
}

.update-status--checking .update-status__icon {
    animation: spin 1s linear infinite;
}

.update-status--success {
    color: var(--color-success);
    border-color: var(--color-success);
}

.update-status--error {
    color: var(--color-error);
    border-color: var(--color-error);
}

.update-status__text {
    font-weight: 500;
    white-space: nowrap;
}

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

/* 手機版隱藏更新狀態文字 */
@media (max-width: 480px) {
    .update-status__text {
        display: none;
    }
}

/* ========================================
   歷史符合記錄（統一）
   ======================================== */

/* ========================================
   選號功能樣式
   ======================================== */

/* 選號訊息欄 */
.selection-message {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-primary);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    user-select: none;
}

.selection-message .message-text {
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
}

.selection-message.clickable {
    background: var(--color-error);
    border-color: var(--color-error);
    cursor: pointer;
}

.selection-message.clickable:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* 可選取的號碼卡片 */
.number-card.selectable {
    cursor: pointer;
    user-select: none;
}

.number-card.selectable:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.number-card.selectable.selected {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.1);
    transform: scale(1.05);
}

.number-card.selectable.selected .number-value {
    color: var(--color-primary);
}

/* 已選號碼顯示區域 */
.selected-numbers-display {
    background: var(--color-bg-alt);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
}

.selected-title {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
}

.selected-balls {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
    margin-bottom: var(--space-sm);
}

.selected-balls .ball {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--color-white);
    border-radius: 50%;
    font-weight: 700;
    font-size: 1rem;
}

/* 歷史符合記錄容器 */
.match-history-wrapper {
    margin-top: var(--space-lg);
}

.match-history-placeholder,
.match-history-empty,
.match-history-loading,
.match-history-error {
    text-align: center;
    padding: var(--space-xl);
}

.placeholder-text,
.empty-text {
    color: var(--color-text-light);
    font-size: 0.875rem;
}

.empty-hint {
    color: var(--color-text-light);
    font-size: 0.75rem;
    margin-top: var(--space-xs);
}

/* 歷史符合記錄結果區塊 */
.match-history-results {
    margin-top: var(--space-lg);
}

.matches-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.title-icon {
    font-size: 1.25rem;
}

.matches-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* 符合項目卡片 */
.match-item {
    padding: var(--space-md);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.match-item:hover {
    border-color: var(--color-primary);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* 符合項目標題列 */
.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.match-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.match-period {
    font-weight: 600;
    color: var(--color-text);
    font-size: 0.875rem;
}

.match-date {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

/* 符合數量徽章 */
.match-badge {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.match-badge.match-perfect {
    background: var(--color-success);
    color: var(--color-white);
}

.match-badge.match-high {
    background: var(--color-primary);
    color: var(--color-white);
}

.match-badge.match-medium {
    background: var(--color-warning);
    color: var(--color-black);
}

.match-badge.match-low {
    background: var(--color-number-cold);
    color: var(--color-white);
}

/* 符合的號碼球 */
.match-numbers {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.match-numbers .ball {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #e5e7eb;
    color: #1f2937;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.875rem;
}

.match-numbers .ball.matched {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: white;
}

/* 修正：今日幸運號碼 - 歷史符合記錄中的號碼球（覆蓋預設樣式） */
.match-item .history-numbers .ball {
    background: #e5e7eb !important;
    color: #1f2937 !important;
}

.match-item .history-numbers .ball.matched {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark)) !important;
    color: white !important;
}

.no-matches {
    text-align: center;
    color: var(--color-text-light);
    padding: var(--space-lg);
}

/* Toast 動畫 */
@keyframes slideDown {
    from {
        transform: translate(-50%, -100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 0);
        opacity: 1;
    }
    to {
        transform: translate(-50%, -100%);
        opacity: 0;
    }
}

/* 歷史符合記錄淡入彈跳動畫 */
@keyframes fadeInBounce {
    0% {
        opacity: 0;
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}
