/* ============================================
   NEXTBALL - MOBILE / TOUCH STYLES
   Loaded on all devices; rules activate only when
   body.is-mobile is set by mobile.js
   ============================================ */

/* Touch controls hidden by default (desktop) */
.touch-controls { display: none; }

/* ============================================
   GLOBAL MOBILE BASE
   ============================================ */
body.is-mobile {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body.is-mobile input,
body.is-mobile textarea {
    -webkit-user-select: text;
    user-select: text;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
}

/* Safe area helpers */
body.is-mobile {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ============================================
   GAME SCREEN - FULLSCREEN CANVAS
   ============================================ */
body.is-mobile #game-screen {
    position: fixed;
    inset: 0;
    height: 100dvh;
    width: 100vw;
    display: block;
    background: #000;
}

body.is-mobile .game-area-wrapper {
    position: absolute;
    inset: 0;
    padding: 0;
    gap: 0;
    display: block;
}

body.is-mobile .game-container {
    position: absolute;
    inset: 0;
    display: block;
}

body.is-mobile #game-canvas {
    position: absolute;
    inset: 0;
    border-radius: 0;
    box-shadow: none;
    touch-action: none;
}

/* Compact floating scoreboard */
body.is-mobile .game-topbar {
    position: absolute;
    top: calc(var(--safe-top) + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    height: 36px;
    padding: 0 14px;
    gap: 14px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    z-index: 30;
    pointer-events: none;
}
body.is-mobile .game-topbar .team-name { font-size: 11px; letter-spacing: 1.5px; }
body.is-mobile .game-topbar .score { font-size: 20px; }
body.is-mobile .game-topbar .game-timer { font-size: 15px; }
body.is-mobile .team-score { gap: 6px; }

/* Hide desktop-only bits */
body.is-mobile .controls-info { display: none !important; }
body.is-mobile .btn-help-ingame { display: none !important; }

/* ============================================
   TOUCH CONTROLS LAYER
   ============================================ */
body.is-mobile .touch-controls {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.touch-zone {
    position: absolute;
    bottom: 0;
    top: 0;
    width: 50%;
    pointer-events: auto;
    touch-action: none;
}
.touch-zone-left  { left: 0; }
.touch-zone-right { right: 0; pointer-events: none; }

/* --- Joystick --- */
.joystick {
    position: absolute;
    width: 130px;
    height: 130px;
    left: calc(var(--safe-left) + 40px);
    bottom: calc(var(--safe-bottom) + 40px);
    opacity: 0.55;
    transition: opacity 0.15s;
    pointer-events: none;
}
.joystick.active { opacity: 0.9; transition: none; }

.joystick-base {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.10);
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.3);
}
.joystick-base::before {
    content: '';
    position: absolute;
    inset: 30%;
    border-radius: 50%;
    border: 1px dashed rgba(255,255,255,0.2);
}

.joystick-knob {
    position: absolute;
    width: 56px;
    height: 56px;
    left: 50%;
    top: 50%;
    margin: -28px 0 0 -28px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #ffffff, #cfd6e0);
    box-shadow: 0 4px 12px rgba(0,0,0,0.45);
    will-change: transform;
}

/* --- Action buttons --- */
.touch-btn {
    position: absolute;
    border: none;
    border-radius: 50%;
    color: #fff;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    opacity: 0.8;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
    transition: transform 0.06s, opacity 0.1s;
    padding: 0;
    -webkit-appearance: none;
}
.touch-btn.pressed { transform: scale(0.9); opacity: 1; }

