/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #22d3ee;
    --success: #10b981;
    --warning: #f59e0b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* Header */
header {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-dark) 100%);
    padding: 2rem 0;
    border-bottom: 1px solid var(--bg-hover);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 0.5rem;
}

.logo-icon {
    font-size: 2.5rem;
}

.logo h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Main Layout */
main {
    padding: 3rem 0;
}

section {
    margin-bottom: 3rem;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

h2::before {
    content: '';
    width: 4px;
    height: 24px;
    background: var(--primary);
    border-radius: 2px;
}

/* Game Grid */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.game-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.game-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.2);
}

.game-card.active {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(34, 211, 238, 0.1) 100%);
}

.game-card.saved {
    border-color: var(--success);
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(16, 185, 129, 0.1) 100%);
}

.game-card-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-cover {
    width: 100%;
    aspect-ratio: 4/5;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
}

.game-card:hover .game-cover {
    transform: scale(1.05);
}

.game-card-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.game-card-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ROM Upload */
.rom-upload {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    border: 2px dashed var(--bg-hover);
    transition: all 0.3s ease;
}

.rom-upload:hover {
    border-color: var(--primary);
}

.rom-upload h3 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

#romUpload {
    display: none;
}

.upload-btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

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

.hint {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Emulator Section */
.emulator-section {
    display: none;
}

.emulator-section.active {
    display: block;
}

.emulator-container {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
}

.screen-wrapper {
    position: relative;
    width: 100%;
    max-width: 960px;
    margin: 0 auto 2rem;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    background: #000;
}

/* 全屏模式 */
.screen-wrapper:fullscreen {
    max-width: none;
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.screen-wrapper:fullscreen #gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
}

.screen-wrapper:fullscreen .screen-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
}

/* 全屏提示条 */
.fullscreen-hint {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
}

.fullscreen-hint.show {
    opacity: 1;
}

.screen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen-overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 2rem;
}

.overlay-content h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--accent);
}

.overlay-content p {
    color: var(--text-secondary);
}

/* Controls Info */
.controls-info {
    margin-bottom: 2rem;
}

.controls-info h3 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-dark);
    padding: 0.75rem 1rem;
    border-radius: 8px;
}

.key {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
    min-width: 60px;
    text-align: center;
}

.desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Actions */
.game-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card);
    border: 1px solid var(--primary);
}

/* About Section */
.about-section {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
}

.about-content {
    color: var(--text-secondary);
    line-height: 1.8;
}

.about-content p {
    margin-bottom: 1rem;
}

.about-content a {
    color: var(--accent);
    text-decoration: none;
}

.about-content a:hover {
    text-decoration: underline;
}

.warning {
    color: var(--warning) !important;
    font-weight: 500;
}

/* Footer */
footer {
    background: var(--bg-card);
    padding: 2rem 0;
    text-align: center;
    color: var(--text-secondary);
    border-top: 1px solid var(--bg-hover);
}

/* Responsive */
@media (max-width: 768px) {
    .logo h1 {
        font-size: 1.5rem;
    }
    
    .game-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .controls-grid {
        grid-template-columns: 1fr;
    }
    
    .screen-wrapper {
        max-width: 100%;
    }
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s infinite;
}

/* ==================== 新增功能样式 ==================== */

/* Header 行布局 */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.login-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-badge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
}

.btn-small {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    border-radius: 6px;
}

.count-badge {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: normal;
}

/* 游戏卡片删除按钮 */
.game-card {
    position: relative;
}

.card-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 5;
}

.game-card:hover .card-delete {
    opacity: 1;
}

.card-delete:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* 模式弹窗 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--bg-hover);
}

.modal h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.modal-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.2rem;
}

.modal input {
    width: 100%;
    padding: 0.8rem 1rem;
    margin-bottom: 0.8rem;
    background: var(--bg-dark);
    border: 1px solid var(--bg-hover);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.modal input:focus {
    border-color: var(--primary);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.modal-error {
    color: #ef4444;
    font-size: 0.85rem;
    margin: 0.25rem 0 0.5rem;
    padding: 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 6px;
}

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0.25rem 0 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.remember-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

/* 手柄已连接提示 */
.gamepad-hint {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(16, 185, 129, 0.9);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    z-index: 10;
    animation: pulse 2s infinite;
}

/* 虚拟手柄 */
.virtual-gamepad {
    display: none;
    justify-content: space-between;
    align-items: flex-end;
    max-width: 512px;
    margin: 1.5rem auto 0;
    padding: 1rem 0.5rem;
    gap: 1rem;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.gp-dpad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 4px;
}

.gp-up    { grid-column: 2; grid-row: 1; }
.gp-left  { grid-column: 1; grid-row: 2; }
.gp-right { grid-column: 3; grid-row: 2; }
.gp-down  { grid-column: 2; grid-row: 3; }

.gp-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.gp-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: rgba(99, 102, 241, 0.6);
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    touch-action: none;
}

.gp-btn:active, .gp-btn.pressed {
    background: var(--primary);
    transform: scale(0.9);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.6);
}

.gp-start, .gp-select {
    width: 52px;
    height: 34px;
    border-radius: 16px;
    background: rgba(148, 163, 184, 0.4);
    font-size: 0.75rem;
}

.gp-a {
    width: 68px;
    height: 68px;
    background: rgba(236, 72, 153, 0.6);
    font-size: 1.4rem;
}

.gp-b {
    width: 56px;
    height: 56px;
    background: rgba(34, 211, 238, 0.6);
    font-size: 1.2rem;
}

.gp-a:active, .gp-a.pressed {
    background: var(--secondary);
    box-shadow: 0 0 20px rgba(236, 72, 153, 0.6);
}

.gp-b:active, .gp-b.pressed {
    background: var(--accent);
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.6);
}

/* 存档按钮高亮 */
#saveBtn, #loadBtn {
    min-width: 110px;
}

@media (max-width: 768px) {
    .header-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .virtual-gamepad {
        gap: 0.5rem;
    }
    .gp-dpad {
        grid-template-columns: repeat(3, 48px);
        grid-template-rows: repeat(3, 48px);
    }
    .gp-btn {
        width: 48px;
        height: 48px;
        font-size: 0.9rem;
    }
    .gp-a { width: 56px; height: 56px; }
    .gp-b { width: 46px; height: 46px; }
    .gp-start, .gp-select { width: 44px; height: 28px; }
}
