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

body {
    background-color: #1a1a2e;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#info-panel {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 8px;
    padding: 10px 24px;
    font-size: 16px;
    min-width: 640px;
    text-align: center;
    color: #e94560;
    font-weight: bold;
    letter-spacing: 1px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    transition: background 0.3s;
}

#info-panel.in-check {
    background: #2a1020;
    border-color: #e94560;
}

.info-next-mg {
    font-size: 12px;
    color: #4ecdc4;
    font-weight: 600;
    letter-spacing: 0.5px;
}

#canvas-container {
    position: relative;
    border: 3px solid #0f3460;
    border-radius: 4px;
    box-shadow: 0 0 30px rgba(233, 69, 96, 0.15);
}

#game-canvas {
    display: block;
    cursor: pointer;
}

#overlay-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

#overlay-container.active {
    display: flex;
}

.overlay-panel {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 32px;
    min-width: 400px;
    max-width: 600px;
    color: #e0e0e0;
    box-shadow: 0 0 40px rgba(233, 69, 96, 0.2);
    animation: scaleIn 0.2s ease-out;
}

.overlay-panel h2 {
    color: #e94560;
    margin-bottom: 16px;
    text-align: center;
}

.btn {
    background: #0f3460;
    color: #e0e0e0;
    border: 1px solid #e94560;
    border-radius: 6px;
    padding: 10px 24px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
}

.btn:hover {
    background: #e94560;
    color: #fff;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: #e94560;
    color: #fff;
}

.btn-primary:hover {
    background: #c73652;
}

/* ── Promotion Dialog ───────────────────────────────────── */

.promotion-choices {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 20px;
}

.promotion-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: #0f3460;
    border: 2px solid #0f3460;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    color: #e0e0e0;
    font-family: inherit;
}

.promotion-btn:hover {
    border-color: #e94560;
    background: #1a1a4e;
}

.promotion-icon {
    font-size: 48px;
    line-height: 1;
}

.promotion-icon.white-piece {
    color: #fff;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}

.promotion-icon.black-piece {
    color: #222;
    text-shadow: 0 0 3px rgba(200, 200, 200, 0.5);
}

.promotion-label {
    font-size: 12px;
    color: #aaa;
}

#promotion-cancel {
    display: block;
    margin: 0 auto;
}

/* ── Game Over Overlay ──────────────────────────────────── */

.game-over-result {
    text-align: center;
    font-size: 20px;
    margin-bottom: 24px;
    color: #e0e0e0;
}

.game-over-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ── Setup Wizard ───────────────────────────────────────── */

.setup-panel {
    min-width: 500px;
    max-width: 680px;
}

/* Screen 1: Player Count */
.setup-player-count {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 20px;
}

.setup-count-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 24px 36px;
    min-width: 160px;
    border-radius: 10px;
    transition: background 0.2s, transform 0.1s;
}

.setup-count-btn .count-num {
    font-size: 48px;
    font-weight: bold;
    line-height: 1;
}

.setup-count-btn .count-label {
    font-size: 18px;
    font-weight: 600;
}

.setup-count-btn .count-sub {
    font-size: 11px;
    color: #aaa;
    margin-top: 4px;
}

.setup-count-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.setup-count-btn.disabled:hover {
    background: #0f3460;
    color: #e0e0e0;
}

/* Screen 2: Player Profiles */
.setup-profiles-row {
    display: flex;
    gap: 12px;
    margin: 16px 0;
}

.setup-profile {
    flex: 1;
    text-align: center;
}

.setup-profile h3 {
    color: #e94560;
    margin-bottom: 10px;
    font-size: 16px;
}

.setup-divider {
    width: 2px;
    background: #0f3460;
    border-radius: 1px;
}

