* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
    color: #f0f0f0;
}

body {
    background-color: #000000;
    display: flex;
    justify-content: center;
    padding: 20px;
    min-height: 100vh; /* 确保body至少有视口高度 */
    align-items: center; /* 垂直居中 */
    margin: 0; /* 移除默认边距 */ 
    overflow: hidden; /* 禁止页面滚动 */
    position: fixed; /* 固定位置 */
    width: 100%; /* 确保宽度占满 */
    height: 100%; /* 确保高度占满 */
}

.container {
    display: flex;
    max-width: 1200px;
    width: 100%;
    gap: 20px;
    align-items: center;
}

/* Grid Section */
.grid-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.grid-controls {
    position: relative;
    height: 500px;
}

.eraser-tool {
    position: absolute;
    top: 20px;
    right: 60px;
    width: 30px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
}

.eraser-icon {
    width: 30px;
    filter: invert(1);
}

.dimension-display {
    position: absolute;
    color: #4499ff;
    font-weight: bold;
    font-size: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dimension-display .dimension-value {
    display: none; /* 隐藏维度数字 */
}

.dimension-display.horizontal {
    top: 20px;
    left: 100px;
    color: #ff6655;
}

.dimension-display.vertical {
    top: 200px;
    left: 50px;
    color: #4499ff;
}

.grid-container {
    position: absolute;
    top: 70px;
    left: 80px;
    border: 1px solid #777;
    width: 500px;
    height: 500px;
    z-index: 1;
    background-color: #222;
}

.grid {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    background-color: #222;
    position: relative;
}

.grid-cell {
    border: 1px solid #555;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    color: #aaa;
    font-weight: bold;
}

.grid-cell[style*="background-color"] {
    color: #000;
}

.grid-resizers {
    position: absolute;
    top: 70px;
    left: 80px;
    width: 500px;
    height: 500px;
    pointer-events: none;
    z-index: 2;
}

/* 蓝色圆点已移除 */
.circle-marker {
    display: none;
    pointer-events: none;
    width: 20px;
    height: 20px;
    background-color: #8cc;
    border-radius: 50%;
    margin-left: 0;
    cursor: grab;
    transition: background-color 0.2s ease;
    position: absolute;
    z-index: 10;
    border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.5);
}

.circle-marker:hover {
    background-color: #7bb;
    transform: scale(1.2);
}

.circle-marker:active {
    cursor: grabbing;
}

.grid-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

.checkbox, .grid-icon {
    width: 30px;
    height: 30px;
    border: 1px solid #aaa;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #333;
}

.grid-icon img, .checkbox img {
    filter: invert(1);
}

/* 连接线已移除 */
.marker-connector {
    display: none;
    position: absolute;
    background-color: #8cc;
    pointer-events: none;
    z-index: 5;
    width: 1px;
    height: 1px;
    transform-origin: 0 0;
    box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
    opacity: 0;
}

/* Controls Section */
.controls-section {
    width: 350px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-self: center;
    justify-content: center;
    height: 100%;
}

.control-box {
    border: 1px solid #777;
    border-radius: 10px;
    overflow: hidden;
    background-color: #222;
}

.box-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background-color: #333;
}

.header-icon {
    background-color: #ff6600;
    color: white;
    width: 26px;
    height: 26px;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
}

.header-text {
    font-size: 20px;
    font-weight: bold;
    color: #f0f0f0;
}

.factor-controls {
    padding: 20px;
    display: flex;
    justify-content: center;
}

.factor-input-container {
    display: flex;
    align-items: center;
    gap: 20px;
}

.factor {
    width: 80px;
    height: 120px;
    border: 1px solid #777;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    background-color: #333;
}

.factor-value {
    font-size: 48px;
    font-weight: bold;
    line-height: 120px;
    color: #f0f0f0;
}

.up-arrow, .down-arrow {
    position: absolute;
    width: 0;
    height: 0;
    cursor: pointer;
}

.up-arrow {
    top: 10px;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-bottom: 20px solid;
}

.down-arrow {
    bottom: 10px;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 20px solid;
}

.up-arrow.blue, .down-arrow.blue {
    border-bottom-color: #4499ff;
    border-top-color: #4499ff;
}

.up-arrow.red, .down-arrow.red {
    border-bottom-color: #ff6655;
    border-top-color: #ff6655;
}

.multiply-sign {
    font-size: 36px;
    color: #f0f0f0;
}

.product-result {
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    font-size: 24px;
}

.area-text {
    font-size: 36px;
    color: #f0f0f0;
}

.result-value {
    background-color: #554400;
    border: 1px solid #aa9933;
    border-radius: 10px;
    padding: 5px 15px;
    font-size: 36px;
    font-weight: bold;
    color: #ffee99;
}

/* Connecting lines */
.connecting-line {
    position: absolute;
    background-color: #aaa;
    pointer-events: none;
    z-index: 5;
}

.connecting-line.horizontal {
    height: 2px;
    box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
}

