:root {
    --app-height: 100dvh;
    --keyboard-inset: 0px;
    --primary-blue: #1a73e8;
    --primary-blue-hover: #174ea6;
    --primary-blue-light: #e8f0fe;
    --bg-color: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #f1f3f4;
    --text-main: #202124;
    --text-secondary: #5f6368;
    --divider-color: #e8eaed;
    --divider-blue: #a8c7fa;
    --fab-bg: #c2e7ff;
    --fab-text: #001d35;
    --shadow-sm: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    --shell-padding: 20px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    min-height: var(--app-height);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #e8eaed;
    display: flex;
    justify-content: center;
    align-items: stretch;
    color: var(--text-main);
}

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 16px;
    top: 12px;
    z-index: 30;
    transform: translateY(-200%);
    background: #ffffff;
    color: var(--text-main);
    border-radius: 999px;
    padding: 10px 14px;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}

.skip-link:focus-visible {
    transform: translateY(0);
}

.material-symbols-rounded {
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
    font-size: 24px;
    color: var(--text-secondary);
    line-height: 1;
}

.icon-btn {
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.16s ease;
}

.icon-btn:hover {
    background-color: rgba(95, 99, 104, 0.04);
}

.icon-btn:active {
    background-color: rgba(95, 99, 104, 0.1);
    transform: scale(0.96);
}

.icon-btn:focus-visible,
.lang-btn:focus-visible,
.action-circle:focus-visible,
.fab-new:focus-visible,
.skip-link:focus-visible,
.avatar:focus-visible,
.text-input:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

.blue-icon .material-symbols-rounded {
    color: var(--primary-blue);
}

.app-container {
    position: relative;
    width: 100%;
    height: var(--app-height);
    min-height: var(--app-height);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color);
}

@media (min-width: 600px) {
    body {
        align-items: center;
        padding: 16px 0;
    }

    .app-container {
        max-width: 414px;
        min-height: 0;
        height: min(896px, calc(var(--app-height) - 24px));
        border-radius: 24px;
        box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15);
        border: 8px solid #ffffff;
    }
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: calc(8px + var(--safe-top)) 12px 8px 12px;
    min-height: calc(64px + var(--safe-top));
    flex-shrink: 0;
    background-color: var(--bg-color);
    z-index: 10;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.header-right {
    flex-shrink: 0;
}

.header-title-container {
    display: flex;
    align-items: center;
    min-width: 0;
    padding-left: 4px;
}

.app-logo-text,
.app-name-text,
.header-back-title {
    white-space: nowrap;
}

.app-logo-text {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.5px;
}

.app-name-text {
    font-size: 20px;
    color: var(--text-secondary);
    margin-left: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-back-title {
    font-size: 17px;
    font-weight: 500;
    margin-left: 4px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #1a73e8;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 14px;
    margin: 0 8px;
}

.state-typing .header-logo-mode,
.state-result .header-logo-mode {
    display: none;
}

.state-empty .header-back-mode {
    display: none;
}

.state-empty .action-history,
.state-empty .action-bookmark {
    display: none;
}

.state-typing .action-history,
.state-typing .action-bookmark,
.state-typing .action-pen {
    display: none;
}

main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 var(--shell-padding);
    overflow: hidden;
}

.keyboard-open.state-typing main {
    overflow-y: auto;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
}

.state-result main {
    overflow-y: auto;
    padding-bottom: calc(120px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scroll-behavior: smooth;
}

.keyboard-open.state-result main {
    padding-bottom: calc(24px + var(--safe-bottom));
}

.input-section {
    position: relative;
    display: flex;
    flex-direction: column;
    padding-top: 16px;
    min-height: 0;
    transition: all 0.24s ease;
}

.state-empty .input-section,
.state-typing .input-section {
    flex: 1;
}

.state-result .input-section {
    flex: 0 0 auto;
}

.lang-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: none;
}

.state-result .lang-label {
    display: block;
}

.text-input {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    overflow: hidden;
    background: transparent;
    color: var(--text-main);
    font-family: inherit;
    font-size: clamp(30px, 8.8vw, 42px);
    line-height: 1.14;
    min-height: 56px;
    max-height: 38vh;
    padding-right: 46px;
    word-break: break-word;
    scrollbar-width: none;
}

.text-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

.text-input::-webkit-scrollbar {
    display: none;
}

.state-result .text-input {
    font-size: clamp(24px, 6.8vw, 30px);
}

.input-pen-icon {
    position: absolute;
    right: 0;
    top: 16px;
}

.state-result .input-pen-icon {
    display: none;
}

.pronunciation {
    font-size: 15px;
    color: var(--text-secondary);
    margin-top: 12px;
    display: none;
    line-height: 1.45;
    min-height: 1.45em;
}

.state-result .pronunciation {
    display: block;
}

.input-spacer {
    flex: 1;
    min-height: 24px;
}

.state-result .input-spacer {
    display: none;
}

.action-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}

.action-icons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.divider {
    height: 1px;
    background-color: var(--divider-blue);
    margin: 20px 0 18px;
    width: 100%;
    opacity: 0.5;
    display: none;
}

