:root {
    /* Fonts */
    --font-title: 'Cinzel', Georgia, serif;
    --font-body: 'Crimson Text', Georgia, serif;

    /* Colors */
    --bg-dark: #0a0a0f;
    --bg-panel: #1a1525;
    --bg-panel-light: #252035;
    --border-gold: #d4a545;
    --border-gold-dim: #8b7355;
    --text-primary: #e8dcc4;
    --text-secondary: #a89b8c;
    --text-gold: #ffd700;

    --health-full: #8b0000;
    --health-empty: #3d1515;
    --shield-color: #4a7c9b;
    --mine-danger: #dc143c;
    --safe-success: #2e8b57;
    --stairs-color: #9b59b6;

    --count-1: #4a9eff;
    --count-2: #2e8b57;
    --count-3: #dc143c;
    --count-4: #9b59b6;
    --count-5: #ff6b35;
    --count-6: #00bcd4;
    --count-7: #333;
    --count-8: #888;

    --cell-size: 42px;
    --border-radius: 4px;
    --panel-padding: 16px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background-image:
        radial-gradient(ellipse at top, #1a1030 0%, transparent 50%),
        radial-gradient(ellipse at bottom, #0f1520 0%, transparent 50%);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-title);
}

#game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    position: relative;
}

#game-container.damage-shake {
    animation: shake 0.3s ease-in-out, damage-flash 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

@keyframes damage-flash {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(255, 0, 0, 0.15); }
}

/* Cell reveal cascade animation */
@keyframes cell-reveal {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.cell.cell-reveal {
    animation: cell-reveal 0.2s ease-out;
}

/* HP pulse when damaged */
@keyframes hp-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); color: var(--danger); }
}

.hp-damaged {
    animation: hp-pulse 0.4s ease-out;
    display: inline-block;
}

/* Gold earn animation */
@keyframes gold-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); color: var(--gold); }
}

.gold-earned {
    animation: gold-pulse 0.3s ease-out;
    display: inline-block;
}

/* Flag place animation */
@keyframes flag-pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.cell.flag-placed {
    animation: flag-pop 0.25s ease-out;
}

/* Board exit animation for floor transition */
@keyframes board-exit {
    to { opacity: 0; transform: scale(0.95); }
}

.board-exit {
    animation: board-exit 0.3s ease-out forwards;
}

.side-panel {
    background: var(--bg-panel);
    border: 2px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    padding: var(--panel-padding);
    min-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.panel-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-gold-dim);
    padding-bottom: 4px;
}

#hp-display {
    font-size: 24px;
    letter-spacing: 2px;
    color: var(--health-full);
    text-shadow: 0 0 10px rgba(139, 0, 0, 0.5);
}

#shield-display {
    font-size: 16px;
    color: var(--shield-color);
    display: none;
}

.gold-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gold-icon {
    font-size: 18px;
}

#gold-display {
    font-family: var(--font-title);
    font-size: 18px;
    color: var(--text-gold);
    font-weight: 600;
}

.score-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#score-display {
    font-family: var(--font-title);
    font-size: 16px;
    color: var(--text-primary);
}

.main-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.floor-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    border: 2px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    padding: 10px 16px;
}

.floor-info .info-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.floor-info .label {
    color: var(--text-secondary);
}

.floor-info .value {
    font-family: var(--font-title);
    color: var(--text-gold);
    font-weight: 600;
}

