:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #000000);
    --hint: var(--tg-theme-hint-color, #999999);
    --link: var(--tg-theme-link-color, #2481cc);
    --button: var(--tg-theme-button-color, #2481cc);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    max-width: 100vw;
    overflow-x: hidden;
}

.header {
    padding: 12px 16px;
    background: var(--secondary-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 18px;
    margin-bottom: 8px;
}

.header-actions {
    display: flex;
    gap: 4px;
    overflow-x: auto;
}

.tab {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--hint);
    font-size: 13px;
    border-radius: 16px;
    cursor: pointer;
    white-space: nowrap;
}

.tab.active {
    background: var(--button);
    color: var(--button-text);
}

.tab-content {
    display: none;
    padding: 16px;
}

.tab-content.active { display: block; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header h2 { font-size: 16px; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
    padding: 12px;
    background: var(--secondary-bg);
    border-radius: 10px;
    cursor: pointer;
}

.list-item-title { font-weight: 600; font-size: 14px; }
.list-item-sub { font-size: 12px; color: var(--hint); margin-top: 4px; }

/* Buttons */
.btn-small {
    padding: 4px 12px;
    border: 1px solid var(--button);
    background: transparent;
    color: var(--button);
    border-radius: 14px;
    font-size: 12px;
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    padding: 10px;
    background: var(--button);
    color: var(--button-text);
    border: none;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
}

.btn-danger { background: #e53935; color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.btn-warning { background: #fb8c00; color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.btn-success { background: #43a047; color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; }

/* Chat */
.chat-container {
    height: calc(100vh - 220px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 8px;
}

.chat-msg {
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 85%;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-msg.user {
    background: var(--button);
    color: var(--button-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
    background: var(--secondary-bg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-input {
    display: flex;
    gap: 8px;
    position: sticky;
    bottom: 0;
    padding: 8px 0;
    background: var(--bg);
}

.chat-input input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--hint);
    border-radius: 20px;
    font-size: 14px;
    background: var(--secondary-bg);
    color: var(--text);
    outline: none;
}

.chat-input button {
    padding: 10px 16px;
    background: var(--button);
    color: var(--button-text);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
}

/* Flashcards */
.flashcard {
    text-align: center;
    padding: 20px;
}

.flashcard-front, .flashcard-back {
    padding: 24px;
    background: var(--secondary-bg);
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.5;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.flashcard-back { font-weight: 600; }

.flashcard-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-card {
    padding: 16px;
    background: var(--secondary-bg);
    border-radius: 10px;
    text-align: center;
}

.stat-value { font-size: 24px; font-weight: 700; color: var(--button); }
.stat-label { font-size: 12px; color: var(--hint); margin-top: 4px; }

/* Loading */
.loading {
    text-align: center;
    padding: 24px;
    color: var(--hint);
}

select {
    padding: 4px 8px;
    border: 1px solid var(--hint);
    border-radius: 8px;
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 13px;
}
