/* === Smart Idioma Design System === */
/* Colors: Primary #2563EB, Accent #F97316, Success #22C55E, BG #F8FAFC, Text #1E293B */
/* Typography: System stack, clean and readable */

/* Font loaded via <link preconnect> in HTML head */

:root {
    --primary: #2563EB;
    --primary-light: #3B82F6;
    --primary-dark: #1D4ED8;
    --accent: #F97316;
    --accent-light: #FB923C;
    --success: #22C55E;
    --success-light: #BBF7D0;
    --success-bg: #F0FDF4;
    --error: #EF4444;
    --error-light: #FEE2E2;
    --warning: #EAB308;
    --bg: #F1F5F9;
    --surface: #FFFFFF;
    --surface-hover: #F8FAFC;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #6B7280; /* was #94A3B8, fixed for 4.5:1 contrast on --bg */
    --border: #E2E8F0;
    --border-light: #F1F5F9;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --radius: 12px;
    --radius-lg: 16px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
html, body {
    height: 100%;
}

.no-select {
    user-select: none;
    -webkit-user-select: none;
}

/* === Navbar === */
.navbar {
    background-color: var(--primary);
    width: 100%;
    padding: 0 8px;
    display: flex;
    align-items: center;
    height: 52px;
    box-shadow: 0 2px 8px rgba(37,99,235,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .estrella {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    color: white;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: default;
}

.navbar a {
    color: white;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}
.navbar a:hover {
    background: rgba(255,255,255,0.15);
    color: white;
}

.dropdown {
    position: relative;
}
.dropdown .dropbtn {
    font-size: 14px;
    font-weight: 500;
    border: none;
    outline: none;
    color: white;
    background: transparent;
    font-family: inherit;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}
.dropdown:hover .dropbtn {
    background: rgba(255,255,255,0.15);
    color: white;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--surface);
    min-width: 180px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    padding: 4px;
    z-index: 200;
    margin-top: 4px;
}
.dropdown-content a {
    color: var(--text);
    padding: 10px 14px;
    display: block;
    text-align: left;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 400;
    transition: background 0.15s;
}
.dropdown-content a:hover {
    background: var(--border-light);
    color: var(--text);
}
.dropdown:hover .dropdown-content {
    display: block;
}

/* === Main Container === */
.table-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: calc(100vh - 52px);
    padding: 16px;
}

table {
    border-collapse: separate;
    border-spacing: 0;
    background-color: var(--surface);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 480px;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

th, td {
    border: none;
    border-bottom: 1px solid var(--border-light);
    text-align: center;
    padding: 12px 16px;
    width: 50%;
}
tr:last-child td {
    border-bottom: none;
}

th {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.5px;
    padding: 14px 16px;
}

/* === Buttons === */
td button {
    background: linear-gradient(135deg, var(--success), #16A34A);
    border: none;
    color: white;
    padding: 12px 20px;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    margin: 2px 0;
    cursor: pointer;
    border-radius: var(--radius-sm);
    width: 100%;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    box-shadow: 0 2px 4px rgba(34,197,94,0.2);
    font-family: inherit;
}
td button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(34,197,94,0.3);
}
td button:active {
    transform: scale(0.97);
}
td button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Letter buttons (stage 1 - shuffled) */
td button2 {
    display: inline-block;
    box-sizing: border-box;
    background: var(--success);
    border: none;
    color: white;
    padding: 0;
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin: 4px;
    cursor: pointer;
    border-radius: 8px;
    width: 48px;
    min-width: 48px;
    height: 48px;
    line-height: 48px;
    transition: transform 0.15s, background 0.2s, opacity 0.3s;
    font-family: inherit;
}
td button2:hover {
    transform: scale(1.05);
}
td button2:active {
    transform: scale(0.92);
}

/* Target letter slots (stage 1) */
td button3 {
    display: inline-block;
    box-sizing: border-box;
    background: rgba(37,99,235,0.06);
    border: 2px solid var(--primary-light);
    color: rgba(37,99,235,0.06);
    padding: 0;
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin: 4px;
    border-radius: 8px;
    width: 48px;
    min-width: 48px;
    height: 48px;
    line-height: 44px;
    transition: color 0.3s, background 0.3s;
    font-family: inherit;
}

/* Skip / Siguiente button */
.btn-skip {
    margin-top: 10px;
    padding: 10px 32px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    max-width: 480px;
    width: 100%;
}
.btn-skip:hover {
    background: var(--primary-dark);
}
.btn-skip:active {
    transform: scale(0.97);
}

/* === Responsive === */
@media (max-width: 600px) {
    .table-container {
        min-height: auto;
        padding: 8px;
    }
    table {
        width: 100%;
        border-radius: var(--radius);
    }
    th, td {
        padding: 10px 12px;
    }
}

/* === Inputs === */
input[type=text] {
    background-color: var(--success-bg);
    border: 2px solid var(--success-light);
    color: var(--text);
    padding: 12px 16px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    margin: 4px 0;
    border-radius: var(--radius-sm);
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
input[type=text]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

input[type=password] {
    font-family: inherit;
}

/* === Word display === */
.palabra {
    background: linear-gradient(135deg, #F0FDF4, #DCFCE7);
    border: none;
    color: var(--text);
    padding: 14px 24px;
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin: 0;
    border-radius: 0;
    width: 100%;
    box-sizing: border-box;
}

.palabra2 {
    border: none;
    color: var(--success);
    padding: 12px 24px;
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin: 4px 0;
    width: 100%;
    box-sizing: border-box;
}

/* === Progress Bar === */
.progress-bar-container {
    width: 100%;
    max-width: 480px;
    background-color: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar {
    width: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width 3s;
    border-radius: 4px;
}

/* === Links === */
.bottom-links {
    margin-top: 10px;
    padding-bottom: 10px;
    width: 100%;
    max-width: 480px;
    text-align: right;
}

.edit-link {
    font-weight: bold;
    color: var(--text-muted);
    transition: color 0.2s;
}
.edit-link:hover {
    color: var(--text-secondary);
}

.correcto {
    margin-bottom: 0;
}

/* === Speaker Button === */
.speak-btn {
    background: rgba(0,0,0,0.08);
    border: none;
    cursor: pointer;
    padding: 8px;
    vertical-align: middle;
    transition: background 0.2s, transform 0.15s;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}
.speak-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.speak-btn:hover {
    background: rgba(0,0,0,0.15);
    transform: scale(1.1);
}
.speak-btn:active {
    transform: scale(0.9);
}

/* === Login/Register Form === */
input[type=password],
select {
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    padding: 12px 16px;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input[type=password]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* === Stats page === */
#statsChart {
    border-radius: var(--radius-sm);
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

/* === Focus visible === */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* === Daily Goal Banner === */
.daily-goal-banner {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    max-width: 480px;
    width: 100%;
}
.daily-goal-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text);
}
.daily-goal-secondary {
    color: var(--text-muted);
    font-size: 12px;
}
.daily-goal-check {
    color: var(--success);
    font-weight: 700;
}
.daily-goal-track {
    background: var(--border);
    border-radius: 3px;
    height: 4px;
    margin-top: 6px;
    overflow: hidden;
}
.daily-goal-fill {
    background: var(--primary);
    height: 4px;
    border-radius: 3px;
    transition: width 0.3s;
}
.daily-goal-fill.done {
    background: var(--success);
}

/* === Stats Page === */
.stats-cell {
    padding: 16px !important;
}
.stats-grid {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    margin-bottom: 12px;
}
.stats-grid-2 {
    margin-bottom: 0;
}
.stats-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    flex: 1;
}
.stats-card small {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
}
.stats-num {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
}
.stats-learned { color: var(--success); }
.stats-progress { color: var(--accent); }
.stats-new { color: var(--primary); }
.stats-streak { color: #E91E63; }
.stats-chart-cell {
    padding: 12px !important;
}
.stats-chart-cell canvas {
    width: 100%;
    max-width: 560px;
    border-radius: var(--radius-sm);
}

/* === Login / Register === */
td a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
td a:hover {
    text-decoration: underline;
}

/* === Word display row (learning card) === */
.word-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #F0FDF4, #DCFCE7);
}
.palabra-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

/* === Word List === */
.cat-filter-row {
    padding: 8px 12px !important;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.cat-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all 0.15s;
}
.cat-tag:hover {
    background: var(--border);
    text-decoration: none;
}
.cat-tag.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.word-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 2px 0;
}
.word-list-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    min-width: 0;
}
.word-list-word {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}
.word-list-trans {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.word-list-peso {
    font-size: 12px;
    font-weight: 600;
    min-width: 36px;
    text-align: right;
}
.speak-btn-sm {
    padding: 4px;
    flex-shrink: 0;
}
.word-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: var(--text-muted);
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.word-delete-btn:hover {
    color: var(--error);
    background: var(--error-light);
}

.word-list-row td {
    padding: 6px 12px !important;
}

/* === Text Cards (texts & stories list) === */
.text-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    margin-top: 8px;
    width: 100%;
    max-width: 480px;
    text-align: left;
}
.text-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.text-card-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    flex: 1;
    min-width: 0;
}
.text-card-topic {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.text-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 8px;
}
.text-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}
.text-card-meta {
    font-size: 12px;
    color: var(--text-muted);
}
.text-card-btn {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, var(--success), #16A34A);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 4px rgba(34,197,94,0.2);
}
.text-card-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(34,197,94,0.3);
    color: white;
    text-decoration: none;
}
.text-card-btn:active {
    transform: scale(0.97);
}

