* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

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

h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #2c3e50;
}

.mode-selector {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}

#mode-select {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
}

.input-section {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
    flex-wrap: wrap;
}

.matrix-size {
    display: flex;
    align-items: center;
    gap: 10px;
}

.size-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 15px;
}

input[type="number"] {
    width: 60px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
}

input[type="range"] {
    width: 100px;
}

button {
    padding: 8px 16px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin: 0 5px;
}

button:hover {
    background-color: #2980b9;
}

.instructions {
    text-align: center;
    margin-bottom: 20px;
}

.action-buttons {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sample-front {
    display: inline-block;
    padding: 2px 8px;
    background-color: white;
    border: 2px solid red;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.5);
    border-radius: 4px;
}

.sample-flipped {
    display: inline-block;
    padding: 2px 8px;
    background-color: white;
    border: 2px solid blue;
    box-shadow: 0 0 8px rgba(0, 0, 255, 0.5);
    border-radius: 4px;
}

.hidden {
    display: none !important;
}

.cards-wrapper {
    width: 100%;
    overflow-x: auto;
    padding: 20px 0;
}

/* 箭头控制容器 */
.arrow-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 0 auto;
    width: max-content;
}

/* 一维模式箭头控制 */
.arrow-controls.mode-1d {
    flex-direction: row;
}

/* 二维模式箭头控制 */
.arrow-controls.mode-2d {
    flex-direction: column;
    align-items: center;
}

.middle-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.top-arrow-container, .bottom-arrow-container {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 10px 0;
}

/* 箭头按钮样式 */
.arrow-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background-color: #f8d030; /* 黄色背景 */
    color: #333;
    font-size: 20px;
    font-weight: bold;
    border: 2px solid #e5b924;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.arrow-btn:hover {
    background-color: #fae078;
}

.arrow-btn:active {
    transform: scale(0.95);
    box-shadow: 0 0 8px rgba(248, 208, 48, 0.8);
}

/* 给箭头添加点击动画 */
@keyframes arrowPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.arrow-btn.pulse {
    animation: arrowPulse 0.2s;
}

.cards-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    min-height: 200px;
    margin: 0 auto;
    width: max-content;
}

/* 一维模式下的卡牌容器 */
.cards-container.mode-1d {
    flex-wrap: nowrap;
}

/* 二维模式下的卡牌容器 */
.cards-container.mode-2d {
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    grid-template-rows: repeat(var(--rows, 3), 1fr);
    gap: 10px;
}

.card {
    position: relative;
    width: 60px; /* 默认宽度，将通过JS动态调整 */
    height: 90px; /* 默认高度，将通过JS动态调整 */
    background-color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.card.normal {
    border: 2px solid red;
}

.card.flipped {
    border: 2px solid blue;
}

/* 选中状态添加与边框颜色对应的泛光效果 */
.card.normal.selected {
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.5); /* 红色边框卡片有红光 */
}

.card.flipped.selected {
    box-shadow: 0 0 10px rgba(0, 0, 255, 0.5); /* 蓝色边框卡片有蓝光 */
}

.card.selected {
    transform: translateY(-10px);
}

.mode-2d .card.selected {
    transform: scale(0.9);
}

.card-number {
    font-weight: bold;
    color: #2c3e50;
    /* 字体大小将通过JS动态调整 */
}

/* 一维模式下卡牌水平翻转 */
.mode-1d .card.flipped .card-number {
    transform: scaleX(-1);
    color: #1565C0; /* 蓝色字体，更容易区分镜像状态 */
}

/* 二维模式下卡牌旋转180度 */
.mode-2d .card.flipped .card-number {
    transform: rotate(180deg);
    color: #1565C0; /* 蓝色字体，更容易区分旋转状态 */
}

@keyframes cardPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.card.highlight {
    animation: cardPulse 0.5s;
}

/* 卡牌移动动画 - 增强版 */
@keyframes moveRight {
    0% { transform: translateX(0); }
    50% { transform: translateX(30px); } /* 增加位移距离 */
    100% { transform: translateX(0); }
}

@keyframes moveLeft {
    0% { transform: translateX(0); }
    50% { transform: translateX(-30px); } /* 增加位移距离 */
    100% { transform: translateX(0); }
}

@keyframes moveUp {
    0% { transform: translateY(0); }
    50% { transform: translateY(-30px); } /* 增加位移距离 */
    100% { transform: translateY(0); }
}

@keyframes moveDown {
    0% { transform: translateY(0); }
    50% { transform: translateY(30px); } /* 增加位移距离 */
    100% { transform: translateY(0); }
}

.card.move-right {
    animation: moveRight 0.5s ease-in-out; /* 延长动画时间并添加缓动效果 */
}

.card.move-left {
    animation: moveLeft 0.5s ease-in-out;
}

.card.move-up {
    animation: moveUp 0.5s ease-in-out;
}

.card.move-down {
    animation: moveDown 0.5s ease-in-out;
}