body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, #1f1f1f, #0d0d0f 45%), #0b0b0d;
    color: #f5f5f5;
    font-family: "Courier New", monospace;
    touch-action: manipulation; /* Prevent double-tap zoom on mobile */
}

.app {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 16px;
    box-sizing: border-box;
    max-width: 1200px;
    margin: 0 auto;
}

.view {
    flex: 1 1 60%;
}

.view h1 {
    margin: 0 0 12px;
    letter-spacing: 1px;
}

.canvas-wrap {
    position: relative;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    max-width: 900px;
    background: #111;
    border: 2px solid #2d2d2d;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.world-map-toggle {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 8px 12px;
    font-size: 12px;
    z-index: 3;
}

.music-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    font-size: 12px;
    z-index: 3;
}

.view-controls {
    display: none;
}

.stats-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 180px;
    padding: 8px 10px;
    background: rgba(20, 20, 24, 0.9);
    border: 1px solid #262633;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.4;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
}

.leaderboard-overlay {
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(12, 12, 18, 0.92);
    border: 1px solid #262633;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.5;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
    display: none;
    width: 100%;
    box-sizing: border-box;
}

.leaderboard-overlay button {
    width: 100%;
    margin-top: 8px;
}

.ad-section {
    min-width: 200px;
    max-width: 95%;
    padding: 12px;
    background: #111119;
    border: 1px dashed #3e3e52;
    border-radius: 8px;
    color: #cfcfd9;
    align-self: flex-start;
}

.ad-section__header {
    font-weight: bold;
    margin-bottom: 6px;
    color: #9bb3ff;
}

.bgm-audio {
    display: none;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 95%;
    background: #141418;
    border: 1px solid #262633;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

#stats {
    line-height: 1.6;
}