/* === Level Badges === */
.level-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
.level-a1 {
    background: #DCFCE7;
    color: #166534;
}
.level-a2 {
    background: #FEF9C3;
    color: #854D0E;
}
.level-b1 {
    background: #DBEAFE;
    color: #1E40AF;
}
.level-b2 {
    background: #F3E8FF;
    color: #6B21A8;
}

/* === Reader (text_reader & story_reader) === */
.reader-header {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    width: 100%;
    max-width: 480px;
    text-align: left;
}
.reader-back-link {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.reader-back-link:hover {
    text-decoration: underline;
}
.reader-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}
.reader-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    flex: 1;
}
.reader-progress-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}
.reader-content {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px 18px;
    margin-top: 8px;
    width: 100%;
    max-width: 480px;
    text-align: left;
    font-size: 17px;
    line-height: 1.8;
    color: var(--text);
    user-select: text;
    -webkit-user-select: text;
}
.reader-word {
    cursor: pointer;
    border-bottom: 1px dotted transparent;
    transition: border-color 0.15s, background 0.15s;
    border-radius: 2px;
    padding: 0 1px;
}
.reader-word:hover {
    border-bottom-color: var(--primary-light);
    background: rgba(37,99,235,0.06);
}
.reader-word-known {
    background: rgba(34,197,94,0.1);
    border-bottom-color: var(--success-light);
}
.reader-word-known:hover {
    background: rgba(34,197,94,0.18);
}

