: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: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;
}

/* 计时器 */
.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;
}

/* ===== 平板 / 桌面端 ===== */
@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 > .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;
    }
}
