* {
    box-sizing: border-box;
}

:root {
    --text: #2c2c2c;
    --muted: #716f69;
    --background: #fdfbf7;
    --surface: #fffefa;
    --border: #ded9cf;
    --accent: #252b43;
    --highlight: #f5f0e6;
    --danger: #8a342d;
    --font-serif: 'EB Garamond', Georgia, serif;
}

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

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(231, 220, 197, 0.35), transparent 30rem),
        var(--background);
    font-family: var(--font-serif);
    font-size: 1.1rem;
    line-height: 1.5;
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.my-chats-site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 74rem;
    margin: 0 auto;
    padding: 1.1rem clamp(1rem, 4vw, 2.5rem);
}

.my-chats-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
    color: var(--accent);
    font-size: clamp(1.05rem, 3vw, 1.35rem);
    font-weight: 600;
    text-decoration: none;
}

.my-chats-brand img {
    width: 2.35rem;
    height: 2.35rem;
    object-fit: contain;
}

.my-chats-library-link,
.my-chat-back-link,
.my-chat-text-action {
    color: var(--accent);
    text-underline-offset: 0.18em;
}

.my-chats-library-link {
    font-size: 0.95rem;
}

.my-chats-main {
    width: min(68rem, calc(100% - 2rem));
    margin: 1.5rem auto 5rem;
}

.my-chats-heading-row,
.my-chat-conversation-heading {
    margin-bottom: 1.4rem;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.25rem;
    font-size: clamp(2.4rem, 6vw, 4rem);
    font-weight: 500;
    letter-spacing: -0.025em;
    line-height: 1;
}

.my-chats-eyebrow {
    margin-bottom: 0.4rem;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.my-chats-intro,
.my-chat-conversation-book,
.my-chat-conversation-context {
    color: var(--muted);
}

.my-chats-filters,
.my-chats-sign-in,
.my-chat-send-form {
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: rgba(255, 254, 250, 0.88);
    box-shadow: 0 12px 30px rgba(61, 49, 32, 0.06);
}

.my-chats-filters {
    margin-bottom: 1.35rem;
    padding: 1rem;
}

.my-chats-filters label,
.my-chats-sign-in label,
.my-chat-send-form label {
    display: block;
    margin-bottom: 0.28rem;
    color: #4f4c46;
    font-size: 0.82rem;
    font-weight: 600;
}

.my-chats-search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.55rem;
}

.my-chats-filters input,
.my-chats-sign-in input,
.my-chat-send-form textarea {
    width: 100%;
    min-height: 2.75rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    padding: 0.55rem 0.7rem;
    color: var(--text);
    background: #fff;
}

.my-chat-send-form textarea {
    min-height: 6.5rem;
    resize: vertical;
}

.my-chats-filters input:focus,
.my-chats-sign-in input:focus,
.my-chat-send-form textarea:focus,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(66, 90, 145, 0.28);
    outline-offset: 2px;
    border-color: #6478a4;
}

.my-chats-filter-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 0.85rem;
}

.my-chats-filter-footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    min-height: 1.7rem;
    margin-top: 0.55rem;
}

.my-chats-filter-message,
.my-chats-form-status {
    margin: 0;
    color: var(--danger);
    font-size: 0.82rem;
}

.my-chat-primary-action,
.my-chat-secondary-action,
.my-chat-text-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
}

.my-chat-primary-action,
.my-chat-secondary-action {
    min-height: 2.55rem;
    border: 1px solid var(--accent);
    padding: 0.45rem 1rem;
    font-size: 0.92rem;
}

.my-chat-primary-action {
    color: #fff;
    background: var(--accent);
}

.my-chat-secondary-action {
    color: var(--accent);
    background: transparent;
}

.my-chat-primary-action:hover,
.my-chat-primary-action:focus-visible {
    background: #39415f;
}

.my-chat-secondary-action:hover,
.my-chat-secondary-action:focus-visible {
    background: var(--highlight);
}