/* === Story Target Words === */
.story-target-word {
    cursor: pointer;
    background: rgba(249,115,22,0.12);
    border-bottom: 2px solid var(--accent-light);
    border-radius: 2px;
    padding: 0 2px;
    transition: background 0.15s;
}
.story-target-word:hover {
    background: rgba(249,115,22,0.25);
}
.story-target-list {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 12px 16px;
    margin-top: 8px;
    width: 100%;
    max-width: 480px;
    text-align: left;
    font-size: 13px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.story-target-pill {
    display: inline-block;
    padding: 2px 10px;
    background: rgba(249,115,22,0.12);
    border: 1px solid var(--accent-light);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
}
.story-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    width: 100%;
    max-width: 480px;
}
.story-actions .text-card-btn {
    flex: 1;
    text-align: center;
}

/* === Word Popup Overlay === */
.word-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.word-popup {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: 100%;
    max-width: 320px;
    position: relative;
    text-align: center;
}
.word-popup-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.word-popup-close:hover {
    color: var(--text);
}
.word-popup-word {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}
.word-popup-status {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    min-height: 20px;
}
.word-popup-translation {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.word-popup-peso {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.word-popup-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.word-popup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
    width: 100%;
}
.word-popup-btn:active {
    transform: scale(0.97);
}
.word-popup-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.word-popup-btn.speak {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}
.word-popup-btn.speak:hover {
    background: var(--border);
}
.word-popup-btn.add {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 2px 4px rgba(37,99,235,0.2);
}
.word-popup-btn.add:hover {
    box-shadow: 0 4px 8px rgba(37,99,235,0.3);
}

/* === Story Form (story_new) === */
.story-form-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    margin-top: 8px;
    width: 100%;
    max-width: 480px;
    text-align: left;
}
.story-form-section {
    margin-bottom: 16px;
}
.story-form-section:last-child {
    margin-bottom: 0;
}
.story-form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}
.story-word-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
    padding: 4px 0;
}
.story-word-tag {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}
.story-word-tag input[type="checkbox"] {
    display: none;
}
.story-word-tag-text {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all 0.15s;
    user-select: none;
}
.story-word-tag input[type="checkbox"]:checked + .story-word-tag-text {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.story-word-tag input[type="checkbox"]:disabled + .story-word-tag-text {
    opacity: 0.4;
    cursor: not-allowed;
}
.story-word-count {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}
.story-loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 8px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Animations === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
