:root {
    --primary-color: #FF9A9E;
    --secondary-color: #FECFEF;
    --accent-color: #A18CD1;
    --bg-gradient: linear-gradient(120deg, #a18cd1 0%, #fbc2eb 100%);
    --white: #ffffff;
    --text-color: #333333;
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* {
    box-sizing: border-box;
    user-select: none;
}

.hidden {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    background-image: var(--bg-gradient);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
    opacity: 0;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.9);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
}

.screen.hidden {
    display: none !important;
}

/* ============================================================
   Start Screen - Mode Selection
   ============================================================ */
h1 {
    font-size: 3rem;
    color: var(--text-color);
    margin-bottom: 2rem;
    text-shadow: 2px 2px 0px rgba(255, 255, 255, 0.5);
}

.bounce {
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-20px);
    }

    60% {
        transform: translateY(-10px);
    }
}

.mode-selection {
    display: flex;
    gap: 20px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    padding: 0 20px;
}

.mode-card {
    background: white;
    border-radius: 20px;
    padding: 25px 20px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    width: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 170px;
}

.mode-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.mode-characters {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.mode-card h3 {
    margin: 10px 0 5px;
    font-size: 1.3rem;
    color: var(--text-color);
}

.mode-card p {
    margin: 0;
    color: #888;
    font-size: 0.9rem;
}

/* ============================================================
   Setup Screen (General Mode)
   ============================================================ */
.setup-container {
    width: 95%;
    max-width: 550px;
    text-align: center;
}

.count-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
}

.count-label {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-color);
    margin-right: 10px;
}

.count-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.count-btn:hover {
    transform: scale(1.1);
}

.count-display {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-color);
    width: 50px;
    text-align: center;
}

.input-header {
    display: flex;
    gap: 10px;
    padding: 0 5px;
    margin-bottom: 8px;
    color: #888;
    font-size: 0.85rem;
}

.input-header span:first-child {
    width: 20px;
}

.input-header span:nth-child(2),
.input-header span:nth-child(3) {
    flex: 1;
    text-align: center;
}

.input-grid {
    padding: 5px;
    overflow: visible;
}

.input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.input-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
}

.input-row input {
    flex: 1;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 1rem;
    text-align: center;
    outline: none;
    font-family: var(--font-main);
    transition: border-color 0.2s;
}

.input-row input:focus {
    border-color: var(--primary-color);
}

.setup-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
}

/* ============================================================
   Shared Buttons
   ============================================================ */
.btn-primary {
    padding: 15px 40px;
    font-size: 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(255, 107, 107, 0.6);
}

.btn-small {
    padding: 8px 16px;
    background: #ccc;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.btn-small:hover {
    background: #bbb;
}

/* ============================================================
   Game Screen
   ============================================================ */
.header {
    width: 100%;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.5);
}

.header-left h2 {
    margin: 0;
    font-size: 1.2rem;
    color: #888;
}

.header-left p {
    margin: 4px 0 0 0;
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--text-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.current-player {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.7);
    padding: 8px 15px;
    border-radius: 30px;
}

.current-avatar {
    font-size: 1.8rem;
}

.instruction {
    margin: 8px 0 0 0;
    font-size: 1rem;
    color: #888;
    text-align: center;
}

/* ============================================================
   Ladder Area
   ============================================================ */

/* Ladder Area */
.ladder-container {
    flex: 1;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px 0;
}

canvas {
    position: absolute;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100% - 130px);
    z-index: 1;
}


.nodes-row {
    display: flex;
    justify-content: space-around;
    width: 100%;
    z-index: 2;
    position: relative;
}

.nodes-row.top {
    margin-bottom: 10px;
}

.nodes-row.bottom {
    margin-top: 10px;
}

/* Entry Point Nodes - Family Mode (Top) */
.entry-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.3s;
}

.entry-node:hover {
    transform: scale(1.15);
}

.entry-node.selected {
    transform: scale(1.2);
}

.entry-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    font-weight: bold;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Player Nodes - General Mode (Top) */
.player-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.3s;
}

.player-node:hover {
    transform: scale(1.1);
}

.player-node.tracing {
    transform: scale(1.15);
}

.player-node.finished {
    opacity: 0.4;
    cursor: default;
}

.player-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    font-weight: bold;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.player-label {
    margin-top: 5px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #333;
}

/* Result Nodes (Bottom) */
.result-node {
    min-width: 55px;
    padding: 0 8px;
    height: 50px;
    background: var(--white);
    border: 3px solid #333;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: #333;
    box-shadow: 0 4px 0px #ccc;
    font-size: 0.95rem;
    position: relative;
    transition: all 0.3s;
}

