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

body {
    font-family: 'Times New Roman', Times, serif;
    background: #f5f5f7;
    height: 100vh;
    color: #1d1d1f;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode {
    background: #1d1d1f;
    color: #f5f5f7;
}

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Hamburger Menu - Top Left (Mobile) */
.hamburger-menu {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    width: 48px;
    height: 48px;
    background: #1d1d1f;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    cursor: pointer;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.dark-mode .hamburger-menu {
    background: #f5f5f7;
}

.hamburger-menu span {
    width: 22px;
    height: 2.5px;
    background: #f5f5f7;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 2px;
}

.dark-mode .hamburger-menu span {
    background: #1d1d1f;
}

.hamburger-menu.active span:nth-child(1) {
    transform: translateY(7.5px) rotate(45deg);
}

.hamburger-menu.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger-menu.active span:nth-child(3) {
    transform: translateY(-7.5px) rotate(-45deg);
}

.hamburger-menu:active {
    transform: scale(0.95);
}

/* Show hamburger on mobile and tablet */
@media (max-width: 1024px) {
    .hamburger-menu {
        display: flex;
    }
}

/* Dark Mode Toggle - Top Right */
.dark-mode-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1001;
    padding: 8px 16px;
    background: #1d1d1f;
    color: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Times New Roman', Times, serif;
    font-size: 0.85em;
    transition: all 0.2s ease;
    min-height: 44px;
}

.dark-mode .dark-mode-toggle {
    background: #f5f5f7;
    color: #1d1d1f;
}

.dark-mode-toggle:hover {
    opacity: 0.8;
}