.touch-btn-kick {
    width: 96px;
    height: 96px;
    right: calc(var(--safe-right) + 36px);
    bottom: calc(var(--safe-bottom) + 36px);
    font-size: 40px;
    background: radial-gradient(circle at 35% 35%, #ff8a75, #d43f2a);
    border: 3px solid rgba(255,255,255,0.35);
}
.touch-btn-kick .touch-btn-icon { filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }

.touch-btn-curve {
    width: 62px;
    height: 62px;
    font-size: 26px;
    background: rgba(40, 46, 60, 0.85);
    border: 2px solid rgba(255,255,255,0.25);
}
.touch-btn-curve-left  { right: calc(var(--safe-right) + 148px); bottom: calc(var(--safe-bottom) + 30px); }
.touch-btn-curve-right { right: calc(var(--safe-right) + 48px);  bottom: calc(var(--safe-bottom) + 146px); }
/* Soft touch (hold) + Lob (tap to arm): smaller, text labels */
.touch-btn-soft, .touch-btn-lob {
    width: 54px;
    height: 54px;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.touch-btn-soft { right: calc(var(--safe-right) + 222px); bottom: calc(var(--safe-bottom) + 34px); }
.touch-btn-lob  { right: calc(var(--safe-right) + 52px);  bottom: calc(var(--safe-bottom) + 220px); }
/* Sprint (hold): left of the power slot, above Touch; the ring shows own stamina (--st 0..1, game.js) */
.touch-btn-sprint {
    --st: 1;
    width: 58px; height: 58px; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
    right: calc(var(--safe-right) + 222px); bottom: calc(var(--safe-bottom) + 106px);
    border: 0;
    background:
        radial-gradient(circle, rgba(40, 46, 60, 0.92) 0 25px, transparent 25.5px),
        conic-gradient(rgba(255, 255, 255, 0.85) calc(var(--st) * 360deg), rgba(255, 255, 255, 0.14) 0);
}
.touch-btn-sprint.low { background:
        radial-gradient(circle, rgba(40, 46, 60, 0.92) 0 25px, transparent 25.5px),
        conic-gradient(#F5B942 calc(var(--st) * 360deg), rgba(255, 255, 255, 0.14) 0); }
.touch-btn-sprint.empty { color: rgba(255, 255, 255, 0.55); background:
        radial-gradient(circle, rgba(40, 46, 60, 0.92) 0 25px, transparent 25.5px),
        conic-gradient(#E5484D calc(var(--st) * 360deg), rgba(255, 255, 255, 0.14) 0); }
/* own match fitness pill: tucked under the right end of the floating scoreboard on phones (clear of the chat floats) */
body.is-mobile .game-fit { position: absolute; top: 40px; right: 10px; left: auto; margin: 0; height: 18px; font-size: 9px; padding: 0 7px; background: rgba(0, 0, 0, 0.45); border-color: rgba(255, 255, 255, 0.1); }

.touch-btn-power {
    width: 64px;
    height: 64px;
    right: calc(var(--safe-right) + 150px);
    bottom: calc(var(--safe-bottom) + 130px);
    font-size: 30px;
    background: radial-gradient(circle at 35% 35%, #ffe37a, #e0a800);
    border: 2px solid rgba(255,255,255,0.4);
    color: #2a1f00;
}
.touch-btn-power.ready { animation: powerPulse 1s infinite; }
@keyframes powerPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 200, 0, 0.6); }
    50%      { box-shadow: 0 0 0 14px rgba(255, 200, 0, 0); }
}

/* --- Top-right utility bar --- */
.touch-utility {
    position: absolute;
    top: calc(var(--safe-top) + 6px);
    right: calc(var(--safe-right) + 10px);
    display: flex;
    gap: 8px;
    pointer-events: auto;
}
.touch-util-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-appearance: none;
}
.touch-util-btn:active { background: rgba(255,255,255,0.2); }
.touch-util-leave { background: rgba(200, 40, 40, 0.65); }

.touch-chat-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #ff3b3b;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   CHAT - SLIDE-UP SHEET
   ============================================ */
body.is-mobile .game-chat-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 55dvh;
    max-height: 320px;
    margin: 0;
    border-radius: 16px 16px 0 0;
    background: rgba(12, 14, 20, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transform: translateY(110%);
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 40;
    padding-bottom: calc(var(--safe-bottom) + 8px);
    display: flex;
    flex-direction: column;
}
body.is-mobile .game-chat-panel.open { transform: translateY(0); }
body.is-mobile .game-chat-panel::before {
    display: none !important;
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.3);
    margin: 10px auto 6px;
    flex-shrink: 0;
}
body.is-mobile .game-chat-panel .chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px;
}
body.is-mobile .game-chat-panel .chat-input-container { padding: 8px 12px 0; }
.m-chat-grab, .m-chat-x { display: none; }
body.is-mobile .game-chat-panel .m-chat-grab { display: flex; flex-shrink: 0; align-items: center; justify-content: center; width: 100%; height: 26px; padding: 0; margin: 0; border: 0; background: transparent; cursor: pointer; touch-action: manipulation; }
body.is-mobile .game-chat-panel .m-chat-grab span { width: 44px; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.35); }
body.is-mobile .game-chat-panel .m-chat-x { display: grid; place-items: center; position: absolute; top: 4px; right: 8px; z-index: 3; width: 34px; height: 34px; padding: 0; border: 1px solid rgba(255,255,255,0.15); border-radius: 50%; background: rgba(255,255,255,0.08); color: #fff; font: 600 22px/1 sans-serif; cursor: pointer; touch-action: manipulation; }

/* Recent messages floating overlay (when chat is closed) */
.touch-chat-float {
    position: absolute;
    left: calc(var(--safe-left) + 12px);
    top: calc(var(--safe-top) + 50px);
    max-width: 55vw;
    pointer-events: none;
    z-index: 25;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.touch-chat-float .tcf-msg {
    font-size: 12px;
    line-height: 1.3;
    color: #fff;
    background: rgba(0,0,0,0.5);
    padding: 3px 8px;
    border-radius: 8px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
    animation: tcfFade 6s forwards;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.touch-chat-float .tcf-msg b { color: #ffd166; }
@keyframes tcfFade {
    0%, 75% { opacity: 1; }
    100%    { opacity: 0; }
}

/* Quick chat overlay - tap friendly */
body.is-mobile .quick-chat-overlay { z-index: 45; }
body.is-mobile .qc-item { min-width: 110px; min-height: 48px; }
body.is-mobile .qc-key { display: none; }

/* ============================================
   ORIENTATION LOCK OVERLAY
   ============================================ */
.rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #0b0d12;
    color: #fff;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    text-align: center;
    padding: 24px;
}
.rotate-overlay .rotate-icon {
    font-size: 64px;
    animation: rotateHint 1.6s ease-in-out infinite;
}
@keyframes rotateHint {
    0%, 100% { transform: rotate(0); }
    50%      { transform: rotate(90deg); }
}
.rotate-overlay h2 { font-size: 20px; margin: 0; }
.rotate-overlay p { opacity: 0.7; margin: 0; font-size: 14px; }

body.is-mobile.needs-landscape .rotate-overlay { display: flex; }

/* ============================================
   GENERIC MOBILE TWEAKS FOR OTHER SCREENS
   (Menu redesign comes in Phase 2; these keep
   things usable meanwhile)
   ============================================ */
body.is-mobile .btn,
body.is-mobile button { min-height: 44px; }
body.is-mobile .btn-sm { min-height: 38px; }
body.is-mobile .modal-content,
body.is-mobile .modal { max-height: 90dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ============================================
   OFFLINE BOT MATCH SETUP SHEET
   ============================================ */
.bot-setup {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.bot-setup.open { opacity: 1; }

.bot-setup-sheet {
    width: 100%;
    max-width: 520px;
    background: #12151d;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    padding: 0 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
    transform: translateY(100%);
    transition: transform 0.24s cubic-bezier(0.2, 0.85, 0.25, 1);
    max-height: 88dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.bot-setup.open .bot-setup-sheet { transform: translateY(0); }

.bot-setup-grab {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.25);
    margin: 10px auto 4px;
}

.bot-setup-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.5px;
    margin: 8px 0 18px;
    text-align: center;
    color: #fff;
}

.bot-setup-group { margin-bottom: 18px; }
.bot-setup-group label {
    display: block;
    font-size: 11px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
    margin-bottom: 8px;
}

.bot-setup-options {
    display: flex;
    gap: 8px;
}

.bot-opt {
    flex: 1;
    min-height: 46px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(255, 255, 255, 0.045);
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    font-weight: 700;
    padding: 0 4px;
    -webkit-appearance: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}
.bot-opt:active { transform: scale(0.96); }
.bot-opt.active {
    background: linear-gradient(180deg, #2f7d4f, #22633e);
    border-color: rgba(120, 255, 175, 0.4);
    color: #fff;
    box-shadow: 0 4px 14px rgba(30, 120, 70, 0.35);
}

.bot-setup-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
}
.bot-setup-actions .btn {
    flex: 1;
    min-height: 50px;
    font-size: 15px;
    font-weight: 800;
    border-radius: 12px;
}

/* Offline play button accent */
.play-btn-offline .play-icon { filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4)); }
/* Lunge (Real Match, tap): left of Sprint; the ring fills back up during the cooldown (--lc 0..1, game.js) */
.touch-btn-lunge {
    --lc: 1;
    width: 58px; height: 58px; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
    right: calc(var(--safe-right) + 292px); bottom: calc(var(--safe-bottom) + 106px);
    border: 0;
    background:
        radial-gradient(circle, rgba(40, 46, 60, 0.92) 0 25px, transparent 25.5px),
        conic-gradient(#FF8A45 calc(var(--lc) * 360deg), rgba(255, 255, 255, 0.14) 0);
}
#game-screen:not(.has-stamina) .touch-btn-lunge { display: none !important; }
