:root {
  --bg-start: #d7eaff;
  --bg-end: #f0f7ff;
  --surface: #ffffff;
  --surface-soft: #f9fcff;
  --primary: #2f95e8;
  --primary-strong: #0077cc;
  --primary-soft: #e7f3ff;
  --text: #1f2937;
  --muted: #5b6472;
  --border: #dbe9f8;
  --success: #2bb673;
  --danger: #dc3545;
  --shadow: 0 10px 28px rgba(15, 44, 88, 0.12);
  --set-card-height: 360px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
  color: var(--text);
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(1100px, calc(100% - 2rem));
  margin: 1.2rem auto 0.8rem;
  padding: 0.9rem 1.2rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.2vw, 1.65rem);
  color: #054d8e;
  line-height: 1.25;
}

.topbar .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.main-container {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.8rem 0 1.8rem;
}

.dashboard-grid,
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.set-card {
  display: flex;
  flex-direction: column;
  height: var(--set-card-height);
  background: var(--surface);
  padding: 1rem 1rem 1.1rem;
  border-radius: 14px;
  border-top: 5px solid var(--primary);
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.set-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 30px rgba(15, 44, 88, 0.16);
}

.set-head {
  flex-shrink: 0;
}

.set-head h2,
.set-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: var(--primary-strong);
}

.lessons {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.3rem;
  scrollbar-gutter: stable;
}

.lessons::-webkit-scrollbar {
  width: 8px;
}

.lessons::-webkit-scrollbar-thumb {
  background: #b8d9fb;
  border-radius: 999px;
}

.lessons::-webkit-scrollbar-track {
  background: transparent;
}

.lesson-link {
  display: block;
  padding: 0.68rem 0.8rem;
  border-radius: 10px;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 500;
  color: #09548e;
  background: var(--primary-soft);
  border: 1px solid #cde4ff;
  transition: background 0.2s ease, color 0.2s ease;
}

.lesson-link:hover {
  background: #d8ebff;
  color: #053f71;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.tab {
  min-height: 46px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: #0f5f9f;
  font-size: 0.98rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}

.tab:hover {
  transform: translateY(-1px);
  background: #f2f8ff;
}

.tab.active {
  border-color: transparent;
  background: linear-gradient(90deg, #4facfe, #00c6ff);
  color: #fff;
  box-shadow: 0 10px 18px rgba(56, 156, 237, 0.24);
}

.card {
  background: var(--surface);
  border-radius: 14px;
  padding: 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card h2 {
  margin-top: 0;
  margin-bottom: 0.9rem;
  color: var(--primary-strong);
  font-size: 1.25rem;
}

.view {
  transition: opacity 0.2s ease;
}

.conversation {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.95rem;
  min-height: 110px;
}

.conversation p {
  margin: 0.55rem 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.conversation b {
  color: #0b4f84;
}

.word-meaning-wrap {
  margin-top: 0.9rem;
}

.word-meaning-section {
  margin-top: 0.7rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f5fbff;
}

.word-meaning-section h3 {
  margin: 0 0 0.5rem;
  color: #0b5c9b;
  font-size: 1rem;
}

.word-meaning-section ul {
  margin: 0;
  padding-left: 1.1rem;
}

.word-meaning-section li {
  margin-bottom: 0.45rem;
  line-height: 1.45;
}

.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.review-item {
  padding: 0.8rem;
  border-radius: 10px;
  border: 1px solid #e4eef8;
  background: #fbfdff;
}

.review-item p {
  margin: 0 0 0.55rem;
  font-weight: 600;
}

.input-word,
.blank-input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #cfdceb;
  font-size: 1rem;
  outline: none;
}

.input-word:focus,
.blank-input:focus {
  border-color: #62aef0;
  box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.2);
}

.input-word.correct,
.blank-input.correct {
  border-color: var(--success);
  background: #ecfff3;
}

.input-word.incorrect,
.blank-input.incorrect {
  border-color: var(--danger);
  background: #fff3f3;
}

#test-conversation .test-item {
  margin-right: 0.5rem !important;
  margin-bottom: 0.45rem;
}

#test-conversation .test-item input.blank-input {
  min-width: 120px;
  max-width: 180px;
}

#test-conversation .test-item small {
  display: block;
  max-width: 180px;
  overflow-wrap: anywhere;
}

.controls {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 40px;
  padding: 0.55rem 0.95rem;
  border: none;
  border-radius: 8px;
  font-size: 0.98rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: #4facfe;
  color: #fff;
  transition: transform 0.14s ease, filter 0.18s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(0.97);
}

.btn.alt {
  background: var(--primary-soft);
  color: #08548f;
  border: 1px solid #cde4ff;
}

.btn.small {
  min-height: 34px;
  font-size: 0.88rem;
  padding: 0.4rem 0.7rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 1.2rem 1rem;
  text-align: center;
  box-shadow: 0 20px 34px rgba(0, 0, 0, 0.24);
}

.modal-card h2 {
  margin: 0.5rem 0 0.3rem;
}

#confetti {
  height: 76px;
}

.footer {
  text-align: center;
  padding: 1rem;
  margin-top: 1rem;
  color: #4b5563;
  font-size: 0.9rem;
}

.error {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: #fff4f4;
  border: 1px solid #f4caca;
  color: #852a2a;
}

.conversation .speak-word {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px dashed #4facfe;
}

.conversation .speak-word:focus-visible {
  outline: 2px solid #4facfe;
  outline-offset: 2px;
  border-bottom-color: transparent;
  border-radius: 3px;
}

.conversation .speak-word.speaking {
  background: #e7f3ff;
  border-bottom-color: #0077cc;
  border-radius: 4px;
}

@media (max-width: 900px) {
  .main-container,
  .topbar {
    width: calc(100% - 1.5rem);
  }

  .main-container {
    padding-bottom: 1.3rem;
  }

  .card {
    padding: 1rem;
  }
}

@media (max-width: 680px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.85rem 0.9rem;
  }

  .topbar h1 {
    font-size: 1.15rem;
  }

  .topbar .subtitle {
    font-size: 0.92rem;
  }

  .tabs {
    grid-template-columns: 1fr;
  }

  .controls {
    justify-content: stretch;
  }

  .controls .btn {
    width: 100%;
  }

  .review-grid,
  .dashboard-grid,
  .grid {
    grid-template-columns: 1fr;
  }

  #test-conversation p {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: flex-start;
  }

  #test-conversation .test-item {
    margin-right: 0 !important;
    width: min(100%, 220px);
  }

  #test-conversation .test-item input.blank-input,
  #test-conversation .test-item small {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .main-container,
  .topbar {
    width: calc(100% - 1rem);
  }

  .card,
  .set-card,
  .conversation {
    padding: 0.8rem;
  }

  .tab {
    min-height: 42px;
    font-size: 0.92rem;
  }

  .btn {
    min-height: 38px;
    font-size: 0.92rem;
  }

  .lesson-link {
    font-size: 0.94rem;
  }

  .set-card {
    height: 320px;
  }
}
