:root {
    --po-gold: hsl(45, 92%, 58%);
    --po-gold-light: hsl(46, 96%, 72%);
    --po-gold-glow: hsla(45, 92%, 55%, 0.35);
    --po-cyan: hsl(192, 90%, 55%);
    --po-cyan-glow: hsla(192, 90%, 55%, 0.3);
    --po-coral: hsl(6, 88%, 60%);
    --po-green: hsl(152, 62%, 48%);
    --po-bg-deep: hsl(272, 40%, 6%);
    --po-bg-surface: hsl(268, 32%, 10%);
    --po-text-primary: hsl(220, 25%, 95%);
    --po-text-secondary: hsl(220, 16%, 68%);
    --po-glass: rgba(18, 12, 32, 0.74);
    --po-glass-border: rgba(168, 140, 255, 0.2);
    --po-z-modal: 1000;
}

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

.hidden { display: none !important; }

/* Site shell owns body background/layout; keep only game-specific resets */
body {
    font-family: var(--font-body, 'DM Sans', system-ui, sans-serif);
    color: var(--po-text-primary);
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.po-shell {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 20px auto 36px;
    padding: 16px 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(160deg, hsl(272, 34%, 12%), hsl(272, 42%, 7%));
    border: 1px solid rgba(168, 140, 255, 0.22);
    border-radius: 24px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55), 0 0 70px var(--po-gold-glow);
    overflow: hidden;
}

/* ─── Topbar: back · brand h1 · chips ─── */
.po-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.po-back-btn {
    display: inline-block;
    padding: 8px 14px;
    background: var(--po-glass);
    border: 1px solid var(--po-glass-border);
    border-radius: 10px;
    color: var(--po-text-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.po-back-btn:hover {
    background: rgba(168, 140, 255, 0.14);
    border-color: rgba(168, 140, 255, 0.45);
}

.po-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: clamp(1rem, 3.4vw, 1.32rem);
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1;
    background: linear-gradient(120deg, var(--po-gold-light), var(--po-gold) 55%, var(--po-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 12px var(--po-gold-glow));
}

.po-brand-mark {
    display: flex;
    filter: drop-shadow(0 0 8px var(--po-gold-glow));
}

.po-brand-mark svg { display: block; }

.po-hud {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

.po-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 74px;
    padding: 6px 12px;
    background: var(--po-glass);
    border: 1px solid var(--po-glass-border);
    border-radius: 12px;
}

.po-chip-best { border-color: rgba(251, 191, 36, 0.4); }

.po-chip-label {
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--po-gold);
}

.po-chip-value {
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1;
    color: var(--po-text-primary);
    font-variant-numeric: tabular-nums;
}

.po-pause-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    background: var(--po-glass);
    border: 1px solid var(--po-glass-border);
    border-radius: 10px;
    color: var(--po-text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.po-pause-btn:hover { border-color: var(--po-cyan); background: rgba(192, 90, 255, 0.12); }

/* ─── Fighter bars + star meter ─── */
.po-bars {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
}

.po-side { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.po-side-foe { align-items: flex-end; }

.po-side-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.po-side-name {
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--po-gold);
}

.po-side-fighter {
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--po-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.po-meter {
    position: relative;
    width: 100%;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--po-glass-border);
    overflow: hidden;
}

.po-meter-hp {
    height: 16px;
    border-radius: 999px;
}

.po-meter-hp .po-meter-fill {
    height: 100%;
    width: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--po-green), hsl(140, 60%, 55%));
    box-shadow: 0 0 14px rgba(52, 211, 153, 0.4);
    transition: width 0.18s linear;
}

.po-meter-foe .po-meter-fill {
    margin-left: auto;
    background: linear-gradient(270deg, var(--po-coral), hsl(24, 92%, 62%));
    box-shadow: 0 0 14px rgba(239, 68, 68, 0.38);
}

.po-meter-stamina {
    display: flex;
    align-items: center;
    gap: 7px;
    background: transparent;
    border: none;
    overflow: visible;
}

.po-meter-caption {
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--po-text-secondary);
}

