* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* iOS Safe Area Support */
:root {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.4);
    --bubble-sender: #0b93f6;
    --bubble-sender-text: #ffffff;
    --bubble-receiver: #3a3a3c;
    --bubble-receiver-text: #ffffff;
    --bubble-sms: #34c759;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-highlight: rgba(255, 255, 255, 0.25);
    --separator: rgba(255, 255, 255, 0.1);
    --accent: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --header-bg: rgba(0, 0, 0, 0.7);
    --input-bg: rgba(0, 0, 0, 0.8);
    --settings-bg: rgba(28, 28, 30, 0.85);
    
    /* Safe area insets */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    
    /* Touch target minimum */
    --touch-target: 44px;
}

/* Letter Avatar */
.avatar-letter {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

/* Typing Indicator */
.typing-indicator-wrapper {
    padding: 0 16px;
    margin-bottom: -8px;
    margin-top: -16px;
}

.typing-indicator {
    align-self: flex-start;
    background: var(--bubble-receiver);
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 0;
    margin-right: 60px;
    margin-bottom: 8px;
    display: none;
    position: relative;
    width: fit-content;
}

.typing-indicator.active {
    display: flex;
    animation: messageAppear 0.3s ease-out;
}

.typing-indicator::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 18px;
    height: 18px;
    background: var(--bubble-receiver);
    border-bottom-right-radius: 14px 12px;
}

.typing-indicator::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -10px;
    width: 10px;
    height: 18px;
    background: var(--bg-primary);
    border-bottom-right-radius: 8px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

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

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

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

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

