:root {
    --bg-page: #f8fafc;
    --stage-bg: #ffffff;
    --hud-bg: rgba(255, 255, 255, 0.88);
    --hud-border: rgba(15, 23, 42, 0.1);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-glow: rgba(79, 70, 229, 0.18);
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

html.dark, html.dark-mode {
    --bg-page: #080d1a;
    --stage-bg: #080d1a;
    --hud-bg: rgba(15, 23, 42, 0.85);
    --hud-border: rgba(255, 255, 255, 0.12);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --card-bg: #111827;
    --card-border: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 16px 36px -6px rgba(0, 0, 0, 0.7);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.game-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hud-bar {
    position: relative;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--hud-bg);
    border-bottom: 1px solid var(--hud-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    gap: 12px;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(125, 125, 125, 0.08);
    border: 1px solid var(--hud-border);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.hud-btn:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.hud-btn.icon-only {
    padding: 7px 9px;
}

.game-selector-container {
    position: relative;
}

.game-title-btn {
    padding: 6px 14px;
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
    gap: 8px;
}

.game-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 260px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    z-index: 100;
    animation: dropIn 0.15s ease-out;
}

.game-dropdown.hidden {
    display: none;
}

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

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease;
    width: 100%;
}

.dropdown-item:hover, .dropdown-item.active {
    background: var(--accent-glow);
}

.dropdown-item.active {
    outline: 1px solid var(--accent);
}

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

.item-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.item-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

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

.hud-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.score-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 14px;
    border-radius: 20px;
    background: rgba(125, 125, 125, 0.08);
    border: 1px solid var(--hud-border);
}

.score-primary {
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.score-sub {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.stage-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--stage-bg);
    overflow: hidden;
    padding: 8px;
}

canvas#gameCanvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
    cursor: crosshair;
    outline: none;
    box-shadow: var(--shadow-sm);
    border-radius: 4px;
    max-width: 100%;
    max-height: 100%;
}

canvas#gameCanvas:active {
    cursor: grabbing;
}

.mobile-action-btn {
    position: absolute;
    right: 20px;
    bottom: 24px;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 30px;
    background: var(--accent);
    color: #ffffff;
    border: none;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 8px 24px var(--accent-glow);
    cursor: pointer;
    touch-action: manipulation;
}

.mobile-action-btn:active {
    transform: scale(0.95);
    background: var(--accent-hover);
}

.mobile-action-btn.hidden {
    display: none;
}

.bottom-status-bar {
    position: relative;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px;
    background: var(--hud-bg);
    border-top: 1px solid var(--hud-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 13px;
    color: var(--text-muted);
}

.status-text {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bottom-pills {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pill-best {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(125, 125, 125, 0.1);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.rules-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(440px, calc(100vw - 32px));
    border: 1px solid var(--card-border);
    border-radius: 16px;
    background: var(--card-bg);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    padding: 0;
}

.rules-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.dialog-content {
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 16px;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dialog-header h2 {
    font-size: 17px;
    font-weight: 700;
}

.close-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
}

.close-btn:hover {
    color: var(--text-primary);
}

.rules-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
}

.rules-list li {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.rules-list li::before {
    content: "•";
    color: var(--accent);
    font-weight: bold;
    font-size: 16px;
    line-height: 1.2;
}

.dialog-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-top: 1px solid var(--card-border);
    padding-top: 14px;
}

.control-tip {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

.primary-btn {
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease;
}

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

@media (max-width: 640px) {
    .hud-bar {
        padding: 8px 12px;
    }
    .game-title-btn span {
        max-width: 80px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .score-primary {
        font-size: 14px;
    }
    .bottom-status-bar {
        padding: 6px 12px;
        font-size: 12px;
    }
}