#board {
    display: grid;
    gap: 2px;
    background: var(--bg-panel);
    border: 3px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 8px;
    box-shadow:
        0 0 20px rgba(212, 165, 69, 0.2),
        inset 0 0 30px rgba(0, 0, 0, 0.5);
    grid-template-columns: repeat(var(--grid-cols, 8), var(--cell-size));
    grid-template-rows: repeat(var(--grid-rows, 8), var(--cell-size));
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 2px;
    transition: var(--transition-fast);
    background: linear-gradient(145deg, #2a2440 0%, #1a1525 100%);
    border: 1px solid var(--border-gold-dim);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    /* Prevent text selection and touch callouts on mobile */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.revealed) {
    background: linear-gradient(145deg, #352f50 0%, #252035 100%);
    border-color: var(--border-gold);
    box-shadow: 0 0 8px rgba(212, 165, 69, 0.3);
}

.cell:active:not(.revealed) {
    transform: scale(0.92);
    opacity: 0.85;
}

.cell.revealed {
    background: var(--bg-dark);
    border-color: #333;
    cursor: default;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.cell.flagged {
    background: linear-gradient(145deg, #3d2a2a 0%, #2a1a1a 100%);
    border-color: var(--mine-danger);
}

.cell.mine {
    background: var(--mine-danger);
    border-color: #ff4444;
}

.cell.mine-hit {
    background: #ff0000;
    animation: mine-pulse 0.5s ease-in-out;
}

@keyframes mine-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Magical dust reveal effect for reveal items */
.cell.scroll-revealed {
    position: relative;
    animation: dust-shimmer 1.5s ease-out forwards;
    z-index: 5;
}

/* Floating dust particles */
.cell.scroll-revealed::before {
    content: '';
    position: absolute;
    inset: -4px;
    background-image:
        radial-gradient(2px 2px at 15% 20%, rgba(255, 215, 0, 1) 50%, transparent 50%),
        radial-gradient(2px 2px at 85% 15%, rgba(255, 255, 255, 1) 50%, transparent 50%),
        radial-gradient(1.5px 1.5px at 75% 80%, rgba(255, 215, 0, 0.9) 50%, transparent 50%),
        radial-gradient(2px 2px at 20% 85%, rgba(255, 255, 255, 0.9) 50%, transparent 50%),
        radial-gradient(1.5px 1.5px at 50% 10%, rgba(255, 200, 100, 1) 50%, transparent 50%),
        radial-gradient(2px 2px at 10% 50%, rgba(255, 215, 0, 0.8) 50%, transparent 50%),
        radial-gradient(1.5px 1.5px at 90% 55%, rgba(255, 255, 200, 1) 50%, transparent 50%),
        radial-gradient(2px 2px at 55% 90%, rgba(255, 215, 0, 0.9) 50%, transparent 50%);
    animation: dust-float 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 10;
}

/* Soft golden shimmer glow on the cell */
@keyframes dust-shimmer {
    0% {
        box-shadow:
            0 0 8px rgba(255, 215, 0, 0.6),
            0 0 16px rgba(255, 215, 0, 0.3),
            inset 0 0 8px rgba(255, 215, 0, 0.4);
        filter: brightness(1.2);
    }
    40% {
        box-shadow:
            0 0 12px rgba(255, 215, 0, 0.5),
            0 0 20px rgba(255, 215, 0, 0.2),
            inset 0 0 6px rgba(255, 215, 0, 0.3);
        filter: brightness(1.15);
    }
    100% {
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
        filter: brightness(1);
    }
}

/* Particles float upward and fade */
@keyframes dust-float {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    50% {
        opacity: 0.8;
        transform: translateY(-6px);
    }
    100% {
        opacity: 0;
        transform: translateY(-12px);
    }
}

.cell.stairs {
    background: linear-gradient(145deg, #4a2f6b 0%, #2e1a45 100%);
    border-color: var(--stairs-color);
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.5);
}

.cell.count-1 { color: var(--count-1); }
.cell.count-2 { color: var(--count-2); }
.cell.count-3 { color: var(--count-3); }
.cell.count-4 { color: var(--count-4); }
.cell.count-5 { color: var(--count-5); }
.cell.count-6 { color: var(--count-6); }
.cell.count-7 { color: var(--count-7); }
.cell.count-8 { color: var(--count-8); }

#message {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 12px 24px;
    font-size: 16px;
    opacity: 0;
    transition: all var(--transition-normal);
    z-index: 1000;
    text-align: center;
    min-width: 200px;
}

#message.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

#message.damage {
    border-color: var(--mine-danger);
    color: var(--mine-danger);
    background: linear-gradient(to bottom, #2a1515, var(--bg-panel));
}

#message.success {
    border-color: var(--safe-success);
    color: var(--safe-success);
    background: linear-gradient(to bottom, #152a1a, var(--bg-panel));
}

#message.info {
    border-color: var(--shield-color);
    color: var(--shield-color);
}

.overlay-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 15, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-20px);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
    padding: 20px;
    box-sizing: border-box;
}

.overlay-screen.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* Shop slides up from bottom */
#shop-screen {
    transform: translateY(30px);
}

#shop-screen.visible {
    transform: translateY(0);
}

