/* ========== RESET & BASE ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #222240;
    --bg-input: #16162b;
    --text: #e8e8f0;
    --text-dim: #8888aa;
    --text-muted: #5a5a7a;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --green: #00b894;
    --green-bg: rgba(0,184,148,0.15);
    --red: #ff6b6b;
    --red-bg: rgba(255,107,107,0.15);
    --yellow: #ffd93d;
    --yellow-bg: rgba(255,217,61,0.15);
    --blue: #74b9ff;
    --blue-bg: rgba(116,185,255,0.15);
    --border: #2a2a45;
    --radius: 14px;
    --radius-sm: 10px;
    --nav-height: 64px;
    --top-bar-height: 52px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

/* ========== TOP BAR ========== */
#top-bar {
    height: var(--top-bar-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-logo { font-size: 22px; }
.app-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.xp-badge {
    background: var(--accent);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
}

/* ========== SCREENS ========== */
.screen {
    display: none;
    flex: 1;
    overflow: hidden;
    position: relative;
}
.screen.active {
    display: flex;
    flex-direction: column;
}

.screen-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

/* ========== SECTIONS ========== */
.section { margin-bottom: 20px; }
.section-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
}
.section-desc {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: -8px;
    margin-bottom: 12px;
}

/* ========== HERO CARD ========== */
.hero-card {
    background: linear-gradient(135deg, var(--accent), #4a3db8);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.hero-level {
    display: flex;
    align-items: center;
    gap: 14px;
}
.level-icon { font-size: 36px; }
.level-info { flex: 1; }
.level-text {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    display: block;
    margin-bottom: 6px;
}
.xp-bar {
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
}
.xp-bar-fill {
    height: 100%;
    background: var(--yellow);
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}
.xp-sub {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    margin-top: 4px;
    display: block;
}

/* ========== STATS ROW ========== */
.stats-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.stat-box {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 10px;
    text-align: center;
    border: 1px solid var(--border);
}
.stat-num {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-light);
    display: block;
}
.stat-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
    display: block;
}

/* ========== PROGRESS BAR ========== */
.progress-bar-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-bottom: 16px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 3px;
    transition: width 0.4s ease;
    width: 0%;
}

/* ========== MODULE CARDS ========== */
.module-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 10px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.module-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
}
.module-header:active { background: var(--bg-card-hover); }
.module-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.module-icon { font-size: 24px; }
.module-card h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.module-sub {
    font-size: 12px;
    color: var(--text-dim);
}
.chevron {
    font-size: 18px;
    color: var(--text-dim);
    transition: transform 0.2s;
}
.chevron.open { transform: rotate(90deg); }

.module-lessons {
    border-top: 1px solid var(--border);
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.module-lessons.collapsed {
    max-height: 0;
    border-top: none;
}

.lesson-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.lesson-btn:last-child { border-bottom: none; }
.lesson-btn:active { background: var(--bg-card-hover); }

.lesson-status {
    font-size: 16px;
    color: var(--text-muted);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.lesson-status.done {
    color: var(--green);
}

/* ========== SOURCES ========== */
.sources-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sources-card a {
    color: var(--blue);
    font-size: 12px;
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 6px;
    word-break: break-all;
}
.sources-card a:hover { background: var(--blue-bg); }

/* ========== LESSON VIEW ========== */
.lesson-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.lesson-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.lesson-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}
.lesson-count {
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
}

.lesson-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 16px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#lesson-content {
    width: 100%;
    max-width: 400px;
}

/* Lesson Cards */
.lesson-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px 20px;
    border: 1px solid var(--border);
}
.card-emoji {
    font-size: 40px;
    margin-bottom: 14px;
}
.card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
}
.card-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    margin-bottom: 12px;
}
.card-text strong { color: var(--accent-light); }
.card-highlight {
    background: var(--accent);
    background: linear-gradient(135deg, rgba(108,92,231,0.2), rgba(162,155,254,0.1));
    border-left: 3px solid var(--accent);
    padding: 12px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent-light);
}

.card-source {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.card-source a {
    color: var(--blue);
    text-decoration: none;
}

/* Quiz in lesson */
.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}
.quiz-option {
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}
.quiz-option:active { transform: scale(0.98); }
.quiz-option.correct {
    background: var(--green-bg);
    border-color: var(--green);
    color: var(--green);
}
.quiz-option.wrong {
    background: var(--red-bg);
    border-color: var(--red);
    color: var(--red);
}
.quiz-option:disabled { cursor: default; }

.quiz-explanation {
    margin-top: 14px;
    padding: 12px;
    background: var(--blue-bg);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--blue);
}

/* Summary card */
.summary-card { background: linear-gradient(135deg, rgba(0,184,148,0.1), rgba(0,184,148,0.05)); border-color: rgba(0,184,148,0.3); }
.summary-points {
    list-style: none;
    padding: 0;
}
.summary-points li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.summary-points li::before {
    content: "✓";
    color: var(--green);
    font-weight: 700;
    flex-shrink: 0;
}
.summary-points li:last-child { border-bottom: none; }