/* Read Receipts */
.message-status {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 2px;
    margin-bottom: 8px;
    margin-right: 4px;
    opacity: 0;
    animation: fadeIn 0.3s ease-out forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.message-status.delivered {
    color: var(--text-tertiary);
}

.message-status.read {
    color: var(--accent);
}

/* Story Playback Controls */
.story-controls {
    position: fixed;
    bottom: max(100px, calc(var(--safe-area-bottom) + 80px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 150;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 20px;
    border-radius: 30px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.story-controls.active {
    opacity: 1;
    visibility: visible;
}

.story-btn {
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
    color: white;
}

.story-btn:active {
    transform: scale(0.92);
    background: var(--glass-highlight);
}

.story-btn svg {
    width: 22px;
    height: 22px;
}

.story-btn.play-pause svg.pause-icon {
    display: none;
}

.story-btn.play-pause.playing svg.play-icon {
    display: none;
}

.story-btn.play-pause.playing svg.pause-icon {
    display: block;
}

.speed-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    font-size: 14px;
    font-weight: 600;
    color: white;
}

/* Story Progress Bar */
.story-progress {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 430px;
    height: 3px;
    background: rgba(255, 255, 255, 0.2);
    z-index: 150;
    opacity: 0;
    transition: opacity 0.3s;
}

.story-progress.active {
    opacity: 1;
}

.story-progress-bar {
    height: 100%;
    background: white;
    width: 0%;
    transition: width 0.3s linear;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f2f2f7;
    --bg-tertiary: #e5e5ea;
    --text-primary: #000000;
    --text-secondary: rgba(0, 0, 0, 0.55);
    --text-tertiary: rgba(0, 0, 0, 0.35);
    --bubble-sender: #0b93f6;
    --bubble-sender-text: #ffffff;
    --bubble-receiver: #e5e5ea;
    --bubble-receiver-text: #000000;
    --bubble-sms: #34c759;
    --glass-bg: rgba(0, 0, 0, 0.04);
    --glass-border: rgba(0, 0, 0, 0.1);
    --glass-highlight: rgba(0, 0, 0, 0.08);
    --separator: rgba(0, 0, 0, 0.1);
    --accent: #007AFF;
    --green: #34c759;
    --red: #ff3b30;
    --header-bg: rgba(255, 255, 255, 0.85);
    --input-bg: rgba(255, 255, 255, 0.9);
    --settings-bg: rgba(242, 242, 247, 0.92);
}

[data-message-type="sms"] .message.sent {
    background: var(--bubble-sms);
}

[data-message-type="sms"] .message.sent.tail::before {
    background: var(--bubble-sms);
}

[data-message-type="sms"] .message-link-preview.sent {
    background: var(--bubble-sms);
}

[data-message-type="sms"] .message-image.sent + .message.sent,
[data-message-type="sms"] .message.sent + .message-image.sent {
    background: var(--bubble-sms);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    /* Prevent pull-to-refresh on iOS */
    overscroll-behavior: none;
    /* Smooth font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent text selection during interactions */
    -webkit-user-select: none;
    user-select: none;
    /* Allow text selection in inputs */
    touch-action: manipulation;
}

/* Allow text selection in text areas */
input, textarea {
    -webkit-user-select: text;
    user-select: text;
}

.app-container {
    max-width: 430px;
    margin: 0 auto;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
    /* Safe area padding */
    padding-top: var(--safe-area-top);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

/* iPad layout - wider container */
@media (min-width: 768px) {
    .app-container {
        max-width: 600px;
        border-left: 0.5px solid var(--separator);
        border-right: 0.5px solid var(--separator);
    }
}

/* iPad Pro / larger tablets - even wider */
@media (min-width: 1024px) {
    .app-container {
        max-width: 700px;
    }
    
    body {
        display: flex;
        justify-content: center;
        background: var(--bg-secondary);
    }
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 12px 16px 12px 16px;
    padding-top: max(12px, var(--safe-area-top));
    background: var(--header-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--accent);
    font-size: 17px;
    font-weight: 400;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 0;
    /* Minimum touch target */
    min-height: var(--touch-target);
    min-width: var(--touch-target);
}

[data-theme="light"] .back-btn {
    color: var(--text-primary);
}

.back-btn svg {
    width: 22px;
    height: 22px;
}

.back-badge {
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: 14px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 2px;
}

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

.header-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    color: var(--accent);
    /* Minimum touch target */
    min-height: var(--touch-target);
    min-width: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    transition: background 0.15s;
}

.header-btn:active {
    background: var(--glass-bg);
}

.header-btn svg {
    width: 24px;
    height: 24px;
}

.contact-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.avatar-container {
    position: relative;
    cursor: pointer;
}

.avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(180deg, #636366 0%, #8e8e93 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

[data-theme="light"] .avatar {
    background: linear-gradient(180deg, #6e6dab 0%, #8786c7 40%, #a5a4d4 100%);
}

.avatar.has-image {
    background: none;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-edit {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 22px;
    height: 22px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-edit svg {
    width: 12px;
    height: 12px;
    color: var(--text-primary);
}

.contact-name-container {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--glass-bg);
    padding: 8px 12px 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
    border: 0.5px solid var(--glass-border);
}

[data-theme="light"] .contact-name-container {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.contact-name-container:hover {
    background: var(--glass-highlight);
}

.contact-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.contact-chevron {
    display: flex;
    align-items: center;
    color: var(--text-tertiary);
}

.contact-chevron svg {
    width: 16px;
    height: 16px;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-bottom: 24px; /* Extra space before input area */
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative;
    /* Better scroll momentum on iOS */
    scroll-behavior: smooth;
}

/* During story playback, start messages from top */
.messages-container.story-playing {
    justify-content: flex-start;
}

/* Hide insert points during story playback */
.messages-container.story-playing .insert-point {
    display: none !important;
}

.messages-container::-webkit-scrollbar {
    display: none;
}

.date-separator {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin: 16px 0 8px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 12px;
    transition: background 0.2s;
    display: inline-block;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.date-separator:hover {
    background: var(--glass-bg);
}

.date-separator-wrapper {
    text-align: center;
    width: 100%;
}

.date-separator-input {
    background: var(--bg-tertiary);
    border: 2px solid var(--accent);
    border-radius: 12px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    font-family: inherit;
    text-align: center;
    outline: none;
    min-width: 180px;
}

.message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 17px;
    line-height: 1.4;
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
}

/* Animation class for new messages */
.message.animate-in {
    animation: messageAppear 0.15s ease-out forwards;
}

@keyframes messageAppear {
    0% {
        opacity: 0.5;
        transform: scale(0.96);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.message.sent {
    align-self: flex-end;
    background: var(--bubble-sender);
    color: var(--bubble-sender-text);
    border-radius: 18px;
    margin-left: 60px;
    margin-bottom: 2px;
}

.message.sent.last {
    margin-bottom: 12px;
}

.message.sent.tail {
    border-bottom-right-radius: 0px;
}

.message.sent.tail::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 18px;
    height: 18px;
    background: var(--bubble-sender);
    border-bottom-left-radius: 14px 12px;
}

.message.sent.tail::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -10px;
    width: 10px;
    height: 18px;
    background: var(--bg-primary);
    border-bottom-left-radius: 8px;
}

.message.sent:not(.tail) {
    border-bottom-right-radius: 18px;
}

.message.received {
    align-self: flex-start;
    background: var(--bubble-receiver);
    color: var(--bubble-receiver-text);
    border-radius: 18px;
    margin-right: 60px;
    margin-bottom: 2px;
}

.message.received.last {
    margin-bottom: 12px;
}

.message.received.tail {
    border-bottom-left-radius: 0px;
}

.message.received.tail::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 18px;
    height: 18px;
    background: var(--bubble-receiver);
    border-bottom-right-radius: 14px 12px;
}

.message.received.tail::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -10px;
    width: 10px;
    height: 18px;
    background: var(--bg-primary);
    border-bottom-right-radius: 8px;
}

.message.received:not(.tail) {
    border-bottom-left-radius: 18px;
}

/* Message Editing */
.message.editing {
    cursor: text;
    min-width: 100px;
}

.message.editing.sent {
    background: var(--bubble-sender);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.message.editing.received {
    background: var(--bubble-receiver);
    box-shadow: 0 0 0 2px var(--accent);
}

.message-edit-input {
    background: transparent !important;
    color: inherit !important;
    caret-color: currentColor;
}

.message-edit-input::placeholder {
    color: inherit;
    opacity: 0.5;
}

/* Editable message hover indicator */
.message[data-message-index]:not(.message-link-preview):not(.editing) {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.message[data-message-index]:not(.message-link-preview):not(.editing):hover {
    transform: scale(1.02);
}

.message[data-message-index]:not(.message-link-preview):not(.editing):active {
    transform: scale(0.98);
}

/* Image message clickable state */
.message-image[data-message-index] {
    cursor: pointer;
    position: relative;
}

.message-image[data-message-index]:hover::after {
    content: 'Tap to edit';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    pointer-events: none;
    white-space: nowrap;
}

/* Text message hint - shows on mobile touch */
.message[data-message-index]:not(.message-image):not(.message-link-preview) {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Message Insertion Points */
.insert-point {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 16px;
    opacity: 0;
    height: 0;
    overflow: visible;
    transition: opacity 0.2s, height 0.2s;
    position: relative;
    z-index: 5;
}

.insert-point:hover,
.insert-point:focus-within {
    opacity: 1;
    height: 32px;
}

.insert-line {
    flex: 1;
    height: 1px;
    background: var(--accent);
    opacity: 0.4;
}

.insert-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 8px;
    transition: transform 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
    /* Larger touch area */
    padding: 0;
}

.insert-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.4);
}

.insert-btn svg {
    width: 16px;
    height: 16px;
    color: white;
}

/* Show insert points on container hover (desktop) */
@media (hover: hover) {
    .messages-container:hover .insert-point {
        opacity: 0.3;
        height: 24px;
    }
    
    .messages-container:hover .insert-point:hover {
        opacity: 1;
        height: 32px;
    }
}

/* Always show first and last insert points slightly */
.insert-point:first-child,
.insert-point:last-child {
    opacity: 0.2;
    height: 20px;
}

.insert-point:first-child:hover,
.insert-point:last-child:hover,
.insert-point:first-child:active,
.insert-point:last-child:active {
    opacity: 1;
    height: 32px;
}

/* Mobile touch - show insert points on tap */
@media (hover: none) {
    .insert-point {
        opacity: 0.35;
        height: 28px;
    }
    
    .insert-point:active {
        opacity: 1;
    }
    
    .insert-btn {
        width: var(--touch-target);
        height: var(--touch-target);
    }
}

/* Image Messages */
.message-image {
    max-width: 260px;
    padding: 0;
    background: none !important;
    margin-bottom: 12px;
    border-radius: 16px;
    height: auto;
    max-height: none;
    overflow: visible;
}

.message-image.sent {
    background: none;
}

.message-image.received {
    background: none;
}

.message-image img {
    max-width: 100%;
    height: auto;
    max-height: none;
    border-radius: 16px;
    display: block;
}

.message-image video {
    max-width: 100%;
    height: auto;
    max-height: none;
    border-radius: 16px;
    display: block;
}

.message-video {
    position: relative;
}

.message-video::before {
    display: none !important;
}

.message-video::after {
    display: none !important;
}

.message-image.tail::before,
.message-image.tail::after {
    display: none !important;
}

/* Link Previews */
.message-link-preview {
    max-width: 280px;
    padding: 0;
    overflow: hidden;
    background: var(--bubble-receiver);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: stretch;
}

.message-link-preview.sent {
    background: var(--bubble-sender);
}

.message-link-preview.loading {
    opacity: 0.7;
}

.message-link-preview.tail::before,
.message-link-preview.tail::after {
    display: none;
}

.link-preview-image {
    width: 72px;
    min-width: 72px;
    height: 72px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

.link-preview-icon {
    width: 72px;
    min-width: 72px;
    height: 72px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.link-preview-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-link-preview.received .link-preview-icon {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .message-link-preview.received .link-preview-icon {
    background: rgba(0, 0, 0, 0.06);
}

.link-preview-icon svg {
    width: 28px;
    height: 28px;
    color: rgba(255, 255, 255, 0.7);
}

.message-link-preview.received .link-preview-icon svg {
    color: var(--text-primary);
    opacity: 0.5;
}

.link-preview-content {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.link-preview-domain {
    font-size: 11px;
    opacity: 0.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.link-preview-title {
    font-size: 14px;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.link-preview-description {
    font-size: 12px;
    opacity: 0.7;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 2px;
}

.link-preview-arrow {
    display: none;
}

.message-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message.sent .message-link {
    color: white;
}

/* Quick Mode Switcher */
.quick-mode-switcher {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--input-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.2s, max-height 0.2s, padding 0.2s;
    padding-top: 0;
    padding-bottom: 0;
}

.quick-mode-switcher.visible {
    opacity: 1;
    max-height: 60px;
    padding-top: 10px;
    padding-bottom: 2px;
}

.quick-mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    min-height: var(--touch-target);
    border-radius: 22px;
    border: 2px solid transparent;
    background: var(--glass-bg);
    color: var(--text-tertiary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

.quick-mode-btn.active[data-mode="sender"] {
    border-color: var(--bubble-sender);
    background: rgba(11, 147, 246, 0.2);
    color: #0b93f6;
    font-weight: 600;
}

.quick-mode-btn.active[data-mode="receiver"] {
    border-color: var(--bubble-receiver);
    background: rgba(58, 58, 60, 0.4);
    color: var(--text-primary);
    font-weight: 600;
}

[data-theme="light"] .quick-mode-btn.active[data-mode="receiver"] {
    background: rgba(229, 229, 234, 0.7);
    border-color: #c7c7cc;
}

.quick-mode-indicator {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.quick-mode-indicator.sender {
    background: var(--bubble-sender);
    box-shadow: 0 0 8px rgba(11, 147, 246, 0.5);
}

.quick-mode-indicator.receiver {
    background: var(--bubble-receiver);
}

.quick-mode-btn.active .quick-mode-indicator.sender {
    box-shadow: 0 0 10px rgba(11, 147, 246, 0.7);
}

[data-message-type="sms"] .quick-mode-indicator.sender {
    background: var(--bubble-sms);
    box-shadow: 0 0 8px rgba(52, 199, 89, 0.5);
}

[data-message-type="sms"] .quick-mode-btn.active[data-mode="sender"] {
    border-color: var(--bubble-sms);
    background: rgba(52, 199, 89, 0.2);
    color: #34c759;
}

[data-message-type="sms"] .quick-mode-btn.active .quick-mode-indicator.sender {
    box-shadow: 0 0 10px rgba(52, 199, 89, 0.7);
}

/* Input Area */
.input-container {
    padding: 8px 12px;
    padding-bottom: max(34px, calc(var(--safe-area-bottom) + 8px));
    background: var(--input-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.input-left-btn {
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    background: var(--glass-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, background 0.15s;
}

.input-left-btn:active {
    transform: scale(0.92);
    background: var(--glass-highlight);
}

.input-left-btn svg {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
}

.text-input-container {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: var(--bg-tertiary);
    border-radius: 20px;
    padding: 6px 6px 6px 14px;
    min-height: var(--touch-target);
    gap: 8px;
    border: 1px solid var(--glass-border);
}

[data-theme="light"] .text-input-container {
    background: #ffffff;
    border: 1px solid #e5e5ea;
}

.text-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 17px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.35;
    padding: 2px 0;
    align-self: center;
    /* iOS-specific fixes */
    -webkit-appearance: none;
    appearance: none;
}

.text-input::placeholder {
    color: var(--text-tertiary);
}

/* Prevent zoom on input focus on iOS */
@supports (-webkit-touch-callout: none) {
    .text-input {
        font-size: 16px; /* iOS won't zoom if font-size >= 16px */
    }
}

.send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.2s;
    align-self: flex-end;
    /* Larger touch area via padding */
    padding: 0;
    margin: 2px;
}

.send-btn.hidden {
    display: none;
}

.send-btn:active:not(:disabled) {
    transform: scale(0.9);
}

.send-btn svg {
    width: 16px;
    height: 16px;
    color: white;
}

.audio-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s;
    align-self: flex-end;
    margin: 2px;
}

.audio-btn.hidden {
    display: none;
}

.audio-btn:active {
    transform: scale(0.9);
}

.audio-btn svg {
    width: 22px;
    height: 22px;
    color: var(--text-tertiary);
}

/* Settings Panel */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.settings-overlay.active {
    opacity: 1;
    visibility: visible;
}

.settings-panel {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: 100%;
    max-width: 430px;
    max-height: calc(90vh - var(--safe-area-top));
    background: var(--settings-bg);
    backdrop-filter: blur(60px) saturate(200%);
    -webkit-backdrop-filter: blur(60px) saturate(200%);
    border-radius: 20px 20px 0 0;
    z-index: 201;
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    /* Safe area for bottom */
    padding-bottom: var(--safe-area-bottom);
}

/* iPad - larger settings panel */
@media (min-width: 768px) {
    .settings-panel {
        max-width: 500px;
        max-height: 80vh;
        border-radius: 20px;
        bottom: 50%;
        transform: translateX(-50%) translateY(50%) scale(0.95);
        opacity: 0;
    }
    
    .settings-panel.active {
        transform: translateX(-50%) translateY(50%) scale(1);
        opacity: 1;
    }
}

.settings-panel.active {
    transform: translateX(-50%) translateY(0);
}

@media (min-width: 768px) {
    .settings-panel.active {
        transform: translateX(-50%) translateY(50%) scale(1);
    }
}

.settings-handle {
    width: 36px;
    height: 5px;
    background: var(--text-tertiary);
    border-radius: 3px;
    margin: 8px auto 16px;
}

/* Hide handle on iPad where we use centered modal */
@media (min-width: 768px) {
    .settings-handle {
        display: none;
    }
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 16px;
    border-bottom: 0.5px solid var(--separator);
}

.settings-title {
    font-size: 17px;
    font-weight: 600;
}

.settings-close {
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    background: var(--glass-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.settings-close:active {
    background: var(--glass-highlight);
}

.settings-close svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.settings-content {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    max-height: calc(90vh - 100px - var(--safe-area-bottom));
}

@media (min-width: 768px) {
    .settings-content {
        max-height: calc(80vh - 100px);
    }
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    padding-left: 16px;
}

.settings-group {
    background: var(--glass-bg);
    border-radius: 14px;
    overflow: hidden;
    border: 0.5px solid var(--glass-border);
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    min-height: var(--touch-target);
    border-bottom: 0.5px solid var(--separator);
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-item-label {
    font-size: 16px;
    color: var(--text-primary);
}

.settings-item-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    width: 140px;
    text-align: right;
    min-height: var(--touch-target);
    /* iOS-specific */
    -webkit-appearance: none;
    appearance: none;
}

.settings-item-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Volume Slider */
.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s;
}

.volume-slider:active::-webkit-slider-thumb {
    transform: scale(1.15);
}

.volume-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Settings Select Dropdown */
.settings-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 8px 32px 8px 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    min-width: 160px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23888'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
}

.settings-select:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px;
}

/* API Key Input */
.api-key-input {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 13px !important;
    letter-spacing: 0.5px;
}

/* Test Voice Button */
.test-voice-btn,
.voice-btn-test {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.test-voice-btn:disabled,
.generate-voices-btn:disabled,
.voice-btn-generate:disabled,
.voice-btn-test:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.test-voice-btn.loading,
.generate-voices-btn.loading,
.voice-btn-generate.loading,
.voice-btn-test.loading {
    position: relative;
    color: transparent;
}

.test-voice-btn.loading svg,
.generate-voices-btn.loading svg,
.voice-btn-generate.loading svg,
.voice-btn-test.loading svg {
    visibility: hidden;
}

.test-voice-btn.loading::after,
.generate-voices-btn.loading::after,
.voice-btn-generate.loading::after,
.voice-btn-test.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Voice Buttons Row */
.voice-buttons-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.voice-btn-generate,
.voice-btn-test,
.voice-btn-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: transform 0.15s, opacity 0.15s;
    color: white;
}

.voice-btn-generate:active,
.voice-btn-test:active,
.voice-btn-clear:active {
    transform: scale(0.96);
}

.voice-btn-generate svg,
.voice-btn-test svg,
.voice-btn-clear svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.voice-btn-generate {
    flex: 1;
    background: linear-gradient(135deg, #34c759 0%, #30d158 100%);
}

.voice-btn-test {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 12px 14px;
}

.voice-btn-clear {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 12px 14px;
}

.voice-btn-clear:hover {
    background: rgba(255, 59, 48, 0.2);
    border-color: var(--red);
    color: var(--red);
}

/* Generate Voices Button (legacy) */
.generate-voices-btn {
    background: linear-gradient(135deg, #34c759 0%, #30d158 100%);
}

/* Clear Cache Button (legacy) */
.clear-cache-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 8px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-cache-btn:hover {
    background: var(--red);
    color: white;
    border-color: var(--red);
}

/* Voice generation status */
.voice-status {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    line-height: 1.4;
}

.voice-status:empty {
    display: none;
}

.voice-status.generating {
    background: rgba(10, 132, 255, 0.15);
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

.voice-status.error {
    background: rgba(255, 59, 48, 0.15);
    color: var(--red);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Toggle Switch - iOS native size */
.toggle-switch {
    position: relative;
    width: 51px;
    height: 31px;
    background: var(--bg-tertiary);
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.3s;
    border: 1px solid var(--separator);
    flex-shrink: 0;
}

.toggle-switch.active {
    background: var(--green);
    border-color: var(--green);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active::after {
    transform: translateX(20px);
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.mode-option {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mode-option.active {
    background: var(--accent);
    color: white;
}

.mode-option.receiver.active {
    background: var(--bubble-receiver);
    color: var(--text-primary);
}

.mode-option.imessage.active {
    background: #0b93f6;
    color: white;
}

.mode-option.sms.active {
    background: #34c759;
    color: white;
}

/* Buttons */
.avatar-upload-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--accent);
    border: none;
    border-radius: 12px;
    padding: 14px 18px;
    min-height: var(--touch-target);
    color: white;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    transition: transform 0.15s, opacity 0.15s;
}

.avatar-upload-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.avatar-upload-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.clear-chat-btn {
    background: var(--red);
}

.video-upload-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.hidden-input {
    display: none;
}

/* Attachment Preview */
.attachment-preview {
    position: relative;
    padding: 12px;
    background: var(--bg-secondary);
    display: none;
}

.attachment-preview.active {
    display: block;
}

.attachment-preview-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.attachment-preview-info {
    flex: 1;
}

.attachment-preview-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.attachment-preview-size {
    font-size: 12px;
    color: var(--text-secondary);
}

.attachment-remove {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-remove svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    gap: 8px;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
}

/* Hide insert points when empty state is shown */
.messages-container:has(.empty-state) .insert-point,
.messages-container .empty-state ~ .insert-point {
    display: none !important;
}

/* Responsive */
@media (max-width: 430px) {
    .app-container, .settings-panel {
        max-width: 100%;
    }
}

/* Export Modal */
.export-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    padding: 20px;
    padding-top: max(20px, var(--safe-area-top));
    padding-bottom: max(20px, var(--safe-area-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.export-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.export-modal {
    background: var(--settings-bg);
    backdrop-filter: blur(60px) saturate(200%);
    -webkit-backdrop-filter: blur(60px) saturate(200%);
    border-radius: 20px;
    width: 90%;
    max-width: 320px;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.export-modal.export-modal-large {
    max-width: 420px;
    width: 95%;
}

/* iPad - larger modal */
@media (min-width: 768px) {
    .export-modal.export-modal-large {
        max-width: 500px;
    }
}

.export-modal-overlay.active .export-modal {
    transform: scale(1);
}

.export-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 0.5px solid var(--separator);
}

.export-modal-header h3 {
    font-size: 17px;
    font-weight: 600;
}

.export-modal-close {
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    background: var(--glass-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.export-modal-close:active {
    background: var(--glass-highlight);
}

.export-modal-close svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.export-modal-content {
    padding: 20px;
}

.export-description {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 20px;
    line-height: 1.4;
}

/* Format Preview Grid */
.format-previews {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.format-previews-2col {
    grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 400px) {
    .format-previews {
        grid-template-columns: 1fr;
    }
}

.format-card {
    background: var(--glass-bg);
    border-radius: 16px;
    padding: 12px;
    border: 1px solid var(--glass-border);
    transition: border-color 0.2s, transform 0.2s;
}

.format-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.format-preview {
    position: relative;
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.02) 100%);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.format-preview.format-9-16 {
    aspect-ratio: 9/16;
}

.format-preview.format-1-1 {
    aspect-ratio: 1/1;
}

.format-preview-messages {
    width: 75%;
    max-height: 70%;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    padding: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.format-preview-messages .preview-msg {
    padding: 4px 8px;
    border-radius: 10px;
    font-size: 7px;
    line-height: 1.3;
    max-width: 85%;
    word-break: break-word;
}

.format-preview-messages .preview-msg.sent {
    align-self: flex-end;
    background: #0b93f6;
    color: white;
}

.format-preview-messages .preview-msg.received {
    align-self: flex-start;
    background: #3a3a3c;
    color: white;
}

.format-label {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 9px;
    color: var(--text-tertiary);
    background: rgba(0,0,0,0.5);
    padding: 2px 5px;
    border-radius: 4px;
}

.format-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin-bottom: 10px;
}

.format-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.format-size {
    font-size: 11px;
    color: var(--text-tertiary);
}

.format-uses {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.7;
}

.format-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.format-btn {
    flex: 1;
    padding: 12px;
    min-height: var(--touch-target);
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, opacity 0.15s;
}

.format-btn:active {
    transform: scale(0.95);
}

.format-btn svg {
    width: 20px;
    height: 20px;
}

.format-btn-play {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.format-btn-export {
    background: var(--accent);
    color: white;
}

.export-section {
    margin-bottom: 20px;
}

.export-section-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.export-select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23888'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
}

.export-select:focus {
    outline: none;
    border-color: var(--accent);
}

.export-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.export-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.15s, opacity 0.15s;
    background: var(--accent);
    color: white;
}

.export-btn:active {
    transform: scale(0.98);
}

.export-btn svg {
    width: 20px;
    height: 20px;
}

.export-btn-record {
    background: var(--red);
}

.export-btn-story {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.export-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    text-align: center;
    margin-top: 8px;
    line-height: 1.5;
}

/* Recording Indicator */
.recording-indicator {
    position: fixed;
    top: max(20px, var(--safe-area-top));
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(255, 59, 48, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 18px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 400;
    transition: transform 0.3s;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.recording-indicator.active {
    transform: translateX(-50%) translateY(0);
}

.recording-dot {
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    animation: recordingPulse 1s ease-in-out infinite;
}

@keyframes recordingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.recording-stop {
    background: white;
    color: var(--red);
    border: none;
    padding: 8px 16px;
    border-radius: 15px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 6px;
    min-height: 36px;
}

.recording-stop:active {
    opacity: 0.8;
}

/* Header button recording state */
.header-btn.recording {
    color: var(--red);
    animation: recordingPulse 1s ease-in-out infinite;
}

/* Export button in header */
#exportBtn.recording svg {
    color: var(--red);
    animation: recordingPulse 1s ease-in-out infinite;
}

/* Story Mode Button */
.story-mode-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.story-mode-btn:active {
    transform: scale(0.98);
}

/* Message appearing animation for story mode */
.message.story-animate {
    animation: storyMessageAppear 0.15s ease-out forwards !important;
}

@keyframes storyMessageAppear {
    0% {
        opacity: 0.5;
        transform: scale(0.96);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Speed selector */
.speed-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.speed-option {
    padding: 10px 16px;
    min-height: 40px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.speed-option:active {
    transform: scale(0.96);
}

.speed-option.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Story floating button - now in header */
.story-play-btn {
    position: relative;
}

.story-play-btn svg {
    width: 22px;
    height: 22px;
    color: #667eea;
}

.story-play-btn.playing svg {
    color: var(--red);
}

.story-play-btn.playing {
    animation: recordingPulse 1s ease-in-out infinite;
}

/* Overlay for story mode */
.story-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 250;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-overlay.active {
    opacity: 1;
    visibility: visible;
}

.story-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 260;
    color: white;
}

.story-close svg {
    width: 20px;
    height: 20px;
}

/* Read receipt styles inline */
.read-receipt-inline {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    margin-top: 4px;
    margin-bottom: 8px;
    padding-right: 4px;
}

.read-receipt-inline svg {
    width: 14px;
    height: 14px;
}

.read-receipt-inline.delivered svg {
    color: var(--text-tertiary);
}

.read-receipt-inline.read svg {
    color: var(--accent);
}

.read-receipt-inline span {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Settings toggle for read receipts */
.receipt-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.receipt-preview svg {
    width: 16px;
    height: 16px;
    color: var(--accent);
}

.receipt-preview span {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ==========================================
   STORY OVERLAY MODE (TikTok Style)
   ========================================== */

.story-overlay-mode {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    background: #000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: max(20px, var(--safe-area-top));
    padding-bottom: max(20px, var(--safe-area-bottom));
    padding-left: max(20px, var(--safe-area-left));
    padding-right: max(20px, var(--safe-area-right));
}

.story-overlay-mode.active {
    display: flex;
}

/* Dimension label - fixed position outside frame */
.story-dimension-label {
    position: fixed;
    top: max(20px, var(--safe-area-top));
    left: max(20px, var(--safe-area-left));
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    z-index: 520;
    letter-spacing: 0.5px;
}

/* Phone frame wrapper for centering */
.story-frame-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Phone frame - actual export dimensions, scaled to fit */
.story-phone-frame {
    position: relative;
    /* Default 9:16 - will be set by JS */
    width: 1080px;
    height: 1920px;
    background: #1a1a1a;
    border-radius: 0;
    overflow: hidden;
    /* Scale down to fit viewport */
    transform-origin: center center;
    flex-shrink: 0;
    /* Ensure crisp rendering when scaled */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* User's uploaded video - fullscreen behind everything */
.story-user-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

/* Placeholder when no video */
.story-phone-frame::before {
    content: 'Upload a video in Settings';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255,255,255,0.3);
    font-size: 24px;
    z-index: 0;
    pointer-events: none;
    text-align: center;
}

[data-theme="light"] .story-phone-frame::before {
    color: rgba(0,0,0,0.3);
}

.story-phone-frame.has-video::before {
    display: none;
}

/* Story Chat Container - floating box style */
.story-chat-container {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 88%;
    display: flex;
    flex-direction: column;
    z-index: 10;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 32px;
    overflow: hidden;
}

/* Story Header - Compact for more message space */
.story-header {
    padding: 16px 24px;
    background: transparent;
}

.story-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.story-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #0a84ff;
    font-size: 24px;
    font-weight: 400;
    background: none;
    border: none;
    cursor: default;
    padding: 0;
}

.story-back-btn svg {
    width: 32px;
    height: 32px;
}

.story-back-badge {
    background: white;
    color: black;
    font-size: 22px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 18px;
}

.story-header-actions {
    display: flex;
    gap: 24px;
}

.story-header-btn {
    background: none;
    border: none;
    cursor: default;
    padding: 0;
    color: #0a84ff;
}

.story-header-btn svg {
    width: 38px;
    height: 38px;
}

.story-contact-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.story-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(180deg, #636366 0%, #8e8e93 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.story-avatar.has-image {
    background: none;
}

.story-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-avatar-letter {
    font-size: 32px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

.story-contact-name-container {
    display: flex;
    align-items: center;
    gap: 3px;
    background: rgba(255, 255, 255, 0.1);
    padding: 12px 18px 12px 22px;
    border-radius: 26px;
}

.story-contact-name {
    font-size: 24px;
    font-weight: 600;
    color: white;
}

.story-contact-chevron {
    display: flex;
    align-items: center;
    color: rgba(255, 255, 255, 0.4);
}

.story-contact-chevron svg {
    width: 22px;
    height: 22px;
}

/* Story Messages Container */
.story-messages-float {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 6px;
}

/* Story Input Container - hidden */
.story-input-container {
    display: none !important;
}

.story-input-wrapper {
    display: flex;
    align-items: center;
    gap: 14px;
}

.story-input-left-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: default;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-input-left-btn svg {
    width: 40px;
    height: 40px;
    color: rgba(255, 255, 255, 0.6);
}

.story-text-input-container {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 36px;
    padding: 16px 24px;
    min-height: 60px;
    display: flex;
    align-items: center;
}

.story-text-placeholder {
    color: rgba(255, 255, 255, 0.4);
    font-size: 28px;
}

/* Overlay box is not used - always use fullchat style */
.story-phone-frame .story-overlay-box {
    display: none !important;
}

/* Simple Overlay Box Style - kept for reference but not used */
.story-overlay-box {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 92%;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.story-overlay-box .story-messages-overlay {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 40px;
    padding: 30px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 4px;
    visibility: hidden;
    opacity: 0;
    transform: scale(0.95);
}

/* Show overlay only when it has content */
.story-overlay-box .story-messages-overlay.has-content {
    visibility: visible;
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

/* Square format for overlay box */
.story-phone-frame.square-format .story-overlay-box {
    top: 40px;
    width: 94%;
}

.story-phone-frame.square-format .story-overlay-box .story-messages-overlay {
    border-radius: 30px;
    padding: 24px;
}

.story-messages-float::-webkit-scrollbar {
    display: none;
}

.story-messages-overlay::-webkit-scrollbar {
    display: none;
}

.story-messages-float .message:not(.message-image):not(.message-link-preview),
.story-messages-overlay .message:not(.message-image):not(.message-link-preview) {
    max-width: 88%;
    padding: 18px 24px;
    border-radius: 26px;
    font-size: 34px;
    line-height: 1.35;
    margin-bottom: 6px;
    animation: none;
}

.story-messages-float .message.sent:not(.message-image),
.story-messages-overlay .message.sent:not(.message-image) {
    align-self: flex-end;
    background: #0b93f6;
    color: white;
    margin-left: 30px;
}

.story-messages-float .message.received:not(.message-image),
.story-messages-overlay .message.received:not(.message-image) {
    align-self: flex-start;
    background: #3a3a3c;
    color: white;
    margin-right: 30px;
}

.story-messages-float .message.sent.tail:not(.message-image),
.story-messages-overlay .message.sent.tail:not(.message-image) {
    border-bottom-right-radius: 6px;
}

.story-messages-float .message.received.tail:not(.message-image),
.story-messages-overlay .message.received.tail:not(.message-image) {
    border-bottom-left-radius: 6px;
}

/* SMS style in story mode */
[data-message-type="sms"] .story-messages-float .message.sent:not(.message-image),
[data-message-type="sms"] .story-messages-overlay .message.sent:not(.message-image) {
    background: #34c759;
}

/* Light theme for story preview */
[data-theme="light"] .story-messages-float .message.received:not(.message-image),
[data-theme="light"] .story-messages-overlay .message.received:not(.message-image) {
    background: #e5e5ea;
    color: #000000;
}

[data-theme="light"] .story-typing-indicator {
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .story-typing-indicator .typing-dot {
    background: rgba(0, 0, 0, 0.6);
}

[data-theme="light"] .story-messages-float .date-separator,
[data-theme="light"] .story-messages-overlay .date-separator {
    color: rgba(0, 0, 0, 0.55);
}

/* Hide the bubble tails in story mode for cleaner look */
.story-messages-float .message::before,
.story-messages-float .message::after,
.story-messages-overlay .message::before,
.story-messages-overlay .message::after {
    display: none !important;
}

.story-messages-float .message.last,
.story-messages-overlay .message.last {
    margin-bottom: 8px;
}

/* Image messages in overlay - high specificity to override general message styles */
.story-messages-float .message.message-image,
.story-messages-overlay .message.message-image {
    padding: 0 !important;
    background: none !important;
    border-radius: 24px !important;
    overflow: visible !important;
    margin-bottom: 12px !important;
    max-width: 380px !important;
    width: auto !important;
    height: auto !important;
    min-height: unset !important;
    max-height: none !important;
    line-height: 0 !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    flex-basis: auto !important;
}

.story-messages-float .message.message-image.sent,
.story-messages-overlay .message.message-image.sent {
    align-self: flex-end !important;
    margin-left: auto !important;
    margin-right: 0 !important;
    background: none !important;
}

.story-messages-float .message.message-image.received,
.story-messages-overlay .message.message-image.received {
    align-self: flex-start !important;
    margin-right: auto !important;
    margin-left: 0 !important;
    background: none !important;
}

.story-messages-float .message.message-image img,
.story-messages-overlay .message.message-image img {
    display: block !important;
    border-radius: 24px !important;
    max-width: 380px !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    min-height: unset !important;
    clip: auto !important;
    clip-path: none !important;
}

.story-messages-float .date-separator-wrapper,
.story-messages-overlay .date-separator-wrapper {
    text-align: center;
    width: 100%;
}

.story-messages-float .date-separator,
.story-messages-overlay .date-separator {
    font-size: 20px;
    color: rgba(255, 255, 255, 0.6);
    cursor: default;
    background: none;
    padding: 8px 0;
}

/* Typing indicator in overlay mode */
.story-overlay-box .story-typing-indicator {
    display: none;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    padding: 14px 18px;
    border-radius: 22px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    margin-right: 40px;
}

.story-overlay-box .story-typing-indicator.active {
    display: flex;
}

.story-overlay-box .story-typing-indicator .typing-dot {
    width: 10px;
    height: 10px;
}

/* Square format adjustments */
.story-phone-frame.square-format .story-chat-container {
    top: 50px;
    width: 90%;
    border-radius: 24px;
}

.story-phone-frame.square-format .story-header {
    padding: 12px 20px;
}

.story-phone-frame.square-format .story-header-top {
    margin-bottom: 8px;
}

.story-phone-frame.square-format .story-back-btn svg {
    width: 26px;
    height: 26px;
}

.story-phone-frame.square-format .story-back-badge {
    font-size: 18px;
    padding: 3px 10px;
}

.story-phone-frame.square-format .story-header-btn svg {
    width: 30px;
    height: 30px;
}

.story-phone-frame.square-format .story-avatar {
    width: 56px;
    height: 56px;
}

.story-phone-frame.square-format .story-avatar-letter {
    font-size: 24px;
}

.story-phone-frame.square-format .story-contact-name-container {
    padding: 10px 14px 10px 18px;
}

.story-phone-frame.square-format .story-contact-name {
    font-size: 20px;
}

.story-phone-frame.square-format .story-contact-chevron svg {
    width: 18px;
    height: 18px;
}

.story-phone-frame.square-format .story-messages-float {
    padding: 16px;
}

.story-phone-frame.square-format .story-messages-float .message:not(.message-image) {
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 26px;
}

.story-phone-frame.square-format .story-typing-indicator {
    padding: 14px 18px;
    border-radius: 24px;
}

.story-phone-frame.square-format .story-typing-indicator .typing-dot {
    width: 11px;
    height: 11px;
}

/* Square format image sizing */
.story-phone-frame.square-format .story-messages-float .message.message-image,
.story-phone-frame.square-format .story-messages-overlay .message.message-image {
    max-width: 320px !important;
    border-radius: 20px !important;
}

.story-phone-frame.square-format .story-messages-float .message.message-image img,
.story-phone-frame.square-format .story-messages-overlay .message.message-image img {
    max-width: 320px !important;
    border-radius: 20px !important;
}

/* Typing indicator in story mode - flows with messages */
.story-phone-frame .story-typing-indicator {
    display: none;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    padding: 16px 22px;
    border-radius: 28px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    margin-right: 60px;
    margin-left: 0;
}

.story-phone-frame .story-typing-indicator.active {
    display: flex;
}

.story-phone-frame .story-typing-indicator .typing-dots {
    display: flex;
    gap: 8px;
}

.story-phone-frame .story-typing-indicator .typing-dot {
    width: 14px;
    height: 14px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

/* Story overlay controls */
.story-overlay-controls {
    position: fixed;
    top: max(20px, var(--safe-area-top));
    right: max(20px, var(--safe-area-right));
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 520;
}

.story-overlay-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: none;
    border-radius: 25px;
    padding: 12px 18px;
    min-height: var(--touch-target);
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.story-overlay-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.story-overlay-btn:active {
    transform: scale(0.95);
}

.story-overlay-btn svg {
    width: 20px;
    height: 20px;
}

/* Progress bar - inside the frame */
.story-overlay-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    overflow: hidden;
    z-index: 15;
}

.story-overlay-progress-bar {
    height: 100%;
    background: white;
    width: 0%;
    transition: width 0.3s ease-out;
}

/* Message animation in story mode - only for subsequent messages */
.story-messages-float .message.story-new,
.story-messages-overlay .message.story-new {
    animation: storyMessagePop 0.15s ease-out forwards;
}

/* First message appears instantly with the container */
.story-messages-overlay:not(.has-content) .message,
.story-messages-float:not(.has-content) .message {
    animation: none;
}

@keyframes storyMessagePop {
    0% {
        opacity: 0.5;
        transform: scale(0.96);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Recording status indicator */
.story-recording-status {
    position: fixed;
    top: max(20px, var(--safe-area-top));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 59, 48, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px 20px;
    border-radius: 25px;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 520;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.story-recording-status.active {
    display: flex;
}

.story-recording-status .recording-dot {
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    animation: recordingPulse 1s ease-in-out infinite;
}

/* Record button style */
.story-overlay-btn.story-overlay-record {
    background: rgba(255, 59, 48, 0.8);
}

.story-overlay-btn.story-overlay-record:hover {
    background: rgba(255, 59, 48, 1);
}

.story-overlay-btn.story-overlay-record.recording {
    background: rgba(255, 59, 48, 1);
    animation: recordingPulse 1s ease-in-out infinite;
}

/* ==========================================
   iOS & iPad RESPONSIVE ENHANCEMENTS
   ========================================== */

/* iPad Mini and larger - optimize layout */
@media (min-width: 768px) {
    /* Larger message bubbles for iPad */
    .message {
        max-width: 65%;
        font-size: 18px;
        padding: 12px 16px;
    }
    
    /* Larger avatar on iPad */
    .avatar {
        width: 68px;
        height: 68px;
    }
    
    .avatar-letter {
        font-size: 28px;
    }
    
    /* Better spacing in messages */
    .messages-container {
        padding: 20px 24px;
    }
    
    /* Larger input area */
    .text-input {
        font-size: 18px;
    }
    
    /* Story preview frame adjustments for iPad */
    .story-overlay-mode {
        padding: 40px;
    }
    
    /* Larger format cards on iPad */
    .format-card {
        padding: 16px;
    }
    
    .format-preview.format-9-16 {
        max-height: 280px;
    }
}

/* iPad Pro landscape */
@media (min-width: 1024px) and (orientation: landscape) {
    .story-overlay-controls {
        flex-direction: row;
        top: auto;
        bottom: max(40px, var(--safe-area-bottom));
        right: 50%;
        transform: translateX(50%);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover states - use active instead */
    .header-btn:hover,
    .settings-close:hover,
    .export-modal-close:hover,
    .story-overlay-btn:hover,
    .quick-mode-btn:hover,
    .speed-option:hover,
    .mode-option:hover {
        background: inherit;
    }
    
    /* Ensure minimum touch targets everywhere */
    .contact-name-container {
        min-height: var(--touch-target);
    }
    
    .date-separator {
        padding: 8px 16px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
    }
    
    /* Better tap feedback */
    .message[data-message-index]:not(.editing):active {
        opacity: 0.8;
    }
    
    /* Larger voice buttons on touch */
    .voice-btn-generate,
    .voice-btn-test,
    .voice-btn-clear {
        padding: 14px 18px;
        min-height: var(--touch-target);
    }
}

/* Standalone PWA mode (added to home screen) */
@media (display-mode: standalone) {
    /* Adjust for no browser chrome */
    .header {
        padding-top: max(16px, var(--safe-area-top));
    }
    
    /* Extra padding at bottom for home indicator */
    .input-container {
        padding-bottom: max(40px, calc(var(--safe-area-bottom) + 12px));
    }
}

/* Dark mode preference (auto-detect) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
    }
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        color-scheme: light;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .typing-dot {
        animation: none;
        opacity: 0.6;
    }
    
    .recording-dot {
        animation: none;
    }
}

/* Landscape phone handling */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 8px 16px;
    }
    
    .contact-info {
        flex-direction: row;
        gap: 12px;
    }
    
    .avatar {
        width: 40px;
        height: 40px;
    }
    
    .avatar-letter {
        font-size: 18px;
    }
    
    .settings-panel {
        max-height: 95vh;
    }
    
    .settings-content {
        max-height: calc(95vh - 80px);
    }
    
    /* Hide non-essential elements in landscape */
    .story-controls {
        bottom: max(20px, var(--safe-area-bottom));
        padding: 8px 16px;
    }
}