.controls {
    margin: 12px 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

button {
    background: linear-gradient(135deg, #353547, #1f1f2c);
    color: #f5f5f5;
    border: 1px solid #3e3e52;
    border-radius: 6px;
    padding: 10px 12px;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 0.3px;
    transition: transform 0.08s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
    border-color: #5c5c7a;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.travel-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.social-card {
    margin-top: 12px;
    padding: 12px;
    background: #111119;
    border: 1px solid #262633;
    border-radius: 8px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}

.social-card__header {
    font-weight: bold;
    margin-bottom: 8px;
}

.version-pill {
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 12px;
    font-size: 12px;
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: inline-block;
}

#helpBtn {
    margin-top: 8px;
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #1d3b4d, #102534);
    color: #dbeafe;
    border: 1px solid #26455c;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

#helpBtn:hover {
    background: linear-gradient(135deg, #23495f, #143148);
}

.coord-debug {
    position: fixed;
    top: 8px;
    right: 8px;
    padding: 6px 10px;
    background: rgba(12, 12, 20, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    font-family: monospace;
    font-size: 12px;
    color: #dbeafe;
    z-index: 9999;
    pointer-events: none;
}

.help-body {
    background: #0c0c12;
    color: #e5e7eb;
    font-family: "Courier New", monospace;
    margin: 0;
}

.help-shell {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.help-header h1 {
    margin: 0 0 6px;
    letter-spacing: 0.5px;
}

.help-header p {
    margin: 0;
    color: #cbd5e1;
}

.help-back {
    color: #8ee3ff;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
}

.help-section h2 {
    margin: 0 0 10px;
    letter-spacing: 0.5px;
}

.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.help-card {
    background: #11111a;
    border: 1px solid #1f2233;
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.help-card h3 {
    margin: 0 0 8px;
}

.help-card ul {
    margin: 0;
    padding-left: 18px;
    line-height: 1.6;
}

.help-note {
    margin-top: 12px;
    color: #cbd5e1;
    font-size: 14px;
}

.help-note code {
    background: #0f172a;
    padding: 2px 6px;
    border-radius: 4px;
}

.social-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.designer-shell {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.designer-header h1 {
    margin: 0 0 6px;
    letter-spacing: 0.8px;
}

.designer-header p {
    margin: 0;
    color: #cfcfd9;
    line-height: 1.5;
}

.designer-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 18px;
    align-items: start;
}

.designer-canvas-card,
.designer-sidebar {
    background: #141418;
    border: 1px solid #262633;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

#designerCanvas {
    width: 360px;
    height: 360px;
    background: #0b0b0d;
    border: 2px solid #2d2d2d;
    border-radius: 8px;
    image-rendering: pixelated;
    display: block;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.palette {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.palette button {
    height: 42px;
    padding: 0;
    border-radius: 8px;
    border: 2px solid #2d2d2d;
    box-shadow: none;
}

.palette button.active {
    border-color: #ffffff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.designer-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.legend {
    margin-top: 10px;
    color: #bcbcc8;
    line-height: 1.4;
    font-size: 14px;
}

.designer-stats-card,
.designer-share-card {
    margin-top: 14px;
    background: #111119;
    border: 1px solid #262633;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}

.designer-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    font-size: 13px;
}

.designer-stats-grid div {
    display: flex;
    justify-content: space-between;
    background: #161620;
    border: 1px solid #262633;
    border-radius: 6px;
    padding: 8px;
}

.designer-share-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.designer-wide-row {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.designer-wide-row .designer-stats-card,
.designer-wide-row .designer-share-card {
    margin-top: 0;
}

.nav-links {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.nav-links a {
    color: #5fb3ff;
    text-decoration: none;
}

.nav-links a:hover {
    text-decoration: underline;
}

.game-end-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 12, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
    box-sizing: border-box;
}

.game-end-card {
    background: #12121a;
    border: 1px solid #303047;
    border-radius: 12px;
    padding: 20px;
    max-width: 520px;
    width: 100%;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55);
    text-align: left;
}

.game-end-card h2 {
    margin: 0 0 12px;
    letter-spacing: 0.5px;
}

.game-end-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
    font-size: 14px;
}

.game-end-grid div {
    background: #1b1b27;
    border: 1px solid #2d2d3f;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
}

.game-end-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.jukebox-modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 12, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    padding: 16px;
    box-sizing: border-box;
}

.jukebox-card {
    background: #12121a;
    border: 1px solid #303047;
    border-radius: 12px;
    padding: 16px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.55);
}

.jukebox-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: bold;
    color: #9bb3ff;
}

.jukebox-card__sub {
    font-weight: normal;
    font-size: 12px;
    color: #c6c6d6;
}

.jukebox-card__body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.jukebox-card select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #3e3e52;
    background: #0c0c12;
    color: #f5f5f5;
}

.jukebox-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.jukebox-close {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    font-size: 16px;
    line-height: 1;
    padding: 0;
}

@media (max-width: 900px) {
    .designer-grid {
        grid-template-columns: 1fr;
    }

    #designerCanvas {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    .designer-wide-row {
        grid-template-columns: 1fr;
    }
}

#log {
    background: #0f0f13;
    border: 1px solid #1f1f2a;
    border-radius: 6px;
    padding: 10px;
    height: 100px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.log-below {
    margin-top: 12px;
}

@media (max-width: 900px) {
    .app {
        flex-direction: column;
        padding: 12px;
    }

    .ad-section {
        order: 1;
        width: 100%;
        max-width: none;
        margin-bottom: 10px;
    }

    .view {
        order: 2;
        width: 100%;
    }

    .panel {
        order: 3;
        width: 100%;
        padding: 12px;
    }

    #log {
        height: 70px;
    }

    .log-below {
        height: 70px;
        margin-top: 8px;
    }

    .stats-overlay {
        position: absolute;
        top: 8px;
        right: 8px;
        width: 150px;
        font-size: 11px;
        line-height: 1.3;
    }

    .controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .controls button {
        padding: 8px 10px;
        font-size: 12px;
        letter-spacing: 0.2px;
        min-height: 40px;
    }
}
