/* ============================================================
   EvilFriend – style.css
   "Evil Kind" dark-neon robot aesthetic for iPad 8 / modern browsers.
   All selectors are namespaced under .malbot-* to avoid WP theme conflicts.
   ============================================================ */

/* ── Custom Properties ──────────────────────────────────────────────────── */
:root {
    --mb-bg:            #05080f;
    --mb-surface:       #0a1220;
    --mb-surface-alt:   #0f1b2d;
    --mb-border:        rgba(0, 255, 200, 0.18);
    --mb-border-bright: rgba(0, 255, 200, 0.55);
    --mb-neon:          #00ffc8;
    --mb-neon-dim:      rgba(0, 255, 200, 0.35);
    --mb-red:           #ff004f;
    --mb-red-dim:       rgba(255, 0, 79, 0.35);
    --mb-text:          #c8e6f0;
    --mb-text-dim:      #567080;
    --mb-radius:        14px;
    --mb-radius-sm:     8px;
    --mb-shadow-neon:   0 0 18px rgba(0, 255, 200, 0.28), 0 0 40px rgba(0, 255, 200, 0.12);
    --mb-shadow-red:    0 0 18px rgba(255, 0, 79, 0.40);
    --mb-font:          'Courier New', 'Courier', monospace;
    --mb-transition:    0.25s ease;
}

/* ── Wrapper ────────────────────────────────────────────────────────────── */
.malbot-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: min(100%, var(--mb-width, 100%));
    height: min(var(--mb-height, 600px), 92dvh);
    min-height: clamp(420px, 78dvh, 860px);
    max-height: 92dvh;
    background: var(--mb-bg);
    border: 1px solid var(--mb-border-bright);
    border-radius: var(--mb-radius);
    box-shadow: var(--mb-shadow-neon), inset 0 0 80px rgba(0, 0, 0, 0.6);
    font-family: var(--mb-font);
    color: var(--mb-text);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    /* iPad 8: prevent elastic scroll inside widget */
    overscroll-behavior: contain;
}

/* Subtle animated scanline sweep over entire widget */
.malbot-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(0, 255, 200, 0.025) 3px,
        rgba(0, 255, 200, 0.025) 4px
    );
    pointer-events: none;
    z-index: 0;
}

/* ── Face container ─────────────────────────────────────────────────────── */
.malbot-face-container {
    position: relative;
    flex: 1 1 auto;
    min-height: 210px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 16px 8px;
    z-index: 1;
}

#malbot-svg {
    display: block;
    width: min(300px, 90vw);
    height: auto;
    filter: drop-shadow(0 0 24px rgba(0, 255, 200, 0.30));
    /* GPU-composited layer keeps SVG animation smooth on iPad */
    will-change: transform;
    transform: translateZ(0);
}

/* ── Chat region ────────────────────────────────────────────────────────── */
.malbot-chat {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 14px 14px;
    background: var(--mb-surface);
    border-top: 1px solid var(--mb-border);
    z-index: 1;
}

/* ── Chat log ───────────────────────────────────────────────────────────── */
.malbot-chat-log {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: clamp(130px, 28dvh, 280px);
    padding-right: 4px;
    scroll-behavior: smooth;
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--mb-neon-dim) transparent;
}
.malbot-chat-log::-webkit-scrollbar { width: 4px; }
.malbot-chat-log::-webkit-scrollbar-thumb {
    background: var(--mb-neon-dim);
    border-radius: 4px;
}

/* Messages */
.malbot-msg {
    max-width: 88%;
    padding: 9px 13px;
    border-radius: var(--mb-radius-sm);
    font-size: 0.88rem;
    line-height: 1.5;
    word-break: break-word;
    animation: mbMsgIn 0.22s ease both;
}

@keyframes mbMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.malbot-msg--user {
    align-self: flex-end;
    background: rgba(0, 255, 200, 0.10);
    border: 1px solid var(--mb-border-bright);
    color: var(--mb-neon);
    border-bottom-right-radius: 3px;
}