.lesson-nav {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ========== BUTTONS ========== */
.btn-primary {
    flex: 1;
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-primary:active { opacity: 0.8; }
.btn-primary.disabled, .btn-primary:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn-secondary {
    padding: 14px;
    background: var(--bg-input);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
}
.btn-secondary:active { opacity: 0.8; }

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-add {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    margin-top: 12px;
}
.btn-add:active { border-color: var(--accent); color: var(--accent); }

/* ========== QUIZ SCREEN ========== */
.quiz-stats-row {
    display: flex;
    gap: 16px;
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.quiz-card-wrap {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px 20px;
    border: 1px solid var(--border);
}
.quiz-question {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text);
}
.quiz-answers {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.answer-btn {
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}
.answer-btn:active { transform: scale(0.98); }
.answer-btn.correct {
    background: var(--green-bg);
    border-color: var(--green);
    color: var(--green);
}
.answer-btn.wrong {
    background: var(--red-bg);
    border-color: var(--red);
    color: var(--red);
}

.quiz-feedback {
    text-align: center;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 30px 20px;
    border: 1px solid var(--border);
}
.feedback-icon {
    font-size: 48px;
    font-weight: 800;
    display: block;
    margin-bottom: 10px;
}
.feedback-icon.correct { color: var(--green); }
.feedback-icon.wrong { color: var(--red); }
.quiz-feedback h3 {
    font-size: 20px;
    margin-bottom: 8px;
}
.quiz-feedback p {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 20px;
}

/* ========== PRODUCTS / HAUSHALT ========== */
.products-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.product-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
}
.product-item:active { background: var(--bg-card-hover); }
.product-emoji { font-size: 28px; }
.product-info { flex: 1; }
.product-name { font-weight: 600; font-size: 14px; }
.product-origin { font-size: 12px; color: var(--text-dim); }
.product-arrow { color: var(--text-muted); font-size: 18px; }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
}

/* ========== MODALS ========== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}
.cat-btn {
    padding: 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
.cat-btn:active { border-color: var(--accent); }

.product-select {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.product-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
}
.product-option:active { border-color: var(--accent); }

/* Product detail */
.detail-map {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
}
.detail-map h4 { font-size: 14px; margin-bottom: 12px; }
.route-step {
    padding: 6px 0;
    font-size: 13px;
}
.route-arrow {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 2px 0;
}

.detail-section {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
}
.detail-section h4 { font-size: 14px; margin-bottom: 10px; }
.price-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.price-row:last-child {
    border-bottom: none;
    font-weight: 600;
    color: var(--accent-light);
}

/* ========== SIMULATOR ========== */
.sim-roles {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}
.role-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    width: 100%;
}
.role-card:active { background: var(--bg-card-hover); }
.role-card.dynamic {
    border-color: var(--accent);
    background: linear-gradient(135deg, rgba(108,92,231,0.1), rgba(108,92,231,0.05));
}
.role-icon { font-size: 32px; flex-shrink: 0; }
.role-card h3 { font-size: 15px; font-weight: 600; }
.role-card p { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.sim-game {
    /* sim-game content is dynamically generated */
}

.sim-header {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.sim-meters { display: flex; flex-direction: column; gap: 8px; }
.meter {
    display: flex;
    align-items: center;
    gap: 10px;
}
.meter-label {
    font-size: 12px;
    color: var(--text-dim);
    width: 120px;
    flex-shrink: 0;
}
.meter-bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.meter-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s;
}
.meter-fill.green { background: var(--green); }
.meter-fill.red { background: var(--red); }
.meter-fill.yellow { background: var(--yellow); }
.meter-fill.blue { background: var(--blue); }

.sim-scenario {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}
.sim-scenario h4 {
    font-size: 14px;
    color: var(--accent-light);
    margin-bottom: 8px;
}
.sim-scenario p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 8px;
}

.sim-choices {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.choice-btn {
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
}
.choice-btn:active { background: var(--bg-card-hover); border-color: var(--accent); }

.next-btn {
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.next-btn:active { opacity: 0.8; }

/* ========== LEXIKON ========== */
.search-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.lexikon-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.lexikon-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    border: 1px solid var(--border);
    cursor: pointer;
}
.lexikon-item:active { background: var(--bg-card-hover); }
.lexikon-item h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--accent-light);
    margin-bottom: 4px;
}
.lexikon-item p {
    font-size: 13px;
    color: var(--text-dim);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lexikon-detail {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
}
.lexikon-detail h3 {
    font-size: 20px;
    color: var(--accent-light);
    margin-bottom: 10px;
}
.lexikon-detail p {
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 14px;
}
.example {
    background: var(--yellow-bg);
    border-left: 3px solid var(--yellow);
    padding: 12px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.example-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--yellow);
    margin-bottom: 4px;
}
.example p {
    font-size: 13px;
    margin: 0;
}

.back-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

/* ========== MAP ========== */
.map-container {
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border);
    min-height: 420px;
}

/* ========== BOTTOM NAV ========== */
#bottom-nav {
    display: flex;
    height: var(--nav-height);
    padding-bottom: var(--safe-bottom);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
}
.nav-item.active {
    color: var(--accent-light);
}
.nav-icon { font-size: 20px; }
.nav-label { font-size: 10px; font-weight: 500; }

/* ========== UTILITY ========== */
.hidden { display: none !important; }

/* Relation items in dynamic sim */
.relation-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.relation-bar {
    width: 100%;
    height: 4px;
    border-radius: 2px;
}

/* Scrollbar styling */
.screen-scroll::-webkit-scrollbar,
.lesson-body::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
    width: 0;
}

/* Animation for lesson cards */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.lesson-card {
    animation: slideIn 0.3s ease;
}

/* ========== RESPONSIVE ========== */
@media (min-width: 481px) {
    #app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}