.po-meter-track {
    position: relative;
    flex: 1;
    height: 7px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--po-glass-border);
    border-radius: 999px;
    overflow: hidden;
}

.po-meter-track .po-meter-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--po-cyan), hsl(200, 92%, 65%));
    transition: width 0.12s linear;
}

.po-meter-track.low .po-meter-fill { background: linear-gradient(90deg, var(--po-coral), hsl(30, 92%, 60%)); }

.po-meter-act { display: flex; justify-content: flex-end; }

.po-act-chip {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--po-gold);
    padding: 4px 11px;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.32);
    border-radius: 999px;
}

.po-stars {
    display: flex;
    gap: 5px;
    padding: 7px 11px;
    background: var(--po-glass);
    border: 1px solid rgba(251, 191, 36, 0.32);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.po-stars .po-star { color: rgba(255, 255, 255, 0.16); text-shadow: none; }

.po-stars .pip-full {
    color: var(--po-gold);
    text-shadow: 0 0 14px var(--po-gold-glow);
}

.po-stars.ready {
    border-color: var(--po-gold);
    box-shadow: 0 0 22px var(--po-gold-glow);
    animation: poStarPulse 1.1s ease-in-out infinite;
}

.po-stars.ready .po-star { color: var(--po-gold); }

@keyframes poStarPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.07); }
}

.po-stars:disabled { cursor: default; opacity: 0.7; animation: none; }

/* ─── Stage ─── */
.po-stage {
    position: relative;
    width: 100%;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid rgba(168, 140, 255, 0.24);
    box-shadow: 0 0 50px rgba(180, 120, 255, 0.14), 0 24px 50px rgba(0, 0, 0, 0.5);
    background: var(--po-bg-deep);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 800 / 520;
    touch-action: none;
}

#gameCanvas:focus-visible {
    outline: 3px solid var(--po-gold);
    outline-offset: -3px;
}

/* ─── Round banner + toast ─── */
.po-banner {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 13px 44px;
    background: rgba(10, 6, 20, 0.88);
    border: 2px solid var(--po-gold);
    border-radius: 999px;
    color: var(--po-text-primary);
    font-size: clamp(1.25rem, 5vw, 2.1rem);
    font-weight: 900;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    white-space: nowrap;
    z-index: 20;
    pointer-events: none;
    box-shadow: 0 0 34px var(--po-gold-glow);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: poBannerFade 1.8s forwards;
}

@keyframes poBannerFade {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
    16% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -58%) scale(1); }
}

.po-toast {
    position: absolute;
    left: 50%;
    bottom: 13%;
    transform: translateX(-50%);
    padding: 9px 20px;
    background: rgba(10, 6, 20, 0.92);
    border: 1px solid rgba(34, 211, 238, 0.45);
    border-radius: 999px;
    color: var(--po-cyan);
    font-size: 0.88rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    white-space: nowrap;
    z-index: 25;
    pointer-events: none;
    box-shadow: 0 0 26px var(--po-cyan-glow);
    animation: poToastIn 0.3s ease;
}

@keyframes poToastIn {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── Touch pad ─── */
.po-pad {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.po-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 62px;
    padding: 9px 6px;
    border-radius: 14px;
    font-family: inherit;
    cursor: pointer;
    background: var(--po-glass);
    border: 1px solid var(--po-glass-border);
    color: var(--po-text-primary);
    transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
    touch-action: manipulation;
}

.po-btn-glyph {
    font-size: 1.32rem;
    font-weight: 900;
    line-height: 1;
    color: var(--po-gold);
}

.po-btn-label {
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--po-text-secondary);
    text-align: center;
    white-space: nowrap;
}

.po-btn-dodge:hover, .po-btn-dodge:focus-visible {
    border-color: var(--po-cyan);
    background: rgba(34, 211, 238, 0.1);
}

.po-btn-punch:hover, .po-btn-punch:focus-visible {
    border-color: var(--po-gold);
    background: rgba(251, 191, 36, 0.1);
}

.po-btn:active { transform: translateY(2px) scale(0.98); }

