:root {
    --bg: #0d0b14;
    --bg2: #14102199;
    --panel: #1b1530;
    --panel2: #241b3f;
    --ink: #f4edff;
    --dim: #9a8fc0;
    --p0: #ffd23f;
    --p0d: #b3860a;
    --p1: #45d6e6;
    --p1d: #188a99;
    --bomb: #ff5a3c;
    --bombd: #a82f18;
    --green: #77e26a;
    --line: #3a2f5e;
    --shadow: #07060d;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: "Courier New", "Lucida Console", monospace;
    overflow: hidden;
    overscroll-behavior: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    background: repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0px,
        rgba(0, 0, 0, 0) 2px,
        rgba(0, 0, 0, 0.16) 3px
    );
    mix-blend-mode: multiply;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden {
    display: none !important;
}

/* ---------------------------------------------------------- HUD */

#hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px 6px;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.hud-side {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    letter-spacing: 1px;
    min-width: 90px;
}

.hud-side.right {
    justify-content: flex-end;
}

.hud-name {
    color: var(--dim);
    font-weight: 700;
    font-size: 12px;
}

.hud-score {
    font-size: 22px;
    font-weight: 700;
}

.left .hud-score {
    color: var(--p0);
}

.right .hud-score {
    color: var(--p1);
}

.pip-dot {
    width: 12px;
    height: 12px;
    display: inline-block;
    border: 2px solid var(--shadow);
}

.p0 {
    background: var(--p0);
}

.p1 {
    background: var(--p1);
}

.hud-center {
    text-align: center;
    flex: 1;
}

.phase-label {
    font-size: 13px;
    letter-spacing: 3px;
    color: var(--ink);
    text-shadow: 2px 2px 0 var(--shadow);
}

.round-pips {
    display: flex;
    gap: 5px;
    justify-content: center;
    margin-top: 6px;
}

.rpip {
    width: 16px;
    height: 10px;
    border: 2px solid var(--shadow);
    background: #2a2246;
}

.rpip.win0 {
    background: var(--p0);
}

.rpip.win1 {
    background: var(--p1);
}

/* -------------------------------------------------------- STAGE */

#stage {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 4px 10px;
}

#screenWrap {
    position: relative;
    line-height: 0;
    filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.35));
}

#screen {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: #0a0812;
    border: 4px solid #2b2350;
    box-shadow: 0 0 0 4px #07060d, 0 0 26px rgba(69, 214, 230, 0.16);
}

#screenGlow {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.06), transparent 65%);
}

.flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    background: #fff;
}

.flash.go {
    animation: flash 0.45s ease-out;
}

@keyframes flash {
    0% { opacity: 0.85; }
    100% { opacity: 0; }
}

.emoji-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.float-emoji {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 30px;
    animation: floatUp 1.1s ease-out forwards;
    text-shadow: 2px 2px 0 var(--shadow);
}

@keyframes floatUp {
    0% { opacity: 0; transform: translate(-50%, -20%) scale(0.5); }
    18% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}

/* ------------------------------------------------------ OVERLAY */

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    z-index: 20;
}

.panel {
    width: min(94%, 460px);
    max-height: 100%;
    overflow: auto;
    background: var(--panel);
    border: 4px solid #453872;
    box-shadow: 0 0 0 4px var(--shadow), 0 10px 0 rgba(0, 0, 0, 0.4);
    padding: 20px 20px 22px;
    text-align: center;
}

.brand {
    font-size: 42px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--bomb);
    text-shadow: 4px 4px 0 var(--bombd), 8px 8px 0 var(--shadow);
    line-height: 1;
}

.brand span {
    color: var(--ink);
    text-shadow: 4px 4px 0 #6a5aa0, 8px 8px 0 var(--shadow);
}

.brand.small {
    font-size: 26px;
}

.tagline {
    margin: 14px 2px 16px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--dim);
}

.howto {
    text-align: left;
    display: grid;
    gap: 8px;
    margin: 0 auto 18px;
    max-width: 340px;
}

.howto-row {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 8px;
    font-size: 12px;
    line-height: 1.45;
    color: #cfc6ea;
}

.howto-row b {
    color: var(--p1);
    letter-spacing: 1px;
}

.lobby-hint {
    margin-top: 14px;
    font-size: 11px;
    color: #7268a0;
}

.btn {
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--ink);
    background: var(--panel2);
    border: 3px solid #55468a;
    box-shadow: 0 4px 0 var(--shadow);
    padding: 12px 18px;
    cursor: pointer;
    transition: transform 0.05s, box-shadow 0.05s;
}

.btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--shadow);
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn.primary {
    background: var(--bomb);
    border-color: #ff8a70;
    color: #200a05;
    text-shadow: none;
}

.btn.ghost {
    background: transparent;
    color: var(--dim);
}

.btn.tiny {
    font-size: 11px;
    padding: 7px 10px;
    box-shadow: 0 3px 0 var(--shadow);
}

.panel .btn.primary {
    width: 100%;
    margin-top: 4px;
}

/* ------------------------------------------------------- RESULT */

.result-kicker {
    font-size: 12px;
    letter-spacing: 4px;
    color: var(--dim);
}

.result-big {
    font-size: 34px;
    font-weight: 700;
    margin: 6px 0 2px;
    letter-spacing: 1px;
    text-shadow: 3px 3px 0 var(--shadow);
}

.result-big.win {
    color: var(--green);
}

.result-big.lose {
    color: var(--bomb);
}

.result-score {
    font-size: 22px;
    color: var(--ink);
    margin-bottom: 12px;
}

.result-recap {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.recap {
    width: 46px;
    padding: 8px 0 6px;
    background: var(--panel2);
    border: 2px solid #3d3263;
    font-size: 18px;
    line-height: 1;
}

.recap small {
    display: block;
    font-size: 8px;
    letter-spacing: 1px;
    margin-top: 5px;
    color: var(--dim);
}

.recap.lost {
    border-color: var(--bombd);
    color: var(--bomb);
}

.recap.won {
    border-color: var(--p1d);
    color: var(--p1);
}

.result-series {
    font-size: 12px;
    color: var(--p0);
    margin-bottom: 14px;
    letter-spacing: 1px;
}

.result-actions {
    display: grid;
    gap: 9px;
}

.result-actions .btn.primary {
    margin: 0;
}

.result-wait {
    margin-top: 12px;
    font-size: 12px;
    color: var(--dim);
}

.dots i {
    animation: blink 1.2s infinite;
    font-style: normal;
}

.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 60%, 100% { opacity: 0.2; }
    30% { opacity: 1; }
}

.goodbye-msg {
    margin: 14px 0 18px;
    color: var(--dim);
    font-size: 13px;
}

/* -------------------------------------------------- WAIT BANNER */

.wait-banner {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--panel);
    border: 3px solid #453872;
    box-shadow: 0 4px 0 var(--shadow);
    padding: 8px 10px;
    font-size: 12px;
    color: var(--dim);
    z-index: 15;
    width: max-content;
    max-width: 94%;
}

.wb-dot {
    width: 10px;
    height: 10px;
    background: var(--bomb);
    animation: pulse 0.9s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

/* ---------------------------------------------------- CONTROLS */

#controls {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 14px calc(10px + env(safe-area-inset-bottom));
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.dpad {
    position: relative;
    width: 138px;
    height: 100px;
    flex: none;
}

.dbtn {
    position: absolute;
    width: 46px;
    height: 46px;
    font-size: 15px;
    color: var(--ink);
    background: var(--panel2);
    border: 3px solid #55468a;
    box-shadow: 0 4px 0 var(--shadow);
    cursor: pointer;
    touch-action: none;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dbtn:active,
.dbtn.held {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--shadow);
    background: #453872;
}

.dbtn.up { left: 46px; top: 0; }
.dbtn.down { left: 46px; top: 54px; }
.dbtn.left { left: 0; top: 27px; }
.dbtn.right { left: 92px; top: 27px; }

.controls-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.reactions {
    display: flex;
    gap: 6px;
}

.reaction-btn {
    width: 38px;
    height: 38px;
    font-size: 18px;
    background: var(--panel);
    border: 2px solid #453872;
    box-shadow: 0 3px 0 var(--shadow);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.reaction-btn:active {
    transform: translateY(3px);
    box-shadow: 0 0 0 var(--shadow);
}

@media (max-width: 560px) {
    .brand { font-size: 34px; }
    .hud-name { display: none; }
    .hud-side { min-width: 60px; }
    #controls { padding-left: 10px; padding-right: 10px; }
    .dpad { width: 120px; height: 88px; }
    .dbtn { width: 40px; height: 40px; }
    .dbtn.up { left: 40px; }
    .dbtn.down { left: 40px; top: 48px; }
    .dbtn.left { top: 24px; }
    .dbtn.right { left: 80px; top: 24px; }
    .reaction-btn { width: 34px; height: 34px; font-size: 16px; }
}

@media (max-height: 620px) {
    .howto { gap: 5px; }
    .howto-row { font-size: 11px; }
    .panel { padding: 14px 16px 16px; }
}