.my-chat-primary-action:disabled,
.my-chat-secondary-action:disabled {
    cursor: wait;
    opacity: 0.6;
}

.my-chat-text-action {
    border: 0;
    padding: 0.2rem;
    background: transparent;
    font-size: 0.88rem;
    text-decoration: underline;
}

.my-chats-list {
    display: grid;
    gap: 0.7rem;
}

.my-chat-card {
    display: grid;
    grid-template-columns: 4.4rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    padding: 0.9rem;
    background: rgba(255, 254, 250, 0.82);
    box-shadow: 0 7px 22px rgba(61, 49, 32, 0.045);
}

.my-chat-portrait-wrap {
    position: relative;
    width: 4.4rem;
    height: 4.4rem;
    overflow: hidden;
    border-radius: 50%;
    background: #e9e2d5;
}

.my-chat-portrait,
.my-chat-portrait-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.my-chat-portrait {
    object-fit: cover;
}

.my-chat-portrait-placeholder {
    display: grid;
    place-items: center;
    color: #656053;
    font-size: 1.65rem;
    font-weight: 600;
}

.my-chat-card-content {
    min-width: 0;
}

.my-chat-character {
    margin-bottom: 0.08rem;
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.15;
}

.my-chat-book,
.my-chat-preview,
.my-chat-time,
.my-chat-unavailable {
    margin-bottom: 0;
}

.my-chat-book,
.my-chat-time {
    color: var(--muted);
    font-size: 0.85rem;
}

.my-chat-preview {
    max-width: 48rem;
    margin-top: 0.28rem;
    overflow: hidden;
    color: #4f4c46;
    font-size: 0.98rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.my-chat-time {
    display: inline-block;
    margin-top: 0.22rem;
}

.my-chat-card-actions {
    max-width: 13rem;
    text-align: right;
}

.my-chat-unavailable {
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.25;
}

.my-chats-state {
    display: grid;
    justify-items: start;
    gap: 0.75rem;
    min-height: 12rem;
    border: 1px dashed var(--border);
    border-radius: 0.9rem;
    padding: 1.25rem;
}

.my-chats-state-title {
    margin: 0;
    font-size: 1.15rem;
}

.my-chat-skeleton {
    width: 100%;
    height: 5rem;
    border-radius: 0.8rem;
    background: linear-gradient(100deg, #eee9df 20%, #f8f5ef 45%, #eee9df 70%);
    background-size: 220% 100%;
    animation: myChatsShimmer 1.3s linear infinite;
}

@keyframes myChatsShimmer {
    to { background-position-x: -220%; }
}

@media (prefers-reduced-motion: reduce) {
    .my-chat-skeleton,
    .my-chats-spinner {
        animation: none;
    }
}

.my-chats-pagination {
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.my-chats-inline-error {
    color: var(--danger);
    font-size: 0.9rem;
}

.my-chats-inline-error .my-chat-text-action {
    margin-left: 0.45rem;
}

.my-chats-auth-shell {
    max-width: 32rem;
    margin: 4rem auto;
}

.my-chats-auth-loading,
.my-chats-conversation-loading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--muted);
}

.my-chats-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: myChatsSpin 0.7s linear infinite;
}

@keyframes myChatsSpin {
    to { transform: rotate(360deg); }
}

.my-chats-sign-in {
    margin-top: 1rem;
    padding: 1.25rem;
}

.my-chats-sign-in h2 {
    margin-bottom: 0.35rem;
}

.my-chats-sign-in p {
    color: var(--muted);
}

.my-chats-sign-in form {
    margin-top: 1rem;
}

.my-chats-sign-in input {
    margin-bottom: 0.8rem;
}

.my-chats-form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55rem;
    margin-top: 0.8rem;
}

.my-chat-toolbar {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    max-width: 50rem;
    margin: 0 auto 1rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: rgba(253, 251, 247, 0.94);
    box-shadow: 0 8px 20px rgba(61, 49, 32, 0.05);
    backdrop-filter: blur(12px);
}

