:root {
    --primary: #05bbc7;
    --primary-dark: #049aa4;
    --primary-soft: rgba(5, 187, 199, 0.12);
    --accent-id: #10b981;
    --accent-id-soft: rgba(16, 185, 129, 0.12);
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 10px 30px -5px rgba(15, 23, 42, 0.08);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-main: #0b1120;
    --bg-card: #1e293b;
    --bg-input: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 30px -5px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-wrapper {
    max-width: 840px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 48px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Header Navigation */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.92rem;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.back-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    transform: translateX(-2px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 1.6rem;
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand h1 span {
    color: var(--primary);
}

.icon-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.icon-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
:root:not([data-theme="dark"]) .sun-icon { display: none; }
:root:not([data-theme="dark"]) .moon-icon { display: block; }

/* Language Switcher */
.lang-switcher-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 16px;
    background: var(--bg-card);
    padding: 6px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.lang-tab {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.lang-tab.active {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(5, 187, 199, 0.3);
}

.lang-tab:not(.active):hover {
    color: var(--text-main);
    background: var(--bg-main);
}

.swap-btn {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.swap-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: rotate(180deg);
}

/* Search Box */
.search-section {
    margin-bottom: 28px;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 16px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

#wordInput {
    width: 100%;
    border: none;
    background: transparent;
    padding: 12px 14px;
    font-size: 1.05rem;
    color: var(--text-main);
    font-family: inherit;
    outline: none;
}

#wordInput::placeholder {
    color: var(--text-muted);
    opacity: 0.75;
}

.clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 10px;
    font-size: 1rem;
    border-radius: 50%;
    transition: var(--transition);
}

.clear-btn:hover {
    color: var(--text-main);
    background: var(--border-color);
}

.submit-btn {
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 12px 22px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

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

/* Quick Tags & History */
.quick-tags, .history-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.history-bar {
    flex-direction: column;
    align-items: flex-start;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
}

.history-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 4px;
}

.word-chip {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.word-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: underline;
}

.text-btn:hover {
    color: #ef4444;
}

/* States */
.state-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 48px 28px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.state-card h2 {
    font-size: 1.35rem;
    margin-bottom: 10px;
}

.state-card p {
    color: var(--text-muted);
    max-width: 540px;
    margin: 0 auto;
    font-size: 0.95rem;
}

/* Result Styling */
.result-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fadeIn 0.3s ease;
}

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

/* Translation Banner Card */
.translation-banner {
    background: linear-gradient(135deg, rgba(5, 187, 199, 0.12), rgba(16, 185, 129, 0.1));
    border: 1px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 22px 26px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.trans-direction-tag {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary);
}

.trans-pair {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
}

.trans-source {
    color: var(--text-muted);
    font-weight: 500;
}

.trans-arrow {
    color: var(--primary);
}

.trans-target {
    color: var(--text-main);
    background: var(--bg-card);
    padding: 4px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

/* Word Header Card */
.word-header-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 26px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: var(--shadow-sm);
}

.word-title-group h2 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.15;
    margin-bottom: 10px;
    color: var(--text-main);
}

.word-sub-id {
    font-family: 'Inter', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent-id);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.phonetics-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.phonetic-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.word-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.audio-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 20px -4px rgba(5, 187, 199, 0.45);
    transition: var(--transition);
    flex-shrink: 0;
}

.audio-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.06);
}

.audio-btn.playing {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(5, 187, 199, 0.6); }
    70% { box-shadow: 0 0 0 14px rgba(5, 187, 199, 0); }
    100% { box-shadow: 0 0 0 0 rgba(5, 187, 199, 0); }
}

.copy-btn {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.copy-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Meaning Cards */
.meaning-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 26px 28px;
    box-shadow: var(--shadow-sm);
}

.pos-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.pos-badge {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 4px 16px;
    border-radius: 30px;
}

.pos-id-badge {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent-id);
    background: var(--accent-id-soft);
    padding: 4px 12px;
    border-radius: 20px;
}

.pos-line {
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.definition-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.definition-item {
    position: relative;
    padding-left: 28px;
}

.definition-num {
    position: absolute;
    left: 0;
    top: 2px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary);
}

.def-id-text {
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.def-en-text {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.example-quote {
    background: var(--bg-main);
    border-left: 3px solid var(--primary);
    padding: 10px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.9rem;
    margin-top: 8px;
}

.ex-en {
    font-style: italic;
    color: var(--text-main);
}

.ex-id {
    color: var(--accent-id);
    font-size: 0.86rem;
    margin-top: 4px;
    font-weight: 500;
}

.relations-box {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.relation-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
}

.relation-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 4px;
}

.source-footer {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 12px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
}

.source-footer a {
    color: var(--primary);
    text-decoration: none;
}

.source-footer a:hover {
    text-decoration: underline;
}

/* Skeleton Loader */
.skeleton-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
}

.skeleton-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.skeleton-line, .skeleton-block, .skeleton-circle {
    background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-main) 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-line.title { width: 45%; height: 42px; }
.skeleton-line.phonetic { width: 25%; height: 24px; margin-bottom: 24px; }
.skeleton-circle { width: 54px; height: 54px; border-radius: 50%; }
.skeleton-block { width: 100%; height: 90px; margin-bottom: 16px; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Footer */
.app-footer {
    margin-top: auto;
    padding-top: 36px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

@media (max-width: 600px) {
    .word-header-card {
        flex-direction: column;
        align-items: flex-start;
    }
    .word-title-group h2 {
        font-size: 2rem;
    }
    .word-actions {
        width: 100%;
        justify-content: space-between;
    }
    .submit-btn {
        padding: 12px 16px;
    }
    .lang-tab {
        font-size: 0.82rem;
        padding: 8px 8px;
    }
}
