:root {
    --bg: #060912;
    --panel: #0c1524;
    --line: rgba(90, 150, 220, 0.28);
    --text: #e8f4ff;
    --muted: #8ba3c7;
    --cyan: #42e8ff;
    --pink: #ff5ecb;
    --gold: #ffd166;
    --green: #7cffb2;
    --violet: #c08bff;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

.hidden { display: none !important; }

#app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

#hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(12, 21, 36, 0.9), rgba(6, 9, 18, 0.6));
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.hud-right { justify-content: flex-end; }
.hud-center { text-align: center; flex: 0 0 auto; min-width: 120px; }

.brand-mini {
    font-weight: 700;
    letter-spacing: 2px;
    font-size: 12px;
    color: var(--cyan);
    white-space: nowrap;
}

.room-name {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loop-label { font-size: 13px; font-weight: 700; letter-spacing: 2px; }
.phase-label { font-size: 10px; color: var(--gold); letter-spacing: 3px; margin-top: 1px; }

.progress {
    height: 4px;
    margin-top: 6px;
    border-radius: 999px;
    background: rgba(90, 150, 220, 0.18);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--cyan), var(--pink));
    transition: width 80ms linear;
}

.partner { font-size: 10px; letter-spacing: 2px; color: var(--muted); }
.partner.online { color: var(--green); }
.partner.offline { color: #ff7b7b; }

#stage {
    position: relative;
    flex: 1;
    min-height: 0;
}

#board {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(6, 9, 18, 0.75);
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(2, 58px);
    gap: 6px;
}
.dbtn {
    border: 1px solid var(--line);
    background: rgba(20, 34, 56, 0.9);
    color: var(--text);
    border-radius: 12px;
    font-size: 18px;
    touch-action: none;
    user-select: none;
    cursor: pointer;
}
.dbtn.active { background: rgba(66, 232, 255, 0.25); border-color: var(--cyan); }
.dbtn.up { grid-column: 2; grid-row: 1; }
.dbtn.left { grid-column: 1; grid-row: 2; }
.dbtn.down { grid-column: 2; grid-row: 2; }
.dbtn.right { grid-column: 3; grid-row: 2; }

.reactions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.reaction {
    border: 1px solid var(--line);
    background: rgba(20, 34, 56, 0.85);
    border-radius: 10px;
    font-size: 18px;
    line-height: 1;
    padding: 8px 9px;
    cursor: pointer;
}
.reaction:active { transform: scale(0.94); }

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(4, 7, 14, 0.66);
    backdrop-filter: blur(4px);
    z-index: 5;
}

.panel {
    width: 100%;
    max-width: 520px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 26px 24px;
    text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.brand {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--text);
}
.brand span { color: var(--cyan); }
.brand.small { font-size: 22px; }

.tagline { margin-top: 8px; color: var(--muted); font-size: 13px; }

.howto { margin: 22px 0 8px; text-align: left; display: grid; gap: 12px; }
.howto-row { display: flex; gap: 12px; align-items: flex-start; font-size: 13px; line-height: 1.45; color: #cfe2fb; }
.howto-row .k {
    flex: 0 0 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: rgba(66, 232, 255, 0.14);
    color: var(--cyan);
    font-size: 12px;
}
.howto-row b.g { color: var(--cyan); }
.howto-row b.c { color: var(--pink); }

.controls-hint { margin: 16px 0 4px; color: var(--muted); font-size: 12px; }

.btn {
    border: 1px solid var(--line);
    background: rgba(20, 34, 56, 0.95);
    color: var(--text);
    border-radius: 12px;
    padding: 14px 22px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 1.5px;
    cursor: pointer;
    font-family: inherit;
}
.btn.primary {
    background: linear-gradient(135deg, var(--cyan), #2aa6ff);
    color: #041018;
    border-color: transparent;
}
.btn.ghost { background: transparent; color: var(--muted); }
.btn.tiny { padding: 8px 12px; font-size: 11px; border-radius: 9px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.panel .btn.primary { margin-top: 20px; width: 100%; }

.result-title { font-size: 24px; font-weight: 800; letter-spacing: 2px; }
.result-title.win { color: var(--green); text-shadow: 0 0 22px rgba(124, 255, 178, 0.5); }
.result-title.lose { color: #ff9f6e; }
.result-sub { margin-top: 10px; font-size: 14px; color: #d7e8ff; }
.result-detail { margin-top: 8px; font-size: 12px; color: var(--muted); }

.result-actions { margin-top: 22px; display: grid; gap: 10px; }
.result-actions .btn { width: 100%; }

.result-wait { margin-top: 14px; color: var(--muted); font-size: 12px; letter-spacing: 1px; }
.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: 16px 0; color: var(--muted); font-size: 14px; }

.wait-banner {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 24px);
    padding: 10px 12px 10px 14px;
    border-radius: 999px;
    background: rgba(12, 21, 36, 0.92);
    border: 1px solid var(--line);
    font-size: 12px;
    color: #cfe2fb;
    z-index: 4;
}
.wb-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--cyan);
    animation: pulse 1.1s infinite;
    flex: 0 0 auto;
}
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.15); } }

@media (hover: hover) and (pointer: fine) {
    #dpad { display: none; }
}
@media (max-width: 560px) {
    .brand { font-size: 27px; letter-spacing: 3px; }
    .panel { padding: 20px 16px; border-radius: 14px; }
    .howto-row { font-size: 12px; }
    .dpad { grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); }
    .hud-center { min-width: 92px; }
    .room-name { display: none; }
    .reaction { font-size: 16px; padding: 7px 8px; }
}
@media (max-height: 520px) {
    .howto { display: none; }
    .controls-hint { display: none; }
    .panel { padding: 14px; }
}
