@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&family=Noto+Sans+SC:wght@400;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: 'Inter', 'Noto Sans SC', sans-serif;
    background: #ffffff;
    color: #000000;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
}

.game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.global-color-switch {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0;
}

.switch-track {
    width: 80px;
    height: 32px;
    border-radius: 16px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    border: 1px solid #000000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    font-size: 0.65rem;
    font-weight: 700;
    user-select: none;
    overflow: hidden;
}

.switch-track:not(.active) {
    background: #e5e7eb;
}

.switch-track.active {
    background: #22c55e;
}

.switch-ball {
    width: 26px;
    height: 26px;
    background: #ffffff;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 1px solid #000000;
    z-index: 3;
}

.switch-track.active .switch-ball {
    transform: translateX(48px);
}

.switch-label-left, .switch-label-right {
    z-index: 2;
    position: relative;
    width: 50%;
    text-align: center;
    line-height: 1;
    font-size: 0.65rem;
    font-weight: 700;
    transition: opacity 0.2s;
}

.switch-label-left {
    color: #ffffff;
    opacity: 0;
}

.switch-track.active .switch-label-left {
    opacity: 1;
}

.switch-label-right {
    color: #000000;
    opacity: 1;
}

.switch-track.active .switch-label-right {
    opacity: 0;
}

.header {
    text-align: center;
    margin-bottom: 12px;
    flex-shrink: 0;
    margin-top: 8px;
}

.title {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.subtitle {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 500;
}

.mode-switcher {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    background: #f3f4f6;
    padding: 4px;
    border-radius: 8px;
    border: 1px solid #000000;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mode-btn {
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
    flex: 1;
    text-align: center;
}

.mode-btn.active {
    background: #000000;
    color: #ffffff;
}

.mode-btn:active {
    transform: scale(0.95);
}

.stats-bar {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    background: #ffffff;
    border: 1px solid #000000;
    border-radius: 10px;
    padding: 12px 8px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.stat-item {
    text-align: center;
    flex: 1;
    position: relative;
}

.stat-item:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 24px;
    background: #e5e7eb;
}

.stat-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    font-weight: 600;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    font-family: 'Inter', monospace;
}

/* 计时器防抖：使用等宽/表格数字 + 固定宽度，避免数字宽度变化导致左右摇晃 */
#timer-display {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    display: inline-block;
    width: 8ch; /* "00:00:00" 正好 8 个字符 */
    text-align: center;
}

.game-area {
    position: relative;
    background: #ffffff;
    border: 1px solid #000000;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    margin: 0 auto;
    width: 100%;
    max-width: 350px;
    aspect-ratio: 1;
}

.game-content {
    width: 100%;
    height: 100%;
}

.classic-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 8px;
    width: 100%;
    height: 100%;
}

.classic-cell {
    background: #ffffff;
    border: 1px solid #000000;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
    user-select: none;
    position: relative;
}

.classic-cell:active {
    transform: scale(0.95);
}

.classic-cell.found {
    cursor: default;
}

/* 黑白模式下错误变粉红 */
.classic-cell.wrong-bw {
    animation: shake 0.2s ease-in-out;
    background: #fee2e2;
    border-color: #dc2626;
    color: #dc2626;
}

/* 彩色模式下错误只震动 */
.classic-cell.wrong-color {
    animation: shake 0.2s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.voronoi-cell {
    cursor: pointer;
    stroke: #000000;
    stroke-width: 1.5;
    transition: all 0.2s;
}

.voronoi-cell.found {
}

/* 修复：黑白模式下Voronoi错误变粉红 */
.voronoi-cell.wrong-bw {
    animation: shake-voronoi 0.2s ease-in-out;
    fill: #fee2e2 !important;
    stroke: #dc2626 !important;
    stroke-width: 2px !important;
}

/* 修复：彩色模式下Voronoi错误只震动，不变红框 */
.voronoi-cell.wrong-color {
    animation: shake-voronoi 0.2s ease-in-out;
}

@keyframes shake-voronoi {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.voronoi-text {
    font-weight: 700;
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: central;
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    fill: #000000;
}

.controls {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-shrink: 0;
    width: 100%;
    max-width: 350px;
    margin-left: auto;
    margin-right: auto;
}

.btn-secondary {
    padding: 10px 20px;
    background: #ffffff;
    color: #000000;
    border: 1px solid #000000;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    font-family: inherit;
    flex: 1;
}

.btn-secondary:active {
    background: #f3f4f6;
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.98);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 30;
    padding: 20px;
    text-align: center;
}

.overlay.hidden {
    display: none;
}

.overlay h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 6px;
}

.overlay p {
    color: #6b7280;
    margin-bottom: 20px;
    font-size: 0.875rem;
    line-height: 1.4;
}

.btn-primary {
    padding: 12px 32px;
    background: #000000;
    color: #ffffff;
    border: 1px solid #000000;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
    width: 100%;
    max-width: 200px;
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: #ffffff;
    border: 1px solid #000000;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 20px;
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.result-item {
    background: #f9fafb;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.result-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    font-weight: 600;
    margin-bottom: 4px;
}

.result-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: #000000;
}

.result-value.accent {
    color: #dc2626;
}

.particle {
    position: fixed;
    pointer-events: none;
    width: 6px;
    height: 6px;
    background: #000000;
    border-radius: 50%;
    z-index: 50;
    animation: particle-float 0.6s ease-out forwards;
}

@keyframes particle-float {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

@media (min-width: 390px) and (max-width: 450px) {
    .title { font-size: 1.75rem; }
    .stat-value { font-size: 1.75rem; }
    .classic-cell { font-size: 1.5rem; }
    .game-area { max-width: 380px; }
    .classic-grid { gap: 8px; padding: 10px; }
}

@media (max-width: 360px) {
    .title { font-size: 1.25rem; }
    .stat-value { font-size: 1.25rem; }
    .classic-cell { font-size: 1rem; }
    .game-area { max-width: 300px; }
    .mode-btn { padding: 6px 8px; font-size: 0.75rem; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .game-wrapper {
        flex-direction: row;
        flex-wrap: wrap;
        align-content: flex-start;
    }
    .header { width: 100%; }
    .mode-switcher { width: 100%; }
    .stats-bar { width: 40%; margin-right: 10px; }
    .game-area { width: 55%; max-width: none; height: auto; aspect-ratio: 1; }
    .controls { width: 100%; }
}

