/* Patch, the AI in the scanner: the character (PatchGuide), his speech (DialogueBox, PatchSpeech), the floating Patch,
 the top-bar button and Ask Patch. */

/* ---------- Patch ---------- */
.patch { position: relative; display: block; aspect-ratio: 120 / 132; }
.patch-svg { display: block; width: 100%; height: 100%; overflow: visible; animation: patch-float 3.2s ease-in-out infinite; }
.patch-shell { stroke: rgba(160, 200, 255, 0.35); stroke-width: 2; }
.patch-glass { stroke: rgba(var(--sc-primary-rgb), 0.35); stroke-width: 1.5; }
.patch-shine { fill: rgba(255, 255, 255, 0.12); }
.patch-port { fill: rgba(160, 200, 255, 0.35); }
.patch-led { fill: rgb(var(--sc-primary-rgb)); opacity: 0.7; animation: patch-led 1.6s steps(2) infinite; }
.patch-antenna { stroke: rgba(160, 200, 255, 0.55); stroke-width: 3; stroke-linecap: round; }
.patch-light { fill: var(--sc-gold); filter: drop-shadow(0 0 6px var(--sc-gold)); animation: patch-light 1.8s ease-in-out infinite; }
.patch-ear { fill: none; stroke: rgba(var(--sc-primary-rgb), 0.55); stroke-width: 3; stroke-linecap: round; }
.patch-trail rect { fill: rgba(var(--sc-primary-rgb), 0.7); animation: patch-pixel 1.6s ease-in-out infinite; }
.patch-trail rect:nth-child(2) { animation-delay: 0.3s; }
.patch-trail rect:nth-child(3) { animation-delay: 0.6s; }
.patch-trail rect:nth-child(4) { animation-delay: 0.9s; }
.patch-face { filter: drop-shadow(0 0 4px rgba(var(--sc-primary-rgb), 0.9)); }
.patch-eye, .patch-mouth-talk, .patch-mouth-o, .patch-pupil { fill: rgb(var(--sc-primary-rgb)); }
.patch-pupil { fill: #06141f; }
.patch-smile, .patch-arc, .patch-zig, .patch-brow { fill: none; stroke: rgb(var(--sc-primary-rgb)); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.patch-blush { fill: rgba(255, 120, 170, 0.45); }
.patch-blink { transform-box: fill-box; transform-origin: center; animation: patch-blink 4.5s infinite; }
.patch-mouth { transform-box: fill-box; transform-origin: center; }
.patch.is-cheer .patch-svg { animation: patch-hop 0.7s var(--sc-ease-spring) 2, patch-float 3.2s ease-in-out 1.4s infinite; }
.patch.is-surprised .patch-svg { animation: patch-jolt 0.4s ease-out, patch-float 3.2s ease-in-out 0.4s infinite; }
.patch.is-glitch .patch-svg { animation: patch-glitch 0.3s steps(2) infinite; filter: drop-shadow(3px 0 0 rgba(255, 0, 90, 0.7)) drop-shadow(-3px 0 0 rgba(0, 240, 255, 0.7)); }
.patch.is-glitch .patch-face, .patch.is-glitch .patch-eye { fill: #ff5c8a; stroke: #ff5c8a; }
@keyframes patch-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes patch-hop { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-18px) scale(1.04, 0.96); } }
@keyframes patch-jolt { 0% { transform: scale(0.8) rotate(-6deg); } 60% { transform: scale(1.08) rotate(3deg); } 100% { transform: scale(1); } }
@keyframes patch-glitch { 0% { transform: translate(0); } 50% { transform: translate(3px, -2px) skewX(4deg); } 100% { transform: translate(-2px, 1px); } }
@keyframes patch-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes patch-talk { from { transform: scaleY(0.4); } to { transform: scaleY(1.1); } }
@keyframes patch-light { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes patch-led { 50% { opacity: 0.25; } }
@keyframes patch-pixel { 0%, 100% { opacity: 0.9; transform: translateY(0); } 50% { opacity: 0.3; transform: translateY(4px); } }

/* ---------- Patch's speech box ---------- */
.dialogue {
    position: relative; padding: 22px 16px 16px; border: 1px solid rgba(var(--sc-primary-rgb), 0.35); border-radius: var(--sc-radius-lg);
    background: rgba(var(--sc-surface-rgb), 0.92); box-shadow: var(--sc-shadow-lg); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    cursor: default; outline: none;
}
.dialogue.can-advance { cursor: pointer; }
.dialogue:focus-visible { box-shadow: 0 0 0 2px var(--sc-primary), var(--sc-shadow-lg); }
.dialogue-speaker {
    position: absolute; top: -12px; left: 14px; padding: 3px 12px; border-radius: var(--sc-radius-pill);
    background: var(--sc-primary); color: var(--sc-bg); font-family: var(--sc-font-display); font-size: 14px; font-weight: 700;
}
.dialogue-text { min-height: 2.9em; margin: 0; color: var(--sc-text); font-size: 17px; line-height: 1.45; text-wrap: pretty; }
.dialogue-rest { visibility: hidden; }
.dialogue-next { position: absolute; right: 14px; bottom: 8px; color: var(--sc-primary); font-size: 16px; animation: dialogue-nudge 0.9s ease-in-out infinite; }
@keyframes dialogue-nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(4px); } }

