/* ============================================================
   TutorMan Design System - Modern Minimal (Blue)
   ============================================================ */

:root {
    --tm-primary: #0f6cbd;
    --tm-primary-dark: #0a559a;
    --tm-accent: #2b88d8;
    --tm-primary-gradient: linear-gradient(135deg, #0f6cbd 0%, #2b88d8 100%);
    --tm-bg: #ffffff;
    --tm-bg-accent: #eff6fc;
    --tm-surface: #ffffff;
    --tm-surface-soft: #f5f9fd;
    --tm-border: #e1e7ee;
    --tm-border-soft: #eef2f7;
    --tm-text: #515765;
    --tm-text-muted: #475569;
    --tm-text-soft: #94a3b8;
    --tm-danger: #ef4444;
    --tm-warning: #f59e0b;
    --tm-success: #10b981;

    --tm-radius-lg: 24px;
    --tm-radius-md: 16px;
    --tm-radius-sm: 10px;
    --tm-shadow-card: 0 10px 40px rgba(15, 23, 42, 0.06), 0 2px 6px rgba(15, 23, 42, 0.04);
    --tm-shadow-popover: 0 12px 32px rgba(15, 23, 42, 0.12);
    --tm-shadow-action: 0 14px 32px rgba(15, 108, 189, 0.38);
}

html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 16px; } }

body {
    background: linear-gradient(180deg, var(--tm-bg) 0%, var(--tm-bg-accent) 100%);
    background-attachment: fixed;
    color: var(--tm-text);
    min-height: 100vh;
}

a { color: var(--tm-primary); text-decoration: none; }
a:hover { color: var(--tm-primary-dark); }

/* ===== Focus rings ===== */
.btn:focus, .btn:active:focus,
.form-control:focus, .form-select:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(15, 108, 189, 0.20);
    outline: none;
}

/* ===== Navbar ===== */
.navbar.tm-nav {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--tm-border-soft);
    padding: 0.65rem 0;
}
.navbar.tm-nav .navbar-brand {
    font-weight: 700;
    letter-spacing: -0.01em;
    background: var(--tm-primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.navbar.tm-nav .nav-link {
    color: var(--tm-text-muted) !important;
    font-weight: 500;
    padding: 0.45rem 0.85rem !important;
    border-radius: 10px;
    transition: all 0.18s ease;
}
.navbar.tm-nav .nav-link:hover { color: var(--tm-primary) !important; background: rgba(15, 108, 189, 0.08); }
.navbar.tm-nav .nav-link.dropdown-toggle::after { margin-left: 0.4em; }
.navbar.tm-nav .navbar-toggler { border-color: var(--tm-border); }
.navbar.tm-nav .navbar-toggler:focus { box-shadow: 0 0 0 0.2rem rgba(15, 108, 189, 0.20); }
.navbar.tm-nav .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23475569' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Logged-in user menu (navbar) */
.navbar.tm-nav .nav-link.nav-user {
    display: inline-flex; align-items: center; gap: 0.55rem;
    padding: 0.35rem 0.85rem 0.35rem 0.4rem !important;
}
.nav-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0;
    border: 1px solid var(--tm-border);
    background: var(--tm-bg-accent);
    display: inline-block; vertical-align: middle;
}
span.nav-avatar.nav-avatar-fallback {
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--tm-primary); font-weight: 600; font-size: 0.78rem;
    line-height: 1;
}
.nav-user-name { font-weight: 500; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 991.98px) {
    .navbar.tm-nav .nav-link.nav-user { padding: 0.5rem 0.85rem !important; }
}

.dropdown-menu {
    border: 1px solid var(--tm-border);
    border-radius: var(--tm-radius-md);
    box-shadow: var(--tm-shadow-popover);
    padding: 0.4rem;
    margin-top: 0.4rem;
}
.dropdown-item { border-radius: 8px; padding: 0.5rem 0.75rem; color: var(--tm-text-muted); }
.dropdown-item:hover, .dropdown-item:focus { background: rgba(15, 108, 189, 0.08); color: var(--tm-primary); }

/* ===== Buttons ===== */
.btn { border-radius: var(--tm-radius-sm); font-weight: 500; padding: 0.5rem 1.1rem; transition: all 0.18s ease; }
.btn-sm { border-radius: 8px; padding: 0.35rem 0.8rem; font-size: 0.825rem; }
.btn-lg { border-radius: 12px; padding: 0.7rem 1.6rem; }