.result-node.covered {
    background: #555;
    color: #555;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><text x="0" y="15" font-size="15">❓</text></svg>');
    background-repeat: no-repeat;
    background-position: center;
}

/* ============================================================
   Result Modal
   ============================================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #999;
    z-index: 10;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

.modal-close-btn:hover {
    background: #f0f0f0;
    color: #333;
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.result-icon {
    font-size: 4rem;
    margin: 20px 0;
}

.modal-btn-area {
    margin-top: 25px;
}

.details-box {
    margin-top: 20px;
    background: #f9f9f9;
    padding: 15px;
    border-radius: 10px;
    text-align: left;
}

.details-list {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.details-list li {
    background: #FF9A9E;
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.9rem;
    text-align: center;
}

/* ============================================================
   Chess Game Screen
   ============================================================ */

/* Game Mode Selection (Chess, Omok shared) */
.chess-mode-select,
.game-mode-select {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
}

.chess-mode-select h2,
.game-mode-select h2 {
    font-size: 2.5rem;
    color: var(--text-color);
    margin: 0;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1);
}

/* Shared Game Mode Selection (chess, omok, etc.) */
.game-mode-subtitle,
.chess-mode-subtitle {
    color: #666;
    font-size: 1.2rem;
    margin: 0 0 20px 0;
}

.game-mode-cards,
.chess-mode-cards {
    display: flex;
    gap: 30px;
}

.game-mode-cards .mode-card,
.chess-mode-cards .mode-card {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
    border: 2px solid transparent;
}

.game-mode-cards .mode-card:hover,
.chess-mode-cards .mode-card:hover {
    transform: translateY(-10px) scale(1.02);
    border-color: var(--accent-color);
    box-shadow: 0 15px 35px rgba(161, 140, 209, 0.3);
}

#omok-pvp-step,
#chess-pvp-step {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Chess Steps (mode/level) */
.chess-step {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* AI Level Selection */
.chess-level-cards {
    display: flex;
    gap: 20px;
}

.level-card {
    background: white;
    border-radius: 20px;
    padding: 25px 30px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s, border-color 0.3s;
    border: 3px solid transparent;
    min-width: 130px;
}

.level-card:hover {
    transform: translateY(-8px) scale(1.03);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.level-card .level-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.level-card h3 {
    margin: 8px 0 4px;
    font-size: 1.2rem;
    color: var(--text-color);
}

.level-card p {
    margin: 0;
    color: #888;
    font-size: 0.85rem;
}

.level-card.level-1:hover {
    border-color: #4CAF50;
    box-shadow: 0 12px 30px rgba(76, 175, 80, 0.3);
}

.level-card.level-2:hover {
    border-color: #FF9800;
    box-shadow: 0 12px 30px rgba(255, 152, 0, 0.3);
}

.level-card.level-3:hover {
    border-color: #F44336;
    box-shadow: 0 12px 30px rgba(244, 67, 54, 0.3);
}

/* PvP Room Code Input */
.pvp-room-section {
    margin-top: 20px;
    text-align: center;
}

.pvp-room-section h3 {
    margin: 0 0 5px;
    font-size: 1.2rem;
}

.pvp-room-section p {
    color: #888;
    margin: 0 0 15px;
    font-size: 0.9rem;
}

.room-code-input {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.room-code-input input {
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 12px;
    font-size: 1.2rem;
    text-align: center;
    width: 180px;
    font-weight: bold;
    letter-spacing: 2px;
}

.room-code-input input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.color-select-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 10px 0;
}

.color-btn {
    padding: 10px 20px;
    border: 2px solid #ddd;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
}

.color-btn.selected {
    border-color: var(--primary-color);
    background: var(--secondary-color);
    box-shadow: 0 0 8px rgba(255, 154, 158, 0.4);
}

/* Chess Game Area */
#chess-game-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.8), rgba(240, 240, 250, 0.8));
}

#chess-game-area.hidden {
    display: none !important;
}