/* Victory bounce effect */
@keyframes victory-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

#victory-screen.visible h1 {
    animation: glow 2s infinite, victory-bounce 0.5s ease-out;
}

/* Game over shake */
#game-over-screen.visible h1 {
    animation: shake 0.5s ease-out;
}

.overlay-screen h1 {
    font-size: 48px;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: var(--border-gold);
    text-shadow: 0 0 20px rgba(212, 165, 69, 0.5);
}

.overlay-screen h2 {
    font-size: 24px;
    color: var(--text-secondary);
}

.overlay-screen .stats {
    display: flex;
    gap: 32px;
    font-size: 18px;
}

.overlay-screen .stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.overlay-screen .stat .label {
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
}

.overlay-screen .stat .value {
    font-family: var(--font-title);
    color: var(--text-gold);
    font-size: 28px;
    font-weight: 600;
}

#menu-screen h1 {
    font-size: 36px;
}

#menu-screen .subtitle {
    color: var(--text-secondary);
    font-style: italic;
    margin-top: -16px;
}

#game-over-screen h1 {
    color: var(--mine-danger);
    text-shadow: 0 0 20px rgba(220, 20, 60, 0.5);
}

#victory-screen h1 {
    color: var(--text-gold);
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { text-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }
    50% { text-shadow: 0 0 40px rgba(255, 215, 0, 0.8), 0 0 60px rgba(255, 215, 0, 0.4); }
}