.malbot-msg--bot {
    align-self: flex-start;
    background: var(--mb-surface-alt);
    border: 1px solid var(--mb-border);
    color: var(--mb-text);
    border-bottom-left-radius: 3px;
    position: relative;
}

/* Robot prefix glyph */
.malbot-msg--bot::before {
    content: '▸ ';
    color: var(--mb-neon);
    font-size: 0.75em;
}

/* ── Controls ───────────────────────────────────────────────────────────── */
.malbot-chat-controls {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.malbot-text-input-wrap {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    background: var(--mb-surface-alt);
    border: 1px solid var(--mb-border);
    border-radius: var(--mb-radius-sm);
    overflow: hidden;
    transition: border-color var(--mb-transition);
}
.malbot-text-input-wrap:focus-within {
    border-color: var(--mb-neon);
    box-shadow: 0 0 0 2px var(--mb-neon-dim);
}

.malbot-text-input {
    flex: 1 1 auto;
    background: transparent;
    border: none;
    outline: none;
    color: var(--mb-text);
    font-family: var(--mb-font);
    font-size: 0.88rem;
    padding: 10px 12px;
    caret-color: var(--mb-neon);
}
.malbot-text-input::placeholder { color: var(--mb-text-dim); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.malbot-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 9px 14px;
    border: 1px solid var(--mb-border-bright);
    border-radius: var(--mb-radius-sm);
    background: transparent;
    color: var(--mb-neon);
    font-family: var(--mb-font);
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition:
        background var(--mb-transition),
        box-shadow var(--mb-transition),
        border-color var(--mb-transition);
    white-space: nowrap;
    /* Touch target min 44×44 for accessibility on iPad */
    min-width: 44px;
    min-height: 44px;
}

.malbot-btn:hover,
.malbot-btn:focus-visible {
    background: rgba(0, 255, 200, 0.10);
    box-shadow: var(--mb-shadow-neon);
    outline: none;
}

.malbot-btn:active {
    transform: scale(0.96);
}

.malbot-btn--mic {
    flex: 0 0 auto;
    min-width: 160px;
}

.malbot-btn--mic.malbot-btn--active {
    background: var(--mb-red-dim);
    border-color: var(--mb-red);
    color: var(--mb-red);
    box-shadow: var(--mb-shadow-red);
    animation: mbPulse 0.8s ease infinite alternate;
}

@keyframes mbPulse {
    from { box-shadow: var(--mb-shadow-red); }
    to   { box-shadow: 0 0 26px rgba(255, 0, 79, 0.70); }
}

.malbot-btn--send {
    flex: 0 0 auto;
    padding: 9px 16px;
    background: rgba(0, 255, 200, 0.08);
    border-color: var(--mb-neon);
}
.malbot-btn--send:hover {
    background: rgba(0, 255, 200, 0.18);
}

.malbot-btn--fs {
    flex: 0 0 auto;
    min-width: 44px;
    padding: 9px 12px;
}

.malbot-icon { font-size: 1.1em; }

.malbot-btn-label {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ── Hidden camera feed ─────────────────────────────────────────────────── */
.malbot-camera {
    position: absolute;
    top: -9999px;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* ── Status bar ─────────────────────────────────────────────────────────── */
.malbot-status {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 14px;
    font-size: 0.72rem;
    color: var(--mb-text-dim);
    letter-spacing: 0.05em;
    text-align: center;
    background: rgba(5, 8, 15, 0.75);
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.3s;
}
.malbot-status:empty { opacity: 0; }

/* ── Start overlay (Safari user-gesture gate) ───────────────────────────── */
.malbot-start-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 8, 15, 0.96);
    border-radius: var(--mb-radius);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.55s ease;
}

.malbot-start-overlay.malbot-start--hidden {
    opacity: 0;
    pointer-events: none;
}

.malbot-start-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 32px;
    border: 1px solid var(--mb-border-bright);
    border-radius: var(--mb-radius);
    background: rgba(0, 255, 200, 0.04);
    box-shadow: var(--mb-shadow-neon);
    animation: mbPulseBox 2.2s ease-in-out infinite alternate;
}

