:root {
    --p1: #ff6f9f;
    --p2: #5fc6ff;
    --accent: #7ee787;
    --bg: #10131f;
    --panel: rgba(14, 18, 32, 0.78);
    --border: rgba(255, 255, 255, 0.16);
    --text: #f7f8ff;
    --muted: rgba(247, 248, 255, 0.68);
    --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
    --font-title: "Arial Black", "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}

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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, #171320 0%, #0c1720 52%, #16171d 100%);
    color: var(--text);
    font-family: var(--font-main);
}

#app {
    height: 100%;
    display: grid;
    grid-template-rows: 52px 1fr 76px;
}

.topbar,
.bottombar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(7, 9, 18, 0.78);
    backdrop-filter: blur(10px);
    z-index: 5;
}

.bottombar {
    justify-content: center;
    border-top: 1px solid var(--border);
    border-bottom: 0;
    flex-wrap: wrap;
    padding-top: 7px;
    padding-bottom: 7px;
}

.title {
    min-width: 0;
    flex: 1;
    font-family: var(--font-title);
    font-size: 1rem;
    font-weight: 900;
    white-space: nowrap;
}

.title span {
    color: var(--p1);
}

.mode-switch {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    width: 138px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
}

.mode-btn {
    min-height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 900;
    font-size: 0.74rem;
    cursor: pointer;
}

.mode-btn.active {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.status {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    white-space: nowrap;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff6464;
}

.dot.on {
    background: var(--accent);
    box-shadow: 0 0 9px var(--accent);
}

#fps {
    min-width: 48px;
    text-align: right;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
}

#stage {
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.solo-camera,
.cam-pane {
    position: absolute;
    overflow: hidden;
}

.solo-camera {
    left: 0;
    right: 0;
    bottom: 0;
    height: 42%;
}

.cam-pane {
    top: 0;
    bottom: 0;
    width: 50%;
}

.cam-pane.left {
    left: 0;
}

.cam-pane.right {
    right: 0;
}

.cam-bg,
.face-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.cam-bg {
    filter: saturate(1.05) contrast(1.08) brightness(0.86);
}

.face-overlay {
    pointer-events: none;
}

.tag {
    position: absolute;
    top: 10px;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.62rem;
    font-weight: 900;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.battle-divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    z-index: 2;
    width: 2px;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
    transform: translateX(-50%);
    pointer-events: none;
    display: none;
}

.cam-pane.left .tag {
    left: 10px;
    color: var(--p1);
}

.cam-pane.right .tag {
    right: 10px;
    color: var(--p2);
}

#arena {
    position: absolute;
    z-index: 3;
    pointer-events: none;
}

.player-card {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: var(--panel);
    backdrop-filter: blur(7px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 9px;
    pointer-events: auto;
}

.p1 {
    box-shadow: 0 0 20px rgba(255, 111, 159, 0.2);
}

.p2 {
    box-shadow: 0 0 20px rgba(95, 198, 255, 0.2);
}

.name {
    font-family: var(--font-title);
    font-size: 0.96rem;
    font-weight: 900;
    line-height: 1;
}

.p1 .name {
    color: var(--p1);
}

.p2 .name {
    color: var(--p2);
}

.hud {
    display: flex;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

.box {
    min-width: 62px;
    padding: 4px 7px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.06);
    text-align: center;
}

.box .k {
    display: block;
    font-size: 0.5rem;
    font-weight: 900;
    color: var(--muted);
}

.box .v {
    display: block;
    font-size: 0.9rem;
    font-weight: 900;
}

.play-row {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;
}

.board-wrap {
    position: relative;
}

canvas.board {
    display: block;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.16);
    background: rgba(0, 0, 0, 0.45);
}

.p1 canvas.board {
    border-color: rgba(255, 111, 159, 0.52);
}

.p2 canvas.board {
    border-color: rgba(95, 198, 255, 0.52);
}

.over {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.72);
    font-weight: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s;
}

.over.show {
    opacity: 1;
}

.side-hud {
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: center;
}

canvas.next {
    width: 74px;
    height: 74px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(0, 0, 0, 0.35);
}

.expr {
    display: grid;
    gap: 5px;
    width: 74px;
}

.chip {
    min-height: 22px;
    padding: 4px 5px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.48rem;
    font-weight: 900;
    text-align: center;
}

