/* ============================================================
   Vocabulary Pro — style.css
   Dark-first, modern, readable design system
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Lora:ital,wght@0,400;1,400&display=swap');

/* ── Design Tokens ────────────────────────────────────────── */
:root {
    /* Brand palette */
    --blue-50:  #eff6ff;
    --blue-400: #60a5fa;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;

    --teal-400: #2dd4bf;
    --teal-500: #14b8a6;

    --amber-400: #fbbf24;
    --amber-500: #f59e0b;

    --red-400:   #f87171;
    --red-500:   #ef4444;

    --green-400: #4ade80;
    --green-500: #22c55e;

    /* Dark surface system */
    --surface-0:  #0d1117;   /* page background */
    --surface-1:  #161b22;   /* card bg */
    --surface-2:  #21262d;   /* input bg */
    --surface-3:  #30363d;   /* hover / divider */
    --surface-4:  #3d444d;   /* border */

    /* Text */
    --text-1: #e6edf3;       /* primary text */
    --text-2: #8b949e;       /* secondary */
    --text-3: #484f58;       /* placeholder / muted */

    /* Semantic */
    --primary:       var(--blue-500);
    --primary-hover: var(--blue-600);
    --accent:        var(--teal-500);
    --danger:        var(--red-500);
    --success:       var(--green-500);
    --warning:       var(--amber-500);

    /* Spacing */
    --radius-sm:  8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    /* Elevation (subtle shadows on dark) */
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,.45);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.5);

    /* Transition */
    --ease: cubic-bezier(.4,0,.2,1);
    --t-fast: 150ms var(--ease);
    --t-base: 250ms var(--ease);
    --t-slow: 400ms var(--ease);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--surface-0);
    color: var(--text-1);
    min-height: 100vh;
    line-height: 1.6;
    padding: 16px;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface-1); }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-2); }

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }

/* ── Layout ───────────────────────────────────────────────── */
.container {
    max-width: 1440px;
    margin: 0 auto;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
    text-align: center;
    padding: 48px 0 40px;
    animation: fadeDown .5s var(--ease) both;
}

.header__title {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 800;
    letter-spacing: -1.5px;
    background: linear-gradient(135deg, var(--blue-400) 0%, var(--teal-400) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.header__sub {
    font-size: 1.05rem;
    color: var(--text-2);
    font-weight: 400;
}

.header__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    background: var(--surface-2);
    border: 1px solid var(--surface-4);
    color: var(--text-2);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: .8rem;
    font-weight: 500;
    letter-spacing: .4px;
    text-transform: uppercase;
}

.header__badge span { color: var(--green-400); font-size: .65rem; }

/* ── Main Grid ────────────────────────────────────────────── */
.main-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 1100px) {
    .main-grid { grid-template-columns: 1fr; }
}

/* ── Panel / Card surface ─────────────────────────────────── */
.panel {
    background: var(--surface-1);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.panel__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -.2px;
}

.panel__title::before {
    content: '';
    display: block;
    width: 4px;
    height: 22px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--blue-500), var(--teal-500));
    flex-shrink: 0;
}

/* ── Form ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 7px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1.5px solid var(--surface-4);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    font-family: inherit;
    color: var(--text-1);
    transition: border-color var(--t-fast), background var(--t-fast);
    resize: none;
    outline: none;
}

.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-3); }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    background: var(--surface-1);
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

/* select option color */
.form-group select option { background: var(--surface-2); color: var(--text-1); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
    white-space: nowrap;
    letter-spacing: .2px;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
}
.btn--primary:hover { background: var(--primary-hover); }

.btn--secondary {
    background: var(--surface-2);
    color: var(--text-1);
    border: 1.5px solid var(--surface-4);
}
.btn--secondary:hover { background: var(--surface-3); border-color: var(--text-2); }

.btn--danger {
    background: transparent;
    color: var(--red-400);
    border: 1.5px solid var(--surface-4);
    padding: 7px 12px;
    font-size: .8rem;
}
.btn--danger:hover { background: rgba(248,113,113,.1); border-color: var(--red-400); }

.btn--edit {
    background: transparent;
    color: var(--blue-400);
    border: 1.5px solid var(--surface-4);
    padding: 7px 12px;
    font-size: .8rem;
}
.btn--edit:hover { background: rgba(96,165,250,.1); border-color: var(--blue-400); }

.btn--export {
    background: var(--surface-2);
    color: var(--amber-400);
    border: 1.5px solid var(--surface-4);
    width: 100%;
}
.btn--export:hover { background: var(--surface-3); border-color: var(--amber-400); }

.btn--show-all {
    background: var(--surface-2);
    color: var(--teal-400);
    border: 1.5px solid var(--surface-4);
}
.btn--show-all:hover { background: var(--surface-3); border-color: var(--teal-400); }

/* ── Stats Grid ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 22px 0 18px;
}

.stat-box {
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-md);
    padding: 16px 14px;
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    color: var(--blue-400);
    line-height: 1.1;
    letter-spacing: -1px;
}

.stat-number.teal { color: var(--teal-400); }

.stat-label {
    font-size: .72rem;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-top: 5px;
    font-weight: 500;
}

/* ── Search & Filter Bar ──────────────────────────────────── */
.filter-bar {
    background: var(--surface-1);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-xl);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 12px;
}

@media (max-width: 700px) {
    .filter-grid { grid-template-columns: 1fr 1fr; }
    .filter-grid .search-wrap { grid-column: 1 / -1; }
}

