:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --secondary: #64748b;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    font-size: 16px;
}

.app {
    max-width: 900px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* 顶部标题 */
.header {
    text-align: center;
    padding: 1rem 1rem 0.75rem;
    background: linear-gradient(180deg, #fff 0%, var(--bg) 100%);
}

.header h1 {
    font-size: 1.35rem;
    margin-bottom: 0.15rem;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--muted);
    font-size: 0.8rem;
}

/* 浏览器提示 */
.browser-tip {
    margin: 0 1rem 0.75rem;
    padding: 0.7rem 0.85rem;
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
    border-radius: 0.6rem;
    font-size: 0.8rem;
    line-height: 1.5;
    display: none;
}

/* 导航标签 - 手机端 3+2 网格 */
.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    padding: 0 1rem;
    margin-bottom: 0.75rem;
}

.tab {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--muted);
    border-radius: 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    min-height: 46px;
    padding: 0.45rem 0.35rem;
    text-align: center;
    transition: all 0.15s ease;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

/* 主内容区 */
.main {
    flex: 1;
    padding: 0 1rem 1rem;
    min-width: 0;
}

.panel {
    display: none;
    animation: fadeIn 0.2s ease;
}

.panel.active {
    display: block;
}

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

/* 面板标题栏 */
.panel-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.panel-header-controls {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.panel-header-controls .btn,
.panel-header-controls select {
    flex: 1;
    min-width: 0;
}

.panel-header > .btn {
    align-self: flex-start;
}

/* 卡片 */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
}

.tag {
    display: inline-block;
    background: #e0e7ff;
    color: var(--primary-dark);
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
}

.card h3 {
    font-size: 1.05rem;
    margin-bottom: 0.6rem;
    line-height: 1.4;
}

.card ul {
    list-style: none;
}

.card li {
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0.25rem 0;
    padding-left: 1.1rem;
    position: relative;
    line-height: 1.5;
}

.card li::before {
    content: "•";
    color: var(--primary);
    position: absolute;
    left: 0;
    font-weight: 700;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.65rem 1rem;
    border-radius: 0.55rem;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.15s ease;
    min-height: 46px;
    touch-action: manipulation;
    white-space: nowrap;
}

.btn.primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
}

.btn.primary:hover,
.btn.primary:active {
    background: var(--primary-dark);
}

.btn.secondary {
    background: #f1f5f9;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.secondary:hover,
.btn.secondary:active {
    background: #e2e8f0;
}

.btn.mic {
    background: var(--success);
    color: #fff;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.2);
}

.btn.mic:hover,
.btn.mic:active {
    background: #059669;
}

.btn.mic.recording {
    background: var(--danger);
    animation: pulse 1.2s infinite;
}

.btn.danger {
    background: var(--danger);
    color: #fff;
}

.btn.danger:hover,
.btn.danger:active {
    background: #dc2626;
}

.user-id-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.user-id-bar code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: var(--text);
    background: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 0.3rem;
    border: 1px solid var(--border);
}

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

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

/* 下拉框 */
select {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    font-size: 0.9rem;
    background: #fff;
    color: var(--text);
    min-height: 46px;
}

/* 输入区 */
.input-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.input-area input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    font-size: 1rem;
    min-height: 46px;
}

.input-area .btn {
    width: 100%;
}

/* AI 对话 */
#panel-chat.active {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-messages {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    flex: 1;
    min-height: 220px;
    height: 42vh;
    max-height: 420px;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    box-shadow: var(--shadow);
}

.message {
    max-width: 88%;
    padding: 0.65rem 0.85rem;
    border-radius: 0.7rem;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 0.2rem;
}

.message.ai {
    align-self: flex-start;
    background: #f1f5f9;
    color: var(--text);
    border-bottom-left-radius: 0.2rem;
}

.message.system {
    align-self: center;
    background: #fff7ed;
    color: #9a3412;
    font-size: 0.8rem;
    max-width: 96%;
    padding: 0.4rem 0.7rem;
}

.message.user.interim {
    align-self: flex-end;
    background: #e2e8f0;
    color: #64748b;
    border-bottom-right-radius: 0.2rem;
}

/* 计时器 */
.timer-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

#timer {
    font-family: "SF Mono", Consolas, monospace;
    font-size: 1.5rem;
    color: var(--primary);
    min-width: 78px;
    font-weight: 600;
}

.timer-box .btn {
    flex: 1;
}

/* 影子跟读文本 */
.shadow-text {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
}

