:root {
    --bg-primary: #f4efe7;
    --bg-secondary: #fffaf2;
    --bg-card: #fff4df;
    --accent-primary: #7a4218;
    --accent-secondary: #b45309;
    --text-primary: #2f2118;
    --text-secondary: #7b6652;
    --border-color: #dec6a3;
    --shadow: 0 8px 24px rgba(73, 45, 20, 0.14);
    --shadow-hover: 0 10px 28px rgba(122, 66, 24, 0.18);
    --gradient-1: linear-gradient(135deg, #8a531f 0%, #c78332 100%);
    --gradient-2: linear-gradient(135deg, #b45309 0%, #d97706 100%);
    --gradient-3: linear-gradient(135deg, #5b3417 0%, #9a5a22 100%);
}

[data-theme="light"] {
    --bg-primary: #f4efe7;
    --bg-secondary: #fffaf2;
    --bg-card: #fff4df;
    --accent-primary: #7a4218;
    --accent-secondary: #b45309;
    --text-primary: #2f2118;
    --text-secondary: #7b6652;
    --border-color: #dec6a3;
    --shadow: 0 8px 24px rgba(73, 45, 20, 0.14);
    --shadow-hover: 0 10px 28px rgba(122, 66, 24, 0.18);
}

[data-theme="dark"] {
    --bg-primary: #1f1711;
    --bg-secondary: #2a1e15;
    --bg-card: #352518;
    --accent-primary: #f0b35f;
    --accent-secondary: #f59e0b;
    --text-primary: #fff8ec;
    --text-secondary: #d7b995;
    --border-color: #604025;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
    --shadow-hover: 0 10px 30px rgba(240, 179, 95, 0.18);
}

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

body {
    font-family: 'Inter', 'Noto Sans SC', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background 0.3s ease;
}

.container {
    max-width: 900px;
    width: 100%;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 24px;
}

.title {
    font-size: 3rem;
    font-weight: 700;
    background: var(--gradient-3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.title-icon {
    font-size: 3.5rem;
    filter: drop-shadow(0 4px 8px rgba(0, 212, 255, 0.3));
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 500;
}

/* Game Selector */
.game-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.game-btn {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 18px 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
}

.game-btn:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent-primary);
}

.game-btn.active {
    background: var(--gradient-1);
    border-color: transparent;
}

.game-icon {
    font-size: 3rem;
}

.game-name {
    font-size: 1.3rem;
    font-weight: 600;
}

.game-desc {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Game Container */
.game-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

/* Game Info */
.game-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.info-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.difficulty-control {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
}

.difficulty-range {
    width: 100%;
    min-width: 0;
    accent-color: var(--accent-primary);
}

.difficulty-value {
    color: var(--accent-primary);
    font-weight: 700;
    white-space: nowrap;
}

.difficulty-select {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.difficulty-select:hover {
    border-color: var(--accent-primary);
}

/* Board Wrapper */
.board-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

#game-board {
    background: #d8a85f;
    border: 2px solid #7a4218;
    border-radius: 8px;
    box-shadow: 0 8px 26px rgba(76, 48, 20, 0.28);
    cursor: pointer;
    max-width: 100%;
    height: auto;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 20px;
    border-radius: 8px;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Controls */
.controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.control-btn {
    flex: 1;
    min-width: 150px;
    padding: 15px 25px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.control-btn.primary {
    background: var(--gradient-1);
    color: white;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
}

.control-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(102, 126, 234, 0.4);
}

.control-btn.secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.control-btn.secondary:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.record-output {
    display: none;
    margin-top: 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.86rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.record-output.active {
    display: block;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 40px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.settlement-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(31, 23, 17, 0.56);
}

.settlement-overlay.active {
    display: flex;
}

.settlement-panel {
    position: relative;
    width: min(440px, 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    box-shadow: 0 18px 60px rgba(31, 23, 17, 0.32);
    padding: 28px;
}

.settlement-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
}

.settlement-kicker {
    color: var(--accent-secondary);
    font-weight: 700;
    margin-bottom: 6px;
}

.settlement-title {
    color: var(--text-primary);
    font-size: 1.8rem;
    margin-bottom: 18px;
}

.settlement-score {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 18px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    margin-bottom: 14px;
}

.settlement-score-label {
    color: var(--text-secondary);
    font-weight: 600;
}

.settlement-score strong {
    color: var(--accent-primary);
    font-size: 2.8rem;
    line-height: 1;
}

.settlement-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}

.settlement-grid div {
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg-card);
}

.settlement-grid span {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 6px;
}

.settlement-grid strong {
    display: block;
    color: var(--accent-primary);
    font-size: 1rem;
}

.settlement-action {
    width: 100%;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding: 10px;
    }

    .container {
        max-width: 100%;
    }

    .header {
        margin-bottom: 14px;
    }

    .title {
        font-size: 1.8rem;
    }

    .title-icon {
        font-size: 2rem;
    }

    .subtitle,
    .footer {
        display: none;
    }

    .game-selector {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 12px;
    }

    .game-btn {
        min-width: 0;
        padding: 12px 8px;
        gap: 4px;
    }

    .game-icon {
        font-size: 1.5rem;
    }

    .game-name {
        font-size: 1rem;
    }

    .game-desc {
        font-size: 0.75rem;
    }

    .game-container {
        padding: 10px;
    }

    .game-info {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 10px;
        order: 2;
    }

    .info-card {
        padding: 10px;
        gap: 5px;
    }

    .info-label {
        font-size: 0.75rem;
    }

    .info-value,
    .difficulty-value {
        font-size: 0.9rem;
    }

    .board-wrapper {
        order: 1;
        margin-bottom: 12px;
    }

    .controls {
        gap: 8px;
        order: 3;
    }

    .control-btn {
        min-width: 0;
        padding: 12px 8px;
        font-size: 0.9rem;
    }

    .settlement-panel {
        padding: 22px;
    }

    .settlement-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 420px) {
    .title {
        font-size: 1.45rem;
    }

    .game-info {
        grid-template-columns: 1fr 1fr;
    }

    .controls {
        display: grid;
        grid-template-columns: 1fr;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-container {
    animation: fadeIn 0.5s ease;
}
