* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --font-ui: "Avenir Next", "SF Pro Display", "Segoe UI", sans-serif;
    --font-body: "SF Pro Text", "Avenir Next", "Segoe UI", sans-serif;

    --bg-top: #0a101f;
    --bg-mid: #141a31;
    --bg-bottom: #17102a;

    --glass: rgba(18, 26, 50, 0.72);
    --glass-strong: rgba(14, 21, 42, 0.88);
    --surface-soft: rgba(146, 179, 255, 0.16);
    --surface-border: rgba(179, 203, 255, 0.2);

    --primary: #6cb3ff;
    --primary-strong: #3d91f2;
    --accent: #5ee7c7;

    --text-primary: #f3f7ff;
    --text-secondary: #aab7d2;
    --text-dim: #8493b0;

    --user-bubble: linear-gradient(135deg, #4f8df6 0%, #6f66ff 100%);
    --ai-bubble: linear-gradient(140deg, rgba(43, 57, 98, 0.92) 0%, rgba(27, 36, 64, 0.96) 100%);

    --success: #45dba8;
    --error: #ff7a90;

    --shadow-lg: 0 22px 46px rgba(6, 10, 25, 0.5);
    --shadow-md: 0 12px 28px rgba(4, 8, 22, 0.35);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
}

body {
    font-family: var(--font-body);
    min-height: 100vh;
    color: var(--text-primary);
    background:
        radial-gradient(circle at 12% 12%, rgba(95, 190, 255, 0.2) 0%, rgba(95, 190, 255, 0) 35%),
        radial-gradient(circle at 88% 16%, rgba(120, 110, 255, 0.18) 0%, rgba(120, 110, 255, 0) 36%),
        radial-gradient(circle at 78% 82%, rgba(79, 227, 187, 0.13) 0%, rgba(79, 227, 187, 0) 38%),
        linear-gradient(165deg, var(--bg-top) 0%, var(--bg-mid) 56%, var(--bg-bottom) 100%);
    overflow: hidden;
}

body::before,
body::after {
    content: "";
    position: fixed;
    z-index: 0;
    pointer-events: none;
    border-radius: 999px;
    filter: blur(60px);
}

body::before {
    width: 280px;
    height: 280px;
    left: -60px;
    top: 24%;
    background: rgba(66, 166, 255, 0.2);
}

body::after {
    width: 320px;
    height: 320px;
    right: -90px;
    bottom: 12%;
    background: rgba(110, 92, 255, 0.22);
}

.app-container {
    position: relative;
    z-index: 1;
    max-width: 940px;
    height: calc(100vh - 32px);
    margin: 16px auto;
    border-radius: 28px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--surface-border);
    background: linear-gradient(160deg, rgba(19, 27, 49, 0.78) 0%, rgba(11, 18, 37, 0.84) 100%);
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow-lg);
}

.header {
    position: relative;
    padding: 22px 70px 18px;
    text-align: center;
    border-bottom: 1px solid rgba(159, 186, 255, 0.16);
    background: linear-gradient(160deg, rgba(33, 47, 83, 0.62), rgba(17, 27, 53, 0.44));
}

.header h1 {
    font-family: var(--font-ui);
    font-weight: 700;
    letter-spacing: 0.02em;
    font-size: 32px;
    line-height: 1;
    background: linear-gradient(120deg, #d7e6ff 0%, #8cc7ff 42%, #5ee7c7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header .subtitle {
    margin-top: 8px;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
}

#settings-btn {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
}

.status-bar {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(159, 186, 255, 0.1);
    background: rgba(14, 21, 43, 0.65);
}

.status-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-secondary);
    background: rgba(171, 197, 255, 0.08);
    border: 1px solid rgba(171, 197, 255, 0.16);
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--error);
    box-shadow: 0 0 0 4px rgba(255, 122, 144, 0.15);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(69, 219, 168, 0.18);
}