.btn {
    background: linear-gradient(to bottom, #3a2f50 0%, #2a2040 100%);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    padding: 12px 32px;
    font-family: var(--font-title);
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn:hover {
    background: linear-gradient(to bottom, #4a3f60 0%, #3a3050 100%);
    border-color: var(--text-gold);
    box-shadow: 0 0 15px rgba(212, 165, 69, 0.4);
    transform: translateY(-2px);
}

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

/* Button press ripple effect */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
    transform: scale(0);
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
}

.btn:active::after {
    transform: scale(2);
    opacity: 1;
}

.btn-primary {
    background: linear-gradient(to bottom, #5a4520 0%, #3a2f10 100%);
}

.btn-primary:hover {
    background: linear-gradient(to bottom, #6a5530 0%, #4a3f20 100%);
}

#leaderboard-screen .player-name {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

#leaderboard-screen #player-nickname {
    color: var(--text-gold);
    font-weight: bold;
}

.rank-separator {
    text-align: center;
    color: var(--text-secondary);
    padding: 8px 0;
    font-size: 14px;
    opacity: 0.6;
}

#leaderboard-list {
    background: var(--bg-panel);
    border: 2px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    padding: 16px;
    min-width: 300px;
    max-width: 400px;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-gold-dim);
    transition: background 0.2s ease;
}

.leaderboard-entry:last-child {
    border-bottom: none;
}

.leaderboard-entry.highlight {
    background: rgba(212, 165, 69, 0.15);
    border-radius: var(--border-radius);
}

.leaderboard-entry .rank {
    font-family: var(--font-title);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    width: 30px;
}

.leaderboard-entry.highlight .rank {
    color: var(--text-gold);
}

.leaderboard-entry:nth-child(1) .rank { color: #ffd700; }
.leaderboard-entry:nth-child(2) .rank { color: #c0c0c0; }
.leaderboard-entry:nth-child(3) .rank { color: #cd7f32; }

.leaderboard-entry .name {
    flex: 1;
    text-align: left;
    margin-left: 10px;
    color: var(--text-primary);
}

.leaderboard-entry .floor {
    color: var(--text-secondary);
    font-size: 12px;
    margin-right: 15px;
}

.leaderboard-entry .score {
    font-family: var(--font-title);
    font-weight: 600;
    color: var(--text-gold);
    min-width: 60px;
    text-align: right;
}

.leaderboard-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
    font-style: italic;
}

.right-panel {
    min-width: 180px;
}

#sidebar-leaderboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg-panel-light);
    border-radius: var(--border-radius);
    font-size: 12px;
}

.sidebar-entry.highlight {
    background: rgba(212, 165, 69, 0.2);
    border: 1px solid var(--border-gold-dim);
}

.sidebar-entry .rank {
    font-family: var(--font-title);
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 20px;
}

.sidebar-entry:nth-child(1) .rank { color: #ffd700; }
.sidebar-entry:nth-child(2) .rank { color: #c0c0c0; }
.sidebar-entry:nth-child(3) .rank { color: #cd7f32; }

.sidebar-entry .name {
    flex: 1;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-entry .score {
    font-family: var(--font-title);
    font-weight: 600;
    color: var(--text-gold);
}

.sidebar-empty {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
    text-align: center;
    padding: 10px;
}

.offline-indicator {
    background: rgba(139, 115, 85, 0.3);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    padding: 4px 8px;
    margin-bottom: 8px;
    border-radius: 3px;
    border: 1px solid var(--border-dimmed);
}

.how-to-play-content {
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 24px 32px;
    max-width: 420px;
    width: 90vw;
}

.how-to-play-content h1 {
    font-size: 28px;
    margin-bottom: 16px;
    text-align: center;
}

/* How to Play Carousel */
.htp-carousel {
    position: relative;
    min-height: 260px;
}

.htp-page {
    display: none;
    animation: htpFadeIn 0.3s ease;
}

.htp-page.active {
    display: block;
}

@keyframes htpFadeIn {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

.htp-page-title {
    font-size: 18px;
    color: var(--text-gold);
    text-align: center;
    margin-bottom: 20px;
    font-weight: 600;
}

.htp-demos {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
}

.htp-demos.vertical {
    gap: 16px;
}

.htp-demo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.demo-cells {
    display: flex;
    align-items: center;
    gap: 8px;
}

.demo-cells.demo-grid {
    display: grid;
    grid-template-columns: repeat(3, 36px);
    gap: 2px;
}

.demo-cell {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    border-radius: 3px;
}

.demo-cell.unrevealed {
    background: linear-gradient(145deg, #3a3050 0%, #252035 100%);
    border: 1px solid var(--border-gold-dim);
}

.demo-cell.revealed {
    background: linear-gradient(145deg, #1a1525 0%, #0f0f18 100%);
    border: 1px solid #333;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.demo-cell.flagged {
    background: linear-gradient(145deg, #3a3050 0%, #252035 100%);
    border: 1px solid var(--border-gold-dim);
}

.demo-cell.count-1 { color: var(--count-1); }
.demo-cell.count-2 { color: var(--count-2); }
.demo-cell.count-3 { color: var(--count-3); }

.demo-cell.mine-demo {
    opacity: 0.6;
}

.demo-cell.highlight-demo {
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
    border-color: var(--border-gold);
}

.demo-arrow {
    color: var(--text-secondary);
    font-size: 18px;
}

.demo-text {
    font-size: 14px;
    color: var(--text-primary);
    text-align: center;
}

.demo-text strong {
    color: var(--text-gold);
}

/* Show/hide controls based on device */
.mobile-control { display: none; }
.desktop-control { display: inline; }

@media (max-width: 1024px) {
    .mobile-control { display: inline; }
    .desktop-control { display: none; }
}

/* Page 3 row style */
.htp-demo-row {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    width: 100%;
}

.htp-icon {
    font-size: 20px;
    min-width: 50px;
    text-align: center;
}

/* Navigation */
.htp-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-gold-dim);
}

.htp-nav-btn {
    min-width: 80px;
    font-size: 13px;
    padding: 8px 12px;
}

.htp-dots {
    display: flex;
    gap: 8px;
}

.htp-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--bg-panel-light);
    border: 1px solid var(--border-gold-dim);
    cursor: pointer;
    transition: all 0.2s ease;
}

.htp-dot.active {
    background: var(--border-gold);
    border-color: var(--border-gold);
}

.htp-dot:hover {
    border-color: var(--border-gold);
}

#menu-screen .btn {
    margin-top: 10px;
}

#version {
    position: fixed;
    bottom: 10px;
    right: 15px;
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.6;
    cursor: pointer;
    transition: opacity 0.2s ease;
    z-index: 50;
}

#version:hover {
    opacity: 1;
    color: var(--text-gold);
}

.changelog-content {
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 24px 32px;
    max-width: 550px;
    width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.changelog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.changelog-header h1 {
    font-size: 28px;
    margin: 0;
}

.changelog-close-x {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: color var(--transition-fast);
}

.changelog-close-x:hover {
    color: var(--text-gold);
}

.changelog-list {
    text-align: left;
    overflow-y: auto;
    flex: 1;
    padding-right: 8px;
}

/* Custom scrollbar for changelog */
.changelog-list::-webkit-scrollbar {
    width: 8px;
}

.changelog-list::-webkit-scrollbar-track {
    background: var(--bg-dark);
    border-radius: 4px;
}

.changelog-list::-webkit-scrollbar-thumb {
    background: var(--border-gold-dim);
    border-radius: 4px;
}

.changelog-list::-webkit-scrollbar-thumb:hover {
    background: var(--border-gold);
}

.changelog-content > .btn {
    flex-shrink: 0;
    margin-top: 20px;
}

.changelog-version {
    margin-bottom: 20px;
}

.changelog-version:last-child {
    margin-bottom: 0;
}

.changelog-version h3 {
    color: var(--text-gold);
    font-size: 18px;
    margin-bottom: 4px;
}

.changelog-date {
    color: var(--text-secondary);
    font-size: 12px;
    display: block;
    margin-bottom: 10px;
}

.changelog-version ul {
    margin: 0;
    padding-left: 20px;
}

.changelog-version li {
    color: var(--text-primary);
    margin-bottom: 6px;
    font-size: 14px;
}

/* Player Name in Sidebar */
.player-name-section {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-gold-dim);
    margin-bottom: 8px;
}

.clickable-name {
    font-family: var(--font-title);
    color: var(--text-gold);
    font-size: 14px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.clickable-name:hover {
    color: var(--border-gold);
    text-decoration: underline;
}

/* Nickname Change Modal */
.nickname-content {
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 24px 32px;
    max-width: 350px;
    text-align: center;
}

.nickname-content h2 {
    color: var(--border-gold);
    font-size: 24px;
    margin-bottom: 8px;
}

.nickname-rules {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 16px;
}

#nickname-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    background: var(--bg-dark);
    border: 2px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    text-align: center;
    outline: none;
    transition: border-color 0.2s ease;
}

#nickname-input:focus {
    border-color: var(--border-gold);
}

#nickname-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

.error-text {
    color: var(--mine-danger);
    font-size: 12px;
    min-height: 20px;
    margin-top: 8px;
}

.nickname-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
}

.nickname-buttons .btn {
    padding: 10px 24px;
    font-size: 14px;
}

/* Sound Section */
.sound-section {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-gold-dim);
}

