:root {
  --bg: #1c2732;
  --surface: #242f3d;
  --surface-hover: #2b3645;
  --separator: rgba(255, 255, 255, 0.06);
  --text: #ffffff;
  --text-secondary: #708499;
  --hint: #6d7f8f;
  --accent: #2481cc;
  --accent-soft: rgba(36, 129, 204, 0.18);
  --success: #3dd68c;
  --danger: #e35d6a;
  --warn: #e0a84a;
  --radius: 14px;
  --header-h: 52px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

.screen {
  display: none;
  height: 100%;
  max-height: 100%;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.screen.is-active {
  display: flex;
  animation: fadeIn 180ms ease;
}

body.has-tabs .screen.is-active {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tg-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tg-header--solo {
  grid-template-columns: 1fr;
}

.tg-header__title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tg-header__actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.verified {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.back-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.back-btn:active {
  background: var(--surface);
}

.progress-pill {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(28px + var(--safe-bottom));
}

.scroll--tabs {
  padding-bottom: calc(20px + var(--safe-bottom));
}

.hero {
  text-align: center;
  padding: 12px 8px 20px;
}

.hero--compact {
  padding-bottom: 12px;
}

.avatar {
  width: 88px;
  height: 88px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  background:
    radial-gradient(circle at 30% 25%, #4aa3e8, transparent 45%),
    linear-gradient(145deg, var(--accent), #1a5f99);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.hero__title {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.hero__desc {
  margin: 0 auto;
  max-width: 320px;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text-secondary);
}

.source-pill {
  margin: 0 auto 14px;
  width: fit-content;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: #18222d;
  margin-bottom: 18px;
}

.search__icon {
  width: 18px;
  height: 18px;
  color: var(--hint);
  flex-shrink: 0;
}

.search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}

.search input::placeholder {
  color: var(--hint);
}

.section-title {
  margin: 18px 0 10px 4px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-title:first-child {
  margin-top: 4px;
}

.page-intro {
  padding: 4px 4px 14px;
}

.page-intro__sub {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.4;
}

.cefr-label {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.list-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-card + .section-title,
#rules-map .list-card + .section-title {
  margin-top: 22px;
}

.home-daily-card,
#home-daily-card {
  margin-bottom: 4px;
}

.list-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  text-align: left;
  min-height: 60px;
  border-bottom: 1px solid var(--separator);
  transition: background 120ms ease;
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row:not(.list-row--static):active {
  background: var(--surface-hover);
}

.list-row--static {
  cursor: default;
}

.row-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--c, #6c5ce7);
}

.row-icon--blue {
  background: var(--accent);
  font-size: 16px;
  font-weight: 600;
}

.row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.row-title--blue {
  color: var(--accent);
  font-weight: 500;
}

.row-title--example {
  font-weight: 500;
  font-size: 15px;
}

.row-sub {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chevron {
  color: var(--hint);
  font-size: 22px;
  line-height: 1;
  padding-left: 2px;
  flex-shrink: 0;
}

.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 4px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.badge--new {
  color: var(--text-secondary);
}

.badge--learning {
  color: var(--accent);
  background: var(--accent-soft);
}

.badge--weak {
  color: var(--danger);
  background: rgba(227, 93, 106, 0.16);
}

.badge--mastered {
  color: var(--success);
  background: rgba(61, 214, 140, 0.14);
}

.detail-block .detail-pad,
.detail-pad {
  margin: 0;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-secondary);
}

.detail-label {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--hint);
}

.mastery-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mastery-score {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.cta-stack {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.primary-btn {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.primary-btn:active {
  filter: brightness(0.92);
}

.ghost-btn {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
}

.ghost-btn:active {
  background: var(--surface-hover);
}

.cta-hint {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--hint);
  line-height: 1.35;
  word-break: break-all;
}

.footer-handle {
  margin: 28px 0 8px;
  text-align: center;
  color: var(--hint);
  font-size: 14px;
}

/* Tab bar */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 480px);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 6px 10px var(--safe-bottom);
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background:
    linear-gradient(180deg, rgba(36, 47, 61, 0.72), rgba(28, 39, 50, 0.96));
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.22);
  z-index: 30;
}

body.has-tabs .tabbar {
  display: grid;
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: calc(var(--tabbar-h) - 12px);
  border-radius: 14px;
  color: var(--hint);
  transition: color 160ms ease, background 160ms ease, transform 120ms ease;
}

.tab:active {
  transform: scale(0.96);
}

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

.tab.is-active::before {
  content: "";
  position: absolute;
  inset: 2px 6px;
  border-radius: 14px;
  background: var(--accent-soft);
  pointer-events: none;
}

.tab__glyph {
  position: relative;
  z-index: 1;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
}

.tab__glyph svg {
  width: 22px;
  height: 22px;
  display: block;
}

.tab__label {
  position: relative;
  z-index: 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

/* Exercises */
.exercise-scroll {
  padding-top: 12px;
}

.exercise-hint {
  margin: 0 4px 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.match-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.match-chip {
  min-height: 48px;
  padding: 12px 10px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  border: 1.5px solid transparent;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}

.match-chip:active {
  transform: scale(0.98);
}

.match-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.match-chip.is-correct {
  border-color: var(--success);
  background: rgba(61, 214, 140, 0.14);
  color: var(--success);
  pointer-events: none;
}

.match-chip.is-wrong {
  border-color: var(--danger);
  background: rgba(227, 93, 106, 0.14);
}

.match-chip.is-done {
  opacity: 0.45;
  pointer-events: none;
}

.quiz-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 18px;
  margin-bottom: 16px;
  text-align: center;
}

.quiz-prompt-label {
  margin: 0 0 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

.quiz-prompt {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-btn {
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  font-size: 16px;
  font-weight: 500;
  border: 1.5px solid transparent;
}

.option-btn:active {
  background: var(--surface-hover);
}

.option-btn.is-correct {
  border-color: var(--success);
  background: rgba(61, 214, 140, 0.14);
  color: var(--success);
}

.option-btn.is-wrong {
  border-color: var(--danger);
  background: rgba(227, 93, 106, 0.14);
  color: var(--danger);
}

.option-btn:disabled {
  pointer-events: none;
}

.feedback {
  margin: 16px 4px 0;
  font-size: 14px;
  line-height: 1.4;
}

.feedback.is-ok {
  color: var(--success);
}

.feedback.is-bad {
  color: var(--danger);
}

.result-scroll {
  padding-top: 24px;
}

.result-hero {
  text-align: center;
  padding: 12px 8px 28px;
}

.result-score {
  width: 112px;
  height: 112px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
  background: var(--surface);
  border: 3px solid var(--accent);
}

.result-title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 700;
}

.result-sub {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
}

/* Boot / toast */
.boot-error {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

.boot-error[hidden] {
  display: none !important;
}

.boot-error p {
  margin: 0;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(90%, 360px);
  padding: 10px 14px;
  border-radius: 10px;
  background: #323f4d;
  color: #fff;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.toast[hidden] {
  display: none;
}

@media (min-width: 481px) {
  body {
    background: #121820;
  }

  .app {
    border-left: 1px solid rgba(255, 255, 255, 0.04);
    border-right: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }
}
