:root {
    --bg: #fff7fa;
    --surface: #ffffff;
    --primary: #ed91b1;
    --primary-dark: #d96e97;
    --soft: #f8dce9;
    --soft-text: #75475b;
    --accent: #e879a1;
    --muted: #b58b9c;
    --border: #f5c2d4;
    --text: #57404b;
    --overlay: rgba(87, 64, 75, 0.5);
}

:root[data-theme="lavender"] {
    --bg: #f8f5ff;
    --surface: #ffffff;
    --primary: #a78bfa;
    --primary-dark: #8b6cf0;
    --soft: #e9e1ff;
    --soft-text: #4c3a7a;
    --accent: #8b6cf0;
    --muted: #9a8cc0;
    --border: #d9ccff;
    --text: #3f3556;
    --overlay: rgba(63, 53, 86, 0.5);
}

:root[data-theme="blue"] {
    --bg: #f3f9ff;
    --surface: #ffffff;
    --primary: #5fa8e8;
    --primary-dark: #3f8bd0;
    --soft: #dcecfb;
    --soft-text: #2f5577;
    --accent: #3f8bd0;
    --muted: #86a3bd;
    --border: #bcd9f2;
    --text: #2f4558;
    --overlay: rgba(47, 69, 88, 0.5);
}

:root[data-theme="green"] {
    --bg: #f4fbf6;
    --surface: #ffffff;
    --primary: #62c58a;
    --primary-dark: #43a96d;
    --soft: #dcf3e5;
    --soft-text: #2f6045;
    --accent: #43a96d;
    --muted: #86b49a;
    --border: #bfe5cf;
    --text: #2f4a3a;
    --overlay: rgba(47, 74, 58, 0.5);
}

