@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400;
  src: url('fonts/Poppins-400.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 500;
  src: url('fonts/Poppins-500.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 600;
  src: url('fonts/Poppins-600.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  src: url('fonts/Nunito-400.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 600;
  src: url('fonts/Nunito-600.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  src: url('fonts/Nunito-700.ttf') format('truetype');
  font-display: swap;
}

:root {
  --page: #0a092d;
  --card: #2e3856;
  --card-2: #333e5f;
  --text: #f6f7fb;
  --muted: #aab2cf;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  flex-wrap: wrap;
}
.brand { font-weight: 600; font-size: 18px; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

select, .btn {
  background: #1a2138;
  color: var(--text);
  border: 1px solid #33406a;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover, select:hover { background: #222b47; }
.btn.active { background: #2e5a4a; border-color: #3d8b6a; }
.btn.focus-active { background: #2e5a4a; border-color: #3d8b6a; }

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 12px 18px 44px;
}

.scene {
  width: min(1120px, 100%);
  height: min(600px, 64vh);
  perspective: 2200px;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
  transition: transform 0.6s cubic-bezier(.2,.7,.2,1);
  transform-style: preserve-3d;
  cursor: pointer;
}
.card.flipped { transform: rotateY(180deg); }

.star {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s, transform 0.2s;
  z-index: 2;
}
.star:hover {
  color: var(--text);
  transform: scale(1.15);
}
.star.filled {
  color: #f0c040;
}
.card.flipped .front .star {
  visibility: hidden;
  pointer-events: none;
}
.card:not(.flipped) .back .star {
  visibility: hidden;
  pointer-events: none;
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 26px 60px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  padding: 26px 30px;
}
.back { transform: rotateY(180deg); }

.front-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.word {
  font-size: clamp(36px, 5.5vw, 60px);
  font-weight: 500;
  letter-spacing: .3px;
  text-align: center;
}

.back-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
}
.text-col {
  flex: 1 1 0;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 28px;
  padding-left: 35px;
}
.def {
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(20px, 2.8vw, 32px);
  line-height: 1.35;
  text-align: left;
}
.back-word {
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(24px, 3.2vw, 38px);
  line-height: 1.35;
  color: var(--text);
  pointer-events: none;
  text-align: left;
  font-weight: 600;
  align-self: flex-start;
}
.syn {
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(22px, 2.8vw, 30px);
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: none;
  text-align: left;
  font-weight: 700;
  align-self: flex-start;
}
.syn-list {
  list-style: disc;
  padding-left: 24px;
  margin: 0;
  text-align: left;
}
.syn-list li {
  margin: 0;
  font-weight: 700;
}
.syn-list li.unbold-syn {
  font-weight: 400;
  color: #727c9b;
}
.syn-list li:last-child {
  margin-bottom: 0;
}
.img-wrap {
  flex: 0 0 auto;
  width: min(42%, 460px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-wrap img {
  max-width: 100%;
  max-height: 46vh;
  object-fit: contain;
  border-radius: 14px;
}
.img-wrap.empty { display: none; }
.back-body.no-img { justify-content: flex-start; }
.back-body.no-img .text-col { max-width: 80%; }

.nav { display: flex; align-items: center; gap: 26px; }
.navbtn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid #33406a;
  background: #1a2138;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}
.navbtn:hover { background: #222b47; }
.navbtn:disabled { opacity: .35; cursor: default; }
.counter { min-width: 110px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.keys { color: var(--muted); font-size: 13px; margin: 0; }
.no-fav-msg {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin: 0;
}

.loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--page); color: var(--muted); z-index: 10;
}
.loading.hidden { display: none; }

.settings {
  position: fixed; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(10,9,45,.85); z-index: 20;
}
.settings-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 30px 36px;
  display: flex; flex-direction: column; gap: 18px;
  min-width: 260px;
}
.setting-row {
  display: flex; align-items: center; gap: 12px;
}
.setting-row label {
  font-size: 15px; color: var(--text);
}
.setting-row input {
  flex: 1; background: #1a2138; color: var(--text);
  border: 1px solid #33406a; border-radius: 10px;
  padding: 8px 12px; font-size: 15px; font-family: inherit;
}

@media (max-width: 680px) {
  .topbar { padding: 14px 18px; gap: 12px; }
  .brand { font-size: 16px; }
  .controls { width: 100%; gap: 8px; justify-content: flex-start; }
  select, .btn { padding: 7px 10px; font-size: 13px; }
  .stage { gap: 18px; padding: 10px 16px 32px; }
  .back-body { flex-direction: column; gap: 20px; }
  .img-wrap { width: 70%; }
  .scene { height: 60vh; }
  .text-col { padding-left: 0; align-items: center; }
  .def { text-align: center; }
  .stats-grid { gap: 8px; }
  .stat-card { min-width: 0; gap: 6px; padding: 10px 8px; }
  .stat-icon { flex: 0 0 32px; width: 32px; height: 32px; font-size: 16px; }
  .stat-value { font-size: 14px; }
  .stat-label { font-size: 9px; }
  .global-pairing-card { padding: 14px 16px; }
  .unit-row { padding: 12px 14px; }
}

/* ==========================================================================
   Writing Test & Pairing Layout Panels (Original Theme Compliant)
   ========================================================================== */
.test-panel {
  width: min(580px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  animation: fadeIn 0.25s ease;
}

.test-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.test-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.test-desc {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.intro-stats {
  background: var(--card-2);
  border: 1px solid #33406a;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 15px;
}

.highlight-val {
  font-weight: 600;
  color: var(--text);
}

.test-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.badge {
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 8px;
  padding: 4px 10px;
  color: var(--text);
}

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 6px;
  background: #1a2138;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #3d8b6a;
  width: 0;
  transition: width 0.3s ease;
}

/* Test card display */
.test-card {
  background: var(--card-2);
  border: 1px solid #33406a;
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.test-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.test-definition-text {
  font-size: 20px;
  line-height: 1.5;
  color: var(--text);
}

.divider {
  border: 0;
  height: 1px;
  background: #33406a;
  margin: 4px 0;
}

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

.input-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hint-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px;
}
.hint-btn:hover {
  color: var(--text);
}

.input-wrapper {
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 10px;
  padding: 10px 14px;
}
.input-wrapper input {
  background: none;
  border: none;
  width: 100%;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.hint-box {
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* Feedback panel styling */
.feedback-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.feedback-status-icon {
  font-size: 18px;
  font-weight: 700;
}

.feedback-status-text {
  font-size: 16px;
  font-weight: 600;
}

.feedback-details {
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

.detail-row {
  display: flex;
  gap: 6px;
  line-height: 1.4;
}

.detail-lbl {
  color: var(--muted);
  font-weight: 600;
}

.detail-val {
  color: var(--text);
}

/* Summary screen */
.summary-title {
  margin: 0;
  text-align: center;
  font-size: 26px;
  font-weight: 600;
}

.score-circle-container {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 10px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-svg {
  position: absolute;
  top: 0;
  left: 0;
  transform: rotate(-90deg);
}

.score-svg-bg {
  stroke: #1a2138;
}

.score-svg-fill {
  stroke: #3d8b6a;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease-out;
}

.score-overlay-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.score-fraction {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

.score-percentage {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.summary-actions {
  display: flex;
  gap: 12px;
}

.summary-actions button {
  flex: 1;
  padding: 12px;
}

/* Incorrect Answers listing */
.incorrect-review-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 10px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.review-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.incorrect-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.incorrect-row {
  background: var(--card-2);
  border: 1px solid #33406a;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.incorrect-row-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  flex: 1;
}

.incorrect-def {
  color: var(--text);
  line-height: 1.4;
}

.incorrect-user-ans {
  color: #ff5252;
  font-weight: 500;
}

.incorrect-correct-details {
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  margin-top: 2px;
}

.star-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}
.star-btn.active {
  color: #f0c040;
}

/* Pairing Game layout details */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 10px 0;
  width: 100%;
}

/* Grid card button states */
.game-card-btn {
  background: var(--card-2);
  color: var(--text);
  border: 1.5px solid #33406a;
  border-radius: 12px;
  height: 58px;
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.game-card-btn:hover:not(:disabled) {
  background: #3c486e;
}

.game-card-btn.selected {
  border-color: #f0c040;
  box-shadow: 0 0 8px rgba(240, 192, 64, 0.4);
}

.game-card-btn.matched {
  background: #2e5a4a;
  border-color: #3d8b6a;
  color: var(--text);
  cursor: default;
}

.game-card-btn.wrong {
  background: rgba(211, 47, 47, 0.2);
  border-color: #ff5252;
  animation: shake 0.2s ease alternate 2;
}

@keyframes shake {
  from { transform: translateX(-4px); }
  to { transform: translateX(4px); }
}

.game-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}

.game-review-panel {
  background: var(--card-2);
  border: 1px solid #33406a;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
  width: 100%;
}

.review-section-title {
  margin: 0 0 8px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.review-item {
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
}

.review-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: #3d8b6a;
}

.review-item-def {
  color: var(--text);
  line-height: 1.4;
}

.review-item-syns {
  color: var(--muted);
  font-size: 12.5px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ==========================================================================
   Home Landing & Unit Dashboard Styles (Original Theme Compliant)
   ========================================================================== */
.brand-container {
  display: flex;
  align-items: center;
}

.welcome-header {
  text-align: center;
  margin-bottom: 8px;
  width: 100%;
}

.welcome-title {
  margin: 0;
  font-size: 34px;
  font-weight: 600;
  color: var(--text);
}

.welcome-subtitle {
  margin: 6px 0 0;
  font-size: 16px;
  color: var(--muted);
}

/* Stats Row */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: min(580px, 100%);
  margin-bottom: 8px;
}

.stat-card {
  background: var(--card);
  border: 1.5px solid #33406a;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-icon {
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: #1a2138;
  border-radius: 50%;
  border: 1px solid #33406a;
}

.stat-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* Global pairing promo card */
.global-pairing-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1.5px solid #33406a;
  border-radius: var(--radius);
  padding: 16px 20px;
  width: min(580px, 100%);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
  margin-bottom: 8px;
}

.global-pairing-card:hover {
  transform: scale(0.99);
  border-color: #f0c040;
}

.global-pairing-icon {
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: #1a2138;
  border-radius: 50%;
  border: 1px solid #33406a;
}

.global-pairing-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.global-pairing-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.global-pairing-desc {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.global-pairing-play {
  font-size: 20px;
  color: #f0c040;
  transition: transform 0.2s ease;
}

/* List section heading */
.section-heading {
  width: min(580px, 100%);
  margin: 16px 0 6px 0;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Decks unit list */
.units-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(580px, 100%);
}

.unit-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1.5px solid #33406a;
  border-radius: 16px;
  padding: 14px 20px;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.unit-row:hover {
  transform: scale(0.99);
  background-color: var(--card-2);
}

.unit-badge {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: #1a2138;
  border-radius: 50%;
  border: 1px solid #33406a;
  color: var(--text);
}

.unit-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.unit-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.unit-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.unit-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.unit-pill {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  background: #1a2138;
  border: 1px solid #33406a;
  border-radius: 12px;
  padding: 4px 10px;
}

.unit-chevron {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
}

/* Dashboard options cards menu */
.dashboard-header {
  text-align: center;
  margin-bottom: 16px;
  width: 100%;
}

.dashboard-title {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  color: var(--text);
}

.dashboard-subtitle {
  margin: 6px 0 0;
  font-size: 16px;
  color: var(--muted);
}

.options-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(580px, 100%);
}

.option-card {
  background: var(--card);
  border: 1.5px solid #33406a;
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.option-icon-wrapper {
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: #1a2138;
  border-radius: 50%;
  border: 1.5px solid #33406a;
  color: #f0c040;
}

.option-card-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.option-card-desc {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
  padding: 0 10px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.option-btn {
  background: #1a2138;
  color: var(--text);
  border: 1px solid #33406a;
  border-radius: 10px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease;
  width: 60%;
  margin-top: 4px;
}

.option-btn:hover {
  background-color: #222b47;
}

/* iPad uses the regular dashboard layout in either orientation; iPhones remain compact. */
@media (min-width: 700px) and (min-height: 600px) {
  .stats-grid,
  .global-pairing-card,
  .section-heading,
  .units-list {
    width: min(1000px, 100%);
  }

  .options-container {
    width: min(1000px, 100%);
    flex-direction: row;
    align-items: stretch;
  }

  .option-card {
    flex: 1 1 0;
    min-width: 0;
  }

  .option-card-desc {
    height: 64px;
  }

  .option-btn {
    width: auto;
  }
}

@media (min-width: 681px) and (max-height: 800px) {
  .scene {
    width: min(960px, 100%);
  }
}

@media (max-width: 680px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-card {
    min-width: 0;
    gap: 6px;
    padding: 10px 8px;
  }

  .stat-icon {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .stat-value { font-size: 14px; }
  .stat-label { font-size: 9px; }
  .global-pairing-card { padding: 14px 16px; }
  .unit-row { padding: 12px 14px; }
}

/* Phone portrait follows the iPhone app: two stats, then Total Words. */
@media (max-width: 699px) and (min-height: 501px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "units starred"
      "words words";
    gap: 12px;
  }

  #statUnitsCard { grid-area: units; }
  #statStarredCard { grid-area: starred; }
  #statWordsCard { grid-area: words; }

  .stat-card {
    gap: 12px;
    padding: 12px 14px;
  }

  .stat-icon {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .stat-value { font-size: 16px; }
  .stat-label { font-size: 11px; }
}

/* The iPhone 7 and smaller iPhones use the app's tighter portrait spacing. */
@media (max-width: 699px) and (min-height: 501px) and (max-height: 700px) {
  .welcome-title { font-size: 28px; }
  .welcome-subtitle { font-size: 14px; }
  .stats-grid { gap: 8px; }
}

/* In landscape, iPhone presents the compact three-column app layout. */
@media (max-width: 999px) and (max-height: 500px) {
  .stage {
    gap: 16px;
    padding: 8px 24px 24px;
  }

  .welcome-title { font-size: 28px; }
  .welcome-subtitle { font-size: 14px; }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    width: min(1000px, 100%);
  }

  .stat-card {
    gap: 12px;
    padding: 12px 14px;
  }

  .stat-icon {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .stat-value { font-size: 16px; }
  .stat-label { font-size: 11px; }

  .options-container {
    width: min(1000px, 100%);
    flex-direction: row;
    align-items: stretch;
    gap: 20px;
  }

  .option-card {
    flex: 1 1 0;
    min-width: 0;
    gap: 12px;
    padding: 20px;
  }

  .option-card-title { font-size: 18px; }
  .option-card-desc { height: 50px; font-size: 13px; }
  .option-btn { width: auto; }
}

/* =======================================================================
   Native iPad / iPhone parity
   These values mirror the SwiftUI spacing, card sizes, and screen modes.
   ======================================================================= */
.topbar {
  min-height: 52px;
  padding: 8px 24px;
  flex-wrap: nowrap;
}

.brand-container { min-width: 0; flex: 1; }
#backBtn {
  background: none;
  border: 0;
  padding: 6px 0;
  font-size: 20px;
  line-height: 1;
}
#backBtn:hover { background: none; }
.brand {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.controls { gap: 18px; }
.controls .btn {
  background: none;
  border-color: transparent;
  padding: 6px 0;
}
.controls .btn:hover { background: none; color: var(--text); }
.controls .btn.active,
.controls .btn.focus-active {
  background: var(--btnActiveBG, #2e5a4a);
  border-color: #3d8b6a;
  padding: 6px 10px;
}

#homeStage {
  align-items: stretch;
  gap: 28px;
  padding: 24px;
}
.welcome-header {
  width: 100%;
  margin: 0;
  text-align: left;
}
.stats-grid,
.global-pairing-card,
.units-list {
  width: 100%;
  margin: 0;
}
.section-heading { display: none; }
.stat-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
}
.global-pairing-card {
  gap: 16px;
  padding: 16px 20px;
  border-color: rgba(240, 192, 64, .3);
  box-shadow: 0 6px 10px rgba(0, 0, 0, .2);
}
.global-pairing-title { font-size: 18px; }
.global-pairing-desc { font-size: 13px; }
.global-pairing-icon {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
}
.global-pairing-play {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #3d8b6a;
  color: var(--page);
  font-size: 12px;
}
.units-list { gap: 16px; }
.unit-row {
  gap: 16px;
  padding: 16px 20px;
  border-width: 1px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, .15);
}
.unit-badge { width: 44px; height: 44px; font-size: 15px; }
.unit-name { font-size: 18px; }
.unit-subtitle { font-size: 13px; }
.unit-pill { padding: 6px 12px; border-radius: 20px; font-size: 13px; }

#dashboardStage {
  min-height: calc(100dvh - 52px);
  justify-content: center;
  gap: 40px;
  padding: 40px 24px;
}
.dashboard-header { margin: 0; }
.dashboard-title { font-size: 36px; }
.dashboard-subtitle { margin-top: 8px; font-size: 18px; }
.options-container {
  width: min(1000px, 100%);
  flex-direction: row;
  align-items: stretch;
  gap: 20px;
}
.option-card {
  flex: 1 1 0;
  min-width: 0;
  gap: 20px;
  padding: 32px;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
.option-icon-wrapper { width: 90px; height: 90px; font-size: 50px; }
.option-card-title { font-size: 24px; }
.option-card-desc { height: 70px; padding: 0; font-size: 15px; }
.option-btn { width: auto; padding: 12px 24px; font-size: 16px; }

#cardsStage {
  min-height: calc(100dvh - 52px);
  gap: 0;
  padding: 0 24px 24px;
}
.scene {
  width: 100%;
  height: min(600px, calc(100dvh - 164px));
  max-height: none;
}
.face { padding: 0; border-radius: 18px; }
.star { top: 12px; right: 16px; font-size: 24px; padding: 4px; }
.word { font-size: 55px; }
.back-body { gap: 40px; padding: 20px 40px; }
.text-col { gap: 28px; padding-left: 0; }
.back-word { font-size: 30px; }
.syn { font-size: 24px; }
.def { font-size: 28px; line-height: 1.35; }
.img-wrap { width: min(42%, 460px); }
.img-wrap img { max-height: 350px; }
.nav { padding: 20px 0 24px; }
.counter { font-family: "Nunito", sans-serif; font-size: 18px; font-weight: 700; }

#testStage,
#gameStage {
  align-items: stretch;
  gap: 0;
  padding: 16px 24px 40px;
}
#testActive,
#gameActive {
  width: min(800px, 100%);
  margin: 0 auto;
  padding: 0;
  background: none;
  box-shadow: none;
  gap: 24px;
}
#testIntro,
#gameIntro { display: none !important; }
.test-status-row { font-family: "Nunito", sans-serif; font-size: 14px; }
.progress-bar { height: 8px; border-radius: 4px; }
.test-card {
  gap: 24px;
  padding: 24px;
  background: var(--card);
  border: 0;
  border-radius: 18px;
  box-shadow: 0 15px 25px rgba(0, 0, 0, .4);
}
.test-definition-text { font-size: 28px; line-height: 1.35; text-align: center; }
.input-wrapper { padding: 14px 16px; }
.game-grid { gap: 16px; margin: 0; }
.game-card-btn { height: 80px; border-radius: 14px; font-size: 18px; background: var(--card); }
.game-review-panel { padding: 0; border: 0; border-radius: 0; background: none; }
.review-section-title { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); }
.review-list { gap: 16px; }
.review-item { padding: 16px; border-radius: 12px; background: rgba(26, 33, 56, .4); font-size: 15px; }
.review-item-header { font-size: 18px; }
.review-item-syns { font-size: 13px; }

.settings-content {
  width: min(540px, calc(100vw - 48px));
  padding: 24px;
  border-radius: 18px;
}
.settings-title { margin: 0; font-size: 22px; text-align: center; }
.setting-row { justify-content: space-between; }

@media (max-width: 699px) and (min-height: 501px) {
  .topbar { min-height: 52px; padding: 8px 24px; }
  .controls { gap: 14px; width: auto; }
  #homeStage { gap: 28px; padding: 24px; }
  .stats-grid { width: 100%; }
  .global-pairing-card,
  .units-list { width: 100%; }
  .units-list { gap: 16px; }

  #dashboardStage {
    min-height: 0;
    justify-content: flex-start;
    gap: 24px;
    padding: 24px;
  }
  .dashboard-title { font-size: 32px; }
  .dashboard-subtitle { font-size: 16px; }
  .options-container {
    width: 100%;
    flex-direction: column;
    gap: 24px;
  }
  .option-card { flex: none; padding: 32px; gap: 20px; }
  .option-icon-wrapper { width: 90px; height: 90px; font-size: 50px; }
  .option-card-title { font-size: 24px; }
  .option-card-desc { height: 70px; font-size: 15px; }
  .option-btn { padding: 12px 24px; font-size: 16px; }

  #cardsStage { min-height: calc(100dvh - 52px); padding: 0 24px 24px; }
  .scene { height: calc(100dvh - 164px); min-height: 320px; }
  .word { font-size: 43px; }
  .back-body { padding: 20px; }
  .back-body:has(.img-wrap:not(.empty)) { flex-direction: column; align-items: stretch; gap: 0; }
  .back-body:has(.img-wrap:not(.empty)) .text-col { max-width: none; }
  .back-body:has(.img-wrap:not(.empty)) .img-wrap { width: 100%; max-width: 240px; max-height: 180px; margin: 0 auto; }
  .back-body:has(.img-wrap:not(.empty)) .img-wrap img { max-height: 180px; }
  .back-body.no-img { flex-direction: row; }
  .back-body.no-img .text-col { max-width: none; align-items: flex-start; }
  .back-word { font-size: 28px; }
  .syn { font-size: 22px; }
  .def { font-size: 24px; }

  #testStage,
  #gameStage { padding: 10px 24px 24px; }
  #testActive,
  #gameActive { width: 100%; gap: 24px; }
  .test-card { padding: 24px; }
  .test-definition-text { font-size: 28px; }
  .game-card-btn { height: 80px; font-size: 18px; }
}

@media (max-width: 699px) and (min-height: 501px) and (max-height: 700px) {
  #homeStage { gap: 18px; padding-top: 12px; }
  .units-list { gap: 12px; }
  .option-card { padding: 22px; gap: 14px; }
  .option-icon-wrapper { width: 72px; height: 72px; font-size: 40px; }
  .option-card-title { font-size: 20px; }
  .option-card-desc { height: 54px; font-size: 13px; }
  .option-btn { padding: 8px 18px; font-size: 14px; }
  .word { font-size: 38px; }
  .back-word { font-size: 25px; }
  .syn { font-size: 19px; }
  .def { font-size: 21px; }
  .test-definition-text { font-size: 22px; }
  .game-card-btn { height: 66px; font-size: 15px; }
}

@media (max-width: 999px) and (max-height: 500px) {
  .topbar { min-height: 44px; padding: 4px 24px; }
  .controls { gap: 12px; }
  #homeStage { gap: 16px; padding: 12px 24px 24px; }
  #dashboardStage { min-height: 0; padding: 24px; gap: 20px; }
  .dashboard-header { margin: 0; }
  .dashboard-title { font-size: 32px; }
  .options-container { gap: 20px; }
  .option-card { padding: 20px; gap: 12px; }
  .option-icon-wrapper { width: 64px; height: 64px; font-size: 36px; }
  .option-card-title { font-size: 18px; }
  .option-card-desc { height: 50px; font-size: 13px; }
  .option-btn { padding: 8px 18px; font-size: 14px; }

  #cardsStage {
    display: grid !important;
    grid-template-columns: 40px minmax(0, 580px) 40px;
    justify-content: center;
    align-items: center;
    column-gap: 16px;
    min-height: calc(100dvh - 44px);
    padding: 8px 24px;
  }
  #cardsStage .scene { grid-column: 2; grid-row: 1; width: 100%; height: calc(100dvh - 60px); min-height: 0; }
  #cardsStage .nav { display: contents; padding: 0; }
  #prevBtn { grid-column: 1; grid-row: 1; width: 40px; height: 40px; font-size: 16px; }
  #nextBtn { grid-column: 3; grid-row: 1; width: 40px; height: 40px; font-size: 16px; }
  #cardsStage .counter,
  #cardsStage .no-fav-msg { display: none !important; }
  .word { font-size: 38px; }
  .back-body { flex-direction: row; gap: 20px; padding: 20px 24px; }
  .back-body:has(.img-wrap:not(.empty)) { flex-direction: row; }
  .back-body:has(.img-wrap:not(.empty)) .img-wrap { width: min(42%, 240px); margin: 0; }
  .back-body.no-img { flex-direction: row; }
  .back-word { font-size: 24px; }
  .syn { font-size: 18px; }
  .def { font-size: 19px; }

  #testStage,
  #gameStage { padding: 8px 12px 10px; }
  #testActive,
  #gameActive { gap: 12px; }
  .progress-bar { height: 8px; }
  .test-card { gap: 12px; padding: 16px; }
  .test-definition-text { font-size: 22px; }
  .input-wrapper { padding: 10px 16px; }
  .game-grid { gap: 10px; }
  .game-card-btn { height: 54px; font-size: 15px; }
  .game-actions .btn { padding: 10px; font-size: 15px; }
}

/* Flashcard content measurements from the native FlashcardView. */
.star { top: 16px; right: 20px; }
.back-body .def {
  align-self: stretch;
  text-align: center;
}

@media (max-width: 699px) and (min-height: 501px) {
  /* Portrait image cards stack text over a 240 × 180 illustration. */
  .back-body:has(.img-wrap:not(.empty)) .text-col {
    align-items: flex-start;
    gap: 0;
  }
  .back-body:has(.img-wrap:not(.empty)) .back-word { margin-bottom: 15px; }
  .back-body:has(.img-wrap:not(.empty)) .syn { margin-bottom: 19px; }
  .back-body:has(.img-wrap:not(.empty)) .def { margin-bottom: 21px; }

  /* Portrait cards without an illustration retain the native side-by-side text scale. */
  .back-body.no-img .back-word { font-size: 30px; }
  .back-body.no-img .syn { font-size: 24px; }
  .back-body.no-img .def { font-size: 28px; }
}

@media (max-width: 699px) and (min-height: 501px) and (max-height: 700px) {
  #testActive { gap: 14px; }
  .test-card { gap: 14px; padding: 16px; }
  .back-body:has(.img-wrap:not(.empty)) .img-wrap {
    max-width: 210px;
    max-height: 150px;
  }
  .back-body:has(.img-wrap:not(.empty)) .img-wrap img { max-height: 150px; }
  .back-body:has(.img-wrap:not(.empty)) .back-word { margin-bottom: 13px; }
  .back-body:has(.img-wrap:not(.empty)) .syn { margin-bottom: 16px; }
  .back-body:has(.img-wrap:not(.empty)) .def { margin-bottom: 18px; }
  .back-body.no-img .back-word { font-size: 26px; }
  .back-body.no-img .syn { font-size: 21px; }
  .back-body.no-img .def { font-size: 24px; }
}

@media (max-width: 999px) and (max-height: 500px) {
  /* iPhone 14 landscape retains its 43px front word; iPhone 7 uses 38px. */
  .word { font-size: 43px; }
}

@media (max-width: 700px) and (max-height: 500px) {
  .word { font-size: 38px; }
}