.po-btn.spent { border-color: rgba(239, 68, 68, 0.6); }

/* ─── Bottom bar ─── */
.po-bottombar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.po-hint {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--po-text-secondary);
}

/* ─── Overlays ─── */
.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 5, 16, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow-y: auto;
    z-index: var(--po-z-modal);
    padding: 16px;
    /* The site header is fixed: keep the card clear of it and the notch. */
    padding-top: max(var(--app-header-h, 72px), var(--safe-area-inset-top, 0px));
    padding-bottom: max(16px, var(--safe-area-inset-bottom, 0px));
    cursor: default;
}

.overlay-card {
    margin: auto;
    background: linear-gradient(150deg, rgba(26, 18, 46, 0.97), rgba(8, 5, 16, 0.99));
    border: 1px solid rgba(168, 140, 255, 0.28);
    border-radius: 22px;
    padding: 32px 30px;
    max-width: min(500px, 92vw);
    width: 100%;
    max-height: 86vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 0 70px rgba(180, 120, 255, 0.18);
    animation: poCardIn 0.35s cubic-bezier(0.34, 1.5, 0.64, 1);
}

@keyframes poCardIn {
    from { opacity: 0; transform: scale(0.88) translateY(18px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay-card h2 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 900;
    letter-spacing: -0.5px;
    background: linear-gradient(120deg, #fff, var(--po-gold));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.overlay-card p,
.story-body p {
    color: var(--po-text-secondary);
    font-size: 0.95rem;
    line-height: 1.55;
    margin-bottom: 14px;
    text-align: left;
}

.overlay-card > p { text-align: center; }

.overlay-sub { margin-bottom: 16px; }

.overlay-kicker {
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--po-gold);
    margin-bottom: 8px;
}

.overlay-kicker.story { color: var(--po-cyan); }

.overlay-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(168, 140, 255, 0.08);
    border: 1px solid rgba(168, 140, 255, 0.18);
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 18px;
    font-size: 0.92rem;
    color: var(--po-text-secondary);
    font-variant-numeric: tabular-nums;
    text-align: left;
}

.overlay-stats strong { color: var(--po-gold); font-weight: 800; }

.defeat-line {
    font-size: 1rem !important;
    color: var(--po-coral) !important;
    font-weight: 600;
    text-align: center !important;
    margin-bottom: 16px !important;
}

.story-card { max-width: min(560px, 94vw); }

.victory-card { border-color: rgba(251, 191, 36, 0.35); box-shadow: 0 0 70px var(--po-gold-glow); }

.fail-card { border-color: rgba(239, 68, 68, 0.35); box-shadow: 0 0 70px rgba(239, 68, 68, 0.14); }

/* ─── Fighter intro card ─── */
.intro-title {
    font-size: 0.86rem;
    font-weight: 800;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--po-cyan) !important;
    text-align: center !important;
    margin-bottom: 4px !important;
}

.intro-record {
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--po-gold) !important;
    text-align: center !important;
    font-variant-numeric: tabular-nums;
}

.intro-taunt {
    font-style: italic;
    font-size: 1rem !important;
    text-align: center !important;
    color: var(--po-text-primary) !important;
    margin-bottom: 18px !important;
}

.intro-card { border-color: rgba(34, 211, 238, 0.3); }

/* ─── Start card content ─── */
.how-to {
    background: rgba(168, 140, 255, 0.07);
    border: 1px solid rgba(168, 140, 255, 0.18);
    border-radius: 14px;
    padding: 14px 16px;
    text-align: left;
    margin-bottom: 16px;
}

.how-to h3 {
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--po-cyan);
    margin-bottom: 10px;
}

.how-to ul { list-style: none; display: flex; flex-direction: column; gap: 7px; }

.how-to li {
    position: relative;
    padding-left: 16px;
    font-size: 0.84rem;
    line-height: 1.45;
    color: var(--po-text-secondary);
}

.how-to li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--po-gold);
}

.input-group { text-align: left; margin-bottom: 16px; }

