/* ==================== CSS Variables ==================== */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.1);
    --error: #ef4444;
    --error-light: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.1);
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16162a;
    --bg-input: #1e1e3a;
    --border: #2d2d4a;
    --border-focus: #6366f1;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --glow: 0 0 20px rgba(99, 102, 241, 0.3);
}

/* ==================== Reset & Base ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow-x: hidden;
}

/* ==================== Background Effects ==================== */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.15), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139, 92, 246, 0.1), transparent),
        radial-gradient(ellipse 40% 30% at 10% 80%, rgba(59, 130, 246, 0.08), transparent);
    pointer-events: none;
    z-index: 0;
}

/* Grid Background */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
}

/* ==================== Layout ==================== */
.container {
    width: 60%;
    min-width: 580px;
    max-width: 900px;
    position: relative;
    z-index: 1;
}

/* ==================== Card ==================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 32px;
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.3),
        0 25px 50px -12px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
}

/* ==================== Header ==================== */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 24px;
    box-shadow: var(--glow);
}

.title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ==================== Form ==================== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-label .icon {
    font-size: 14px;
}

.input-wrapper {
    position: relative;
}

input, textarea {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: 'JetBrains Mono', monospace;
    transition: all 0.2s ease;
    outline: none;
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
    font-family: 'Noto Sans SC', sans-serif;
}

input:focus, textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

input:disabled, textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

input.error, textarea.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px var(--error-light);
}

input.success {
    border-color: var(--success);
    box-shadow: 0 0 0 3px var(--success-light);
}

textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.5;
}

/* Card Input Special Styles */
.card-input {
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 500;
}

/* ==================== Input Hints ==================== */
.input-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.input-hint.success {
    color: var(--success);
}

.input-hint.error {
    color: var(--error);
}

.input-hint.warning {
    color: var(--warning);
}

/* ==================== Detected Type Badge ==================== */
.detected-type {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--primary);
    margin-top: 8px;
}

/* ==================== Buttons ==================== */
.btn {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Noto Sans SC', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    margin-top: 12px;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
    border-color: var(--text-muted);
    color: var(--text-primary);
}

/* ==================== Loading Spinner ==================== */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==================== Status Area ==================== */
.status-area {
    margin-top: 24px;
    padding: 16px;
    border-radius: 12px;
    animation: fadeIn 0.3s ease;
}

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

.status-area.polling {
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.status-area.success {
    background: var(--success-light);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-area.error {
    background: var(--error-light);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.status-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.status-text {
    flex: 1;
}

.status-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.status-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.status-area.polling .status-title { color: var(--primary); }
.status-area.success .status-title { color: var(--success); }
.status-area.error .status-title { color: var(--error); }

/* ==================== Progress Bar ==================== */
.progress-bar {
    margin-top: 12px;
    height: 4px;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    animation: progressPulse 2s ease-in-out infinite;
}

@keyframes progressPulse {
    0%, 100% { width: 30%; margin-left: 0; }
    50% { width: 60%; margin-left: 40%; }
}

/* ==================== Result Link ==================== */
.result-link {
    display: block;
    margin-top: 12px;
    padding: 12px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 8px;
    color: var(--success);
    font-size: 13px;
    text-decoration: none;
    word-break: break-all;
    transition: all 0.2s;
}

.result-link:hover {
    background: rgba(16, 185, 129, 0.2);
}

/* ==================== Footer ==================== */
.footer {
    margin-top: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

.footer a:hover {
    color: var(--primary);
}

/* ==================== Badges ==================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
}

.badge-info {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

/* ==================== Auto Fill Notice ==================== */
.auto-fill-notice {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 13px;
    color: var(--primary);
    animation: fadeIn 0.3s ease;
}

/* ==================== Responsive ==================== */
@media (max-width: 960px) {
    .container {
        width: 90%;
        min-width: unset;
        max-width: 100%;
    }
}

@media (max-width: 620px) {
    .container {
        width: 100%;
        padding: 0 16px;
    }
    
    .card {
        padding: 28px 20px;
        border-radius: 16px;
    }

    .title {
        font-size: 20px;
    }

    .logo {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    input, textarea {
        padding: 12px 14px;
        font-size: 16px; /* Prevent iOS zoom */
    }

    .btn {
        padding: 14px 20px;
    }
}

/* 更小屏幕（手机竖屏）*/
@media (max-width: 400px) {
    .container {
        padding: 0 12px;
    }
    
    .card {
        padding: 24px 16px;
    }
    
    .title {
        font-size: 18px;
    }
}

/* ==================== Pulse Animation ==================== */
.pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ==================== 测试模式开关 ==================== */
.test-mode-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.test-mode-toggle:hover {
    border-color: var(--text-muted);
}

.toggle-icon {
    font-size: 18px;
}

.toggle-text {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.toggle-switch {
    width: 44px;
    height: 24px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    position: relative;
    transition: all 0.3s ease;
}

.toggle-switch.active {
    background: var(--warning);
    border-color: var(--warning);
}

.toggle-knob {
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch.active .toggle-knob {
    transform: translateX(20px);
}

/* ==================== 测试环境提示 ==================== */
.test-mode-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--warning-light);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 12px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

.banner-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.banner-content {
    flex: 1;
}

.banner-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--warning);
    margin-bottom: 2px;
}

.banner-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

.panel-toggle-btn {
    padding: 6px 12px;
    background: rgba(245, 158, 11, 0.2);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--warning);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.panel-toggle-btn:hover {
    background: rgba(245, 158, 11, 0.3);
}

/* ==================== 测试面板 ==================== */
.test-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    animation: slideDown 0.3s ease;
}

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

.test-message {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

.test-message.info {
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--primary);
}

.test-message.success {
    background: var(--success-light);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.test-message.error {
    background: var(--error-light);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
}

.test-section {
    margin-bottom: 20px;
}

.test-section:last-child {
    margin-bottom: 0;
}

.test-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.test-section-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* 输入组 */
.test-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.test-input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    text-transform: uppercase;
}

.test-input:focus {
    outline: none;
    border-color: var(--border-focus);
}

.test-btn {
    padding: 10px 16px;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.test-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.test-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.test-btn.secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.test-btn.secondary:hover:not(:disabled) {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.test-btn.danger {
    background: var(--error);
}

/* 操作按钮组 */
.test-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

/* 卡密列表 */
.test-cards-list {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
}

.test-cards-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.refresh-btn {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.refresh-btn:hover:not(:disabled) {
    background: var(--bg-secondary);
}

.refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.test-loading,
.test-empty {
    padding: 20px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.test-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.test-card-item {
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.test-card-item:hover:not(.used) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.test-card-item.used {
    opacity: 0.5;
    cursor: not-allowed;
}

.card-code {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.card-status {
    font-size: 10px;
    color: var(--text-muted);
}

.test-card-item:not(.used) .card-status {
    color: var(--success);
}

/* 关键词网格 */
.keyword-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.keyword-item {
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.keyword-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.keyword-result {
    font-size: 16px;
    margin-bottom: 6px;
}

.keyword-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 4px;
}

.keyword-desc {
    font-size: 11px;
    color: var(--text-muted);
}

/* 响应式 */
@media (max-width: 520px) {
    .test-mode-banner {
        flex-wrap: wrap;
    }
    
    .panel-toggle-btn {
        width: 100%;
        margin-top: 8px;
    }
    
    .test-actions {
        flex-direction: column;
    }
    
    .test-btn {
        width: 100%;
    }
    
    .keyword-grid {
        grid-template-columns: 1fr;
    }
    
    .test-cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