.chess-header {
    width: 100%;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.6);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.chess-header h2 {
    margin: 0;
    font-size: 1.6rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chess-status {
    padding: 10px 20px;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    text-align: center;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    margin: 10px auto 5px;
    max-width: 90%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.chess-status.check {
    color: #fff;
    background: linear-gradient(135deg, #ff2222, #cc0000);
    box-shadow: 0 4px 25px rgba(255, 0, 0, 0.6), 0 0 50px rgba(255, 0, 0, 0.3);
    animation: checkPulse 0.7s infinite;
    font-size: 1.5rem;
    padding: 14px 35px;
    border: 2px solid rgba(255, 255, 255, 0.6);
    letter-spacing: 2px;
}

@keyframes checkPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 25px rgba(255, 0, 0, 0.6), 0 0 50px rgba(255, 0, 0, 0.3);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 4px 35px rgba(255, 0, 0, 0.9), 0 0 70px rgba(255, 0, 0, 0.5);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 4px 25px rgba(255, 0, 0, 0.6), 0 0 50px rgba(255, 0, 0, 0.3);
    }
}

/* Captured Pieces */
.chess-captured {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    min-height: 35px;
    padding: 5px 15px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    margin: 0 auto;
    width: fit-content;
    flex-wrap: wrap;
}

.captured-piece {
    font-size: 1.2rem;
    line-height: 1;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.chess-board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 10px;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(80vh, 85vw, 700px);
    height: min(80vh, 85vw, 700px);
    border: 8px solid #5d4037;
    /* Wood dark border */
    border-radius: 6px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3), 0 5px 10px rgba(0, 0, 0, 0.1);
    background-color: #5d4037;
    position: relative;
    user-select: none;
}

.chess-square {
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: background-color 0.15s;
}

/* Classic Wood/Green Theme or Slate/White Theme */
.chess-square.light {
    background-color: #EEEED2;
    /* Warm white */
}

.chess-square.dark {
    background-color: #769656;
    /* Classic chess green */
}

.chess-square.selected {
    background-color: #F6F669 !important;
    /* Yellow highlight */
}

/* Highlight for valid moves */
.chess-square.valid-move::after {
    content: '';
    width: 25%;
    height: 25%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    position: absolute;
    transition: transform 0.2s;
}

.chess-square.valid-move:hover::after {
    transform: scale(1.2);
    background: rgba(0, 0, 0, 0.3);
}

/* Capture indicator */
.chess-square.valid-capture {
    box-shadow: inset 0 0 0 0px transparent;
    /* Reset */
}

.chess-square.valid-capture::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 5px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    /* Make it a ring corner */
    box-sizing: border-box;
    clip-path: polygon(0% 0%, 0% 20%, 20% 0%, 100% 0%, 100% 20%, 80% 0%, 100% 100%, 80% 100%, 100% 80%, 0% 100%, 20% 100%, 0% 80%);
    /* Actually a simple ring might be better */
    clip-path: none;
    border-radius: 0;
    border: 4px solid rgba(0, 0, 0, 0.15);
}

/* Better capture: corner indicators */
.chess-square.valid-capture::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(transparent 50%, rgba(0, 0, 0, 0.1) 100%);
    z-index: 0;
}

.chess-square.last-move {
    background-color: rgba(245, 246, 130, 0.6) !important;
}

.chess-square.in-check {
    background: #ff3333 !important;
    box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.8), 0 0 15px rgba(255, 0, 0, 0.6);
    animation: kingCheckFlash 0.4s infinite alternate !important;
}

@keyframes kingCheckFlash {
    from {
        background-color: #ff3333;
        box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.8), 0 0 15px rgba(255, 0, 0, 0.6);
    }

    to {
        background-color: #ff6666;
        box-shadow: inset 0 0 30px rgba(255, 0, 0, 1), 0 0 30px rgba(255, 0, 0, 0.8);
    }
}

/* Board border flash when in check */
.chess-board.board-in-check {
    border-color: #ff0000 !important;
    box-shadow: 0 0 40px rgba(255, 0, 0, 0.6), 0 15px 40px rgba(0, 0, 0, 0.3);
    animation: boardCheckBorder 0.6s infinite alternate;
}

@keyframes boardCheckBorder {
    from {
        border-color: #ff0000;
        box-shadow: 0 0 40px rgba(255, 0, 0, 0.6), 0 15px 40px rgba(0, 0, 0, 0.3);
    }

    to {
        border-color: #ff6666;
        box-shadow: 0 0 60px rgba(255, 0, 0, 0.8), 0 15px 40px rgba(0, 0, 0, 0.3);
    }
}

/* Big CHECK alert overlay on the board */
.check-alert-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    pointer-events: none;
    animation: checkAlertFade 1.8s ease-out forwards;
}

.check-alert-text {
    font-size: 5rem;
    font-weight: 900;
    color: #ff0000;
    text-shadow: 0 0 30px rgba(255, 0, 0, 0.9), 0 0 60px rgba(255, 0, 0, 0.5),
        3px 3px 0 #fff, -3px -3px 0 #fff, 3px -3px 0 #fff, -3px 3px 0 #fff;
    letter-spacing: 15px;
    animation: checkAlertPop 1.8s ease-out forwards;
}

@keyframes checkAlertPop {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-10deg);
    }

    15% {
        opacity: 1;
        transform: scale(1.4) rotate(3deg);
    }

    30% {
        transform: scale(1) rotate(0deg);
    }

    70% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: scale(1.3) rotate(0deg);
    }
}

