@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #140b07;
    color: #fff5e6;
    font-family: 'Press Start 2P', monospace;
}

.viewport {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #140b07;
}

.stage-wrap {
    position: relative;
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    background: #d89b6a;
    border: 4px solid #23110a;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hud-top {
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
    gap: 8px;
}

.hud-group {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.px-tag {
    background: rgba(20, 11, 7, 0.85);
    border: 2px solid #23110a;
    outline: 2px solid #6b3d2b;
    padding: 6px 10px;
    font-size: 10px;
    color: #fff5e6;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.px-tag.accent { color: #ffcc33; }
.px-tag.danger { color: #ff6b6b; }
.px-tag.invert { color: #e0aaff; border-color: #7b2cbf; }
.px-tag.auto { color: #ffd166; border-color: #d97706; }

.px-btn {
    background: #3e2318;
    color: #fff5e6;
    border: 2px solid #8a513a;
    box-shadow: 0 3px 0 #1a0d08;
    padding: 6px 10px;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.px-btn:hover { background: #5c3424; }
.px-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #1a0d08;
}
.px-btn.primary {
    background: #d97706;
    border-color: #ffcc33;
    color: #140b07;
}
.px-btn.danger {
    background: #9d0208;
    border-color: #ff6b6b;
    color: #fff5e6;
}
.px-btn.danger:hover { background: #c1121f; }

.taunt-text {
    position: absolute;
    top: 48px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 11, 7, 0.9);
    border: 2px solid #8a513a;
    color: #ffcc33;
    padding: 6px 12px;
    font-size: 10px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 15;
    white-space: nowrap;
}
.taunt-text.show { opacity: 1; }

.overlay {
    position: absolute;
    inset: 0;
    background: #23120b;
    display: none;
    flex-direction: column;
    z-index: 30;
}
.overlay.open { display: flex; }
#settingsOverlay, #leaderboardOverlay, #statsOverlay, #confirmRestartOverlay, #victoryOverlay { z-index: 45; }

.map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: #180c07;
    border-bottom: 4px solid #3e2318;
    gap: 10px;
}

.map-title {
    font-size: 13px;
    color: #ffcc33;
}

.map-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 10px;
    color: #f3d5b5;
}

.progress-bar {
    width: 140px;
    height: 14px;
    background: #2b160e;
    border: 2px solid #6b3d2b;
    padding: 2px;
}

.progress-fill {
    height: 100%;
    background: #ffcc33;
    width: 0%;
    transition: width 0.25s steps(5);
}

.map-canvas-wrap {
    position: relative;
    flex: 1;
    width: 100%;
    overflow: hidden;
}

#mapCanvas {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.map-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: #180c07;
    border-top: 4px solid #3e2318;
    gap: 10px;
}

.map-selected-info {
    font-size: 10px;
    color: #f3d5b5;
}

.victory-box {
    margin: auto;
    text-align: center;
    padding: 20px 24px;
    background: #180c07;
    border: 4px solid #ffcc33;
    width: min(520px, 92%);
    max-height: 92%;
    overflow-y: auto;
}
.lb-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 10px;
}
.lb-list {
    background: #23120b;
    border: 2px solid #6b3d2b;
    padding: 8px 10px;
    margin-bottom: 14px;
    min-height: 110px;
    max-height: 170px;
    overflow-y: auto;
    font-size: 9px;
    text-align: left;
}
.lb-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 4px;
    border-bottom: 1px solid #3e2318;
    color: #fff5e6;
}
.lb-row:last-child { border-bottom: none; }
.lb-row.top { color: #ffcc33; }
.lb-account-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    background: #23120b;
    border: 2px solid #6b3d2b;
    padding: 8px 10px;
    margin-bottom: 12px;
    text-align: left;
}
.lb-discord-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.lb-discord-avatar {
    display: block;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid #5865F2;
    box-shadow: 0 0 0 2px #140b07;
    background: #140b07;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    flex-shrink: 0;
}
.lb-discord-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.lb-discord-label {
    font-size: 7px;
    color: #9bb1ff;
}
.lb-discord-link {
    font-size: 9px;
    color: #ffcc33;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lb-discord-link:hover {
    color: #ffffff;
    text-decoration: underline;
}
.lb-account-status {
    font-size: 8px;
    color: #bfa086;
}
.px-btn.discord {
    background: #5865F2;
    border-color: #9bb1ff;
    color: #ffffff;
}
.px-btn.discord:hover { background: #4752c4; }
.px-btn.sm {
    padding: 4px 8px;
    font-size: 8px;
}
.stats-box {
    margin: auto;
    text-align: center;
    padding: 18px 20px;
    background: #180c07;
    border: 4px solid #ffcc33;
    width: min(760px, 95%);
    max-height: 92%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.stats-box h2 {
    font-size: 14px;
    color: #ffcc33;
    margin: 0;
}
.stats-body {
    background: #23120b;
    border: 2px solid #6b3d2b;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
    min-height: 220px;
    max-height: 54vh;
    text-align: left;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}
.stat-card {
    background: #180c07;
    border: 2px solid #4a281c;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.stat-card-val {
    font-size: 12px;
    color: #ffcc33;
}
.stat-card-val.danger { color: #ff6b6b; }
.stat-card-val.good { color: #80ed99; }
.stat-card-val.info { color: #72efdd; }
.stat-card-lbl {
    font-size: 7px;
    color: #bfa086;
    line-height: 1.4;
}
.stat-card-sub {
    font-size: 7px;
    color: #fff5e6;
    opacity: 0.85;
}
.stat-section-title {
    font-size: 9px;
    color: #ffcc33;
    margin: 10px 0 8px;
    padding-bottom: 4px;
    border-bottom: 2px solid #3e2318;
}
.stat-controls-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 10px;
    justify-content: space-between;
}
.stat-select {
    background: #180c07;
    color: #fff5e6;
    border: 2px solid #8a513a;
    padding: 5px 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    cursor: pointer;
}
.stat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8px;
}
.stat-table th, .stat-table td {
    padding: 6px 5px;
    border-bottom: 1px solid #3e2318;
    text-align: left;
}
.stat-table th {
    color: #ffcc33;
    background: #180c07;
    position: sticky;
    top: -12px;
    z-index: 2;
}
.stat-table tr.summary-row td {
    color: #72efdd;
    background: #1a0d08;
    border-top: 2px solid #6b3d2b;
    font-weight: bold;
}
.stat-cause-row {
    margin-bottom: 9px;
    font-size: 8px;
}
.stat-cause-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    color: #fff5e6;
}
.stat-cause-bar {
    width: 100%;
    height: 10px;
    background: #140b07;
    border: 1px solid #6b3d2b;
}
.stat-cause-fill {
    height: 100%;
    background: #ff6b6b;
}
.settings-box {
    margin: auto;
    text-align: center;
    padding: 24px 28px;
    background: #180c07;
    border: 4px solid #8a513a;
    width: min(420px, 90%);
}
.settings-box h2 {
    font-size: 15px;
    color: #ffcc33;
    margin: 0 0 18px;
}
.confirm-box {
    border-color: #e63946;
}
.confirm-box h2 {
    color: #ff6b6b;
}
.confirm-text {
    font-size: 10px;
    color: #f3d5b5;
    line-height: 1.7;
    margin: 0 0 20px;
}
.setting-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    text-align: left;
    font-size: 10px;
    color: #f3d5b5;
}
.setting-row input[type="range"] {
    width: 100%;
    accent-color: #ffcc33;
    cursor: pointer;
}
.victory-box img {
    width: 72px;
    height: 72px;
    image-rendering: pixelated;
    margin-bottom: 14px;
}
.victory-box h2 {
    font-size: 16px;
    color: #ffcc33;
    margin: 0 0 14px;
    line-height: 1.5;
}
.victory-box p {
    font-size: 11px;
    color: #f3d5b5;
    margin: 0 0 22px;
    line-height: 1.6;
}

.touch-controls {
    display: none;
    position: absolute;
    bottom: 14px;
    left: 14px;
    right: 14px;
    justify-content: space-between;
    pointer-events: none;
    z-index: 20;
}
.touch-group {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}
.touch-btn {
    width: 58px;
    height: 50px;
    background: rgba(35, 17, 10, 0.78);
    border: 2px solid #8a513a;
    color: #fff5e6;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.touch-btn:active {
    background: #ffcc33;
    color: #140b07;
}

@media (max-width: 820px), (pointer: coarse) {
    .touch-controls { display: flex; }
}