/* Sidebar Backdrop */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        backdrop-filter 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Dark mode backdrop */
.dark-mode .sidebar-backdrop {
    background: rgba(0, 0, 0, 0.75);
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {

    .sidebar-backdrop,
    .hamburger-menu,
    .hamburger-menu span,
    .info-panel,
    .cell,
    .btn,
    .mode-btn {
        transition: none !important;
        animation: none !important;
    }
}

.game-wrapper {
    display: flex;
    gap: 16px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    padding: 12px;
}

/* Sidebar / Info Panel */
.info-panel {
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e5e5e7;
    width: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.info-panel::-webkit-scrollbar {
    width: 6px;
}

.info-panel::-webkit-scrollbar-track {
    background: transparent;
}

.info-panel::-webkit-scrollbar-thumb {
    background: #d2d2d7;
    border-radius: 3px;
}

.dark-mode .info-panel::-webkit-scrollbar-thumb {
    background: #424245;
}

.dark-mode .info-panel {
    background: #2c2c2e;
    border-color: #424245;
}

/* Mobile: sidebar hidden by default, slides in from left */
@media (max-width: 1024px) {
    .info-panel {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 85%;
        max-width: 320px;
        border-radius: 0 16px 16px 0;
        z-index: 1000;
        transform: translateX(-100%);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .info-panel.active {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.2);
    }

    .dark-mode .info-panel {
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
    }

    .dark-mode .info-panel.active {
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.6);
    }
}

/* Sidebar Header */
.sidebar-header {
    text-align: center;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e5e7;
    margin-bottom: 16px;
}

.dark-mode .sidebar-header {
    border-bottom-color: #424245;
}

.sidebar-header h1 {
    font-size: 1.8em;
    font-weight: 400;
    margin: 0 0 4px 0;
    letter-spacing: -0.5px;
}

.sidebar-header .subtitle {
    font-size: 0.85em;
    color: #86868b;
    font-weight: 300;
}

.dark-mode .sidebar-header .subtitle {
    color: #98989d;
}

/* Game Mode Selector */
.game-mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

/* Difficulty Selector */
.difficulty-selector {
    margin-bottom: 16px;
}

.difficulty-label {
    display: block;
    font-size: 0.8em;
    color: #86868b;
    margin-bottom: 6px;
    font-weight: 400;
}

.dark-mode .difficulty-label {
    color: #98989d;
}

.difficulty-buttons {
    display: flex;
    gap: 6px;
}

.diff-btn {
    flex: 1;
    padding: 8px;
    background: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Times New Roman', Times, serif;
    font-size: 0.75em;
    transition: all 0.2s ease;
    min-height: 36px;
}

.dark-mode .diff-btn {
    background: #1d1d1f;
    border-color: #424245;
    color: #f5f5f7;
}

.diff-btn.active {
    background: #1d1d1f;
    color: #ffffff;
    border-color: #1d1d1f;
}

.dark-mode .diff-btn.active {
    background: #f5f5f7;
    color: #1d1d1f;
    border-color: #f5f5f7;
}

.diff-btn:hover {
    opacity: 0.8;
}

.difficulty-selector.hidden {
    display: none;
}

/* Online Multiplayer UI */
.online-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.online-menu.hidden {
    display: none;
}

.room-browser {
    margin-bottom: 16px;
}

.room-browser.hidden {
    display: none;
}

.browser-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.browser-header h3 {
    font-size: 0.9em;
    font-weight: 500;
    color: #1d1d1f;
    margin: 0;
}

.dark-mode .browser-header h3 {
    color: #f5f5f7;
}

.btn-icon {
    background: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.dark-mode .btn-icon {
    background: #1d1d1f;
    border-color: #424245;
    color: #f5f5f7;
}

.btn-icon:hover {
    opacity: 0.8;
}

.room-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.room-card {
    background: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dark-mode .room-card {
    background: #1d1d1f;
    border-color: #424245;
}

.room-card:hover {
    border-color: #1d1d1f;
}

.dark-mode .room-card:hover {
    border-color: #f5f5f7;
}

.room-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.room-card-title {
    font-size: 0.85em;
    font-weight: 500;
    color: #1d1d1f;
}

.dark-mode .room-card-title {
    color: #f5f5f7;
}

.room-card-status {
    font-size: 0.7em;
    padding: 2px 8px;
    border-radius: 4px;
    background: #86868b;
    color: white;
}

.room-card-status.waiting {
    background: #34c759;
}

.room-card-status.playing {
    background: #ff9500;
}

.room-card-info {
    font-size: 0.7em;
    color: #86868b;
    margin-bottom: 8px;
}

.room-card-join {
    width: 100%;
    padding: 8px;
    background: #1d1d1f;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.75em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dark-mode .room-card-join {
    background: #f5f5f7;
    color: #1d1d1f;
}

.room-card-join:hover {
    opacity: 0.8;
}

.room-card-join:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.loading-text {
    text-align: center;
    color: #86868b;
    font-size: 0.8em;
    padding: 20px;
}

.waiting-room {
    text-align: center;
    margin-bottom: 16px;
}

.waiting-room.hidden {
    display: none;
}

.waiting-room h3 {
    font-size: 0.9em;
    font-weight: 500;
    color: #1d1d1f;
    margin: 0 0 12px 0;
}

.dark-mode .waiting-room h3 {
    color: #f5f5f7;
}

.room-code-display {
    background: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.dark-mode .room-code-display {
    background: #1d1d1f;
    border-color: #424245;
}

.room-code-label {
    font-size: 0.7em;
    color: #86868b;
    margin: 0 0 4px 0;
}

.room-code {
    font-size: 1.2em;
    font-weight: 500;
    color: #1d1d1f;
    margin: 0 0 8px 0;
    letter-spacing: 2px;
}

.dark-mode .room-code {
    color: #f5f5f7;
}

.btn-small {
    padding: 6px 12px;
    background: #1d1d1f;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.7em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dark-mode .btn-small {
    background: #f5f5f7;
    color: #1d1d1f;
}

.btn-small:hover {
    opacity: 0.8;
}

.waiting-text {
    font-size: 0.8em;
    color: #86868b;
    margin: 0 0 12px 0;
    font-style: italic;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    background: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Times New Roman', Times, serif;
    font-size: 0.85em;
    transition: all 0.2s ease;
    min-height: 44px;
}

.dark-mode .mode-btn {
    background: #1d1d1f;
    border-color: #424245;
    color: #f5f5f7;
}

.mode-btn.active {
    background: #1d1d1f;
    color: #ffffff;
    border-color: #1d1d1f;
}

.dark-mode .mode-btn.active {
    background: #f5f5f7;
    color: #1d1d1f;
    border-color: #f5f5f7;
}

.mode-btn:hover {
    opacity: 0.8;
}

/* Game Status */
.game-status {
    margin-bottom: 16px;
}

.status-message {
    background: #f5f5f7;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e5e5e7;
    text-align: center;
    font-size: 0.9em;
    color: #1d1d1f;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dark-mode .status-message {
    background: #1d1d1f;
    border-color: #424245;
    color: #f5f5f7;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.btn {
    padding: 12px 16px;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    font-size: 0.85em;
    font-weight: 400;
    font-family: 'Times New Roman', Times, serif;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
    color: #1d1d1f;
    min-height: 44px;
}

.dark-mode .btn {
    background: #2c2c2e;
    color: #f5f5f7;
    border-color: #424245;
}

.btn:hover {
    background: #f5f5f7;
    border-color: #1d1d1f;
}

.dark-mode .btn:hover {
    background: #424245;
    border-color: #f5f5f7;
}

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

.btn-primary {
    background: #1d1d1f;
    color: #ffffff;
    border-color: #1d1d1f;
}

.dark-mode .btn-primary {
    background: #f5f5f7;
    color: #1d1d1f;
}

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

.dark-mode .btn-primary:hover {
    background: #ffffff;
}

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

.btn.hidden {
    display: none;
}

/* Rules Section */
.rules-section {
    margin-top: auto;
    flex-shrink: 0;
}

.rules-toggle {
    color: #1d1d1f;
    margin-bottom: 8px;
    font-size: 0.9em;
    font-weight: 500;
    letter-spacing: -0.3px;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dark-mode .rules-toggle {
    color: #f5f5f7;
}

.rules-arrow {
    transition: transform 0.3s ease;
    font-size: 0.7em;
}

.rules-section.collapsed .rules-arrow {
    transform: rotate(-90deg);
}

.rules-section.collapsed .rules-content {
    display: none;
}

.rules-content {
    font-size: 0.7em;
    line-height: 1.4;
    color: #515154;
}

.dark-mode .rules-content {
    color: #98989d;
}

.rules-content h4 {
    color: #1d1d1f;
    margin-top: 8px;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 0.95em;
}

.dark-mode .rules-content h4 {
    color: #f5f5f7;
}

.rules-content ul {
    list-style-position: inside;
    margin: 0 0 6px 0;
}

.rules-content li {
    margin-bottom: 3px;
}

.rules-content p {
    margin: 4px 0;
}

/* Board Container */
.board-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-width: 0;
    min-height: 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 0;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #d2d2d7;
    overflow: hidden;
    width: 100%;
    height: 100%;
    max-width: min(calc(100vh - 100px), calc(100vw - 330px));
    max-height: min(calc(100vh - 100px), calc(100vw - 330px));
    aspect-ratio: 1;
}

.dark-mode .board {
    background: #2c2c2e;
    border-color: #424245;
}

/* Mobile: full-width board when sidebar is collapsed */
@media (max-width: 1024px) {
    .board {
        max-width: min(calc(100vh - 80px), calc(100vw - 24px));
        max-height: min(calc(100vh - 80px), calc(100vw - 24px));
    }
}

/* Board Cells */
.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5em;
    font-weight: normal;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.cell:active {
    transform: scale(0.92);
}

@media (hover: hover) {
    .cell:hover {
        opacity: 0.9;
    }
}

/* Drag and Drop Styling */
.cell[draggable="true"] {
    cursor: grab;
}

.cell[draggable="true"]:active {
    cursor: grabbing;
}

.cell.drag-over {
    border: 2px dashed #646f40;
}

.cell.light {
    background: #f0d9b5;
}

.cell.dark {
    background: #b58863;
}

.dark-mode .cell.light {
    background: #2c2c2e;
}

.dark-mode .cell.dark {
    background: #1d1d1f;
}

/* Selected Cell - Improved Visibility */
.cell.selected {
    background: #f6f669 !important;
    box-shadow: inset 0 0 0 3px #646f40;
}

.dark-mode .cell.selected {
    background: #f6f669 !important;
    box-shadow: inset 0 0 0 3px #6d7f3c;
}

/* Possible Moves - Improved Visibility */
.cell.possible-move::after {
    content: '●';
    position: absolute;
    font-size: 0.4em;
    color: rgba(0, 0, 0, 0.25);
    font-weight: bold;
}

.dark-mode .cell.possible-move::after {
    color: rgba(0, 0, 0, 0.3);
}

.piece {
    text-shadow: none;
    pointer-events: none;
    display: inline-block;
}

/* SVG Piece Styling - Uniform sizing across all browsers */
.piece-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.piece-svg {
    width: 80%;
    height: 80%;
    object-fit: contain;
    /* Preserve aspect ratio */
    image-rendering: auto;
    -webkit-user-select: none;
    user-select: none;
}

/* Last move highlighting */
.cell.last-move {
    background-color: rgba(186, 202, 68, 0.4) !important;
}

.dark-mode .cell.last-move {
    background-color: rgba(186, 202, 68, 0.3) !important;
}

/* Flying piece animation */
.flying-piece {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    will-change: transform;
}

/* Piece colors - Light mode */
.piece-white {
    color: #ffffff;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.piece-black {
    color: #000000;
    filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.3));
}

/* Piece colors - Dark mode (improved contrast) */
.dark-mode .piece-white {
    color: #e8e8ed;
    -webkit-text-fill-color: #e8e8ed;
    font-weight: 500;
}

.dark-mode .piece-black {
    color: #ff6b6b;
    -webkit-text-fill-color: #ff6b6b;
    font-weight: 500;
}

/* Ensure piece colors are visible on all backgrounds */
.cell .piece {
    filter: none;
    -webkit-filter: none;
}

/* Mobile: ensure pieces have proper contrast */
@media (max-width: 1024px) {
    .piece {
        font-weight: 600;
    }
}

/* Captured Pieces Section - Redesigned */
.captured-pieces-section {
    margin-bottom: 12px;
    padding: 0;
    background: transparent;
    border: none;
}

.captured-group {
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #f5f5f7;
    border-radius: 6px;
    border: 1px solid #e5e5e7;
}

.dark-mode .captured-group {
    background: #1d1d1f;
    border-color: #424245;
}

.captured-group:last-child {
    margin-bottom: 0;
}

.captured-label {
    font-size: 0.7em;
    color: #86868b;
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dark-mode .captured-label {
    color: #98989d;
}

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 20px;
    align-items: center;
}

.captured-piece {
    width: 18px;
    height: 18px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.captured-piece:hover {
    opacity: 1;
}

.captured-piece-count {
    font-size: 0.65em;
    color: #86868b;
    margin-left: 2px;
    font-weight: 600;
}


/* Move History Section - Redesigned */
.move-history-section {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.move-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e5e7;
}

.dark-mode .move-history-header {
    border-bottom-color: #424245;
}

.move-history-header h3 {
    font-size: 0.85em;
    font-weight: 600;
    color: #1d1d1f;
    margin: 0;
    letter-spacing: -0.3px;
}

.dark-mode .move-history-header h3 {
    color: #f5f5f7;
}

.move-history-list {
    background: transparent;
    border: none;
    padding: 0;
    overflow-y: auto;
    max-height: 180px;
    font-size: 0.75em;
    scrollbar-width: thin;
}

.move-history-list::-webkit-scrollbar {
    width: 4px;
}

.move-history-list::-webkit-scrollbar-track {
    background: transparent;
}

.move-history-list::-webkit-scrollbar-thumb {
    background: #d2d2d7;
    border-radius: 2px;
}

.dark-mode .move-history-list::-webkit-scrollbar-thumb {
    background: #424245;
}

.move-pair {
    display: grid;
    grid-template-columns: 28px 1fr 1fr;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s ease;
    align-items: center;
}

.move-pair:hover {
    background: rgba(0, 0, 0, 0.03);
}

.dark-mode .move-pair:hover {
    background: rgba(255, 255, 255, 0.03);
}

.move-number {
    color: #86868b;
    font-weight: 600;
    font-size: 0.9em;
    text-align: right;
}

.move-notation {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 0.95em;
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.move-notation.white-move {
    background: rgba(44, 62, 80, 0.08);
    color: #2c3e50;
}

.dark-mode .move-notation.white-move {
    background: rgba(232, 232, 237, 0.1);
    color: #e8e8ed;
}

.move-notation.black-move {
    background: rgba(231, 76, 60, 0.08);
    color: #c0392b;
}

.dark-mode .move-notation.black-move {
    background: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
}

.no-moves {
    text-align: center;
    color: #86868b;
    padding: 24px 12px;
    font-size: 0.8em;
    font-style: italic;
}


/* Loading Indicator */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.98);
    padding: 28px 36px;
    border-radius: 12px;
    border: 1px solid #d2d2d7;
    text-align: center;
    z-index: 100;
}

.dark-mode .loading {
    background: rgba(44, 44, 46, 0.98);
    border-color: #424245;
}

.loading.hidden {
    display: none;
}

.loading p {
    color: #1d1d1f;
    font-size: 0.9em;
}

.dark-mode .loading p {
    color: #f5f5f7;
}

.spinner {
    border: 3px solid #e5e5e7;
    border-top: 3px solid #1d1d1f;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

.dark-mode .spinner {
    border-color: #424245;
    border-top-color: #f5f5f7;
}

/* Footer */
footer {
    text-align: center;
    color: #86868b;
    padding: 8px 12px;
    font-size: 0.7em;
    flex-shrink: 0;
}

.dark-mode footer {
    color: #98989d;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Mobile Optimization - Portrait & Tablet */
@media (max-width: 768px) {
    .game-wrapper {
        padding: 8px;
    }

    .board-container {
        flex: 1;
    }

    .cell {
        font-size: 2em;
    }

    .sidebar-header h1 {
        font-size: 1.5em;
    }

    /* Auto-collapse rules on mobile */
    .rules-section {
        margin-top: 12px;
    }

    .rules-section .rules-content {
        max-height: 150px;
        overflow-y: auto;
    }

    footer {
        font-size: 0.65em;
        padding: 6px;
    }
}

/* Mobile Optimization - Small Phones */
@media (max-width: 480px) {
    .game-wrapper {
        padding: 6px;
        gap: 12px;
    }

    .info-panel {
        padding: 16px;
        width: 90%;
        max-width: 300px;
    }

    .sidebar-header {
        padding-bottom: 12px;
        margin-bottom: 12px;
    }

    .sidebar-header h1 {
        font-size: 1.3em;
    }

    .sidebar-header .subtitle {
        font-size: 0.8em;
    }

    .game-mode-selector {
        margin-bottom: 12px;
    }

    .mode-btn {
        padding: 10px;
        font-size: 0.82em;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }

    .status-message {
        padding: 10px;
        font-size: 0.85em;
        min-height: 44px;
    }

    .controls {
        gap: 8px;
        margin-bottom: 12px;
    }

    .btn {
        padding: 12px 14px;
        font-size: 0.82em;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }

    .board {
        max-width: min(calc(100vh - 80px), calc(100vw - 12px));
        max-height: min(calc(100vh - 80px), calc(100vw - 12px));
    }

    .cell {
        font-size: 1.8em;
    }

    .dark-mode-toggle {
        padding: 8px 12px;
        font-size: 0.75em;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }

    .hamburger-menu {
        top: 10px;
        left: 10px;
    }

    .dark-mode-toggle {
        top: 10px;
        right: 10px;
    }

    .rules-content {
        font-size: 0.65em;
    }
}

/* Landscape Mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .game-wrapper {
        flex-direction: row;
    }

    .info-panel {
        width: 240px;
        max-width: 260px;
        max-height: 100vh;
        order: 1;
        padding: 16px;
    }

    .info-panel.active {
        width: 70%;
        max-width: 280px;
    }

    .board-container {
        order: 2;
    }

    .board {
        max-width: min(calc(100vh - 30px), calc(100vw - 24px));
        max-height: min(calc(100vh - 30px), calc(100vw - 24px));
    }

    .cell {
        font-size: 1.8em;
    }

    .rules-section {
        margin-top: 8px;
    }

    .rules-content {
        max-height: 120px;
        overflow-y: auto;
        font-size: 0.6em;
    }

    footer {
        font-size: 0.6em;
        padding: 4px;
    }

    .hamburger-menu {
        top: 8px;
        left: 8px;
        width: 44px;
        height: 44px;
    }

    .dark-mode-toggle {
        top: 8px;
        right: 8px;
        padding: 6px 10px;
        min-height: 44px;
    }
}

/* Game Modal */
.game-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.game-modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #ffffff;
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 1px solid #e5e5e7;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark-mode .modal-content {
    background: #2c2c2e;
    border-color: #424245;
}

.game-modal.active .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    font-size: 2em;
    margin: 0 0 16px 0;
    color: #1d1d1f;
    font-weight: 400;
}

.dark-mode .modal-content h2 {
    color: #f5f5f7;
}

.modal-content p {
    font-size: 1.1em;
    color: #515154;
    margin: 0 0 24px 0;
    line-height: 1.5;
}

.dark-mode .modal-content p {
    color: #98989d;
}

#modal-new-game {
    width: 100%;
    padding: 14px;
    font-size: 0.95em;
}

@media (max-width: 480px) {
    .modal-content {
        padding: 32px 24px;
    }

    .modal-content h2 {
        font-size: 1.6em;
    }

    .modal-content p {
        font-size: 1em;
    }
}