:root {
  --blue: #1a5fb4;
  --blue-light: #e8f0fb;
  --green: #1c8a3d;
  --green-light: #e6f6ea;
  --red: #c0392b;
  --red-light: #fbeae8;
  --gray: #6b7280;
  --border: #e2e5ea;
  --bg: #f7f8fa;
  --text: #1f2430;
  --yellow-light: #fdf1c4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--blue);
  color: white;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
}

.app-header h1 {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.app-header .title-uz {
  font-size: 19px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header .title-de {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  line-height: 1;
  padding: 4px 8px 4px 0;
  cursor: pointer;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* Category picker */
.topic-group {
  margin-bottom: 18px;
}

.topic-group-title {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gray);
  margin: 0 0 8px 4px;
  letter-spacing: 0.02em;
}

.topic-group-title-de {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}

.topic-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text);
}

.topic-card .names {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topic-card .name-uz {
  font-weight: 600;
}

.topic-card .name-de {
  font-size: 13px;
  color: var(--gray);
}

.topic-card .meta {
  flex-shrink: 0;
  font-size: 13px;
  color: var(--gray);
  text-align: right;
  white-space: nowrap;
}

.topic-card .learned {
  color: var(--green);
  font-weight: 600;
}

.topic-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Quiz view */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--blue);
}

.question-counter {
  font-size: 14px;
  color: var(--gray);
  margin-bottom: 6px;
}

.question-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 16px;
}

.question-text-uz {
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 6px;
}

.question-text-de {
  font-size: 14px;
  color: var(--gray);
  margin: 0 0 14px;
}

.question-image {
  display: block;
  max-width: 100%;
  max-height: 260px;
  margin: 0 auto 14px;
  border-radius: 8px;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  background: white;
}

.answer input {
  margin-top: 3px;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.answer .answer-text-uz {
  font-weight: 500;
}

.answer .answer-text-de {
  font-size: 13px;
  color: var(--gray);
  margin-top: 2px;
}

.answer.correct {
  border-color: var(--green);
  background: var(--green-light);
}

.answer.incorrect {
  border-color: var(--red);
  background: var(--red-light);
}

.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

button.primary {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 11px 26px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

button.primary:disabled {
  background: var(--border);
  color: var(--gray);
  cursor: not-allowed;
}

.btn-uz {
  font-size: 16px;
  font-weight: 600;
}

.btn-de {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
}

/* Summary view */
.summary-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 20px;
  text-align: center;
}

.summary-score {
  font-size: 40px;
  font-weight: 700;
  color: var(--blue);
  margin: 8px 0;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

button.secondary {
  background: white;
  color: var(--blue);
  border: 1.5px solid var(--blue);
  border-radius: 10px;
  padding: 11px 26px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.summary-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Chat-Widget */
.chat-container {
  margin-top: 4px;
}

.chat-toggle {
  width: 100%;
  background: white;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: var(--blue);
}

.chat-panel {
  margin-top: 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.chat-messages {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.chat-msg {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 85%;
  white-space: pre-wrap;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--blue-light);
  color: var(--text);
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text);
}

.chat-loading {
  opacity: 0.5;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}

.chat-form input:disabled {
  opacity: 0.6;
}

.chat-send {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-size: 16px;
  cursor: pointer;
}

.mic-btn {
  background: white;
  color: var(--blue);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.mic-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mic-btn.recording {
  background: var(--red);
  border-color: var(--red);
  color: white;
  animation: mic-pulse 1.1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(192, 57, 43, 0); }
}

.chat-status {
  font-size: 13px;
  color: var(--red);
  margin-bottom: 8px;
}

.lock-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 20px;
  text-align: center;
  margin-top: 40px;
}

.lock-text-uz {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
}

.lock-text-de {
  font-size: 14px;
  color: var(--gray);
  margin: 0 0 18px;
}

.lock-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lock-card input {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 17px;
  text-align: center;
}

.lock-error {
  font-size: 14px;
  color: var(--red);
  margin: 14px 0 0;
}

.summary-label .title-de {
  font-size: 13px;
  color: var(--gray);
  font-weight: 400;
}

/* Statistik */
.stats-entry-btn {
  width: 100%;
  background: white;
  border: 1.5px solid var(--blue);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
  cursor: pointer;
  color: var(--blue);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.stats-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  text-align: center;
}

.stats-panel-title {
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stats-panel-title .btn-uz {
  font-size: 17px;
}

.bar-chart {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 12px;
  height: 200px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
}

.bar-value {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
}

.bar-track {
  flex: 1;
  width: 100%;
  max-width: 56px;
  display: flex;
  align-items: flex-end;
  background: var(--bg);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  min-height: 2px;
  border-radius: 6px 6px 0 0;
}

.bar-total { background: var(--red-light); }
.bar-once { background: var(--yellow-light); }
.bar-mastered { background: var(--green-light); }

.bar-label {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: center;
}

.bar-label .btn-uz {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.bar-label .btn-de {
  font-size: 10px;
  color: var(--gray);
  opacity: 1;
}

.pie-chart-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.pie-chart {
  position: relative;
  width: 180px;
  height: 180px;
  border-radius: 50%;
}

.pie-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.pie-legend {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}

.stats-empty {
  color: var(--gray);
  font-size: 14px;
  padding: 20px 0;
}