.hint {
    margin-top: 0.6rem;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

/* 操作按钮组 */
.actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.actions .btn {
    width: 100%;
}

/* 结果框 */
.result-box {
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: 0.75rem;
    padding: 0.85rem;
}

.result-box h4 {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.result-text {
    font-size: 0.95rem;
    color: var(--text);
    min-height: 1.5rem;
    line-height: 1.55;
    word-break: break-word;
}

/* 无法录音时的手动输入 fallback */
.text-fallback {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.text-fallback textarea,
.text-fallback input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 46px;
}

.text-fallback textarea {
    min-height: 80px;
}

/* 录音回放 */
.audio-wrap {
    margin: 0.75rem 0;
}

.playback-audio {
    width: 100%;
    height: 44px;
    border-radius: 0.55rem;
}

/* 每日表达 */
.expression-card .expr-en {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 0.2rem;
    line-height: 1.4;
}

.expression-card .expr-zh {
    color: var(--muted);
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}

.expression-card .expr-example {
    font-style: italic;
    color: var(--text);
    line-height: 1.55;
    font-size: 0.95rem;
}

/* 练习记录 */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.7rem 0.85rem;
    font-size: 0.9rem;
    box-shadow: var(--shadow);
}

.history-item time {
    color: var(--muted);
    font-size: 0.75rem;
    display: block;
    margin-bottom: 0.2rem;
}

.history-item strong {
    color: var(--primary-dark);
    font-weight: 600;
}

/* 提示 */
.tip {
    margin-top: 0.5rem;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.5;
}

/* 页脚 */
.footer {
    text-align: center;
    padding: 0.75rem 1rem;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.5;
}

.footer .icp {
    font-size: 0.65rem;
    margin-top: 0.25rem;
}

/* 雅思口语 */
.ielts-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: #e0e7ff;
    color: #4f46e5;
    font-size: 0.75rem;
    font-weight: 600;
}

#ielts-card {
    margin-bottom: 0.75rem;
}

#ielts-card h3 {
    margin-bottom: 0.5rem;
    color: #4f46e5;
}

#ielts-points {
    margin-top: 0.5rem;
    padding-left: 1.2rem;
    color: var(--text);
}

#ielts-points li {
    margin-bottom: 0.25rem;
}

/* 手机端隐藏文字输入框和发送按钮，只留麦克风 */
@media (max-width: 639px) {
    .input-area input,
    .input-area .btn {
        display: none;
    }

    .input-area .mic {
        display: block;
        width: 100%;
    }

    .input-area {
        flex-direction: column;
        gap: 0;
    }
}

/* ===== 平板 / 桌面端 ===== */
@media (min-width: 640px) {
    .header {
        padding: 1.5rem 1rem 1rem;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .tabs {
        display: flex;
        justify-content: center;
        gap: 0.5rem;
    }

    .tab {
        flex: 1 1 0;
        max-width: 150px;
        min-width: 100px;
        font-size: 0.9rem;
        padding: 0.6rem 0.75rem;
        white-space: nowrap;
    }

    .panel-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .panel-header h2 {
        font-size: 1.25rem;
    }

    .panel-header-controls {
        width: auto;
        justify-content: flex-end;
    }

    .panel-header-controls select {
        flex: 0 0 auto;
        min-width: 120px;
        width: auto;
    }

    .panel-header > .btn {
        align-self: center;
    }

    .actions {
        flex-direction: row;
    }

    .actions .btn {
        width: auto;
        flex: 1 1 0;
    }

    .input-area {
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .input-area input {
        flex: 1;
        width: auto;
    }

    .input-area .btn {
        width: auto;
    }

    .chat-messages {
        height: 380px;
        padding: 1rem;
    }

    .timer-box {
        gap: 1rem;
    }

    #timer {
        font-size: 1.8rem;
    }
}

/* ===== MiscHub 首页模块卡片 ===== */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    padding: 24px 0;
}

.module-card {
    display: block;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 28px 22px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
}

.module-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.module-icon {
    font-size: 2.4rem;
    margin-bottom: 12px;
}

.module-card h2 {
    margin: 0 0 8px;
    font-size: 1.25rem;
}

.module-card p {
    margin: 0;
    color: #6b7280;
    font-size: 0.92rem;
    line-height: 1.6;
}

.module-status {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 999px;
}

.module-status.available {
    background: #dcfce7;
    color: #15803d;
}

.module-status.coming {
    background: #fef3c7;
    color: #b45309;
}

.placeholder-box {
    background: #fff;
    border: 1px dashed #d1d5db;
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    color: #6b7280;
}

.placeholder-box p {
    margin: 8px 0;
}

.back-home {
    margin-top: 8px;
    font-size: 0.85rem;
}

.back-home a {
    color: #6366f1;
    text-decoration: none;
}

.back-home a:hover {
    text-decoration: underline;
}

/* ===== 全站统一排版（Flask 页面） ===== */
.header h1 { font-size: 1.4rem; }
.header .subtitle { font-size: 0.85rem; }
.panel h2 { font-size: 1.15rem; }
.card h3 { font-size: 1.05rem; }
.card h4 { font-size: 0.95rem; }
body { line-height: 1.65; }

@media (max-width: 639px) {
    .header h1 { font-size: 1.25rem; }
    .header .subtitle { font-size: 0.8rem; }
    .panel h2 { font-size: 1.05rem; }
    .card h3 { font-size: 1rem; }
    body { font-size: 15px; }
}

/* ===== 高清发音开关 ===== */
.hd-toggle {
    text-align: center;
    margin: 8px 0;
    font-size: 0.85rem;
    color: #4b5563;
}

.hd-toggle label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    padding: 5px 14px;
    cursor: pointer;
}

.hd-toggle input { accent-color: #4f46e5; }
