:root {
    --primary-color: #2c3e50;
    --success-color: #2ecc71;
    --error-color: #e74c3c;
    --bg-color: #f8f9fa;
    --text-color: #2c3e50;
    --sticker-bg: #FFFFFF;
    --anchor-stroke: #ecf0f1;
}

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

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.hidden {
    display: none !important;
}

/* 首页菜单重新设计 */
#menu-view header {
    padding: 42px 20px 30px;
    text-align: center;
    background: transparent;
}

#menu-view h1 {
    margin: 0;
    font-size: 32px;
    letter-spacing: 0;
    font-weight: 800;
    color: #1a1a1a;
}

.menu-guide {
    margin: 10px 0 18px;
    color: #5d6a72;
    font-size: 17px;
    font-weight: 600;
}

.platform-panel {
    width: min(760px, calc(100vw - 40px));
    margin: 0 auto;
    padding: 14px 16px;
    border: 1px solid #dde5ea;
    border-radius: 8px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    text-align: left;
    box-shadow: 0 8px 24px rgba(44, 62, 80, 0.06);
}

.platform-status {
    color: #1f2d36;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
    word-break: break-word;
}

.save-status {
    color: #6d7a82;
    font-size: 13px;
    line-height: 1.5;
}

.save-status.is-ready {
    color: #248a50;
}

.platform-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.platform-actions button {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid #d5dde2;
    border-radius: 8px;
    background: #f7f9fa;
    color: #26343c;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.platform-actions button:hover {
    background: #eef3f5;
}

#category-container {
    padding: 0 20px 60px;
    overflow-y: auto;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

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

.level-card {
    background: white;
    border-radius: 24px;
    padding: 0;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.04);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.02);
}

.level-card:hover {
    transform: translateY(-10px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.level-card:active {
    transform: scale(0.98);
}

.level-card.completed::after {
    content: "已完成 ✓";
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--success-color);
    color: white;
    padding: 6px 12px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
    z-index: 2;
}

.level-thumb {
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #f0f3f5;
    overflow: hidden;
}

.level-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.level-card:hover .level-thumb img {
    transform: scale(1.1);
}

.level-title-text {
    padding: 20px 15px;
    font-size: 17px;
    font-weight: 700;
    color: #1a1a1a;
    background: white;
}

/* 游戏头部优化 */
.game-header {
    height: 70px;
    padding: 0 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    border-bottom: 1px solid #f0f0f0;
    z-index: 10;
}

.game-header button {
    padding: 10px 18px;
    border: none;
    border-radius: 12px;
    background: #f0f0f0;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.game-header button:hover {
    background: #e0e0e0;
}

.primary-btn {
    background: #1a1a1a !important;
    color: white !important;
}

.primary-btn:hover {
    background: #333 !important;
}

.header-btns {
    display: flex;
    gap: 5px;
}

#calibration-instructions {
    background: #fff;
    padding: 15px;
    text-align: center;
    font-size: 16px;
    border-top: 1px solid #eee;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

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

/* 游戏画布区域 */
#game-container, #calibration-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #222; /* 暗色背景衬托 9:16 图片 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

#game-board, #calibration-board {
    position: relative;
    aspect-ratio: 3 / 4; /* 修改为 3:4 比例 */
    height: 100%; /* 优先撑满高度 */
    max-width: 100%;
    background-color: #000;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 适配不同屏幕比例 */
@media (max-aspect-ratio: 3/4) {
    #game-board, #calibration-board {
        width: 100%; /* 如果屏幕太窄，则宽度撑满 */
        height: auto;
    }
}

#background-img, #reference-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    display: block;
}

#anchors-layer, #drag-layer, #calibration-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#drag-layer, #calibration-layer {
    pointer-events: auto;
}

/* 英文锚点样式 - 作为固定的提示 */
.anchor {
    position: absolute;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.95);
    border: 1.5px solid var(--anchor-stroke);
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    transform: translate(-50%, -50%); /* 中心对齐 */
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    font-weight: 500;
}

.anchor.matched {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4);
    z-index: 11;
}

/* 贴纸条优化 */
#sticker-bar-container {
    height: 110px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    overflow-x: auto;
    padding: 0 20px;
}

#sticker-bar {
    display: flex;
    gap: 15px;
    height: 100%;
    align-items: center;
    padding-right: 50px; /* 留白 */
}

.sticker {
    padding: 10px 20px;
    background: var(--sticker-bg);
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    white-space: nowrap;
    cursor: grab;
    user-select: none;
    font-weight: 500;
    touch-action: none; /* 重要：防止拖拽时页面滚动 */
}

.sticker.dragging {
    position: fixed;
    z-index: 1000;
    opacity: 0.9;
    cursor: grabbing;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}

.sticker.matched {
    display: none; /* 被吸附后在原处消失，显示在锚点下方或直接覆盖 */
}

/* 抖动动画 */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
    border-color: var(--error-color);
}

/* 成功弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    width: 80%;
    max-width: 400px;
}

.modal-content h2 {
    color: var(--success-color);
    margin-top: 0;
}

.modal-content button {
    display: block;
    width: 100%;
    margin: 10px 0;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

#modal-next-btn {
    background: var(--primary-color);
    color: white;
}

/* 加载层 */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.loading-card {
    width: min(360px, calc(100vw - 48px));
    padding: 28px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(44, 62, 80, 0.16);
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
    margin-left: auto;
    margin-right: auto;
}

#loading-text {
    margin: 8px 0 4px;
    font-size: 17px;
    font-weight: 800;
}

#loading-hint {
    margin: 0 0 16px;
    color: #65737b;
    font-size: 14px;
    line-height: 1.5;
}

.loading-progress {
    width: 100%;
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8eef1;
}

#loading-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--success-color);
    transition: width 0.25s ease;
}

#loading-progress-text {
    margin-top: 8px;
    color: #41515a;
    font-size: 13px;
    font-weight: 700;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (max-width: 700px) {
    #menu-view header {
        padding: 28px 14px 22px;
    }

    #menu-view h1 {
        font-size: 27px;
    }

    .platform-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .platform-actions button {
        flex: 1;
    }
}
