:root {
    color-scheme: dark;
    --bg: #070812;
    --panel: rgba(14, 16, 31, 0.78);
    --panel-strong: rgba(18, 21, 40, 0.94);
    --line: rgba(255, 255, 255, 0.09);
    --text: #f6f4ff;
    --muted: #9b9bb3;
    --accent: #ae77ff;
    --accent-2: #64d8ff;
    --success: #7bf0bc;
    --danger: #ff7f9f;
    --shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 10%, rgba(121, 68, 255, 0.22), transparent 35%),
        radial-gradient(circle at 88% 85%, rgba(62, 198, 255, 0.15), transparent 34%),
        linear-gradient(145deg, #060711 0%, #0a0c18 52%, #080914 100%);
}

button,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

.app-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(330px, 43%) minmax(420px, 57%);
    width: min(1440px, calc(100% - 32px));
    min-height: calc(100vh - 32px);
    margin: 16px auto;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 32px;
    background: rgba(8, 10, 21, 0.74);
    box-shadow: var(--shadow);
    backdrop-filter: blur(24px);
}

.companion-panel {
    position: relative;
    display: flex;
    min-height: 680px;
    overflow: hidden;
    flex-direction: column;
    padding: 28px;
    border-right: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(20, 19, 44, 0.92), rgba(8, 10, 22, 0.97)),
        radial-gradient(circle at 50% 40%, rgba(174, 119, 255, 0.16), transparent 45%);
}

.ambient {
    position: absolute;
    border-radius: 999px;
    filter: blur(18px);
    opacity: 0.7;
    pointer-events: none;
}

.ambient-one {
    top: 12%;
    left: -80px;
    width: 240px;
    height: 240px;
    background: rgba(156, 77, 255, 0.18);
    animation: drift 9s ease-in-out infinite alternate;
}

.ambient-two {
    right: -70px;
    bottom: 17%;
    width: 220px;
    height: 220px;
    background: rgba(65, 197, 255, 0.14);
    animation: drift 11s ease-in-out infinite alternate-reverse;
}

.topbar {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.brand {
    font-size: 25px;
    font-weight: 800;
    letter-spacing: 0.22em;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 7px;
    color: var(--muted);
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 16px var(--success);
    animation: statusPulse 2s ease-in-out infinite;
}

.icon-button {
    display: grid;
    width: 44px;
    height: 44px;
    cursor: pointer;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.055);
    font-size: 26px;
    font-weight: 300;
    transition:
        transform 160ms ease,
        background 160ms ease,
        border-color 160ms ease;
}

.icon-button:hover {
    transform: translateY(-2px);
    border-color: rgba(174, 119, 255, 0.45);
    background: rgba(174, 119, 255, 0.12);
}

.character-stage {
    position: relative;
    z-index: 2;
    display: grid;
    flex: 1;
    min-height: 450px;
    place-items: center;
}

.character-glow {
    position: absolute;
    width: min(72%, 430px);
    aspect-ratio: 1;
    border-radius: 50%;
    background:
        radial-gradient(circle, rgba(174, 119, 255, 0.33) 0%, rgba(103, 213, 255, 0.12) 42%, transparent 72%);
    filter: blur(4px);
    animation: breathe 5s ease-in-out infinite;
}