.btn-primary, .btn-primary:focus {
    background: var(--tm-primary-gradient); border: none; color: #fff; font-weight: 600;
    box-shadow: 0 6px 18px rgba(15, 108, 189, 0.25);
}
.btn-primary:hover { background: var(--tm-primary-gradient); transform: translateY(-1px); box-shadow: 0 10px 24px rgba(15, 108, 189, 0.35); color: #fff; }
.btn-primary:active, .btn-primary:disabled { transform: translateY(0); opacity: 0.65; }

.btn-outline-secondary {
    background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text-muted);
}
.btn-outline-secondary:hover { background: var(--tm-surface-soft); border-color: #cbd5e1; color: var(--tm-text); }

.btn-outline-danger {
    background: var(--tm-surface); border: 1px solid #fecaca; color: var(--tm-danger);
}
.btn-outline-danger:hover { background: #fef2f2; border-color: #fca5a5; color: #dc2626; }

.btn-dark {
    background: var(--tm-text); border: none; color: #fff;
}
.btn-dark:hover { background: #1e293b; color: #fff; }

.btn-light { background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text); }
.btn-light:hover { background: var(--tm-surface-soft); border-color: #cbd5e1; }

.btn-link { color: var(--tm-primary); text-decoration: none; }
.btn-link:hover { color: var(--tm-primary-dark); }

/* ===== Forms ===== */
.form-control, .form-select {
    border-radius: var(--tm-radius-sm);
    border: 1px solid var(--tm-border);
    padding: 0.55rem 0.9rem;
    background: var(--tm-surface);
    color: var(--tm-text);
    transition: all 0.18s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--tm-primary);
    box-shadow: 0 0 0 0.2rem rgba(15, 108, 189, 0.15);
}
.form-control::placeholder { color: var(--tm-text-soft); }
.form-label { color: var(--tm-text-muted); font-weight: 500; font-size: 0.875rem; margin-bottom: 0.4rem; }
.form-check-input:checked { background-color: var(--tm-primary); border-color: var(--tm-primary); }
.form-check-input:focus { border-color: var(--tm-primary); box-shadow: 0 0 0 0.2rem rgba(15, 108, 189, 0.20); }

/* ===== Cards ===== */
.card {
    border: none;
    border-radius: var(--tm-radius-md);
    background: var(--tm-surface);
    box-shadow: var(--tm-shadow-card);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--tm-border-soft);
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--tm-text);
    border-top-left-radius: var(--tm-radius-md) !important;
    border-top-right-radius: var(--tm-radius-md) !important;
}
.card-body { padding: 1.25rem; }
.card-footer { background: var(--tm-surface-soft); border-top: 1px solid var(--tm-border-soft); }

/* ===== List Group ===== */
.list-group {
    border-radius: var(--tm-radius-md);
    overflow: hidden;
    background: var(--tm-surface);
    box-shadow: var(--tm-shadow-card);
}
.list-group-item {
    border: none;
    border-bottom: 1px solid var(--tm-border-soft);
    background: transparent;
    padding: 0.95rem 1.25rem;
    color: var(--tm-text);
}
.list-group-item:last-child { border-bottom: none; }
.list-group-item-action { color: var(--tm-text); }
.list-group-item-action:hover, .list-group-item-action:focus { background: rgba(15, 108, 189, 0.05); color: var(--tm-text); }
.card > .list-group, .card .list-group-flush { box-shadow: none; border-radius: 0; }

/* ===== Tables ===== */
.table { color: var(--tm-text); border-color: var(--tm-border-soft); margin-bottom: 0; }
.table > thead { background: var(--tm-surface-soft); }
.table > thead th {
    color: var(--tm-text-muted); font-weight: 600; font-size: 0.78rem;
    text-transform: uppercase; letter-spacing: 0.06em;
    border-bottom: 1px solid var(--tm-border); padding: 0.85rem 1rem;
}
.table > tbody td { padding: 0.85rem 1rem; border-color: var(--tm-border-soft); vertical-align: middle; }
.table-hover > tbody > tr:hover > * { background: rgba(15, 108, 189, 0.04); --bs-table-bg-state: transparent; }

