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

:root {
    --bg-color: #121213;
    --text-color: #ffffff;
    --border-color: #3a3a3c;
    --tile-border: #3a3a3c;
    --key-bg: #818384;
    --modal-bg: #121213;
    --modal-border: #3a3a3c;
    --correct-color: #538d4e;
    --present-color: #b59f3b;
    --absent-color: #3a3a3c;
}

body.light-mode {
    --bg-color: #ffffff;
    --text-color: #121213;
    --border-color: #d3d6da;
    --tile-border: #d3d6da;
    --key-bg: #d3d6da;
    --modal-bg: #ffffff;
    --modal-border: #d3d6da;
    --absent-color: #787c7e;
}

body.color-blind-mode {
    --correct-color: #f5793a;
    --present-color: #85c0f9;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: all 0.3s;
}

/* Header */
header {
    border-bottom: 1px solid var(--border-color);
    padding: 0.4rem 1rem; /* 减少内边距 */
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-color);
    z-index: 1000;
    max-width: 500px;
    margin: 0 auto;
}

.header-left, .header-right {
    display: flex;
    gap: 0.5rem;
    flex: 0 0 auto; /* 不伸缩 */
}

.header-center {
    flex: 1;
    text-align: center;
    min-width: 0; /* 允许缩小 */
}

h1 {
    font-size: 1.3rem; /* 进一步调小字体 */
    font-weight: 700;
    letter-spacing: 0.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

/* 调整图标按钮大小 */
.icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.35rem; /* 减小内边距 */
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn svg {
    width: 18px; /* 减小图标大小 */
    height: 18px;
}

/* Main Game Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.8rem 0.5rem 1rem; /* 减少顶部内边距 */
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

/* Board */
#board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    margin-bottom: 2rem;
    width: 100%;
    max-width: 350px;
}

.row {
    display: grid;
    grid-template-columns: repeat(var(--word-length, 5), 1fr);
    gap: 5px;
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid var(--tile-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.2s;
}

.tile.filled {
    border-color: #565758;
    animation: pop 0.1s;
}

.tile.correct {
    background-color: var(--correct-color);
    border-color: var(--correct-color);
    color: white;
}

.tile.present {
    background-color: var(--present-color);
    border-color: var(--present-color);
    color: white;
}

.tile.absent {
    background-color: var(--absent-color);
    border-color: var(--absent-color);
    color: white;
}

.tile.flip {
    animation: flip 0.6s ease;
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes flip {
    0% {
        transform: rotateX(0);
    }
    50% {
        transform: rotateX(-90deg);
    }
    100% {
        transform: rotateX(0);
    }
}

/* Keyboard */
#keyboard {
    width: 100%;
    max-width: 500px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.key {
    background-color: var(--key-bg);
    color: var(--text-color);
    border: none;
    border-radius: 4px;
    padding: 1rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    flex: 1;
    max-width: 43px;
    transition: all 0.1s;
}

.key:hover {
    opacity: 0.8;
}

.key:active {
    transform: scale(0.95);
}

.key.wide {
    max-width: 65px;
    font-size: 0.75rem;
}

.key.correct {
    background-color: var(--correct-color);
}

.key.present {
    background-color: var(--present-color);
}

.key.absent {
    background-color: var(--absent-color);
}

/* Toast Messages */
#toast {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-color);
    color: var(--text-color);
    padding: 1rem 2rem;
    border-radius: 4px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
    border: 1px solid var(--border-color);
}

#toast.show {
    opacity: 1;
}

/* Full Page Overlays */
.overlay {
    display: none;
    position: fixed;
    top: 70px; /* Below the header */
    left: 0;
    width: 100%;
    height: calc(100% - 70px);
    background: var(--bg-color);
    z-index: 999;
    overflow-y: auto;
    padding: 1rem;
}

.overlay.show {
    display: block;
}

.overlay-content {
    max-width: 500px;
    margin: 0 auto;
    padding: 2rem 0;
}

.overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

/* Enhanced Close Button */
.close-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-weight: 300;
}

.close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.close-btn:active {
    transform: scale(0.95);
}

/* Help Section */
.help-section {
    margin-bottom: 2rem;
}

.help-section p {
    margin-bottom: 1rem;
    line-height: 1.8;
    color: var(--text-color);
}

.help-examples {
    margin-top: 2rem;
}

.help-examples h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    text-transform: uppercase;
}

.example-item {
    margin-bottom: 1.5rem;
}

.example-row {
    display: flex;
    gap: 5px;
    margin-bottom: 0.75rem;
}

.example-tile {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.25rem;
}

.example-tile.correct {
    background-color: var(--correct-color);
    border-color: var(--correct-color);
    color: white;
}

.example-tile.present {
    background-color: var(--present-color);
    border-color: var(--present-color);
    color: white;
}

.example-tile.absent {
    background-color: var(--absent-color);
    border-color: var(--absent-color);
    color: white;
}

.example-text {
    color: var(--text-color);
    line-height: 1.6;
}

.example-text strong {
    font-weight: 700;
}

/* Settings */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-group {
    display: flex;
    flex-direction: column;
}