.p1 .chip.active {
    color: #ffe0ea;
    border-color: rgba(255, 111, 159, 0.82);
    background: rgba(255, 111, 159, 0.22);
}

.p2 .chip.active {
    color: #d8f3ff;
    border-color: rgba(95, 198, 255, 0.82);
    background: rgba(95, 198, 255, 0.22);
}

.btn {
    min-height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 900;
    padding: 7px 12px;
    cursor: pointer;
}

.btn.primary {
    border-color: rgba(126, 231, 135, 0.48);
    background: rgba(126, 231, 135, 0.18);
}

.btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.help-text {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 14px;
    color: rgba(255, 255, 255, 0.76);
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1.25;
    text-align: center;
}

#videoEl {
    position: fixed;
    width: 1280px;
    height: 720px;
    left: -9999px;
    top: -9999px;
    opacity: 0;
    pointer-events: none;
}

#result {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.78);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
}

#result.show {
    opacity: 1;
    pointer-events: auto;
}

.result-card {
    min-width: 260px;
    display: grid;
    gap: 11px;
    padding: 18px 22px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(22, 25, 39, 0.96);
    text-align: center;
}

.result-title {
    font-family: var(--font-title);
    font-size: 1.7rem;
    font-weight: 900;
}

#app[data-mode="solo"] .cam-pane,
#app[data-mode="solo"] #card2 {
    display: none;
}

#app[data-mode="solo"] #arena {
    left: 0;
    right: 0;
    top: 0;
    height: 58%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

#app[data-mode="solo"] .player-card {
    width: min(96vw, 430px);
    max-height: 100%;
}

#app[data-mode="solo"] .play-row {
    width: 100%;
}

#app[data-mode="solo"] .side-hud {
    min-width: 76px;
}

#app[data-mode="battle"] .solo-camera {
    display: none;
}

#app[data-mode="battle"] .battle-divider {
    display: block;
}

#app[data-mode="battle"] #arena {
    inset: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(18px, 8vw, 120px);
}

#app[data-mode="battle"] .player-card {
    width: auto;
    padding: 0;
    gap: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
}

#app[data-mode="battle"] .name,
#app[data-mode="battle"] .hud,
#app[data-mode="battle"] .side-hud {
    display: none;
}

#app[data-mode="battle"] .play-row {
    gap: 0;
}

#app[data-mode="battle"] canvas.board {
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.42);
    background: rgba(0, 0, 0, 0.56);
}

@media (orientation: portrait) {
    #app[data-mode="solo"] {
        grid-template-rows: 48px 1fr 92px;
    }

    #app[data-mode="solo"] .topbar {
        padding: 0 8px;
        gap: 6px;
    }

    #app[data-mode="solo"] .title {
        font-size: 0.84rem;
        flex: 0 1 auto;
    }

    #app[data-mode="solo"] .mode-switch {
        width: 118px;
    }

    #app[data-mode="solo"] .status {
        display: none;
    }

    #app[data-mode="solo"] #fps {
        display: none;
    }

    #app[data-mode="solo"] .solo-camera {
        height: 42%;
    }

    #app[data-mode="solo"] #arena {
        height: 58%;
    }

    #app[data-mode="solo"] .hud {
        gap: 5px;
    }

    #app[data-mode="solo"] .box {
        min-width: 58px;
    }

    #app[data-mode="solo"] .help-text {
        display: grid;
        gap: 2px;
        font-size: 0.62rem;
    }
}

@media (orientation: portrait) and (max-width: 420px) {
    #app[data-mode="solo"] .player-card {
        padding: 7px;
        gap: 5px;
    }

    #app[data-mode="solo"] .name {
        display: none;
    }

    #app[data-mode="solo"] canvas.next,
    #app[data-mode="solo"] .expr {
        width: 62px;
    }

    #app[data-mode="solo"] canvas.next {
        height: 62px;
    }
}

@media (orientation: portrait) {
    #app[data-mode="battle"] {
        grid-template-rows: 52px 1fr 82px;
    }

    #app[data-mode="battle"] #arena {
        flex-direction: column;
        inset: 6px;
        gap: 10px;
    }

    #app[data-mode="battle"] .player-card {
        width: auto;
        max-height: none;
    }
}