.connecting-line.vertical {
    width: 2px;
    box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
}

/* Add responsive styles */
@media (max-width: 992px) {
    .container {
        flex-direction: column;
    }
    
    .controls-section {
        width: 100%;
    }
}

@media (max-width: 1024px) and (min-width: 768px) {
    /* iPad specific styles */
    body {
        padding: 0; /* Remove extra padding */
        overflow-x: hidden; /* Prevent horizontal scrolling */
        width: 100%;
        height: 100%;
    }
    
    .container {
        flex-direction: row; /* Keep grid on left, controls on right as per user preference */
        justify-content: space-between;
        width: 100%;
        max-width: 100%;
        padding: 10px;
        gap: 10px;
        box-sizing: border-box;
    }
    
    .grid-section {
        width: 60%;
    }
    
    .controls-section {
        width: 35%;
    }
    
    .grid-controls {
        height: 350px;
        transform: scale(0.85);
        transform-origin: top left;
    }
    
    .grid-container {
        width: calc(100% - 60px);
        height: 350px;
        max-width: 350px;
        left: 50px;
        top: 50px;
    }
    
    .grid-resizers {
        width: calc(100% - 60px);
        height: 350px;
        max-width: 350px;
        left: 50px;
        top: 50px;
    }
    
    /* iPad红色圆点适配 */
    .red-dot-container {
        width: calc(100% - 60px);
        height: 350px;
        max-width: 350px;
        left: 50px;
        top: 50px;
    }
    
    .red-dot {
        width: 12px;
        height: 12px;
    }
    
    .factor {
        width: 60px; /* Slightly smaller control elements */
        height: 80px;
    }
    
    .factor-value {
        font-size: 36px;
        line-height: 80px;
    }
}

@media (max-width: 768px) and (min-width: 577px) {
    .grid-controls {
        height: 380px;
    }
    
    .grid-container {
        width: calc(100% - 100px);
        height: 380px;
        max-width: 380px;
    }
    
    .grid-resizers {
        width: calc(100% - 100px);
        height: 380px;
        max-width: 380px;
    }
    
    /* 平板红色圆点适配 */
    .red-dot-container {
        width: calc(100% - 100px);
        height: 380px;
        max-width: 380px;
    }
}

@media (max-width: 576px) {
    body {
        padding: 10px;
    }
    
    .container {
        gap: 10px;
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
    
    .grid-section {
        width: 65%;
        margin-right: 5px;
    }
    
    .controls-section {
        width: 30%;
        display: flex;
        flex-direction: column;
    }
    
    .grid-controls {
        height: 300px;
        position: relative;
    }
    
    .grid-container {
        width: calc(100% - 80px);
        height: 300px;
        left: 40px;
        top: 40px;
    }
    
    .grid-resizers {
        width: calc(100% - 80px);
        height: 300px;
        left: 40px;
        top: 40px;
    }
    
    /* 小屏幕设备红色圆点适配 */
    .red-dot-container {
        width: calc(100% - 80px);
        height: 300px;
        left: 40px;
        top: 40px;
    }
    
    .red-dot {
        width: 10px;
        height: 10px;
        border-width: 1px;
    }
    
    .dimension-display {
        font-size: 18px;
    }
    
    .dimension-display.horizontal {
        left: 40px;
        top: 10px;
    }
    
    .dimension-display.vertical {
        top: 80px;
        left: 20px;
    }
}

.back-button {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 20px);
    left: 20px;
    width: 32px;
    height: 32px;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.back-button:hover {
    opacity: 0.8;
    transform: none;
    box-shadow: none;
}

.back-button i {
    color: white;
    font-size: 12px;
}

/* 红色圆点样式 */
.red-dot-container {
    position: absolute;
    top: 70px;
    left: 80px;
    width: 500px;
    height: 500px;
    pointer-events: none;
    z-index: 3;
}

.red-dot {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px; /* 增加触摸区域到原来的两倍 */
    height: 30px; /* 增加触摸区域到原来的两倍 */
    background-color: #ff3333;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.5);
    z-index: 10;
    cursor: grab;
    pointer-events: auto;
    transition: transform 0.2s ease, background-color 0.2s ease;
    /* 使用伪元素来显示较小的视觉点 */
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent; /* 移除背景色 */
}

.red-dot::after {
    content: '';
    position: absolute;
    width: 15px; /* 保持原来的视觉大小 */
    height: 15px; /* 保持原来的视觉大小 */
    background-color: #ff3333;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(255, 255, 255, 0.5);
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.red-dot:hover::after {
    background-color: #ff5555;
    transform: scale(1.1);
}

.red-dot:active {
    cursor: grabbing;
}

.red-dot:active::after {
    background-color: #ff0000;
}

.red-dot-container {
    position: absolute;
    top: 70px;
    left: 80px;
    width: 500px;
    height: 500px;
    z-index: 3;
    pointer-events: none;
}