.mute-button {
    background: none;
    border: 1px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition-fast);
    width: 100%;
}

.mute-button:hover {
    border-color: var(--border-gold);
    color: var(--text-gold);
}

.mute-button.muted {
    opacity: 0.5;
}

/* Inventory Display */
.inventory-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.inventory-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-dark);
    border: 1px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
    font-size: 18px;
}

.inventory-item:hover {
    border-color: var(--border-gold);
    transform: scale(1.1);
    z-index: 1;
}

.inventory-item .item-count {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: var(--text-gold);
    color: var(--bg-dark);
    font-size: 10px;
    font-weight: bold;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

.inventory-empty {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
}

/* Item Tooltip */
.item-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    border: 1px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    margin-bottom: 8px;
}

.inventory-item:hover .item-tooltip {
    opacity: 1;
}

.item-tooltip .tooltip-name {
    color: var(--text-gold);
    font-weight: 600;
    font-size: 12px;
}

.item-tooltip .tooltip-desc {
    color: var(--text-secondary);
    font-size: 11px;
    margin-top: 2px;
}

.item-tooltip .tooltip-hint {
    color: var(--text-gold);
    font-size: 10px;
    margin-top: 4px;
}

/* Shop Screen */
.shop-content {
    text-align: center;
    max-width: 600px;
    width: 90%;
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 32px;
}