@keyframes checkAlertFade {
    0% {
        background: rgba(255, 0, 0, 0.15);
    }

    30% {
        background: rgba(255, 0, 0, 0.1);
    }

    70% {
        background: rgba(255, 0, 0, 0.05);
    }

    100% {
        background: transparent;
    }
}

.chess-square:hover {
    filter: brightness(1.05);
}

/* Piece Styling */
.chess-piece {
    font-size: calc(min(60vh, 90vw, 480px) / 8 * 0.7);
    line-height: 1;
    filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.4));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
    user-select: none;
    cursor: pointer;
}

.piece-white {
    color: #fff;
    text-shadow: 0 0 2px #000, 0 0 2px #000, 1px 1px 0 #000, -1px -1px 0 #000;
}

.piece-black {
    color: #333;
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.3);
}

.chess-square.selected .chess-piece {
    transform: translateY(-5px) scale(1.15);
}

/* Animations */
@keyframes pieceLand {
    0% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.piece-landed {
    animation: pieceLand 0.3s ease-out;
}

.chess-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 20px 20px 0 0;
}

.chess-btn {
    padding: 10px 25px !important;
    font-size: 1.1rem !important;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Game Result Modal - shared by chess, omok, ladder */
#result-modal .modal-content {
    background: linear-gradient(135deg, #ffffff, #f8f0ff);
    border: 3px solid #e0c4f0;
}

#result-modal .modal-content h2 {
    font-size: 1.8rem;
    margin-bottom: 0;
}

#result-modal .result-icon {
    font-size: 4rem;
    margin: 15px 0 10px;
}

#result-modal .modal-btn-area {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

#result-modal .modal-btn-area .btn-primary,
#result-modal .modal-btn-area .btn-secondary {
    min-width: 100px;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    border: none;
}

#result-modal .modal-btn-area .btn-secondary {
    background: #f0f0f0;
    color: #666;
}

#result-modal .modal-btn-area .btn-secondary:hover {
    background: #e0e0e0;
}

/* ============================================================
   Mobile Responsive Styles
   ============================================================ */
@media (max-width: 768px) {

    body,
    .app-container {
        overflow-y: auto;
        /* Allow vertical scrolling on mobile */
        height: auto;
        min-height: 100vh;
    }

    .screen {
        position: relative;
        /* Change from absolute to relative for stacking if needed, or keep absolute but ensure height handles content */
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        padding-bottom: 50px;
        /* Add some bottom padding */
    }

    /* Start Screen */
    h1 {
        font-size: 2rem;
        /* Reduce font size */
        margin-top: 2rem;
    }

    .mode-selection {
        flex-direction: column;
        /* Stack cards vertically */
        align-items: center;
        gap: 15px;
        padding-bottom: 30px;
    }

    .mode-card {
        width: 100%;
        max-width: 280px;
        /* Limit width */
        min-height: 100px;
        /* Reduce min-height */
        display: flex;
        flex-direction: row;
        /* Horizontal layout for cards on mobile */
        align-items: center;
        padding: 15px;
        text-align: left;
        gap: 15px;
    }

    .mode-characters {
        font-size: 2rem;
        margin-bottom: 0;
        width: 50px;
        text-align: center;
    }

    .mode-card h3 {
        margin: 0 0 5px 0;
        font-size: 1.1rem;
    }

    .mode-card p {
        font-size: 0.85rem;
    }

    /* Setup Screen */
    .setup-container {
        width: 100%;
        padding: 0 15px;
    }

    .input-row input {
        width: 100%;
        /* Ensure inputs take full width */
    }

    /* Game Header */
    .header {
        padding: 10px 15px;
        flex-direction: column;
        gap: 10px;
    }

    .header-left,
    .header-right {
        width: 100%;
        justify-content: center;
        display: flex;
    }

    .header-left {
        flex-direction: column;
        align-items: center;
    }

    .header-right {
        flex-wrap: wrap;
        /* Allow buttons to wrap */
        gap: 8px;
    }

    /* Modals */
    .modal-content {
        width: 95%;
        padding: 25px 15px;
    }

    /* Omok & Chess Mobile Adjustments */
    .omok-board-container,
    .chess-board-container {
        width: 95vw;
        height: 95vw;
        /* Maintain 1:1 aspect ratio */
        max-width: 400px;
        max-height: 400px;
        margin: 0 auto;
    }

    .omok-board,
    .chess-board {
        width: 100%;
        height: 100%;
    }

    /* Ladder Container */
    .ladder-container {
        width: 100%;
        overflow-x: hidden;
    }

    canvas {
        width: 100%;
        height: auto;
    }

    /* Global Button updates for mobile touches */
    button {
        min-height: 44px;
        /* Better touch targets */
    }

    .btn-small {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}