.status-dot.offline {
    background: var(--error);
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 24px 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.welcome-message {
    margin: 44px auto 18px;
    max-width: 660px;
    border: 1px solid rgba(164, 196, 255, 0.2);
    border-radius: var(--radius-lg);
    background: linear-gradient(155deg, rgba(90, 140, 250, 0.14), rgba(83, 227, 196, 0.1));
    padding: 24px 24px;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.welcome-message h2 {
    font-size: 26px;
    letter-spacing: 0.01em;
    margin-bottom: 10px;
}

.welcome-message p {
    color: var(--text-secondary);
    line-height: 1.6;
}

.welcome-message .tip {
    margin-top: 14px;
    color: #9deedc;
    font-size: 13px;
}

.message {
    position: relative;
    max-width: min(78%, 720px);
    border-radius: 18px;
    line-height: 1.62;
    padding: 13px 14px;
    border: 1px solid transparent;
    box-shadow: var(--shadow-md);
    animation: messageIn 0.28s ease;
}

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

.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    border-bottom-right-radius: 6px;
    border-color: rgba(224, 236, 255, 0.26);
}

.message.ai {
    align-self: flex-start;
    background: var(--ai-bubble);
    border-bottom-left-radius: 6px;
    border-color: rgba(163, 188, 243, 0.22);
}

.message .message-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.message .speaker-btn {
    margin-top: 8px;
    margin-left: 2px;
    padding: 6px;
    border: 1px solid rgba(175, 198, 255, 0.3);
    border-radius: 999px;
    background: rgba(159, 188, 255, 0.1);
    color: #c9ddff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}

.message .speaker-btn:hover {
    background: rgba(114, 191, 255, 0.24);
    color: #f6fbff;
    transform: translateY(-1px);
}

.correction {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    border-left: 4px solid #f2c74f;
    background: linear-gradient(145deg, rgba(255, 236, 194, 0.97), rgba(255, 222, 157, 0.9));
    color: #3f2a00;
}

.correction-label {
    font-weight: 700;
    margin-bottom: 6px;
}

.correction-original {
    color: #94434d;
    text-decoration: line-through;
    margin-bottom: 4px;
}

.correction-fixed {
    color: #1d5f34;
    font-weight: 600;
    margin-bottom: 4px;
}

.correction-explanation {
    color: #6d4d07;
    font-size: 13px;
}

.input-area {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px 16px;
    border-top: 1px solid rgba(159, 186, 255, 0.12);
    background: linear-gradient(180deg, rgba(20, 30, 57, 0.78), rgba(10, 16, 33, 0.94));
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-radius: 18px;
    border: 1px solid rgba(165, 193, 255, 0.2);
    background: rgba(133, 170, 255, 0.11);
    padding: 8px 12px;
}

#text-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    padding: 8px 0;
    resize: none;
    max-height: 108px;
}

#text-input::placeholder {
    color: var(--text-dim);
}