.shop-subtitle {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.shop-gold-display {
    color: var(--text-gold);
    font-size: 18px;
    margin-bottom: 24px;
}

.shop-gold-display span {
    font-weight: bold;
}

.shop-items-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.shop-item {
    background: var(--bg-dark);
    border: 1px solid var(--border-gold-dim);
    border-radius: var(--border-radius);
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.shop-item:hover:not(.shop-item-disabled):not(.shop-item-sold) {
    border-color: var(--border-gold);
    transform: translateY(-2px);
}

.shop-item-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.shop-item-sold {
    opacity: 0.4;
    cursor: default;
    position: relative;
}

.shop-item-sold::after {
    content: 'SOLD';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent-gold);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.shop-item-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.shop-item-icon {
    font-size: 28px;
}

.shop-item-name {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 14px;
}

.shop-item-desc {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 10px;
}

.shop-item-cost {
    color: var(--text-gold);
    font-weight: bold;
    font-size: 14px;
}

.shop-item-cost::before {
    content: '💰 ';
}

/* Targeting Mode */
#targeting-message {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: var(--border-radius);
    padding: 12px 24px;
    color: var(--text-gold);
    font-size: 14px;
    z-index: 1000;
    display: none;
    animation: pulse-border 1.5s ease-in-out infinite;
}

#targeting-message.visible {
    display: block;
}

.targeting-cancel-btn {
    position: fixed;
    top: calc(70px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--border-radius);
    padding: 8px 24px;
    font-family: var(--font-body);
    font-size: 14px;
    cursor: pointer;
    z-index: 1000;
    display: none;
    transition: all var(--transition-fast);
}

.targeting-cancel-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--border-gold);
    color: var(--text-primary);
}

.targeting-cancel-btn.visible {
    display: block;
}

@keyframes pulse-border {
    0%, 100% { border-color: var(--border-gold); }
    50% { border-color: var(--border-gold-dim); }
}

/* Mine Detector Highlight */
.cell.mine-adjacent-highlight {
    animation: detector-pulse 0.8s ease-in-out infinite;
}

@keyframes detector-pulse {
    0%, 100% {
        box-shadow: inset 0 0 0 2px rgba(220, 20, 60, 0.3);
    }
    50% {
        box-shadow: inset 0 0 0 2px rgba(220, 20, 60, 0.7);
    }
}

/* Tablet breakpoint */
@media (max-width: 768px) {
    .right-panel {
        display: none;
    }
}

/* Mobile breakpoint - clean minimal layout */
@media (max-width: 600px) {
    body {
        padding: 8px;
    }

    #game-container {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    /* Hide the right panel (highscores) completely on mobile */
    .right-panel {
        display: none !important;
    }

    /* Compact left side panel */
    .side-panel:not(.right-panel) {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        min-width: auto;
        width: 100%;
        justify-content: space-around;
        align-items: center;
        padding: 10px 12px;
        gap: 8px;
        background: var(--bg-panel);
        border-radius: var(--border-radius);
        order: 1; /* Stats below board */
    }

    /* Hide player name section and score on mobile */
    .player-name-section {
        display: none !important;
    }

    /* Compact panel sections */
    .panel-section {
        min-width: auto;
        padding: 0;
        background: transparent;
        border: none;
        text-align: center;
        flex-shrink: 0;
    }

    /* Hide score section on mobile */
    .panel-section:has(#score-display) {
        display: none;
    }

    .panel-section h3 {
        font-size: 10px;
        margin-bottom: 4px;
        opacity: 0.7;
    }

    /* Compact HP display */
    #hp-display {
        font-size: 18px;
        letter-spacing: 0;
    }

    #shield-display {
        font-size: 14px;
    }

    /* Compact gold display */
    .gold-row {
        font-size: 18px;
        gap: 4px;
    }

    .gold-icon {
        font-size: 16px;
    }

    /* Compact inventory - inline */
    .panel-section:has(#inventory-display) {
        flex-grow: 0;
    }

    .inventory-grid {
        gap: 4px;
        justify-content: center;
    }

    .inventory-item {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }

    .inventory-empty {
        font-size: 11px;
        opacity: 0.5;
    }

    /* Floor info bar - more compact */
    .floor-info {
        padding: 8px 16px;
        gap: 24px;
    }

    .floor-info .label {
        font-size: 10px;
    }

    .floor-info .value {
        font-size: 20px;
    }

    /* Board takes priority - show first */
    .main-area {
        width: 100%;
        max-width: 100vw;
        order: 0;
    }

    #board {
        max-width: calc(100vw - 16px);
    }

    /* Mobile overlay/menu screens */
    .overlay-screen h1 {
        font-size: 28px;
        letter-spacing: 2px;
        text-align: center;
    }

    .overlay-screen h2 {
        font-size: 16px;
    }

    #menu-screen h1 {
        font-size: 24px;
    }

    .overlay-screen .btn {
        padding: 12px 32px;
        font-size: 14px;
    }

    /* Mobile shop styles */
    .shop-content {
        padding: 20px 16px;
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .shop-content h1 {
        font-size: 24px;
        margin-bottom: 4px;
    }

    .shop-subtitle {
        font-size: 14px;
        margin-bottom: 12px;
    }

    .shop-gold-display {
        font-size: 16px;
        margin-bottom: 16px;
    }

    .shop-items-grid {
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 16px;
    }

    .shop-item {
        padding: 12px;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .shop-item-header {
        flex-direction: row;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .shop-item-icon {
        font-size: 24px;
    }

    .shop-item-name {
        font-size: 14px;
    }

    .shop-item-desc {
        flex-grow: 1;
        font-size: 11px;
        margin-bottom: 0;
    }

    .shop-item-cost {
        font-size: 14px;
        flex-shrink: 0;
    }
}

/* Small phone tweaks */
@media (max-width: 375px) {
    body {
        padding: 4px;
    }

    .side-panel {
        padding: 6px 8px;
    }

    #hp-display {
        font-size: 14px;
    }

    .gold-row {
        font-size: 14px;
    }

    .inventory-item {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .floor-info {
        padding: 4px 8px;
        gap: 15px;
    }

    .floor-info .value {
        font-size: 16px;
    }
}

/* Contextual Tips */
#contextual-tip {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(to bottom, #1f2a1a, var(--bg-panel));
    border: 2px solid #5a9b4a;
    border-radius: 8px;
    padding: 12px 20px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 900;
    text-align: center;
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(90, 155, 74, 0.3);
}

#contextual-tip.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

#contextual-tip .tip-label {
    font-family: var(--font-title);
    font-size: 11px;
    font-weight: 600;
    color: #5a9b4a;
    letter-spacing: 2px;
    margin-bottom: 6px;
}