.setup-name-input {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #0f3460;
    border-radius: 6px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.setup-name-input:focus {
    border-color: #e94560;
}

.setup-name-input::placeholder {
    color: #555;
}

.setup-icon-label {
    font-size: 12px;
    color: #888;
    margin: 10px 0 6px;
}

.setup-icon-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.setup-icon-btn {
    font-size: 22px;
    padding: 6px;
    background: #0f3460;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
    line-height: 1.2;
}

.setup-icon-btn:hover {
    border-color: #e94560;
    transform: scale(1.1);
}

.setup-icon-btn.selected {
    border-color: #e94560;
    background: #1a1a4e;
    box-shadow: 0 0 8px rgba(233, 69, 96, 0.4);
}

/* Screen 3: Minigame Selection */
.setup-minigame-list {
    margin: 12px 0 16px;
    max-height: 200px;
    overflow-y: auto;
}

.setup-minigame-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.setup-minigame-item:hover {
    background: rgba(15, 52, 96, 0.5);
}

.setup-minigame-item input[type="checkbox"] {
    accent-color: #e94560;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.setup-mg-thumb {
    font-size: 28px;
    line-height: 1;
}

.setup-mg-name {
    font-size: 15px;
    font-weight: 500;
}

.setup-no-games {
    text-align: center;
    color: #888;
    padding: 24px 12px;
    line-height: 1.6;
}

.setup-mode-section {
    border-top: 1px solid #0f3460;
    padding-top: 14px;
    margin-bottom: 8px;
}

.setup-mode-label {
    display: block;
    font-size: 13px;
    color: #888;
    margin-bottom: 8px;
    text-align: center;
}

.setup-mode-options {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.setup-mode-options.disabled {
    opacity: 0.35;
    pointer-events: none;
}

.setup-mode-btn {
    padding: 6px 14px;
    font-size: 12px;
    border-radius: 16px;
}

.setup-mode-btn.active {
    background: #e94560;
    color: #fff;
    border-color: #e94560;
}

/* Screen 4: Attacker Loss Rule */
.setup-rule-desc {
    text-align: center;
    color: #bbb;
    margin-bottom: 20px;
    line-height: 1.5;
}

.setup-rule-options {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}

.setup-rule-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 28px;
    min-width: 160px;
    border-radius: 10px;
}

.setup-rule-btn .rule-icon {
    font-size: 32px;
    line-height: 1;
}

.setup-rule-btn .rule-title {
    font-size: 20px;
    font-weight: 700;
}

.setup-rule-btn .rule-sub {
    font-size: 11px;
    color: #aaa;
}

/* Shared: Setup actions row */
.setup-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
}

/* ── Minigame Screen ────────────────────────────────────── */

.mg-screen {
    display: flex;
    width: 100%;
    height: 100%;
    max-width: 1000px;
    max-height: 700px;
    margin: auto;
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    overflow: hidden;
}

.mg-sidebar {
    width: 160px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 10px;
    background: #0f2040;
}

.mg-sidebar-left {
    border-right: 2px solid #0f3460;
}

.mg-sidebar-right {
    border-left: 2px solid #0f3460;
}

.mg-player-icon {
    font-size: 40px;
    line-height: 1;
}

.mg-player-name {
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
    text-align: center;
    word-break: break-word;
}

.mg-player-role {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 8px;
    border-radius: 4px;
}

.mg-role-attacker {
    color: #e94560;
    background: rgba(233, 69, 96, 0.15);
}

.mg-role-defender {
    color: #4ecdc4;
    background: rgba(78, 205, 196, 0.15);
}

.mg-controls-hint {
    font-size: 11px;
    color: #777;
    text-align: center;
    margin-top: 12px;
    line-height: 1.4;
    white-space: pre-line;
}

.mg-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.mg-title {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #e94560;
    padding: 10px;
    border-bottom: 1px solid #0f3460;
}

.mg-arena {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #0d1b2a;
}

/* Minigame Explanation Overlay */
.mg-explanation {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: rgba(13, 27, 42, 0.95);
    z-index: 10;
    padding: 24px;
}

.mg-explanation-text {
    font-size: 16px;
    color: #e0e0e0;
    text-align: center;
    line-height: 1.6;
    max-width: 400px;
}

/* Minigame Result Overlay */
.mg-result-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(13, 27, 42, 0.9);
    z-index: 10;
}

.mg-result-panel {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.mg-result-icon {
    font-size: 48px;
}

.mg-result-title {
    font-size: 24px;
    color: #e94560;
}

.mg-result-name {
    font-size: 16px;
    color: #e0e0e0;
}

/* ── Minigame Chooser ───────────────────────────────────── */

.mg-chooser-panel {
    min-width: 400px;
    max-width: 550px;
}

.mg-chooser-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.mg-chooser-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    background: #0f3460;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    color: #e0e0e0;
    font-family: inherit;
}

.mg-chooser-btn:hover {
    border-color: #e94560;
    background: #1a1a4e;
}

.mg-chooser-thumb {
    font-size: 40px;
    line-height: 1;
}

.mg-chooser-name {
    font-size: 13px;
    font-weight: 600;
}

/* ── Check Warning Popup ────────────────────────────────── */

.check-warning-panel {
    min-width: 420px;
    max-width: 500px;
    text-align: center;
}

.check-warning-text {
    font-size: 16px;
    color: #e0e0e0;
    line-height: 1.6;
    margin-bottom: 16px;
}

.check-warning-suppress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    color: #888;
    margin-bottom: 20px;
    cursor: pointer;
}

.check-warning-checkbox {
    accent-color: #e94560;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.check-warning-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