.send-btn {
    border: 1px solid rgba(143, 182, 255, 0.3);
    border-radius: 12px;
    background: rgba(111, 170, 255, 0.18);
    color: #d6ebff;
    cursor: pointer;
    padding: 8px;
    display: inline-flex;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.send-btn:hover {
    background: rgba(98, 175, 255, 0.28);
    color: #ffffff;
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.mic-btn {
    width: 56px;
    height: 56px;
    border: 1px solid rgba(187, 216, 255, 0.34);
    border-radius: 50%;
    color: white;
    background: linear-gradient(145deg, #4f9fff, #5e6dff);
    box-shadow: 0 12px 20px rgba(42, 89, 194, 0.36);
    cursor: pointer;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.mic-btn:hover {
    transform: translateY(-1px) scale(1.03);
    filter: saturate(1.08);
}

.mic-btn.recording {
    background: linear-gradient(145deg, #ff6e8f, #ff8c7e);
    box-shadow: 0 12px 22px rgba(208, 65, 97, 0.42);
    animation: recordingPulse 1.5s infinite;
}

@keyframes recordingPulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

.mic-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mic-ripple {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(138, 193, 255, 0.8);
    opacity: 0;
    pointer-events: none;
}

.mic-btn.recording .mic-ripple {
    animation: ripple 1.5s infinite;
}

@keyframes ripple {
    0% {
        transform: scale(1);
        opacity: 0.65;
    }
    100% {
        transform: scale(1.95);
        opacity: 0;
    }
}

.icon-btn {
    border: 1px solid rgba(166, 195, 255, 0.22);
    border-radius: 12px;
    background: rgba(136, 174, 255, 0.1);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.icon-btn:hover {
    color: var(--text-primary);
    background: rgba(125, 173, 255, 0.2);
    transform: translateY(-1px);
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    background: rgba(5, 9, 21, 0.68);
    backdrop-filter: blur(4px);
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    width: min(560px, 100%);
    border-radius: 22px;
    border: 1px solid rgba(159, 188, 255, 0.24);
    background: linear-gradient(170deg, rgba(24, 34, 66, 0.95), rgba(15, 24, 47, 0.98));
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(162, 190, 255, 0.16);
}

.modal-header h2 {
    font-family: var(--font-ui);
    font-size: 20px;
    letter-spacing: 0.01em;
}

.close-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    max-height: min(72vh, 640px);
    overflow-y: auto;
    padding: 18px 20px;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.setting-group select,
.setting-group input[type="text"] {
    width: 100%;
    border: 1px solid rgba(162, 191, 255, 0.22);
    border-radius: 12px;
    background: rgba(132, 169, 255, 0.1);
    color: var(--text-primary);
    padding: 11px 12px;
    font-size: 14px;
}

.setting-group select:focus,
.setting-group input[type="text"]:focus {
    outline: none;
    border-color: rgba(113, 188, 255, 0.8);
    box-shadow: 0 0 0 3px rgba(90, 178, 255, 0.2);
}

.setting-group input[type="range"] {
    width: calc(100% - 56px);
    vertical-align: middle;
}

.setting-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #7eb9ff;
    cursor: pointer;
}

#tts-speed-value {
    margin-left: 10px;
    color: #9bd9ff;
    font-weight: 600;
}

.test-btn {
    margin-top: 10px;
    border: 1px solid rgba(126, 188, 255, 0.34);
    border-radius: 10px;
    background: rgba(101, 168, 255, 0.18);
    color: #dcf2ff;
    cursor: pointer;
    font-size: 12px;
    padding: 7px 12px;
    transition: background 0.2s ease;
}

.test-btn:hover {
    background: rgba(104, 186, 255, 0.32);
}

.setting-hint {
    margin-top: 8px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.45;
}

#voice-select {
    font-size: 13px;
}

.modal-footer {
    padding: 14px 20px 18px;
    text-align: right;
    border-top: 1px solid rgba(162, 190, 255, 0.16);
}

.primary-btn {
    border: 1px solid rgba(153, 203, 255, 0.3);
    border-radius: 12px;
    background: linear-gradient(135deg, #5ea6ff, #50d6c1);
    color: #062035;
    font-size: 14px;
    font-weight: 700;
    padding: 10px 22px;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.2s ease;
}

.primary-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.typing-indicator {
    align-self: flex-start;
    display: inline-flex;
    gap: 6px;
    border-radius: 999px;
    padding: 9px 12px;
    border: 1px solid rgba(164, 191, 246, 0.22);
    background: rgba(39, 51, 86, 0.88);
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b9caf0;
    animation: typing 1.4s infinite;
}

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

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

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

.chat-container::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 8px;
}

.chat-container::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    border-radius: 8px;
    background: rgba(145, 176, 241, 0.45);
}

.chat-container::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(145, 176, 241, 0.65);
}

@media (max-width: 860px) {
    .app-container {
        margin: 0;
        height: 100vh;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .header {
        padding: 18px 58px 16px;
    }

    .header h1 {
        font-size: 28px;
    }

    .chat-container {
        padding: 18px 14px 12px;
    }

    .message {
        max-width: 90%;
    }

    .input-area {
        gap: 10px;
        padding: 10px 12px 12px;
    }

    .mic-btn {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 560px) {
    .header .subtitle {
        font-size: 11px;
    }

    .status-bar {
        justify-content: flex-start;
    }

    .status-item {
        font-size: 11px;
    }

    .welcome-message {
        margin-top: 22px;
        padding: 18px 14px;
    }

    .welcome-message h2 {
        font-size: 22px;
    }

    .message {
        max-width: 96%;
        font-size: 14px;
    }

    #text-input {
        font-size: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
