:root {
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-main: #212529;
    --text-muted: #6c757d;
    --primary-color: #007aff;
    --border-color: #e9ecef;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --nav-height: 65px;
}

body.dark-theme {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-main: #f8f9fa;
    --text-muted: #adb5bd;
    --border-color: #333333;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh; height: 100dvh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

header {
    position: relative;
    background-color: #0b1329;
    background-image: url('banner-c.jpg');
    background-size: cover;
    background-position: center top;
    height: 75px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
    flex-shrink: 0;
    overflow: hidden;
    padding: 0 52px;
}

header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at center, rgba(15, 23, 42, 0.40) 0%, rgba(2, 6, 23, 0.85) 100%);
    z-index: 1;
}

header .build-version {
    position: absolute;
    top: 6px;
    left: 12px;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.55);
    font-family: monospace;
    z-index: 2;
    pointer-events: none;
}

#ui-header {
    position: relative;
    z-index: 2;
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.2px;
    white-space: nowrap;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.85);
    text-align: center;
}

.header-slogan-center {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 480px;
    text-align: center;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.85);
    font-style: italic;
    z-index: 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

header .menu-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    background: rgba(255, 255, 255, 0.18);
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ffffff;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

#dropdown-menu {
    position: fixed;
    top: 70px;
    right: 16px;
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 230px;
    transform-origin: top right;
    transition: transform 0.2s ease, opacity 0.2s ease;
    border: 1px solid var(--border-color);
}
.dropdown-hidden { transform: scale(0.9); opacity: 0; pointer-events: none; }
.dropdown-item { padding: 14px 20px; color: var(--text-main); font-size: 15px; font-weight: 500; border-bottom: 1px solid var(--border-color); cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.dropdown-item span { color: var(--text-main); text-shadow: none; font-size: 15px; font-weight: 500; }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:active { background-color: var(--bg-color); }

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 14px 16px;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 12px);
}
#country-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.status-container { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; color: var(--text-muted); text-align: center; padding: 20px; }
.spinner { border: 3px solid var(--border-color); border-top: 3px solid var(--primary-color); border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; margin-bottom: 12px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.hidden { display: none !important; }
.btn-reset { margin-top: 15px; padding: 10px 20px; border: none; background: #dc3545; color: white; border-radius: 8px; font-weight: 600; cursor: pointer; }

.card { background-color: var(--card-bg); border-radius: 16px; padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow); width: 100%; flex-shrink: 0; transition: background-color 0.3s; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-title { font-size: 16px; font-weight: 700; color: var(--text-main); }
.rate-status { font-size: 12px; font-weight: 500; color: var(--text-muted); }

.input-group { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border-color); transition: border-color 0.3s ease; width: 100%; }
.input-group:focus-within { border-bottom-color: var(--primary-color); }
.input-group:last-child { margin-bottom: 0; border-bottom: none; padding-bottom: 0; }
.input-group label { font-weight: 500; color: var(--text-muted); flex-shrink: 0; font-size: 14.5px; }
.input-wrapper { display: flex; align-items: center; flex: 1; justify-content: flex-end; }
.input-group input { border: none; background: transparent; font-size: 20px; font-weight: 600; text-align: right; color: var(--text-main); width: 100%; min-width: 0; outline: none; padding-left: 10px; }
.camera-btn { background: var(--primary-color); color: white; border: none; border-radius: 8px; width: 32px; height: 32px; display: flex; justify-content: center; align-items: center; margin-left: 10px; cursor: pointer; box-shadow: 0 2px 5px rgba(0, 122, 255, 0.3); flex-shrink: 0; }

#vocab-card { display: flex; flex-direction: column; flex: 1; min-height: 0; margin-bottom: 0; }
.vocab-tabs-container { display: flex; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; background-color: var(--bg-color); border-radius: 10px 10px 0 0; padding: 6px 8px 0 8px; margin: 0 -18px 10px -18px; border-bottom: 1px solid var(--border-color); border-top: 1px solid var(--border-color); flex-shrink: 0; transition: background-color 0.3s; }
.vocab-tabs-container::-webkit-scrollbar { display: none; }
.vocab-tab { padding: 9px 14px; white-space: nowrap; font-size: 13.5px; color: var(--text-muted); background-color: transparent; border-radius: 8px 8px 0 0; cursor: pointer; margin-right: 4px; font-weight: 500; }
.vocab-tab.active { background-color: var(--card-bg); color: var(--primary-color); font-weight: 700; box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.03); }
#vocab-content { flex: 1; overflow-y: auto; padding-right: 4px; padding-bottom: 8px; }
.vocab-item { display: flex; justify-content: space-between; align-items: center; padding: 11px 6px; border-bottom: 1px solid var(--border-color); }
.vocab-item:last-child { border-bottom: none; }
.vocab-es { font-weight: 600; color: var(--text-main); flex: 1; padding-right: 10px; font-size: 14.5px; }
.vocab-local { color: var(--text-muted); text-align: right; display: flex; align-items: center; justify-content: flex-end; font-size: 14.5px; }
.tts-btn { background: none; border: none; color: var(--primary-color); margin-left: 10px; cursor: pointer; padding: 4px; display: flex; align-items: center; }
.tts-btn:active { opacity: 0.5; }