:root[data-theme="dark"] {
    --bg: #14111a;
    --surface: #1f1a28;
    --primary: #d9628f;
    --primary-dark: #b84c78;
    --soft: #2d2538;
    --soft-text: #f1d9e6;
    --accent: #f08ab0;
    --muted: #9b8aa8;
    --border: #3a3047;
    --text: #eadff0;
    --overlay: rgba(0, 0, 0, 0.65);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.chat-container {
    width: 100%;
    max-width: none;
    height: 100dvh;
    margin: 0;
    padding: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

@media (min-width: 700px) {
    .chat-container {
        max-width: 600px;
        margin: 0 auto;
    }
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.menu-btn {
    background: var(--soft);
    color: var(--soft-text);
    padding: 8px 12px;
    font-size: 18px;
    border-radius: 10px;
}

.header-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.header-info h1 {
    margin: 0;
    padding: 0;
    text-align: left;
    font-size: 20px;
    color: var(--accent);
}

.subtitle {
    margin: 0;
    padding: 0;
    text-align: left;
    font-size: 13px;
    color: var(--muted);
}

#messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 15px;
    background: var(--bg);
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: bubbleAppear 0.3s ease-out;
    transform-origin: bottom;
}

.user {
    align-self: flex-end;
    justify-content: flex-end;
}

.rin {
    align-self: flex-start;
}

.message-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user .message-body {
    align-items: flex-end;
}

.rin .message-body {
    align-items: flex-start;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.message-bubble {
    padding: 12px 15px;
    border-radius: 16px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.user .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.rin .message-bubble {
    background: var(--soft);
    color: var(--soft-text);
    border-bottom-left-radius: 4px;
}

.message-name {
    font-size: 12px;
    font-weight: bold;
    color: var(--muted);
    margin: 0 4px 4px;
}

.message-time {
    font-size: 10px;
    color: var(--muted);
    margin: 4px 4px 0;
}

.message-content {
    display: block;
}

.message-img {
    display: block;
    width: 220px;
    max-width: 100%;
    border-radius: 12px;
}

.message-img + .message-content {
    margin-top: 8px;
}

.typing-row .message-content,
.typing-row .message-time {
    display: none;
}

.typing-row .message-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
}

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

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

@keyframes bubbleAppear {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

input {
    flex: 1;
    min-width: 0;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 12px;
    outline: none;
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
}

button {
    padding: 12px 18px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: bold;
}

button:active {
    background: var(--primary-dark);
}

.attach-btn {
    background: var(--soft);
    color: var(--soft-text);
    padding: 12px 14px;
}

.preview-bar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.preview-bar.show {
    display: flex;
}

.preview-bar img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 10px;
}

.preview-remove {
    background: var(--soft);
    color: var(--soft-text);
    padding: 6px 10px;
}

.confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
}

.confirm-overlay.show {
    display: flex;
}

.confirm-card {
    background: var(--surface);
    color: var(--text);
    border-radius: 16px;
    padding: 20px;
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.confirm-card p {
    margin: 0 0 16px;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 8px;
}

.confirm-actions button {
    flex: 1;
}

.confirm-no {
    background: var(--soft);
    color: var(--soft-text);
}

.confirm-yes {
    background: var(--primary);
    color: white;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 5;
}

.sidebar-overlay.show {
    display: block;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    background: var(--surface);
    color: var(--text);
    z-index: 6;
    transform: translateX(-100%);
    transition: transform 0.25s;
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.sidebar.show {
    transform: translateX(0);
}

.sidebar-title {
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 12px;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
}

.chat-item.active {
    background: var(--soft);
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-del {
    background: transparent;
    color: var(--muted);
    padding: 4px 8px;
}

.theme-title {
    font-weight: bold;
    color: var(--accent);
    margin: 12px 0 8px;
}

.theme-row {
    display: flex;
    gap: 10px;
}

.theme-dot {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    border: 3px solid transparent;
}

.theme-dot.active {
    border-color: var(--text);
}

.new-chat-btn {
    margin-top: 12px;
    padding: 14px;
}

.rename-input {
    width: 100%;
    margin-bottom: 16px;
}

.chat-item {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 4px 0;
}

.message-footer .message-time {
    margin: 0;
}

.typing-row .message-footer {
    display: none;
}

.copy-btn {
    background: transparent;
    color: var(--muted);
    padding: 2px 6px;
    font-size: 11px;
    font-weight: normal;
    border-radius: 8px;
}

.copy-btn:active {
    background: var(--soft);
}

.word {
    display: inline-block;
    opacity: 0;
    animation: wordUp 0.4s ease-out forwards;
}

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

:root[data-theme="orange"] {
    --bg: #fff8f1;
    --surface: #ffffff;
    --primary: #f5a25d;
    --primary-dark: #e0842f;
    --soft: #fde5cf;
    --soft-text: #7a4a1f;
    --accent: #e0842f;
    --muted: #b8926f;
    --border: #f6d3b0;
    --text: #54402f;
    --overlay: rgba(84, 64, 47, 0.5);
}

:root[data-theme="teal"] {
    --bg: #f1fbfa;
    --surface: #ffffff;
    --primary: #3cb8b0;
    --primary-dark: #2a9a93;
    --soft: #d6f1ee;
    --soft-text: #1f5a56;
    --accent: #2a9a93;
    --muted: #7fb0ac;
    --border: #b5e2de;
    --text: #2c4a48;
    --overlay: rgba(44, 74, 72, 0.5);
}

:root[data-theme="red"] {
    --bg: #fff5f5;
    --surface: #ffffff;
    --primary: #e5646e;
    --primary-dark: #c94853;
    --soft: #fbdcde;
    --soft-text: #7a2f36;
    --accent: #d94c58;
    --muted: #bd8c90;
    --border: #f3bcc0;
    --text: #55393b;
    --overlay: rgba(85, 57, 59, 0.5);
}

:root[data-theme="midnight"] {
    --bg: #0d1524;
    --surface: #16213a;
    --primary: #4f8cff;
    --primary-dark: #3a72dc;
    --soft: #1f2e4f;
    --soft-text: #d6e4ff;
    --accent: #7aa9ff;
    --muted: #8a9bbd;
    --border: #2a3b60;
    --text: #e3ebfa;
    --overlay: rgba(0, 0, 0, 0.65);
}

:root[data-theme="mocha"] {
    --bg: #1b1512;
    --surface: #261e19;
    --primary: #c98b5a;
    --primary-dark: #a96f43;
    --soft: #362a22;
    --soft-text: #f1e1d3;
    --accent: #e0a574;
    --muted: #a58f7e;
    --border: #43342a;
    --text: #efe3d8;
    --overlay: rgba(0, 0, 0, 0.65);
}

.theme-row {
    flex-wrap: wrap;
}