.my-chat-toolbar-action {
    min-height: 2.25rem;
    padding: 0.3rem 0.8rem;
    font-size: 0.86rem;
}

.my-chat-toolbar .my-chat-call-action {
    gap: 0.35rem;
    min-height: 2.25rem;
    padding: 0.3rem 0.75rem;
}

.my-chat-call-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.55rem;
    border: 1px solid var(--border);
    border-radius: 0.45rem;
    padding: 0.45rem 0.55rem;
    color: var(--text);
    background: transparent;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.my-chat-call-action:hover {
    border-color: var(--muted);
    background: var(--highlight);
}

.my-chat-call-action:focus-visible,
.my-chat-call-control:focus-visible {
    outline: 3px solid rgba(37, 43, 67, 0.24);
    outline-offset: 2px;
}

.my-chat-call-launch-status {
    flex: 1 1 100%;
    min-height: 0;
    margin: 0;
    color: var(--danger);
    font-size: 0.86rem;
}

.my-chat-call-launch-status:empty {
    display: none;
}

.my-chats-callout {
    border-left: 4px solid #a67641;
    border-radius: 0.4rem;
    padding: 0.8rem 1rem;
    color: #5c4935;
    background: #f6ecdc;
}

.my-chats-callout .my-chat-secondary-action {
    margin-left: 0.75rem;
}

.my-chat-back-link {
    display: inline-block;
    margin-bottom: 1.5rem;
}

.my-chat-conversation-heading {
    max-width: 50rem;
    margin-left: auto;
    margin-right: auto;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.2rem;
}

.my-chat-conversation-heading.has-portrait {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    align-items: center;
    gap: clamp(1rem, 3vw, 1.75rem);
}

.my-chat-conversation-portrait {
    position: relative;
    width: 7rem;
    height: 7rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--highlight);
    box-shadow: 0 10px 24px rgba(61, 49, 32, 0.1);
}

.my-chat-conversation-portrait span,
.my-chat-conversation-portrait img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.my-chat-conversation-portrait span {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 2.5rem;
}

.my-chat-conversation-portrait img {
    object-fit: cover;
}

.my-chat-conversation-heading-content {
    min-width: 0;
}

.my-chat-conversation-heading h1 {
    margin-bottom: 0.3rem;
}

.my-chat-conversation-book,
.my-chat-conversation-context {
    margin-bottom: 0.2rem;
}

.my-chat-messages {
    display: grid;
    gap: 0.9rem;
    max-width: 50rem;
    margin: 0 auto 1.5rem;
}

.my-chat-message {
    max-width: min(88%, 39rem);
    border-radius: 1rem;
    padding: 0.85rem 1rem;
}

.my-chat-message.is-user {
    justify-self: end;
    background: #e8edf7;
}

.my-chat-message.is-character {
    justify-self: start;
    border: 1px solid var(--border);
    background: var(--surface);
}

.my-chat-message-speaker {
    margin-bottom: 0.2rem;
    font-size: 0.82rem;
    font-weight: 600;
}

.my-chat-message-content {
    margin-bottom: 0;
    white-space: pre-wrap;
}

.my-chat-message-time {
    display: block;
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.75rem;
}

.my-chat-send-form {
    position: sticky;
    bottom: 0.75rem;
    max-width: 50rem;
    margin: 0 auto;
    padding: 0.85rem;
    backdrop-filter: blur(12px);
}

.my-chat-send-form .my-chat-primary-action {
    margin-left: auto;
}

.my-chat-call-modal {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.my-chat-call-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(24, 23, 21, 0.55);
}