#contextual-tip .tip-content {
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.4;
}

@media (max-width: 600px) {
    #contextual-tip {
        bottom: 80px;
        max-width: 280px;
        padding: 10px 16px;
    }

    /* How to Play mobile fixes */
    .how-to-play-content {
        padding: 16px 20px;
        width: 95vw;
        max-width: none;
    }

    .how-to-play-content h1 {
        font-size: 22px;
        margin-bottom: 12px;
    }

    .htp-carousel {
        min-height: auto;
    }

    .htp-page-title {
        font-size: 14px;
        margin-bottom: 16px;
    }

    .htp-demos {
        gap: 18px;
    }

    .demo-cell {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    .demo-cells.demo-grid {
        grid-template-columns: repeat(3, 32px);
    }

    .demo-text {
        font-size: 13px;
    }

    .htp-demo-row {
        gap: 10px;
    }

    .htp-icon {
        font-size: 16px;
        min-width: 40px;
    }

    .htp-demo-row .demo-text {
        font-size: 12px;
    }

    .htp-nav {
        margin-top: 16px;
        padding-top: 12px;
    }

    .htp-nav-btn {
        min-width: 70px;
        font-size: 12px;
        padding: 8px 10px;
    }
}

/* Touch device How to Play fixes (landscape phones, tablets) */
@media (pointer: coarse) and (max-width: 1024px) {
    .how-to-play-content {
        padding: 16px 20px;
        width: 95vw;
        max-width: none;
    }

    .how-to-play-content h1 {
        font-size: 22px;
        margin-bottom: 12px;
    }

    .htp-carousel {
        min-height: auto;
    }

    .htp-page-title {
        font-size: 14px;
        margin-bottom: 16px;
    }

    .htp-demos {
        gap: 18px;
    }

    .demo-cell {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    .demo-cells.demo-grid {
        grid-template-columns: repeat(3, 32px);
    }

    .demo-text {
        font-size: 13px;
    }

    .htp-demo-row {
        gap: 10px;
    }

    .htp-icon {
        font-size: 16px;
        min-width: 40px;
    }

    .htp-demo-row .demo-text {
        font-size: 12px;
    }

    .htp-nav {
        margin-top: 16px;
        padding-top: 12px;
    }

    .htp-nav-btn {
        min-width: 70px;
        font-size: 12px;
        padding: 8px 10px;
    }
}
