:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f6f8);
  --muted: #c5ced8;
  --card: var(--tg-theme-secondary-bg-color, #232e3c);
  --line: rgba(255, 255, 255, 0.12);
  --btn: var(--tg-theme-button-color, #3a8ee6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --radius: 14px;
  --nav-h: 72px;
}

html[data-theme="light"] {
  --muted: #5c6570;
  --line: rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  height: 100dvh;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}

.topbar {
  flex-shrink: 0;
  padding: 14px 20px 8px;
}

.topbar-title {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.topbar-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 16px;
  -webkit-overflow-scrolling: touch;
}

.screen.is-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 10px;
}

.tabbar {
  flex-shrink: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0;
  cursor: pointer;
}

.tab.active {
  color: var(--text);
}

.tab-label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-ico {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.tab-ico svg {
  width: 22px;
  height: 22px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}

.card.clickable {
  cursor: pointer;
}

.card.locked {
  opacity: 0.55;
}

.card h3 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0;
  color: var(--text);
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.progress {
  margin-top: 10px;
  height: 3px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--text);
  border-radius: 99px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  margin-top: 12px;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s ease, filter 0.18s ease, opacity 0.18s ease;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  width: auto;
  padding: 8px 0;
  margin-top: 4px;
  font-weight: 500;
}

.btn.option {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  text-align: left;
  justify-content: flex-start;
  font-weight: 500;
  margin-top: 0;
  margin-bottom: 8px;
}

.btn.option.ok {
  border-color: #34c759;
}

.btn.option.bad {
  border-color: #ff3b30;
}

.hint-btn {
  width: 100%;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.hint-box {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  line-height: 1.45;
}

.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  line-height: 1.5;
}

.lesson-body {
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  margin-top: 8px;
}

.topic-picker {
  position: relative;
  flex-shrink: 0;
  margin-bottom: 10px;
}

.topic-picker-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--card);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.topic-picker-k {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

.topic-picker-v {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-picker-chevron {
  color: var(--muted);
  font-size: 12px;
}

.topic-picker-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  max-height: 40vh;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.topic-picker-list.hidden {
  display: none;
}

.topic-picker-list button {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
  font-size: 15px;
  cursor: pointer;
}

.topic-picker-list button:last-child {
  border-bottom: 0;
}

.topic-picker-list button.active {
  font-weight: 600;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 10px;
}

.chat-hint {
  margin: auto 8px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--btn);
  color: var(--btn-text);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
}

.chat-form {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.chat-form input::placeholder {
  color: var(--muted);
}

.chat-form .btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  margin-top: 0;
  padding: 0;
  border-radius: 12px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.badge s {
  opacity: 0.55;
  margin-right: 6px;
  font-weight: 500;
}

.result {
  text-align: center;
  padding: 24px 8px;
}

.result .score {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
}