.character-placeholder {
    position: relative;
    width: min(62%, 350px);
    aspect-ratio: 0.76;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 48% 48% 38% 38% / 34% 34% 28% 28%;
    background:
        radial-gradient(circle at 50% 28%, #f4c8bc 0 12%, transparent 12.5%),
        radial-gradient(circle at 50% 30%, #251d37 0 25%, transparent 25.5%),
        linear-gradient(165deg, rgba(178, 111, 255, 0.9), rgba(72, 105, 182, 0.68) 45%, rgba(17, 20, 42, 0.96));
    box-shadow:
        inset 0 0 55px rgba(255, 255, 255, 0.08),
        0 28px 70px rgba(0, 0, 0, 0.38);
    animation: floatCharacter 5.5s ease-in-out infinite;
}

.character-placeholder::before,
.character-placeholder::after {
    position: absolute;
    content: "";
    pointer-events: none;
}

.character-placeholder::before {
    inset: 3% 4% auto;
    height: 44%;
    border-radius: 50% 50% 35% 35%;
    background:
        radial-gradient(circle at 30% 40%, rgba(255, 255, 255, 0.15), transparent 28%),
        linear-gradient(145deg, #1a1727, #433058 58%, #161522);
    filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.3));
}

.character-placeholder::after {
    right: 13%;
    bottom: 12%;
    left: 13%;
    height: 44%;
    border-radius: 48% 48% 18% 18%;
    background:
        linear-gradient(145deg, rgba(113, 86, 182, 0.88), rgba(28, 31, 64, 0.97));
    box-shadow: inset 0 1px rgba(255, 255, 255, 0.1);
}

.character-face {
    position: absolute;
    z-index: 4;
    top: 25%;
    left: 50%;
    width: 32%;
    height: 21%;
    transform: translateX(-50%);
    border-radius: 48% 48% 46% 46%;
    background: linear-gradient(145deg, #f3c8bc, #dba89f);
    box-shadow: inset 0 -8px 18px rgba(137, 73, 85, 0.12);
}

.eye {
    position: absolute;
    top: 44%;
    width: 12%;
    height: 8%;
    border-radius: 50%;
    background: #30243f;
    animation: blink 6s infinite;
}

.eye-left {
    left: 25%;
}

.eye-right {
    right: 25%;
}

.mouth {
    position: absolute;
    bottom: 25%;
    left: 50%;
    width: 17%;
    height: 6%;
    transform: translateX(-50%);
    border-radius: 0 0 999px 999px;
    background: rgba(126, 61, 84, 0.65);
}

.presence-card {
    position: absolute;
    right: 2%;
    bottom: 3%;
    left: 2%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 17px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(8, 10, 24, 0.64);
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(18px);
}

.presence-card strong,
.presence-card span {
    display: block;
}

.presence-card strong {
    margin-bottom: 4px;
    font-size: 14px;
}

.presence-card div > span {
    color: var(--muted);
    font-size: 12px;
}

.pulse-ring {
    position: relative;
    width: 15px;
    height: 15px;
    flex: 0 0 15px;
    border: 2px solid var(--accent-2);
    border-radius: 50%;
    box-shadow: 0 0 14px rgba(100, 216, 255, 0.7);
}

.pulse-ring::after {
    position: absolute;
    inset: -7px;
    content: "";
    border: 1px solid rgba(100, 216, 255, 0.45);
    border-radius: 50%;
    animation: ripple 2s ease-out infinite;
}

.memory-strip {
    position: relative;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.035);
}

.memory-stat {
    padding: 17px 20px;
}

.memory-stat + .memory-stat {
    border-left: 1px solid var(--line);
}

.memory-value,
.memory-label {
    display: block;
}

.memory-value {
    overflow: hidden;
    margin-bottom: 4px;
    font-size: 19px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.memory-label {
    color: var(--muted);
    font-size: 12px;
}

.chat-panel {
    display: flex;
    min-width: 0;
    min-height: 680px;
    flex-direction: column;
    background:
        linear-gradient(180deg, rgba(10, 12, 25, 0.94), rgba(7, 8, 17, 0.98));
}

.messages {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    flex-direction: column;
    gap: 18px;
    padding: 36px 38px 24px;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    background-clip: padding-box;
}

.message {
    display: flex;
    width: min(82%, 720px);
    gap: 12px;
    animation: messageIn 220ms ease-out;
}

.message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 13px;
    background: linear-gradient(145deg, var(--accent), #6155cb);
    font-size: 13px;
    font-weight: 750;
    box-shadow: 0 8px 22px rgba(123, 75, 230, 0.28);
}

.message-user .avatar {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

.bubble {
    padding: 15px 17px;
    border: 1px solid var(--line);
    border-radius: 8px 21px 21px 21px;
    background: rgba(255, 255, 255, 0.055);
    color: #ededf7;
    line-height: 1.55;
}

.message-user .bubble {
    border-color: rgba(174, 119, 255, 0.25);
    border-radius: 21px 8px 21px 21px;
    background: linear-gradient(145deg, rgba(140, 84, 234, 0.9), rgba(82, 82, 192, 0.82));
}

.bubble p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble p + p {
    margin-top: 8px;
}

.message-loading .bubble {
    display: flex;
    align-items: center;
    min-height: 50px;
    gap: 5px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: typing 1.1s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 120ms;
}

.typing-dot:nth-child(3) {
    animation-delay: 240ms;
}

.quick-actions {
    display: flex;
    overflow-x: auto;
    gap: 9px;
    padding: 0 38px 15px;
    scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar {
    display: none;
}

.quick-actions button {
    flex: 0 0 auto;
    cursor: pointer;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    color: #cfcfe0;
    font-size: 12px;
    transition:
        background 160ms ease,
        border-color 160ms ease,
        transform 160ms ease;
}

.quick-actions button:hover {
    transform: translateY(-1px);
    border-color: rgba(174, 119, 255, 0.38);
    background: rgba(174, 119, 255, 0.1);
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 12px;
    margin: 0 38px;
    padding: 10px 10px 10px 18px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.055);
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.22);
    transition:
        border-color 160ms ease,
        box-shadow 160ms ease;
}

.composer:focus-within {
    border-color: rgba(174, 119, 255, 0.5);
    box-shadow:
        0 14px 38px rgba(0, 0, 0, 0.22),
        0 0 0 4px rgba(174, 119, 255, 0.07);
}

.composer textarea {
    width: 100%;
    max-height: 160px;
    resize: none;
    overflow-y: auto;
    padding: 10px 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    line-height: 1.45;
}

.composer textarea::placeholder {
    color: #77788f;
}

.send-button {
    display: grid;
    width: 46px;
    height: 46px;
    cursor: pointer;
    place-items: center;
    border: 0;
    border-radius: 17px;
    background: linear-gradient(145deg, #b77aff, #7564ef);
    box-shadow: 0 10px 25px rgba(133, 84, 230, 0.32);
    font-size: 23px;
    font-weight: 700;
    transition:
        transform 160ms ease,
        filter 160ms ease,
        opacity 160ms ease;
}

.send-button:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.send-button:disabled {
    cursor: wait;
    transform: none;
    opacity: 0.5;
}

.footer-note {
    padding: 12px 38px 18px;
    color: #696a7e;
    font-size: 11px;
    text-align: center;
}

.is-speaking .character-placeholder {
    animation:
        floatCharacter 5.5s ease-in-out infinite,
        speakingGlow 1.3s ease-in-out infinite alternate;
}

.is-thinking .character-glow {
    animation: thinking 1.2s linear infinite;
}

@keyframes drift {
    from {
        transform: translate3d(-12px, -8px, 0) scale(0.95);
    }
    to {
        transform: translate3d(20px, 18px, 0) scale(1.08);
    }
}

@keyframes statusPulse {
    0%,
    100% {
        opacity: 0.65;
        transform: scale(0.88);
    }
    50% {
        opacity: 1;
        transform: scale(1.12);
    }
}

@keyframes breathe {
    0%,
    100% {
        opacity: 0.7;
        transform: scale(0.96);
    }
    50% {
        opacity: 1;
        transform: scale(1.04);
    }
}

@keyframes floatCharacter {
    0%,
    100% {
        transform: translateY(4px) rotate(-0.35deg);
    }
    50% {
        transform: translateY(-9px) rotate(0.35deg);
    }
}

@keyframes blink {
    0%,
    45%,
    48%,
    100% {
        transform: scaleY(1);
    }
    46%,
    47% {
        transform: scaleY(0.08);
    }
}

@keyframes ripple {
    0% {
        opacity: 0.75;
        transform: scale(0.55);
    }
    100% {
        opacity: 0;
        transform: scale(1.45);
    }
}

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

@keyframes typing {
    0%,
    60%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

@keyframes speakingGlow {
    from {
        box-shadow:
            inset 0 0 55px rgba(255, 255, 255, 0.08),
            0 28px 70px rgba(0, 0, 0, 0.38);
    }
    to {
        box-shadow:
            inset 0 0 65px rgba(255, 255, 255, 0.12),
            0 28px 85px rgba(139, 90, 255, 0.38);
    }
}

@keyframes thinking {
    0% {
        transform: rotate(0deg) scale(0.98);
    }
    50% {
        transform: rotate(180deg) scale(1.04);
    }
    100% {
        transform: rotate(360deg) scale(0.98);
    }
}

@media (max-width: 900px) {
    body {
        background: #080a15;
    }

    .app-shell {
        display: flex;
        width: 100%;
        min-height: 100dvh;
        margin: 0;
        flex-direction: column;
        border: 0;
        border-radius: 0;
    }

    .companion-panel {
        min-height: 390px;
        padding: 20px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .character-stage {
        min-height: 245px;
    }

    .character-placeholder {
        width: min(43%, 190px);
    }

    .presence-card {
        right: 0;
        bottom: 0;
        left: 0;
    }

    .memory-strip {
        display: none;
    }

    .chat-panel {
        min-height: 58dvh;
    }

    .messages {
        min-height: 310px;
        padding: 24px 18px 18px;
    }

    .message {
        width: min(92%, 650px);
    }

    .quick-actions {
        padding: 0 18px 12px;
    }

    .composer {
        margin: 0 14px;
    }

    .footer-note {
        padding: 10px 18px 15px;
    }
}

@media (max-width: 520px) {
    .companion-panel {
        min-height: 330px;
    }

    .brand {
        font-size: 20px;
    }

    .icon-button {
        width: 40px;
        height: 40px;
    }

    .character-stage {
        min-height: 205px;
    }

    .character-placeholder {
        width: 145px;
    }

    .presence-card {
        padding: 12px 14px;
    }

    .presence-card div > span {
        overflow: hidden;
        max-width: 235px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .messages {
        padding-top: 20px;
    }

    .bubble {
        padding: 13px 15px;
        font-size: 14px;
    }

    .avatar {
        width: 32px;
        height: 32px;
        flex-basis: 32px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}


/* Real companion image */
.character-image-wrap {
    width: min(78%, 430px);
    aspect-ratio: 1122 / 1402;
    overflow: hidden;
    border-radius: 42% 42% 30% 30% / 28% 28% 22% 22%;
    background: transparent;
}

.character-image-wrap::before,
.character-image-wrap::after {
    display: none;
}

.character-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    user-select: none;
    pointer-events: none;
}

@media (max-width: 900px) {
    .character-image-wrap {
        width: min(52%, 240px);
    }
}

@media (max-width: 520px) {
    .character-image-wrap {
        width: 180px;
    }
}


/* Voice controls */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.voice-button {
    font-size: 18px;
}

.voice-button.is-active {
    border-color: rgba(100, 216, 255, 0.55);
    background: rgba(100, 216, 255, 0.12);
    box-shadow: 0 0 22px rgba(100, 216, 255, 0.18);
}

.voice-button:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}