.input-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--po-text-secondary);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 11px 14px;
    background: rgba(168, 140, 255, 0.09);
    border: 1px solid var(--po-glass-border);
    border-radius: 10px;
    color: var(--po-text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.input-group input:focus { border-color: var(--po-gold); }

.input-group input:focus-visible {
    outline: 2px solid var(--po-gold);
    outline-offset: 2px;
}

/* ─── Buttons ─── */
.btn-primary,
.btn-secondary {
    display: block;
    width: 100%;
    padding: 13px 22px;
    border-radius: 14px;
    font-family: inherit;
    font-size: 0.98rem;
    font-weight: 800;
    letter-spacing: 0.6px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    margin-top: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--po-gold), hsl(32, 95%, 52%));
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #15100a;
    box-shadow: 0 6px 24px var(--po-gold-glow);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 30px var(--po-gold-glow); }

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: transparent;
    border: 1px solid var(--po-glass-border);
    color: var(--po-text-secondary);
}

.btn-secondary:hover {
    border-color: var(--po-cyan);
    color: var(--po-text-primary);
}

:where(a, button, input, [tabindex]):focus-visible {
    outline: 3px solid var(--po-cyan);
    outline-offset: 3px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    body {
        padding-top: max(60px, calc(60px + var(--safe-area-inset-top)));
        padding-left: max(0px, var(--safe-area-inset-left));
        padding-right: max(0px, var(--safe-area-inset-right));
        padding-bottom: max(0px, var(--safe-area-inset-bottom));
    }

    .po-shell {
        max-width: 100%;
        margin: 8px auto 24px;
        padding: 12px 10px 14px;
        gap: 10px;
        border-radius: 18px;
    }

    .po-topbar { gap: 8px; }
    .po-back-btn { font-size: 0.75rem; padding: 7px 10px; }
    .po-brand { font-size: 0.95rem; gap: 7px; order: 3; width: 100%; justify-content: center; }
    .po-brand-mark svg { width: 24px; height: 24px; }
    .po-hud { gap: 5px; flex: 1; justify-content: flex-end; }
    .po-chip { min-width: 0; flex: 1; padding: 5px 5px; border-radius: 10px; }
    .po-chip-label { font-size: 0.56rem; letter-spacing: 0.8px; }
    .po-chip-value { font-size: 0.92rem; }
    .po-pause-btn { width: 34px; height: 34px; }

    .po-bars { grid-template-columns: 1fr auto 1fr; gap: 8px; }
    .po-side-fighter { font-size: 0.76rem; }
    .po-meter-hp { height: 13px; }
    .po-stars { padding: 6px 8px; font-size: 1.05rem; }

    .po-stage { border-radius: 14px; }

    .po-pad { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
    .po-btn { min-height: 56px; padding: 8px 3px; border-radius: 12px; }
    .po-btn-glyph { font-size: 1.18rem; }
    .po-btn-label { font-size: 0.56rem; letter-spacing: 0.04em; }

    .po-banner { padding: 10px 24px; }
    .po-toast { font-size: 0.72rem; padding: 7px 14px; }
    .po-hint { font-size: 0.72rem; }

    .overlay-card { padding: 24px 18px; max-width: 96vw; }
    .overlay-card h2 { font-size: 1.45rem; }
    .overlay-card p, .story-body p { font-size: 0.88rem; }
}

@media (max-width: 420px) {
    .po-chip-label { font-size: 0.5rem; letter-spacing: 0.4px; }
    .po-chip-value { font-size: 0.84rem; }
    .overlay-card { padding: 20px 14px; }
    .btn-primary, .btn-secondary { font-size: 0.9rem; padding: 12px 16px; }
    .po-btn-label { font-size: 0.5rem; }
    .po-btn { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
    .po-banner,
    .po-toast,
    .overlay-card { animation: none; }

    .po-stars.ready { animation: none; }
    .btn-primary:hover { transform: none; }
    .po-btn:active { transform: none; }
    .po-meter-hp .po-meter-fill,
    .po-meter-track .po-meter-fill { transition: none; }
}