.filter-grid input,
.filter-grid select {
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1.5px solid var(--surface-4);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-family: inherit;
    color: var(--text-1);
    outline: none;
    transition: border-color var(--t-fast);
}

.filter-grid input::placeholder { color: var(--text-3); }

.filter-grid input:focus,
.filter-grid select:focus { border-color: var(--primary); }

.filter-grid select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.filter-grid select option { background: var(--surface-2); color: var(--text-1); }

.filter-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Words Section ────────────────────────────────────────── */
.words-section {
    background: var(--surface-1);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-xl);
    padding: 24px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-header h3::before {
    content: '';
    display: block;
    width: 4px;
    height: 22px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--blue-500), var(--teal-500));
    flex-shrink: 0;
}

.results-count {
    font-size: .8rem;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--surface-3);
    padding: 4px 12px;
    border-radius: 20px;
}

/* ── Cards Grid ───────────────────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 18px;
}

/* ── Flip Card ────────────────────────────────────────────── */
.flip-card-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.flip-card {
    height: 260px;
    perspective: 1200px;
    cursor: pointer;
}

.flip-card__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform .55s var(--ease);
}

.flip-card.is-flipped .flip-card__inner {
    transform: rotateY(180deg);
}

.flip-card__face {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-lg);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    text-align: center;
    border: 1px solid var(--surface-3);
    transition: border-color var(--t-base);
}

/* Front face */
.flip-card__face--front {
    background: var(--surface-2);
}

.flip-card:hover .flip-card__face--front {
    border-color: var(--blue-500);
}

/* Back face */
.flip-card__face--back {
    background: var(--surface-2);
    transform: rotateY(180deg);
}

.flip-card:hover .flip-card__face--back {
    border-color: var(--teal-500);
}

/* Card content */
.card__word {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-1);
    letter-spacing: -.5px;
    margin-bottom: 12px;
    line-height: 1.2;
}

.card__sentence {
    font-size: .875rem;
    color: var(--text-2);
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    line-height: 1.55;
}

.card__badge {
    margin-top: 14px;
    display: inline-flex;
    align-items: center;
    background: var(--surface-3);
    color: var(--text-2);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.card__badge--blue  { color: var(--blue-400); }
.card__badge--teal  { color: var(--teal-400); }

.card__meaning {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--teal-400);
    letter-spacing: -.3px;
    line-height: 1.3;
    margin-bottom: 12px;
}

.card__hint {
    font-size: .78rem;
    color: var(--text-3);
    margin-top: auto;
}

/* Card action buttons */
.card-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Level / Group Headers ────────────────────────────────── */
.level-section { margin-bottom: 36px; }

.level-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--surface-3);
}

.level-pill {
    background: var(--blue-600);
    color: #fff;
    padding: 5px 14px;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .3px;
}

.level-header h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-1);
}

.level-header .word-count {
    margin-left: auto;
    font-size: .8rem;
    color: var(--text-2);
}

.type-group { margin-bottom: 24px; padding-left: 16px; border-left: 2px solid var(--surface-3); }

.type-group__title {
    font-size: .85rem;
    color: var(--teal-400);
    font-weight: 600;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 56px 32px;
    color: var(--text-2);
}

.empty-state__icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: .6;
}

.empty-state p {
    font-size: .95rem;
    line-height: 1.7;
    color: var(--text-2);
}

/* ── Loading State ────────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px;
    color: var(--text-2);
    font-size: .9rem;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--surface-4);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

/* ── Modal (Edit) ─────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(4px);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn .2s var(--ease) both;
}

.modal {
    background: var(--surface-1);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-xl);
    padding: 32px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: scaleUp .25s var(--ease) both;
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal__title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-1);
}

.modal__close {
    background: none;
    border: none;
    color: var(--text-2);
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
    padding: 4px;
    transition: color var(--t-fast);
}
.modal__close:hover { color: var(--text-1); }

.modal__footer {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.modal__footer .btn { flex: 1; }

/* ── Toast Notifications ──────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 40px));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 18px;
    background: var(--surface-2);
    border: 1px solid var(--surface-4);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: .875rem;
    font-weight: 500;
    color: var(--text-1);
    animation: slideInRight .3s var(--ease) both;
    border-left: 3px solid transparent;
}

.toast--success { border-left-color: var(--green-400); }
.toast--error   { border-left-color: var(--red-400); }
.toast--info    { border-left-color: var(--blue-400); }
.toast--warning { border-left-color: var(--amber-400); }

.toast__icon { font-size: 1.1rem; flex-shrink: 0; }
.toast__msg  { line-height: 1.4; }

.toast.is-hiding { animation: fadeOutRight .3s var(--ease) both; }

/* ── Confirm Dialog ───────────────────────────────────────── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 950;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.confirm-box {
    background: var(--surface-1);
    border: 1px solid var(--surface-3);
    border-radius: var(--radius-xl);
    padding: 28px 32px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.confirm-box h4 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: 8px;
}

.confirm-box p {
    font-size: .9rem;
    color: var(--text-2);
    margin-bottom: 22px;
    line-height: 1.5;
}

.confirm-box__btns {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeDown {
    from { opacity: 0; transform: translateY(-24px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes scaleUp {
    from { opacity: 0; transform: scale(.92); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(60px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOutRight {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(60px); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Responsive tweaks ────────────────────────────────────── */
@media (max-width: 600px) {
    body { padding: 10px; }

    .header { padding: 28px 0 24px; }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    .filter-grid .search-wrap { grid-column: 1; }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .modal { padding: 22px; }

    .section-header { flex-direction: column; align-items: flex-start; }
}