@keyframes mbPulseBox {
    from { box-shadow: var(--mb-shadow-neon); }
    to   { box-shadow: 0 0 40px rgba(0, 255, 200, 0.45), 0 0 80px rgba(0, 255, 200, 0.15); }
}

.malbot-start-eye {
    font-size: 3rem;
    line-height: 1;
    filter: drop-shadow(0 0 12px var(--mb-neon));
    animation: mbSpin 8s linear infinite;
}

@keyframes mbSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.malbot-start-title {
    font-family: var(--mb-font);
    font-size: 1.8rem;
    letter-spacing: 0.2em;
    color: var(--mb-neon);
    text-shadow: 0 0 14px var(--mb-neon);
    margin: 0;
    text-transform: uppercase;
}

.malbot-start-label {
    font-family: var(--mb-font);
    font-size: 1rem;
    color: var(--mb-text);
    letter-spacing: 0.08em;
    margin: 0;
}

.malbot-start-sub {
    font-family: var(--mb-font);
    font-size: 0.72rem;
    color: var(--mb-text-dim);
    letter-spacing: 0.1em;
    margin: 0;
    text-transform: uppercase;
}

/* Touch ripple on tap (iPad feedback) */
.malbot-start-overlay:active .malbot-start-inner {
    background: rgba(0, 255, 200, 0.10);
    transition: background 0.05s;
}

/* ── Corner decoration ──────────────────────────────────────────────────── */
.malbot-wrapper::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mb-red);
    box-shadow: 0 0 8px var(--mb-red);
    animation: mbBlink 2.6s ease-in-out infinite;
    z-index: 5;
}

/* Fullscreen mode (native Fullscreen API) */
.malbot-wrapper:fullscreen,
.malbot-wrapper:-webkit-full-screen {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh;
    min-height: 100dvh;
    border-radius: 0;
    border: 0;
    box-shadow: none;
}

.malbot-wrapper:fullscreen .malbot-face-container,
.malbot-wrapper:-webkit-full-screen .malbot-face-container {
    min-height: 32dvh;
}

.malbot-wrapper:fullscreen .malbot-chat-log,
.malbot-wrapper:-webkit-full-screen .malbot-chat-log {
    max-height: 38dvh;
}

/* iPad Safari fallback fullscreen (without Fullscreen API) */
.malbot-wrapper.malbot-wrapper--pseudo-fs {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh;
    min-height: 100dvh;
    border-radius: 0;
    border: 0;
    box-shadow: none;
}

.malbot-wrapper.malbot-wrapper--pseudo-fs .malbot-face-container {
    min-height: 32dvh;
}

.malbot-wrapper.malbot-wrapper--pseudo-fs .malbot-chat-log {
    max-height: 38dvh;
}

body.malbot-no-scroll {
    overflow: hidden;
    touch-action: none;
}

@keyframes mbBlink {
    0%, 90%, 100% { opacity: 1; }
    95%            { opacity: 0.1; }
}

/* ── Responsive tweaks ──────────────────────────────────────────────────── */

/* iPad 8 portrait (768 × 1024) */
@media (max-width: 820px) {
    .malbot-wrapper  { min-height: 66dvh; }
    .malbot-chat-log { max-height: 160px; }
    .malbot-msg      { font-size: 0.84rem; }
}

/* Small phones */
@media (max-width: 480px) {
    .malbot-wrapper   { min-height: 72dvh; }
    .malbot-btn-label { display: none; }
    .malbot-chat-log  { max-height: 130px; }
    .malbot-btn--mic  { min-width: 52px; }
    #malbot-svg,
    #malbot-frame-img { width: min(260px, 85vw); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