.state-result .divider {
    display: block;
}

.result-section {
    display: none;
    flex-direction: column;
    padding-bottom: 8px;
    min-height: 0;
    animation: fadeIn 0.28s ease forwards;
}

.state-result .result-section {
    display: flex;
}

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

.target-lang-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--primary-blue);
    margin-bottom: 12px;
}

.translated-text {
    font-size: clamp(30px, 9vw, 42px);
    line-height: 1.16;
    color: var(--primary-blue);
    word-break: break-word;
    letter-spacing: -0.02em;
    font-weight: 500;
}

.pinyin {
    font-size: 15px;
    color: var(--primary-blue);
    margin-top: 12px;
    margin-bottom: 24px;
    line-height: 1.45;
    min-height: 1.45em;
}

.result-section[data-result-kind="error"] .translated-text {
    font-size: clamp(24px, 8vw, 34px);
    line-height: 1.2;
}

.result-section[data-result-kind="error"] .pinyin {
    color: var(--text-secondary);
}

.example-card {
    background-color: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    margin-top: 28px;
    border: 1px solid var(--divider-color);
}

.example-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.example-content {
    display: flex;
    gap: 12px;
    font-size: 17px;
    color: var(--text-main);
    line-height: 1.5;
}

.quote-icon {
    color: var(--text-main);
    font-size: 24px;
    font-family: Georgia, serif;
    line-height: 1;
    margin-top: -4px;
}

.bottom-area {
    flex-shrink: 0;
    padding: 12px var(--shell-padding) calc(20px + var(--safe-bottom)) var(--shell-padding);
    background-color: var(--bg-color);
    border-top: 1px solid rgba(232, 234, 237, 0.7);
}

.language-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    background-color: var(--bg-secondary);
    border-radius: 999px;
    padding: 4px 8px;
    margin-bottom: 18px;
}

.lang-btn {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    padding: 14px 0;
    font-size: clamp(14px, 3.8vw, 16px);
    font-weight: 500;
    color: var(--text-main);
    border-radius: 999px;
    transition: background-color 0.2s ease;
}

.lang-btn:active {
    background-color: var(--bg-tertiary);
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    align-items: center;
    justify-items: center;
    min-height: 76px;
}

.action-circle {
    width: min(56px, 15vw);
    height: min(56px, 15vw);
    min-width: 52px;
    min-height: 52px;
    border-radius: 50%;
    background-color: var(--bg-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    transition: transform 0.12s ease, background-color 0.2s ease;
}

.action-circle:active {
    transform: scale(0.95);
    background-color: var(--bg-tertiary);
}

.action-circle .material-symbols-rounded {
    color: var(--primary-blue);
    font-size: 26px;
}

.quick-primary {
    background-color: var(--primary-blue-light);
}

.mic-btn-large {
    width: min(72px, 18vw);
    height: min(72px, 18vw);
    min-width: 64px;
    min-height: 64px;
    background-color: var(--primary-blue);
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.3);
}

.mic-btn-large:active {
    background-color: var(--primary-blue-hover);
}

.mic-btn-large .material-symbols-rounded {
    color: white;
    font-size: 34px;
}

.state-typing .quick-actions {
    display: none;
}

.state-typing .language-bar {
    margin-bottom: 0;
}

.keyboard-open .bottom-area {
    padding-bottom: calc(12px + var(--safe-bottom));
}

.keyboard-open .fab-new {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.state-result .bottom-area {
    display: none;
}

.fab-new {
    position: absolute;
    right: 24px;
    bottom: calc(24px + var(--safe-bottom));
    background-color: var(--fab-bg);
    color: var(--fab-text);
    border: none;
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
}

.fab-new .material-symbols-rounded {
    color: var(--fab-text);
    font-size: 22px;
}

.state-result .fab-new {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

@media (max-width: 380px) {
    :root {
        --shell-padding: 16px;
    }

    .app-name-text {
        font-size: 18px;
    }

    .avatar {
        margin: 0 4px;
    }

    .quick-actions {
        gap: 10px;
    }

    .action-circle {
        width: min(52px, 15vw);
        height: min(52px, 15vw);
        min-width: 48px;
        min-height: 48px;
    }

    .mic-btn-large {
        width: min(68px, 18vw);
        height: min(68px, 18vw);
        min-width: 60px;
        min-height: 60px;
    }
}

@media (max-height: 720px) {
    .language-bar {
        margin-bottom: 12px;
    }

    .quick-actions {
        min-height: 68px;
    }

    .example-card {
        margin-top: 22px;
        padding: 16px;
    }
}

@media (max-height: 640px) {
    .keyboard-open.state-typing .input-section {
        padding-top: 12px;
    }

    .keyboard-open.state-result .text-input {
        font-size: clamp(22px, 7vw, 28px);
        max-height: 22vh;
    }

    .keyboard-open.state-result .translated-text {
        font-size: clamp(24px, 8vw, 32px);
    }

    .keyboard-open.state-result .example-card {
        margin-top: 18px;
    }
}

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