.setting-label {
    font-size: 0.9rem;
    color: var(--text-color);
    margin-bottom: 0.25rem;
}

.setting-description {
    font-size: 0.75rem;
    color: var(--text-color);
    opacity: 0.7;
}

.setting-control {
    display: flex;
    align-items: center;
}

select {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 4px;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--correct-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* Stats */
.stats-container {
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin: 2rem 0;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    color: #818384;
}

.btn {
    background: var(--correct-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    margin-top: 1rem;
}

.btn:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: #818384;
}

/* Footer */
footer {
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    margin-top: auto;
}

.footer-content {
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
}

.footer-content p {
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
}

.footer-links a {
    color: var(--text-color);
    text-decoration: none;
    transition: opacity 0.2s;
}

.footer-links a:hover {
    opacity: 0.7;
    text-decoration: underline;
}

.footer-links span {
    color: var(--text-color);
    opacity: 0.7;
}

/* Simple Page Content */
.simple-page-content {
    padding: 1rem 0;
    line-height: 1.6;
}

.simple-page-content h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.simple-page-content p {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.simple-page-content ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.simple-page-content li {
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

/* 游戏操作按钮 */
.game-actions {
    display: flex;
    gap: 12px;
    margin: 8px 0 8px 0; /* 上下间距相同，更加协调 */
    width: 100%;
    max-width: 500px;
    justify-content: center;
}

.btn-action {
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #818384;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    /* 移除固定宽度，让按钮根据内容自适应 */
    width: auto;
}

.btn-action:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-action:active {
    transform: translateY(0);
}

/* 内容区块 */
.content-sections {
    width: 100%;
    max-width: 500px;
    margin-top: 2rem;
}

.content-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.content-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    text-align: center;
}

/* 游戏说明 */
.game-instructions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.instruction-step {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.step-number {
    background: var(--correct-color);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: bold;
    flex-shrink: 0;
}

.instruction-step p {
    margin: 0;
    line-height: 1.5;
    color: var(--text-color);
}

/* 其他游戏网格 */
.other-games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.game-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s;
}

.game-card:hover {
    background: var(--border-color);
    transform: translateY(-2px);
}

.game-icon {
    width: 40px;
    height: 40px;
    background: var(--correct-color);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.game-card span {
    font-size: 0.875rem;
    text-align: center;
}

/* 创建游戏覆盖层 */
.share-link-container {
    margin: 1.5rem 0;
}

.share-link-container label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.link-input-group {
    display: flex;
    gap: 0.5rem;
}

#shareLink {
    flex: 1;
    padding: 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-size: 0.875rem;
}

.game-options {
    margin-top: 1.5rem;
}

.btn-copy {
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.btn-copy.disabled {
    background: #5a6268 !important;
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn-copy.disabled:hover {
    opacity: 0.6;
    transform: none !important;
}

.btn-copy:disabled {
    background: #5a6268 !important;
    opacity: 0.6;
    cursor: not-allowed;
}

/* 创建游戏页面样式优化 */
.create-game-section {
    margin-bottom: 1.5rem;
}

.create-game-section p {
    margin-bottom: 1rem;
    line-height: 1.5;
    color: var(--text-color);
}

/* 游戏轮播样式 */
.games-carousel {
    position: relative;
    margin-top: 1rem;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.game-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0.5rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s;
    text-align: center;
    min-height: 100px;
}

.game-card:hover {
    background: var(--border-color);
    transform: translateY(-2px);
}

.game-number {
    width: 32px;
    height: 32px;
    background: var(--correct-color);
    color: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.game-title {
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.game-description {
    font-size: 0.75rem;
    opacity: 0.8;
    line-height: 1.3;
}

/* 轮播控制 */
.carousel-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.carousel-btn {
    background: var(--key-bg);
    border: none;
    border-radius: 4px;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.carousel-btn:hover {
    background: var(--border-color);
}

.carousel-btn svg {
    width: 20px;
    height: 20px;
}

.carousel-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.carousel-indicators {
    display: flex;
    gap: 0.5rem;
}

.carousel-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-color);
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.carousel-indicator.active {
    background: var(--correct-color);
}

/* Responsive */
@media (max-width: 768px) {
    .games-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .game-card {
        padding: 0.75rem 0.25rem;
        min-height: 90px;
    }

    .game-number {
        width: 28px;
        height: 28px;
        font-size: 0.875rem;
    }

    .game-title {
        font-size: 0.8rem;
    }

    .game-description {
        font-size: 0.7rem;
    }

    .carousel-controls {
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .tile {
        font-size: 1.5rem;
    }

    .key {
        padding: 0.875rem 0.375rem;
        font-size: 0.75rem;
    }

    h1 {
        font-size: 1.1rem; /* 手机端更小的标题 */
        letter-spacing: 0.03rem;
    }

    header {
        padding: 0.5rem;
    }

    .game-actions {
        gap: 10px;
        margin: 6px 0 6px 0;
    }

    .btn-action {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .games-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .game-card {
        min-height: 85px;
        padding: 0.5rem 0.25rem;
    }
}

/* 特别小的屏幕 */
@media (max-width: 360px) {
    .btn-action {
        padding: 4px 8px;
        font-size: 0.7rem;
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