/* ===== Alerts ===== */
.alert { border: none; border-radius: var(--tm-radius-md); padding: 0.85rem 1.1rem; font-size: 0.9rem; }
.alert-success { background: #ecfdf5; color: #047857; }
.alert-danger { background: #fef2f2; color: #b91c1c; }
.alert-warning { background: #fffbeb; color: #b45309; }

/* ===== Pagination ===== */
.pagination .page-link {
    color: var(--tm-text-muted); border: 1px solid var(--tm-border); background: var(--tm-surface);
    margin: 0 0.15rem; border-radius: 10px !important;
    padding: 0.4rem 0.75rem; transition: all 0.18s ease;
}
.pagination .page-link:hover { background: var(--tm-surface-soft); color: var(--tm-primary); border-color: #b6d4ee; }
.pagination .page-item.active .page-link { background: var(--tm-primary-gradient); border-color: transparent; color: #fff; }
.pagination .page-item.disabled .page-link { background: var(--tm-surface-soft); color: #cbd5e1; }

/* ===== Modal ===== */
.modal-content { border: none; border-radius: 20px; box-shadow: 0 20px 60px rgba(15, 23, 42, 0.15); }
.modal-header { border-bottom: 1px solid var(--tm-border-soft); }
.modal-footer { border-top: 1px solid var(--tm-border-soft); }

/* ===== Badge ===== */
.badge { font-weight: 500; padding: 0.35em 0.6em; border-radius: 6px; }

/* ===== Typography & layout helpers ===== */
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--tm-text); letter-spacing: -0.01em; margin-bottom: 0; }
.page-subtitle { color: var(--tm-text-muted); font-size: 0.95rem; margin-bottom: 0; }
.eyebrow { font-size: 0.72rem; letter-spacing: 0.22em; color: var(--tm-text-soft); text-transform: uppercase; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; gap: 0.75rem; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ===== Empty state ===== */
.empty-state {
    text-align: center; padding: 3.5rem 1.5rem;
    background: var(--tm-surface); border-radius: var(--tm-radius-md);
    box-shadow: var(--tm-shadow-card); color: var(--tm-text-soft);
}
.empty-state .empty-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--tm-bg-accent); color: var(--tm-primary);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 1rem; font-size: 1.5rem;
}

/* ===== Auth card (Welcome / Invite / Login modal body) ===== */
.auth-card {
    background: var(--tm-surface); border-radius: 20px;
    box-shadow: var(--tm-shadow-card); padding: 2rem;
}

/* ===== Page wrapper (form pages get tighter width) ===== */
.form-page { max-width: 640px; margin: 0 auto; }
.form-actions { display: flex; gap: 0.6rem; margin-top: 1.5rem; }

/* ===== Selectable list (for checkbox lists like words-lib picker) ===== */
.select-list { box-shadow: none; }
.select-list .list-group-item { padding: 0.75rem 1rem; cursor: pointer; }
.select-list .list-group-item:has(input:checked) { background: rgba(15, 108, 189, 0.06); color: var(--tm-text); }

/* ============================================================
   Launch Page
   ============================================================ */
.launch-wrapper { min-height: calc(100vh - 130px); display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.launch-card { width: 100%; max-width: 460px; background: var(--tm-surface); border-radius: var(--tm-radius-lg); padding: 3rem 2.5rem 2.5rem; box-shadow: var(--tm-shadow-card); text-align: center; }
.launch-title { font-size: 1.5rem; font-weight: 600; color: var(--tm-text); margin-bottom: 2.25rem; word-break: break-all; }
.start-stage { position: relative; width: 210px; height: 210px; margin: 0 auto 2rem; display: flex; align-items: center; justify-content: center; }
.pulse-ring { position: absolute; inset: 0; border-radius: 50%; border: 1px solid rgba(15, 108, 189, 0.35); animation: launchPulse 2.4s ease-out infinite; }
.pulse-ring:nth-child(2) { animation-delay: 0.8s; }
.pulse-ring:nth-child(3) { animation-delay: 1.6s; }
@keyframes launchPulse {
    0%   { transform: scale(0.72); opacity: 0.9; }
    100% { transform: scale(1.08); opacity: 0; }
}
.start-btn {
    position: relative; width: 156px; height: 156px; border-radius: 50%;
    background: var(--tm-primary-gradient); color: #fff;
    font-size: 1.25rem; font-weight: 600; letter-spacing: 0.18em;
    display: flex; align-items: center; justify-content: center; text-decoration: none;
    box-shadow: var(--tm-shadow-action); transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.start-btn:hover { color: #fff; transform: scale(1.04); box-shadow: 0 18px 38px rgba(15, 108, 189, 0.48); }
.start-btn:active { transform: scale(0.97); }

.random-toggle.form-check {
    display: inline-flex; align-items: center; gap: 0.6rem;
    padding: 0.45rem 1.1rem; background: #eff6fc; border-radius: 999px;
    margin-bottom: 1.75rem; min-height: auto;
}
.random-toggle .form-check-input { float: none; margin: 0; cursor: pointer; }
.random-toggle label { font-size: 0.875rem; color: var(--tm-text-muted); cursor: pointer; margin: 0; }

.info-panel {
    background: var(--tm-surface-soft); border: 1px solid var(--tm-border-soft);
    border-radius: var(--tm-radius-md); padding: 1.1rem 1.4rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; text-align: left;
}
.info-panel .lib-name {
    font-size: 0.95rem; color: var(--tm-text); font-weight: 500;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.info-panel .lib-meta { font-size: 0.7rem; color: var(--tm-text-soft); margin-top: 0.2rem; letter-spacing: 0.12em; text-transform: uppercase; }
.info-panel .word-count { flex-shrink: 0; text-align: right; }
.info-panel .word-count .num { font-size: 1.85rem; font-weight: 700; color: var(--tm-primary); line-height: 1; }
.info-panel .word-count .unit { font-size: 0.65rem; color: var(--tm-text-soft); margin-top: 0.3rem; letter-spacing: 0.14em; }

/* ============================================================
   Practice Page
   ============================================================ */
@font-face {
    font-family: 'Hkkai';
    src: url('/font/hkkai.woff2') format('woff2');
    font-weight: normal; font-style: normal; font-display: swap;
}

.practice-stage { background: linear-gradient(180deg, var(--tm-bg) 0%, var(--tm-bg-accent) 100%); }
.practice-topbar { padding: 0.9rem 1.25rem; }

.icon-pill {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text-muted);
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0; text-decoration: none; transition: all 0.18s ease;
}
.icon-pill:hover { color: var(--tm-text); border-color: #cbd5e1; background: var(--tm-surface-soft); }
.icon-pill.close-pill { font-size: 1.4rem; line-height: 1; }

.progress-chip {
    background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text-muted);
    font-weight: 600; padding: 0.5rem 1.1rem; border-radius: 999px;
    font-size: 0.9rem; letter-spacing: 0.05em; cursor: pointer;
    display: inline-flex; align-items: center; transition: all 0.18s ease;
}
.progress-chip:hover { border-color: #b6d4ee; color: var(--tm-primary-dark); }

.lang-chip {
    background: var(--tm-primary-gradient); color: #fff; font-weight: 600;
    padding: 0.4rem 0.75rem; border-radius: 10px; cursor: pointer;
    font-size: 0.8rem; letter-spacing: 0.1em;
}

.font-btn {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text-muted);
    font-size: 0.85rem; font-weight: 600; padding: 0; transition: all 0.18s ease;
}
.font-btn:hover { background: var(--tm-surface-soft); color: var(--tm-text); border-color: #cbd5e1; }

.add-mistake-btn {
    width: 40px; height: 40px; border-radius: 50%;
    background: #fff7ed; border: 1px solid #fed7aa; color: var(--tm-warning);
    display: inline-flex; align-items: center; justify-content: center; padding: 0;
    transition: all 0.18s ease;
}
.add-mistake-btn:hover { background: #ffedd5; color: #d97706; }

.mistake-toggle-btn {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text-muted);
    position: relative; padding: 0;
    display: inline-flex; align-items: center; justify-content: center; transition: all 0.18s ease;
}
.mistake-toggle-btn:hover { background: var(--tm-surface-soft); color: var(--tm-text); border-color: #cbd5e1; }
.mistake-badge {
    position: absolute; top: -2px; right: -2px;
    background: linear-gradient(135deg, #ef4444, #f43f5e); color: #fff;
    font-size: 0.6rem; font-weight: 600; padding: 0.12rem 0.38rem;
    border-radius: 999px; min-width: 18px; line-height: 1.2;
    border: 2px solid var(--tm-surface-soft);
}

.word-card {
    background: var(--tm-surface); border-radius: var(--tm-radius-lg); border: none;
    box-shadow: var(--tm-shadow-card); overflow: hidden;
}
.word-card .card-body { padding: 2.5rem 2rem; }
#wordDisplay { color: var(--tm-text); letter-spacing: 0.02em; }
.cn-mode #wordDisplay { font-family: 'Hkkai', 'Microsoft YaHei', 'PingFang SC', 'Noto Sans SC', sans-serif; }
#speakerIcon { color: var(--tm-primary); }

.hint-footer { background: var(--tm-surface-soft); border-top: 1px solid var(--tm-border-soft); padding: 0.9rem 1.5rem; }
.hint-footer #hintText { color: #64748b; }

.control-btn {
    width: 64px; height: 64px; border-radius: 50%;
    background: var(--tm-surface); border: 1px solid var(--tm-border); color: var(--tm-text-muted);
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0; font-size: 1.2rem; transition: all 0.18s ease;
}
.control-btn:hover { background: var(--tm-surface-soft); color: var(--tm-text); border-color: #cbd5e1; transform: translateY(-2px); }
.control-btn:active { transform: translateY(0); }

.primary-action {
    width: 112px; height: 112px; border-radius: 50%;
    background: var(--tm-primary-gradient); color: #fff; border: none;
    font-size: 1.15rem; font-weight: 700; letter-spacing: 0.18em;
    box-shadow: var(--tm-shadow-action);
    display: inline-flex; align-items: center; justify-content: center; transition: all 0.2s ease;
}
.primary-action:hover { color: #fff; transform: scale(1.04); box-shadow: 0 18px 38px rgba(15, 108, 189, 0.48); }
.primary-action:active { transform: scale(0.97); }

.mistake-popover {
    background: var(--tm-surface);
    border: 1px solid var(--tm-border) !important;
    border-radius: var(--tm-radius-md) !important;
    box-shadow: var(--tm-shadow-popover) !important;
}
.mistake-popover .popover-head { padding: 0.75rem 1rem; border-bottom: 1px solid var(--tm-border-soft); }
.mistake-popover .popover-head .title { font-size: 0.85rem; font-weight: 600; color: var(--tm-text); }
.mistake-popover .list-group, .mistake-popover .list-group-flush { box-shadow: none; border-radius: 0; }
.mistake-popover .list-group-item { border: none; border-bottom: 1px solid var(--tm-border-soft); background: transparent; }
.mistake-popover .list-group-item:last-child { border-bottom: none; }

/* ===== Tabs (Settings page) ===== */
.tm-tabs.nav-tabs {
    border-bottom: 1px solid var(--tm-border);
    margin-bottom: 1.25rem;
    gap: 0.25rem;
}
.tm-tabs.nav-tabs .nav-link {
    color: var(--tm-text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    border-radius: 0;
    padding: 0.7rem 1.1rem;
    font-weight: 500;
    margin-bottom: -1px;
    transition: all 0.18s ease;
}
.tm-tabs.nav-tabs .nav-link:hover {
    color: var(--tm-primary);
    background: rgba(15, 108, 189, 0.04);
}
.tm-tabs.nav-tabs .nav-link.active {
    color: var(--tm-primary);
    background: transparent;
    border-bottom-color: var(--tm-primary);
    font-weight: 600;
}
.tm-tabs.nav-tabs .nav-link:focus { box-shadow: none; outline: none; }

.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--tm-bg-accent); color: var(--tm-primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.78rem; font-weight: 600; flex-shrink: 0;
    object-fit: cover; overflow: hidden;
}

.status-pill {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.2rem 0.6rem; border-radius: 999px;
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
}
.status-pill.active { background: #ecfdf5; color: #047857; }
.status-pill.pending { background: #fffbeb; color: #b45309; }
.status-pill.admin { background: rgba(15, 108, 189, 0.10); color: var(--tm-primary); }
.status-pill.user { background: var(--tm-surface-soft); color: var(--tm-text-muted); }

/* ===== Misc legacy keyboard btn (kept for compatibility) ===== */
.keyboard-btn { padding: 0.25rem 0.5rem; font-weight: 500; }