.my-chat-call-container {
    position: relative;
    z-index: 1;
    display: flex;
    width: min(100%, 26rem);
    max-height: 85vh;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2rem 1.5rem 1.5rem;
    background: var(--background);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.my-chat-call-portrait {
    width: 7.5rem;
    height: 9.375rem;
    border-radius: 0.75rem;
    object-fit: cover;
}

.my-chat-call-portrait.speaking {
    animation: my-chat-call-speaking 1.6s ease-in-out infinite;
}

@keyframes my-chat-call-speaking {
    0%, 100% { box-shadow: 0 0 0 0 var(--highlight); }
    50% { box-shadow: 0 0 0 10px var(--highlight); }
}

.my-chat-call-container h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 500;
}

.my-chat-call-status {
    min-height: 1.2em;
    color: var(--muted);
    font-size: 0.85rem;
    font-style: italic;
}

.my-chat-call-error {
    width: 100%;
    border-left: 4px solid var(--danger);
    padding: 0.65rem 0.8rem;
    color: var(--danger);
    background: #f9ebe9;
}

.my-chat-call-captions {
    display: flex;
    width: 100%;
    max-height: 30vh;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.my-chat-call-captions:empty {
    display: none;
}

.my-chat-call-caption {
    max-width: 85%;
    border-radius: 0.75rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
    line-height: 1.4;
}

.my-chat-call-caption.user {
    align-self: flex-end;
    border-bottom-right-radius: 0.25rem;
    color: var(--background);
    background: var(--text);
}

.my-chat-call-caption.character {
    align-self: flex-start;
    border-bottom-left-radius: 0.25rem;
    background: var(--highlight);
}

.my-chat-call-caption.partial {
    opacity: 0.65;
}

.my-chat-call-controls {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.5rem;
}

.my-chat-call-control {
    display: inline-flex;
    width: 3.25rem;
    height: 3.25rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text);
    background: var(--background);
    cursor: pointer;
}

.my-chat-call-control:hover {
    background: var(--highlight);
}

.my-chat-call-control.muted {
    color: var(--background);
    background: var(--text);
}

.my-chat-call-control.is-end {
    border-color: #b3423a;
    color: #fff;
    background: #b3423a;
}

.my-chat-call-control.is-end:hover {
    background: #97352e;
}

@media (max-width: 820px) {
    .my-chats-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .my-chat-card {
        grid-template-columns: 3.5rem minmax(0, 1fr);
    }

    .my-chat-portrait-wrap {
        width: 3.5rem;
        height: 3.5rem;
    }

    .my-chat-card-actions {
        grid-column: 2;
        max-width: none;
        text-align: left;
    }
}

@media (max-width: 540px) {
    body {
        font-size: 1rem;
    }

    .my-chats-main {
        width: min(100% - 1.25rem, 68rem);
        margin-top: 0.8rem;
    }

    .my-chats-brand span {
        font-size: 1rem;
    }

    .my-chats-filter-grid {
        grid-template-columns: 1fr;
    }

    .my-chats-search-row {
        grid-template-columns: 1fr;
    }

    .my-chats-search-row .my-chat-primary-action {
        width: 100%;
    }

    .my-chat-card {
        align-items: start;
        padding: 0.75rem;
    }

    .my-chat-preview {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .my-chat-card-actions .my-chat-primary-action {
        width: 100%;
    }

    .my-chat-message {
        max-width: 94%;
    }

    .my-chat-conversation-heading.has-portrait {
        grid-template-columns: 4.5rem minmax(0, 1fr);
        align-items: start;
        gap: 0.85rem;
    }

    .my-chat-conversation-portrait {
        width: 4.5rem;
        height: 4.5rem;
        border-radius: 0.8rem;
    }

    .my-chat-conversation-portrait span {
        font-size: 1.8rem;
    }

    .my-chat-conversation-heading h1 {
        font-size: clamp(2rem, 11vw, 3rem);
    }

    .my-chat-toolbar {
        gap: 0.35rem;
        padding: 0.4rem;
    }

    .my-chat-toolbar-action,
    .my-chat-toolbar .my-chat-call-action {
        flex: 1 1 calc(50% - 0.35rem);
    }
}