nav { position: fixed; bottom: 0; left: 0; width: 100%; height: var(--nav-height); background-color: var(--card-bg); display: flex; justify-content: flex-start; align-items: center; box-shadow: 0 -2px 15px rgba(0, 0, 0, 0.08); padding-bottom: env(safe-area-inset-bottom); z-index: 100; transition: background-color 0.3s; overflow-x: auto; scrollbar-width: none; padding-left: 10px; padding-right: 10px; }
nav::-webkit-scrollbar { display: none; }
.nav-btn { background: none; border: none; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); font-size: 11px; font-weight: 500; height: 100%; cursor: pointer; opacity: 0.55; transition: all 0.3s ease; flex-shrink: 0; min-width: 72px; }
.nav-btn .flag { font-size: 22px; margin-bottom: 4px; height: 24px; display: flex; align-items: center; justify-content: center; filter: grayscale(75%); transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.nav-btn .flag img { width: 26px; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.nav-btn.active { color: var(--primary-color); opacity: 1; }
.nav-btn.active .flag { transform: scale(1.35) translateY(-2px); filter: grayscale(0%); }
.nav-btn.active .flag img { box-shadow: 0 6px 12px rgba(0, 122, 255, 0.4); border: 1px solid rgba(0, 122, 255, 0.3); }

#country-manager-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 10000; display: flex; flex-direction: column; justify-content: flex-end; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
#country-manager-modal.show { opacity: 1; pointer-events: auto; }
.cm-content { background: var(--bg-color); width: 100%; max-height: 85vh; border-radius: 24px 24px 0 0; display: flex; flex-direction: column; transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
#country-manager-modal.show .cm-content { transform: translateY(0); }
.cm-header { padding: 18px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--card-bg); border-radius: 24px 24px 0 0; }
.cm-header h3 { margin: 0; font-size: 18px; color: var(--text-main); }
.cm-close { background: none; border: none; font-size: 24px; color: var(--text-muted); cursor: pointer; }
.cm-body { padding: 10px 20px; overflow-y: auto; flex: 1; }
.cm-item { display: flex; justify-content: space-between; align-items: center; padding: 15px 10px; border-bottom: 1px solid var(--border-color); background: var(--bg-color); transition: box-shadow 0.2s, transform 0.2s; }
.cm-item:last-child { border-bottom: none; }
.cm-item img { width: 24px; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.drag-handle { font-size: 22px; color: var(--text-muted); cursor: grab; padding-right: 15px; touch-action: none; user-select: none; opacity: 0.6; }
.cm-item.dragging { opacity: 0.9; transform: scale(1.02); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15); z-index: 100; border-radius: 8px; border-bottom: none; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(20px); }

main {
    padding: 12px 14px calc(var(--nav-height) + env(safe-area-inset-bottom) + 12px) 14px !important;
}
#vocab-card {
    padding-bottom: 4px !important;
    overflow: hidden !important;
}
#vocab-content {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    padding-bottom: 24px !important;
}

.cm-footer {
    padding: 14px 20px calc(16px + env(safe-area-inset-bottom)) 20px !important;
    background: var(--card-bg) !important;
    border-top: 1px solid var(--border-color) !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}

body.dark-theme .cm-footer {
    background: var(--card-bg, #1e1e1e) !important;
    border-top-color: var(--border-color, #333333) !important;
}

.cm-footer button,
.cm-footer .btn,
.cm-footer input[type="button"],
.cm-footer input[type="submit"] {
    width: 100% !important;
    height: 48px !important;
    background: #0284c7 !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 12px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    font-family: inherit !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    cursor: pointer !important;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3) !important;
    transition: background 0.15s ease, transform 0.1s ease !important;
    -webkit-tap-highlight-color: transparent !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    outline: none !important;
}

.cm-footer button:hover,
.cm-footer .btn:hover {
    background: #0369a1 !important;
}

.cm-footer button:active,
.cm-footer .btn:active {
    transform: scale(0.98) !important;
}

body.dark-theme .cm-footer button,
body.dark-theme .cm-footer .btn {
    background: #0284c7 !important;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.45) !important;
}

.modal-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}