/* ---------- Speaking: the mouth moves in time with the typing, whatever the mood; the LED chatters ---------- */
.patch.is-speaking .patch-mouth { animation: patch-talk 0.16s ease-in-out infinite alternate; }
.patch.is-speaking .patch-mouth-talk { animation-duration: 0.12s; }
.patch.is-speaking .patch-led { animation: patch-led 0.18s steps(2) infinite; opacity: 1; }
.patch.is-speaking .patch-light { animation-duration: 0.5s; }
.patch.is-speaking:not(.is-glitch) .patch-svg { animation: patch-float 3.2s ease-in-out infinite, patch-nod 0.5s ease-in-out infinite alternate; }
@keyframes patch-nod { from { rotate: -1.5deg; } to { rotate: 1.5deg; } }

/* ---------- The speech bubble ---------- */
.dialogue {
    border-color: rgba(var(--sc-primary-rgb), 0.4);
    background: linear-gradient(180deg, rgba(var(--sc-surface-rgb), 0.96), rgba(var(--sc-surface-rgb), 0.9));
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}
.dialogue-speaker { letter-spacing: 0.02em; box-shadow: 0 4px 12px rgba(var(--sc-primary-rgb), 0.35); }
/* The tail, pointing up at Patch (intro) — PatchSpeech moves it to point left */
.dialogue::before {
    content: "";
    position: absolute;
    top: -8px;
    right: 28px;
    width: 14px;
    height: 14px;
    border-top: 1px solid rgba(var(--sc-primary-rgb), 0.4);
    border-left: 1px solid rgba(var(--sc-primary-rgb), 0.4);
    border-radius: 3px 0 0 0;
    background: rgb(var(--sc-surface-rgb));
    transform: rotate(45deg);
}
.dialogue.is-quiet::before { display: none; }
.dialogue { animation: ps-pop 0.35s var(--sc-ease-spring) both; transform-origin: 85% 0; }
@keyframes ps-pop { from { opacity: 0; transform: scale(0.92) translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- PatchSpeech (.ps): Patch and his bubble as one ---------- */
.ps { display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: end; gap: 12px; }
.ps-patch { width: 72px; align-self: end; margin-bottom: 4px; }
.ps-bubble { min-width: 0; transform-origin: 0 100%; }
.ps-bubble::before {
    top: auto;
    right: auto;
    left: -8px;
    bottom: 22px;
    border-top: 0;
    border-right: 0;
    border-bottom: 1px solid rgba(var(--sc-primary-rgb), 0.4);
    border-left: 1px solid rgba(var(--sc-primary-rgb), 0.4);
    border-radius: 0 0 0 3px;
}
.ps-bubble .dialogue-text { font-size: 16px; min-height: 2.9em; }

.ps.is-compact { grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: center; }
.ps.is-compact .ps-patch { width: 44px; margin: 0; }
.ps.is-compact .ps-bubble { padding: 16px 14px 12px; }
.ps.is-compact .ps-bubble::before { bottom: 50%; margin-bottom: -7px; }
.ps.is-compact .dialogue-text { min-height: 0; font-size: 14.5px; line-height: 1.4; }
.ps.is-compact .dialogue-speaker { top: -10px; padding: 2px 10px; font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
    .patch.is-speaking .patch-mouth, .patch.is-speaking .patch-svg, .patch.is-speaking .patch-led, .dialogue { animation: none !important; }
}
/* ---------- The floating Patch (PatchBubble.razor) ---------- */
.pb {
    position: fixed;
    right: 12px;
    bottom: calc(var(--sc-tabbar-height, 72px) + env(safe-area-inset-bottom, 0px) + 12px);
    left: 12px;
    z-index: 1100;
    max-width: 420px;
    margin-left: auto;
    pointer-events: none;
    animation: pb-in 0.42s var(--sc-ease-spring) both;
}
.pb > * { pointer-events: auto; }
.pb.is-battle { top: calc(env(safe-area-inset-top, 0px) + 10px); bottom: auto; animation-name: pb-in-top; }
.pb.is-leaving { animation: pb-out 0.22s ease-in both; }
.pb .ps { padding-right: 6px; }
.pb .ps-bubble { cursor: pointer; box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04) inset; }
.pb .ps-bubble.is-actionable { border-color: rgba(var(--sc-primary-rgb), 0.7); }
.pb .dialogue-next { display: none; }
.pb-go { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; color: var(--sc-primary); font-size: 12.5px; font-weight: 700; }
.pb-close {
    position: absolute;
    top: -8px;
    right: -2px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid rgba(var(--sc-primary-rgb), 0.35);
    border-radius: 50%;
    background: rgb(var(--sc-surface-rgb));
    color: var(--sc-text-muted);
    font-size: 15px;
    cursor: pointer;
}
.pb-close:hover { color: var(--sc-text); }
@keyframes pb-in { from { opacity: 0; transform: translateY(24px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes pb-in-top { from { opacity: 0; transform: translateY(-24px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes pb-out { to { opacity: 0; transform: translateX(30px) scale(0.96); } }
@media (prefers-reduced-motion: reduce) {
    .pb, .pb.is-leaving { animation: none; }
}

/* ---------- Coach tips, spoken by Patch (CoachTip.razor; the bubble itself is in manual.css) ---------- */
.coach-tip { align-items: center; padding-left: 8px; }
.coach-tip-patch { flex: none; width: 36px; }
.coach-tip-speaker { color: var(--sc-primary); font-size: 11.5px !important; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.coach-tip-body > span { color: var(--sc-text) !important; }

/* ---------- Patch's button in the top bar ---------- */
.app-patch {
    position: relative;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(var(--sc-primary-rgb), 0.35);
    border-radius: 50%;
    background: radial-gradient(circle at 50% 35%, rgba(var(--sc-primary-rgb), 0.18), rgba(var(--sc-surface-rgb), 0.9) 70%);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.2s ease;
}
.app-patch:hover { border-color: rgba(var(--sc-primary-rgb), 0.7); }
.app-patch:active { transform: scale(0.94); }
.app-patch-face { width: 28px; margin-top: 2px; }
.app-patch-face .patch-svg { animation-duration: 4s; }
.app-patch-face .patch-trail { display: none; }
.app-patch.has-hint::after {
    content: "";
    position: absolute;
    top: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border: 2px solid rgb(var(--sc-surface-rgb));
    border-radius: 50%;
    background: var(--sc-gold);
    animation: app-patch-ping 2s ease-in-out infinite;
}
@keyframes app-patch-ping { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.6); } 50% { box-shadow: 0 0 0 5px rgba(255, 200, 61, 0); } }

/* ---------- Patch's sheet (PatchSheet.razor): drops down under the top bar ---------- */
.psheet-backdrop { position: fixed; inset: 0; z-index: 1150; background: rgba(4, 8, 20, 0.45); animation: mm-fade 0.2s ease both; }
.psheet {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 64px);
    right: 12px;
    left: 12px;
    z-index: 1151;
    display: grid;
    gap: 16px;
    max-width: 420px;
    margin-left: auto;
    padding: 20px 16px 16px;
    border: 1px solid rgba(var(--sc-primary-rgb), 0.35);
    border-radius: var(--sc-radius-lg);
    background: linear-gradient(170deg, var(--sc-surface-2), var(--sc-surface) 80%);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    transform-origin: calc(100% - 120px) 0;
    animation: psheet-in 0.32s var(--sc-ease-spring) both;
}
@keyframes psheet-in { from { opacity: 0; transform: translateY(-10px) scale(0.96); } to { opacity: 1; transform: none; } }
.psheet-close { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--sc-text-muted); font-size: 18px; cursor: pointer; }
.psheet-close:hover { background: rgba(255, 255, 255, 0.08); color: var(--sc-text); }
.psheet .ps { margin-top: 8px; }
.psheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.psheet-actions .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.psheet-chatter { display: grid; gap: 6px; padding-top: 12px; border-top: 1px solid var(--sc-line); }
.psheet-chatter > span { color: var(--sc-text-muted); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.psheet-chatter small { color: var(--sc-text-muted); font-size: 12.5px; }
.psheet-segments { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: var(--sc-radius-pill); background: rgba(255, 255, 255, 0.05); }
.psheet-segments button { padding: 7px 0; border: 0; border-radius: var(--sc-radius-pill); background: transparent; color: var(--sc-text-muted); font-size: 13.5px; font-weight: 700; cursor: pointer; transition: background 0.2s ease, color 0.2s ease; }
.psheet-segments button.is-on { background: var(--sc-primary); color: var(--sc-bg); }
@media (prefers-reduced-motion: reduce) {
    .psheet, .psheet-backdrop, .app-patch.has-hint::after { animation: none; }
}

/* PatchSpeech flipped: Patch on the right, the bubble's tail pointing right at him */
.ps.is-flip { grid-template-columns: minmax(0, 1fr) var(--ps-size, 72px); }
.ps.is-flip .ps-patch { order: 2; }
.ps.is-flip .ps-bubble { order: 1; transform-origin: 100% 100%; }
.ps.is-flip .ps-bubble::before {
    left: auto;
    right: -8px;
    border-bottom: 0;
    border-left: 0;
    border-top: 1px solid rgba(var(--sc-primary-rgb), 0.4);
    border-right: 1px solid rgba(var(--sc-primary-rgb), 0.4);
    border-radius: 0 3px 0 0;
}
