/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== Variables ===== */
:root {
    --color-bg: #F8FAFB;
    --color-card: #ffffff;
    --color-white: #ffffff;
    --color-text: #1a1a1a;
    --color-text-light: #999999;
    --color-icon-disabled: #c0c0c0;
    --color-icon-active: #333333;
    --color-border: #e8e8e8;
    --color-annotation: #999999;
    --header-height: 54px;
    --radius-card: 12px;
    --card-padding: 24px;
    --card-divisor: 2.5;
}

html {
    height: 100%;
    background: linear-gradient(180deg, #ffffff calc(54px + env(safe-area-inset-top, 0px)), #F8FAFB calc(54px + env(safe-area-inset-top, 0px)));
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
                 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue',
                 Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* White cover for notch / status-bar safe area */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    background: #ffffff;
    z-index: 999;
    pointer-events: none;
}

/* ===== Header ===== */
.header {
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.header-logo {
    height: 14px;
    width: auto;
    display: block;
}

.header-right {
    position: relative;
    display: flex;
    align-items: center;
}

.header-setting {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text);
    border-radius: 6px;
    transition: background 0.15s;
}

.header-setting:hover {
    background: rgba(0,0,0,0.06);
}

.header-setting svg {
    fill: currentColor;
}

/* ===== Settings Panel ===== */
.settings-panel {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 220px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    padding: 8px 0;
    z-index: 1000;
    display: none;
}

.settings-panel.open {
    display: block;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
}

.settings-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-item-flag {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    overflow: hidden;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

.settings-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
}

.switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.slider {
    position: absolute;
    inset: 0;
    background: #e0e0e0;
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.switch input:checked + .slider {
    background: #1a1a1a;
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
}

.switch input:disabled + .slider {
    opacity: 0.4;
    cursor: default;
}

/* ===== Main ===== */
.main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px 24px 0;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

/* ===== Language Card ===== */
.language-card {
    background: var(--color-card);
    border-radius: var(--radius-card);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    height: calc((100vh - 110px) / var(--card-divisor));
    min-height: 220px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: var(--card-padding) var(--card-padding) 0;
    flex-shrink: 0;
}

.card-flag {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    overflow: hidden;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

.card-lang {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text);
}

/* ===== Card Body ===== */
.card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px var(--card-padding) 0;
    min-height: 0;
    overflow: hidden;
    cursor: text;
}

.card-textarea {
    width: 100%;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1.6;
    resize: none;
    font-family: inherit;
    color: var(--color-text);
    outline: none;
    overflow-y: auto;
    flex-shrink: 0;
}

.card-textarea::placeholder {
    color: #D0D5DC;
}

.card-textarea.translating {
    opacity: 0.5;
}

/* ===== Annotation (Pinyin / Phonetic) ===== */
.card-annotation {
    font-size: 14px;
    line-height: 1.4;
    color: var(--color-annotation);
    margin: 2px 0 0;
    padding: 0;
    display: none;
    flex-shrink: 0;
}

.card-annotation.visible {
    display: block;
}

/* ===== Card Toolbar ===== */
.card-toolbar {
    display: flex;
    align-items: center;
    gap: 40px;
    padding: 12px var(--card-padding) var(--card-padding);
    flex-shrink: 0;
    margin-top: auto;
}

.tool-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--color-icon-disabled);
    transition: color 0.15s, background 0.15s;
    position: relative;
}

.tool-btn svg {
    fill: currentColor;
    display: block;
}

/* ===== Tooltip bubble (PC only) ===== */
@media (hover: hover) {
    .tool-btn[data-tip]::before {
        content: attr(data-tip);
        position: absolute;
        bottom: calc(100% + 4px);
        left: 50%;
        transform: translateX(-50%);
        padding: 6px 12px;
        background: var(--color-card);
        color: var(--color-text-light);
        font-size: 13px;
        font-weight: 500;
        line-height: 1.4;
        white-space: nowrap;
        border-radius: 8px;
        border: 1px solid var(--color-border);
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s;
        z-index: 10;
    }

    .tool-btn[data-tip]:hover::before {
        opacity: 1;
    }
}

.tool-btn:disabled {
    cursor: default;
    color: var(--color-icon-disabled);
}

.tool-btn:not(:disabled) {
    color: var(--color-icon-active);
}

/* PC: hover shows background */
@media (hover: hover) {
    .tool-btn:not(:disabled):hover {
        background: rgba(0,0,0,0.06);
    }

    .tool-btn:not(:disabled):active {
        background: rgba(0,0,0,0.1);
    }
}

/* Touch: only show background while finger is down */
@media (hover: none) {
    .tool-btn:not(:disabled):active {
        background: rgba(0,0,0,0.08);
    }

    .tool-btn {
        -webkit-tap-highlight-color: transparent;
    }
}

/* Toggle button active state - circular pressed background */
.tool-btn.toggle-btn.active {
    background: rgba(0,0,0,0.08);
}

/* Speaking state: show filled icon, hide line icon */
.speak-btn.speaking .icon-volume {
    display: none !important;
}

.speak-btn.speaking .icon-volume-press {
    display: block !important;
}

.speak-btn .icon-volume {
    display: block;
}

.speak-btn .icon-volume-press {
    display: none;
}

/* ===== Footer ===== */
.footer {
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    padding: 24px 24px 32px;
    text-align: left;
    font-size: 12px;
    color: var(--color-text-light);
    flex-shrink: 0;
}

.footer strong {
    font-weight: 700;
    color: var(--color-text);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .header {
        padding: env(safe-area-inset-top, 0px) 16px 0;
    }

    .main {
        padding: 16px 16px 0;
        gap: 12px;
    }

    .language-card {
        height: calc((100vh - 94px) / var(--card-divisor));
        min-height: 180px;
    }

    .card-header {
        padding: 20px 20px 0;
    }

    .card-body {
        padding: 8px 20px 0;
    }

    .card-toolbar {
        padding: 10px 20px 20px;
        gap: 32px;
    }

    .card-textarea {
        font-size: 20px;
    }

    .card-lang {
        font-size: 20px;
    }

    .footer {
        padding: 20px 16px 28px;
    }

    .settings-panel {
        width: 200px;
    }
}
