:root {
  --purple: #5146d9;
  --purple-dark: #3930b5;
  --purple-soft: #efedff;
  --ink: #171a2c;
  --muted: #686b7b;
  --line: #e2e3ec;
  --surface: #ffffff;
  --background: #f5f6fb;
  --success: #1eaa77;
  --danger: #e5484d;
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top left, #eceaff 0, var(--background) 42%); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(81,70,217,.25); outline-offset: 2px; }
#startStudyBtn { width:100% }
.app-shell { width: min(100%, 760px); margin: 0 auto; min-height: 100vh; padding: env(safe-area-inset-top) 18px calc(92px + env(safe-area-inset-bottom)); }
.app-header { display: flex; align-items: center; gap: 14px; padding: 22px 4px 18px; }
.app-header h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2rem); }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; color: white; background: linear-gradient(135deg, var(--purple), #776df0); font-size: 1.55rem; }
.app-header .install-btn { margin-left: auto; }
.eyebrow { margin: 0 0 4px; color: var(--purple); text-transform: uppercase; letter-spacing: .12em; font-size: .73rem; font-weight: 800; }
.view { display: none; animation: fade .2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .25; transform: translateY(4px); } }
.panel, .hero-panel { background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.hero-panel { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; background: linear-gradient(135deg, #f0efff, #fbfbff); }
.hero-panel .primary-btn { grid-column: 2; justify-self: start; }
.hero-panel h2, .section-heading h2, .page-heading h2 { margin: 0; }
.hero-panel p:not(.eyebrow) { margin: 6px 0 0; color: var(--muted); }
.hero-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--purple); color: white; font-size: 2rem; grid-row: span 2; }
.section-heading { margin-bottom: 14px; }
.section-heading.row { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.segment { border: 0; background: transparent; padding: 14px 10px; color: var(--ink); }
.segment.active { background: var(--purple); color: white; }
.primary-btn, .secondary-btn, .text-btn { border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 750; }
.primary-btn { background: var(--purple); color: white; }
.primary-btn:hover { background: var(--purple-dark); }
.primary-btn.compact { padding: 10px 14px; }
.secondary-btn { display: inline-flex; justify-content: center; background: white; color: var(--ink); border: 1px solid var(--line); }
.text-btn { padding: 8px; color: var(--purple); background: transparent; }
.full { width: 100%; margin-top: 12px; text-align: center; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.stat-card { background: white; border: 1px solid var(--line); border-radius: 18px; padding: 16px 10px; text-align: center; }
.stat-card span { display: block; color: var(--muted); font-size: .82rem; }
.stat-card strong { display: block; margin-top: 5px; font-size: 1.6rem; }
.category-list, .term-list, .category-manager-list, .category-stats { display: grid; gap: 10px; }
.category-row, .term-row, .manager-row, .category-stat-row { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: white; }
.category-row label { display: flex; gap: 12px; align-items: center; flex: 1; cursor: pointer; }
.category-row input { width: 20px; height: 20px; accent-color: var(--purple); }
.category-icon { width: 40px; height: 40px; display: grid; place-items: center; background: var(--purple-soft); border-radius: 12px; }
.category-meta, .term-main { min-width: 0; flex: 1; }
.category-meta strong, .term-main strong { display: block; }
.category-meta small, .term-main p { color: var(--muted); margin: 3px 0 0; }
.term-main p { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.category-chip { display: inline-block; margin-top: 8px; padding: 4px 8px; border-radius: 999px; background: var(--purple-soft); color: var(--purple-dark); font-size: .75rem; }
.icon-btn { width: 42px; height: 42px; border: 1px solid var(--line); background: white; border-radius: 13px; display: grid; place-items: center; color: var(--ink); }
.page-heading { margin: 10px 0 16px; }
.search-field input, .field-label input, .field-label select, .field-label textarea { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; background: white; color: var(--ink); }
.search-field input { margin-bottom: 12px; }
.field-label { display: block; color: var(--ink); font-weight: 700; margin-bottom: 14px; }
.field-label input, .field-label select, .field-label textarea { display: block; margin-top: 7px; font-weight: 400; }
.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%,760px); display: grid; grid-template-columns: repeat(4,1fr); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.94); backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.nav-item { border: 0; background: transparent; color: var(--muted); display: grid; gap: 3px; justify-items: center; padding: 7px; font-size: .76rem; }
.nav-item span { font-size: 1.35rem; }
.nav-item.active { color: var(--purple); }
.study-toolbar { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.progress-track { height: 6px; background: #e8e8ef; border-radius: 999px; overflow: hidden; margin: 18px 0 28px; }
.progress-bar { height: 100%; background: var(--purple); width: 0; transition: width .2s ease; }
.side-label { color: var(--purple); font-weight: 800; letter-spacing: .12em; font-size: .74rem; }
.flashcard { width: 100%; min-height: 340px; border: 1px solid var(--line); border-radius: 24px; background: white; padding: 28px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 28px; color: var(--ink); box-shadow: 0 18px 42px rgba(37,39,70,.08); }
.flashcard span { font-size: clamp(1.5rem, 5vw, 2.2rem); font-weight: 750; line-height: 1.3; }
.flashcard small { color: var(--muted); }
.study-actions { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-top: 22px; }
.study-action { border: 1px solid var(--line); background: white; border-radius: 16px; padding: 13px 6px; display: grid; gap: 5px; }
.study-action span { font-size: 1.4rem; }
.study-action.danger { color: var(--danger); }
.study-action.success { color: var(--success); }
.study-action:disabled { opacity: .42; cursor: not-allowed; }
.modal { border: 0; background: transparent; padding: 18px; width: min(100%, 640px); }
.modal::backdrop { background: rgba(24,25,42,.5); backdrop-filter: blur(3px); }
.modal-card { background: var(--background); border-radius: 24px; padding: 20px; max-height: calc(100vh - 36px); overflow: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.inline-add { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; }
.inline-add .field-label { margin-bottom: 0; }
.manager-row button { margin-left: auto; }
.category-stat-row { display: grid; grid-template-columns: 1fr auto; }
.stat-bar { grid-column: 1 / -1; height: 9px; border-radius: 999px; background: #ececf2; overflow: hidden; }
.stat-bar > span { display: block; height: 100%; background: var(--purple); }
.danger-text { color: var(--danger); }
.file-btn { cursor: pointer; }
.empty-state { text-align: center; color: var(--muted); padding: 28px 14px; border: 1px dashed var(--line); border-radius: 16px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 11px 15px; border-radius: 999px; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 520px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .hero-panel { grid-template-columns: auto 1fr; }
  .stats-grid { gap: 7px; }
  .stat-card strong { font-size: 1.25rem; }
  .study-actions { gap: 7px; }
  .inline-add { grid-template-columns: 1fr; }
}

/* Study mode: keep the complete game surface inside the visible viewport. */
body.study-mode { overflow: hidden; }
body.study-mode .app-header { display: none; }
body.study-mode .app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: max(10px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
}
body.study-mode main { height: 100%; min-height: 0; }
#studyView.active {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.3vh, 14px);
  overflow: hidden;
}
#studyView .study-toolbar { margin: 0; min-height: 42px; }
#studyView .progress-track { margin: 0; }
#studyView .side-label { margin: 0; }
#studyView .flashcard {
  min-height: 0;
  height: 100%;
  padding: clamp(16px, 3.5vh, 30px);
  gap: clamp(10px, 2vh, 24px);
  overflow: hidden;
  will-change: transform, opacity;
  touch-action: manipulation;
}
#studyView .flashcard-copy {
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  font-size: clamp(1.15rem, min(5vw, 4vh), 2.2rem);
}
#studyView .study-actions { margin: 0; }

/* Directional card transitions. */
.flashcard.card-exit-left { animation: cardExitLeft 180ms ease-in forwards; pointer-events: none; }
.flashcard.card-exit-right { animation: cardExitRight 180ms ease-in forwards; pointer-events: none; }
.flashcard.card-enter-right { animation: cardEnterRight 230ms cubic-bezier(.2,.75,.25,1) both; }
.flashcard.card-enter-left { animation: cardEnterLeft 230ms cubic-bezier(.2,.75,.25,1) both; }
@keyframes cardExitLeft {
  to { opacity: 0; transform: translateX(-18%) scale(.97); }
}
@keyframes cardExitRight {
  to { opacity: 0; transform: translateX(18%) scale(.97); }
}
@keyframes cardEnterRight {
  from { opacity: 0; transform: translateX(18%) scale(.97); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes cardEnterLeft {
  from { opacity: 0; transform: translateX(-18%) scale(.97); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@media (max-height: 650px) {
  #studyView.active { gap: 6px; }
  #studyView .study-toolbar { min-height: 38px; }
  #studyView .icon-btn { width: 38px; height: 38px; }
  #studyView .study-action { padding: 8px 4px; gap: 2px; font-size: .78rem; }
  #studyView .study-action span { font-size: 1.1rem; }
  #studyView .flashcard small { font-size: .75rem; }
}

@media (min-width: 760px) and (min-height: 700px) {
  body.study-mode .app-shell { width: min(100%, 920px); padding-left: 28px; padding-right: 28px; }
  #studyView .flashcard { max-width: 760px; justify-self: center; }
  #studyView .study-actions { width: min(100%, 760px); justify-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  .flashcard.card-exit-left,
  .flashcard.card-exit-right,
  .flashcard.card-enter-right,
  .flashcard.card-enter-left { animation-duration: 1ms; }
  .progress-bar, .view, .toast { transition-duration: 1ms; animation-duration: 1ms; }
}

/* The primary navigation is never shown while a study session is active. */
body.study-mode .bottom-nav,
.bottom-nav[hidden] {
  display: none !important;
}

/* True 3D card flip. The outer button owns slide-in/out motion; the complete inner card shell flips. */
.flashcard {
  perspective: 1200px;
  -webkit-perspective: 1200px;
  padding: 0;
  overflow: visible;
  isolation: isolate;
  background: transparent;
  border: 0;
  border-radius: 24px;
  box-shadow: none;
}
#studyView .flashcard {
  padding: 0;
  gap: 0;
  overflow: visible;
}
.flashcard-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  overflow: visible;
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(.2,.72,.2,1);
  transform-origin: center center;
  will-change: transform;
}
.flashcard.is-flipped .flashcard-inner {
  transform: rotateY(-180deg);
  -webkit-transform: rotateY(-180deg);
}
/* Disable the 3D transition while a new card is being prepared off-screen. */
.flashcard.suppress-flip-animation .flashcard-inner,
.flashcard.suppress-flip-animation .flashcard-face {
  transition: none !important;
}
.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vh, 24px);
  padding: clamp(16px, 3.5vh, 30px);
  border: 1px solid var(--line);
  border-radius: inherit;
  background: white;
  box-shadow: 0 18px 42px rgba(37,39,70,.08);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: visibility 0s linear 260ms;
}
.flashcard-front {
  z-index: 2;
  visibility: visible;
  transform: rotateY(0deg) translateZ(1px);
  -webkit-transform: rotateY(0deg) translateZ(1px);
}
.flashcard-back {
  z-index: 1;
  visibility: hidden;
  transform: rotateY(-180deg) translateZ(1px);
  -webkit-transform: rotateY(-180deg) translateZ(1px);
}
.flashcard.is-flipped .flashcard-front {
  visibility: hidden;
}
.flashcard.is-flipped .flashcard-back {
  visibility: visible;
}

.face-kicker {
  position: absolute;
  top: clamp(14px, 2.5vh, 24px);
  left: clamp(16px, 3vw, 28px);
  font-size: .72rem !important;
  font-weight: 800 !important;
  letter-spacing: .12em;
  color: var(--purple);
  background: var(--purple-soft);
  border-radius: 999px;
  padding: 5px 9px;
}

.flashcard-copy {
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  font-size: clamp(1.15rem, min(5vw, 4vh), 2.2rem);
  font-weight: 750;
  line-height: 1.3;
}

@media (prefers-reduced-motion: reduce) {
  .flashcard-inner { transition-duration: 1ms; }
}

/* Multi-category term selection */
.category-fieldset { border: 0; padding: 0; min-width: 0; }
.category-fieldset legend { padding: 0; font-weight: 700; }
.field-help { margin: 5px 0 9px; color: var(--muted); font-size: .84rem; font-weight: 400; }
.term-category-choices { display: grid; gap: 8px; max-height: 210px; overflow-y: auto; padding: 3px; }
.term-category-option { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 13px; background: white; cursor: pointer; font-weight: 600; }
.term-category-option:has(input:checked) { border-color: var(--purple); background: var(--purple-soft); color: var(--purple-dark); }
.term-category-option input { width: 19px; height: 19px; margin: 0; accent-color: var(--purple); flex: 0 0 auto; }
.category-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.category-chips .category-chip { margin-top: 0; }
.term-category-option input[type="checkbox"] { width: 19px; height: 19px; padding: 0; border: 0; border-radius: 0; background: transparent; appearance: auto; display: block; margin: 0; }


/* Game type selector */
.activity-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.activity-option { min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: white; color: var(--ink); }
.activity-option.active { margin: -1px; border-width: 2px; border-color: var(--purple); background: var(--purple-soft); }
.activity-option > span:last-child { display: grid; gap: 3px; min-width: 0; }
.activity-option small { color: var(--muted); line-height: 1.3; }
.activity-icon { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 12px; background: var(--purple-soft); color: var(--purple); font-size: .75em; font-weight: 800; }
.activity-option.active .activity-icon { background: var(--purple); color: white; }

/* Definition match game */
body.match-mode { overflow: hidden; }
body.match-mode .app-header { display: none; }
body.match-mode .app-shell { width: min(100%, 1180px); height: 100vh; height: 100dvh; min-height: 0; padding: max(10px, env(safe-area-inset-top)) 18px max(10px, env(safe-area-inset-bottom)); }
body.match-mode main { height: 100%; min-height: 0; }
body.match-mode .bottom-nav { display: none !important; }
#matchView.active { height: 100%; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 10px; overflow: hidden; }
.match-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 42px; }
.match-toolbar p { margin: 0; font-weight: 700; }
.match-progress-track { margin: 0; }
.match-board { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: clamp(10px, 1.8vh, 20px); padding: clamp(14px, 2.2vh, 24px); background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 18px 42px rgba(37,39,70,.07); overflow: hidden; }
.match-kicker { justify-self: start; margin: 0; padding: 6px 11px; border-radius: 999px; background: var(--purple-soft); color: var(--purple); font-size: .74rem; font-weight: 850; letter-spacing: .1em; }
.match-instructions { margin: 0; text-align: center; color: var(--ink); font-weight: 600; }
.match-stage { position: relative; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, .62fr) minmax(0, 1.08fr); }
.match-column { position: relative; z-index: 2; display: grid; grid-template-rows: repeat(var(--match-count, 5), minmax(0, 1fr)); gap: clamp(7px, 1.2vh, 13px); min-height: 0; }
.match-terms { grid-column: 1; }
.match-definitions { grid-column: 3; }
.match-lines { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; overflow: visible; }
.match-connector { fill: none; stroke-width: 2.5; stroke-linecap: round; }
.match-connector.animate-in { animation: drawConnector .35s ease both; }
@keyframes drawConnector { from { stroke-dasharray: 8 8; opacity: .25; } to { stroke-dasharray: none; opacity: 1; } }
.match-item { position: relative; min-width: 0; display: flex; align-items: center; gap: 12px; padding: clamp(10px, 1.8vh, 16px); border: 1px solid var(--line); border-radius: 15px; background: white; color: var(--ink); text-align: left; box-shadow: 0 5px 14px rgba(37,39,70,.055); transition: border-color .16s ease, background .16s ease, transform .16s ease, box-shadow .16s ease; }
.match-item:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(37,39,70,.08); }
.term-match-item.selected { border-color: var(--match-color); background: color-mix(in srgb, var(--match-color) 8%, white); box-shadow: 0 0 0 2px color-mix(in srgb, var(--match-color) 22%, transparent); }
.match-item.matched { cursor: default; }
.match-item-text { min-width: 0; line-height: 1.35; font-weight: 650; }
.definition-match-item { padding-left: clamp(20px, 3.6vh, 32px); }
.definition-match-item .match-item-text { font-weight: 500; }
.match-node { width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%; background: var(--match-color); border: 6px solid white; box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--match-color) 55%, white); }
.term-node { position: absolute; right: -10px; top: 50%; transform: translateY(-50%); }
.definition-node { position: absolute; left: -10px; top: 50%; transform: translateY(-50%); }
.definition-match-item:not(.matched) { --match-color: #9295a3 !important; }
.definition-match-item.incorrect { animation: matchShake .35s ease; border-color: var(--danger); }
.definition-match-item.hinted { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(81,70,217,.16); }
@keyframes matchShake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
.match-footer { min-height: 58px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.hint-btn { grid-column: 2; border: 0; border-radius: 999px; padding: 11px 18px; background: var(--purple-soft); color: var(--purple); font-weight: 800; }
.hint-btn span { display: inline-grid; place-items: center; min-width: 24px; height: 24px; margin-left: 5px; border-radius: 999px; background: var(--purple); color: white; }
.hint-btn:disabled { opacity: .45; cursor: default; }
.match-complete { display: grid; gap: 2px; color: var(--success); }
.match-complete span { color: var(--muted); font-size: .84rem; }
.match-next { justify-self: end; }

@media (max-width: 700px) {
  .activity-options { grid-template-columns: 1fr; }
  body.match-mode .app-shell { padding-left: 10px; padding-right: 10px; }
  .match-board { padding: 12px; gap: 9px; }
  .match-instructions { font-size: .83rem; }
  .match-stage { grid-template-columns: minmax(0, 1fr) 46px minmax(0, 1.18fr); }
  .match-item { padding: 8px 10px; border-radius: 12px; gap: 7px; }
  .definition-match-item { padding-left: 20px; }
  .match-item-text { font-size: clamp(.68rem, 2.6vw, .88rem); line-height: 1.23; }
  .match-node { width: 16px; height: 16px; border-width: 5px; }
  .term-node { right: -8px; }
  .definition-node { left: -8px; }
  .match-footer { min-height: 48px; padding-top: 8px; }
  .hint-btn { padding: 8px 13px; }
  .match-complete span { display: none; }
}

@media (max-height: 650px) {
  .match-board { padding-top: 10px; padding-bottom: 10px; gap: 7px; }
  .match-kicker { padding: 4px 8px; }
  .match-item { padding-top: 6px; padding-bottom: 6px; }
  .match-footer { min-height: 42px; }
}

/* Definition match results */
#matchResultsView.active { height: 100%; min-height: 0; overflow: auto; padding: clamp(8px, 2vh, 22px) 0; }
.results-page { width: min(100%, 820px); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding: clamp(18px, 3vw, 34px); background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 18px 42px rgba(37,39,70,.07); }
.results-header { text-align: center; }
.results-header .match-kicker { display: inline-block; }
.results-header h2 { margin: 12px 0 5px; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.results-header > p:last-child { margin: 0; color: var(--muted); }
.results-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.results-summary div { padding: 14px 10px; text-align: center; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-soft, #f8f8fd); }
.results-summary span { display: block; font-size: clamp(1.25rem, 4vw, 1.8rem); font-weight: 850; color: var(--purple); }
.results-summary small { color: var(--muted); }
.results-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; min-height: 0; }
.results-group { min-width: 0; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.results-group h3 { margin: 0; display: flex; align-items: center; justify-content: space-between; padding: 13px 15px; font-size: 1rem; }
.results-group h3 b { min-width: 28px; height: 28px; display: grid; place-items: center; border-radius: 999px; font-size: .82rem; }
.correct-results h3 { color: var(--success); background: color-mix(in srgb, var(--success) 8%, white); }
.correct-results h3 b { background: color-mix(in srgb, var(--success) 15%, white); }
.incorrect-results h3 { color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, white); }
.incorrect-results h3 b { background: color-mix(in srgb, var(--danger) 13%, white); }
.results-list { list-style: none; padding: 8px 14px; margin: 0; display: grid; gap: 2px; }
.results-list li { display: flex; align-items: center; gap: 11px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.results-list li:last-child { border-bottom: 0; }
.results-list li > span:last-child { min-width: 0; display: grid; gap: 2px; }
.results-list strong { overflow-wrap: anywhere; }
.results-list small { color: var(--muted); line-height: 1.3; }

.result-term-details { min-width: 0; display: grid; gap: 3px; width: 100%; }
.result-mastery { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 9px; margin-top: 5px; }
.result-mastery .mastery-badge { font-size: .68rem; }
.result-mastery small { font-size: .72rem; font-weight: 700; }
.result-status { width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; font-weight: 900; }
.result-status.success { color: var(--success); background: color-mix(in srgb, var(--success) 12%, white); }
.result-status.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, white); }
.results-empty { color: var(--muted); font-style: italic; }
.results-actions { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.secondary-btn { min-height: 48px; border: 1px solid var(--purple); border-radius: 14px; background: white; color: var(--purple); font-weight: 750; }
@media (max-width: 620px) {
  #matchResultsView.active { padding: 0; }
  .results-page { border-radius: 18px; padding: 16px 12px; gap: 14px; }
  .results-summary { gap: 6px; }
  .results-summary div { padding: 10px 5px; }
  .results-summary small { font-size: .68rem; }
  .results-groups { grid-template-columns: 1fr; }
}

/* Flash Card completion options */
.study-options-page { width: min(100%, 720px); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding: clamp(18px, 3vw, 34px); background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 18px 42px rgba(37,39,70,.07); }
.study-options-panel { display: grid; gap: 14px; min-height: 0; }
.study-options-panel .section-heading h3 { margin: 2px 0 0; font-size: 1.2rem; }
.study-options-summary { margin: 0; color: var(--muted); text-align: center; font-weight: 650; }
@media (max-width: 560px) {
  .study-options-page { border-radius: 18px; padding: 16px 12px; gap: 14px; }
}

.term-title-line, .term-stat-heading { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.mastery-badge { flex:0 0 auto; font-size:.72rem; font-weight:800; color:#6047f5; background:#eeeaff; border-radius:999px; padding:4px 8px; }
.mastery-badge.mastered { color:#087a4d; background:#dcf8eb; }
.term-performance { display:block; margin-top:9px; font-size:.75rem; color:var(--muted); font-weight:700; }
.term-stats-list { display:grid; gap:10px; }
.term-stat-row { border:1px solid var(--line); border-radius:16px; padding:14px; background:#fff; }
.term-stat-meta { display:flex; flex-wrap:wrap; gap:6px 12px; margin:8px 0; color:var(--muted); font-size:.78rem; font-weight:700; }


/* Order of draw activity */
.activity-options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tube-picker { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.tube-choice { transform: translateZ(0); display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 15px; background: white; cursor: pointer; }
.tube-choice.selected { margin: -1px; border-color: var(--purple); border-width: 2px; background: var(--purple-soft); }
.tube-choice input { width: 19px; height: 19px; accent-color: var(--purple); }
.tube-choice > span:last-child { display: grid; gap: 2px; min-width: 0; }
.tube-choice small { color: var(--muted); }
.mini-tube { overflow:hidden; position: relative; width: 20px; height: 45px; flex: 0 0 auto; border: 2px solid #a7a0ff; border-radius: 5px 5px 9px 9px; background: linear-gradient(90deg,#fff,#eef0f5 52%,#fff); }
.mini-tube::before {   mix-blend-mode: multiply; content:""; position:absolute; left:-3px; right:-3px; top:-4px; height:13px; border-radius:5px; background:var(--tube-cap-bg,var(--tube-cap)); }
.mini-tube i { position:absolute; left:2px; right:2px; bottom:3px; height:8px; border-radius:0 0 6px 6px; background:#d6d8df; }
.mini-tube::after { content: ""; position: absolute; left: 1px; right: 13px; top: 11px; height: 17px; border-radius: 2px; background: var(--tube-label-color,transparent); }
.tube-selection-actions { display:flex; justify-content:flex-start; gap:8px; margin-top:8px; }

body.order-mode { overflow: hidden; }
body.order-mode .app-header { display:none; }
body.order-mode .app-shell { width:min(100%,1380px); height:100vh; height:100dvh; min-height:0; padding:max(8px,env(safe-area-inset-top)) clamp(7px,1.4vw,18px) max(8px,env(safe-area-inset-bottom)); }
body.order-mode main { height:100%; min-height:0; }
body.order-mode .bottom-nav { display:none !important; }
#orderDrawView.active { height:100%; min-height:0; display:grid; grid-template-rows:auto auto minmax(0,1fr); gap:clamp(5px,1vh,10px); overflow:hidden; }
.order-toolbar { display:grid; grid-template-columns:44px 1fr 44px; align-items:center; min-height:42px; }
.order-toolbar p { margin:0; font-weight:700; text-align:center; }
.order-toolbar-spacer { width:44px; height:44px; }
.order-progress-track { margin:0; }
.order-board { min-height:0; display:grid; grid-template-rows:auto auto minmax(0,1fr) auto auto; gap:clamp(5px,1.25vh,14px); padding:clamp(8px,1.8vh,20px); background:rgba(255,255,255,.97); border:1px solid var(--line); border-radius:22px; box-shadow:0 18px 42px rgba(37,39,70,.07); overflow:hidden; }
.order-instructions { text-align:center; }
.order-instructions h2 { margin:0; font-size:clamp(.92rem,1.8vw,1.22rem); }
.order-instructions p { margin:4px 0 20px 0; color:var(--muted); font-size:clamp(.72rem,1.4vw,.95rem); }
.tube-order-list { justify-content: center; --tube-gap:clamp(2px,.55vw,9px); min-height:0; width:100%; display:flex; align-items:stretch; gap:var(--tube-gap); overflow:visible; padding:4px 1px 6px; }
.tube-card { position:relative; flex:1 1 0; max-width: 100px; max-height:250px; min-width:0; width:calc((100% - (var(--tube-count) - 1) * var(--tube-gap)) / var(--tube-count)); display:grid; grid-template-rows:auto minmax(0,1fr); justify-items:center; gap:clamp(2px,.6vh,6px); padding:clamp(3px,.5vw,8px) 1px; border:1px solid var(--line); border-radius:clamp(7px,1.2vw,15px); background:white; box-shadow:0 4px 10px rgba(37,39,70,.04); user-select:none; touch-action:none; cursor:grab; transition:border-color .12s,box-shadow .12s,transform .12s; }
.tube-card:active { cursor:grabbing; }
.tube-card.drag-floating { position:fixed !important; z-index:1000; flex:none; margin:0; opacity:1 !important; cursor:grabbing; pointer-events:none; transform:scale(1.02); box-shadow:0 18px 34px rgba(37,39,70,.2); }
.tube-drop-placeholder { position:relative; flex:1 1 0; max-width: 100px; max-height:300px; min-width:0; width:calc((100% - (var(--tube-count) - 1) * var(--tube-gap)) / var(--tube-count)); border:2px dashed var(--purple); border-radius:clamp(7px,1.2vw,15px); background:rgba(81,70,217,.07); box-shadow:inset 0 0 0 3px rgba(81,70,217,.05); }
.tube-drop-placeholder::after { content:"Place here"; position:absolute; inset:0; display:grid; place-items:center; color:var(--purple); font-size:clamp(.35rem,.72vw,.62rem); font-weight:800; writing-mode:vertical-rl; transform:rotate(180deg); text-transform:uppercase; letter-spacing:.04em; }
.tube-card.hinted-tube { box-shadow:0 0 0 3px rgba(81,70,217,.22); border-color:var(--purple); }
.drag-dots { color:#85899c; font-size:clamp(.72rem,1.8vw,1.1rem); line-height:1; }
.blood-tube { position:relative; width:min(72%,62px); height:100%; min-height:0; display:flex; flex-direction:column; align-items:center; padding-top:clamp(21px,5.5vh,40px); filter:drop-shadow(0 5px 4px rgba(30,32,50,.11)); }
.tube-cap { position:absolute; top:0; width:88%; height:clamp(27px,7vh,52px); border-radius:clamp(4px,.8vw,8px) clamp(4px,.8vw,8px) 5px 5px; background:var(--tube-cap-bg,linear-gradient(90deg,color-mix(in srgb,var(--tube-cap) 82%,black),var(--tube-cap) 48%,color-mix(in srgb,var(--tube-cap) 78%,white))); box-shadow:inset 0 -4px 0 rgba(0,0,0,.08); }
.tube-cap::after {   content: ""; position: absolute; inset: 13% 4%; opacity: .3; background: repeating-linear-gradient(90deg,transparent 2px 5px,rgb(0, 0, 0) 10px 12px); mix-blend-mode: soft-light;}
.tube-neck { width:63%; height:clamp(14px,4vh,28px); flex:0 0 auto; border:clamp(1px,.18vw,2px) solid #d3d5dc; border-bottom:0; background:linear-gradient(90deg,#fff,#e9ebf0,#fff); }
.tube-spacer{ flex:0.7; }
.tube-label { position:relative; width:63%; flex:1 1 auto; min-height:0; display:flex; flex-direction:column; justify-content:right; align-items:center; gap:clamp(2px,.6vh,7px); border-left:clamp(1px,.18vw,2px) solid #d3d5dc; background:white; writing-mode:vertical-rl; transform:rotate(180deg); text-align:center; overflow:hidden; }
.tube-label::before { position:absolute; color: transparent; min-width:14%; flex: .7; content: "."; width: 12%; height: 100%; top: 0; background:var(--tube-label-color,var(--tube-cap)); }
.tube-label strong,.tube-label small {   padding-top: 4px; padding-bottom: 4px; width:100%; text-overflow: ellipsis; overflow:hidden; min-height: 1em; min-width: 1.2em; display:block; max-height:100%; max-width:100%; white-space:nowrap; }
.tube-label strong {  flex: 1; font-size:clamp(.65rem,.72vw,.66rem);  }
.tube-label small {  flex: 1; font-size:clamp(.6rem,.56vw,.52rem); color:var(--muted); }
.tube-base { width:63%; height:clamp(27px,7vh,54px); flex:0 0 auto; border:clamp(1px,.18vw,2px) solid #cfd1d8; border-top:0; border-radius:0 0 48% 48%; background:linear-gradient(90deg,#fefefe,#dfe1e6 45%,#fff); }
.order-tip { display:none; margin:0; text-align:center; color:var(--muted); font-size:clamp(.65rem,1.3vw,.88rem); }
.order-footer { display:flex; align-items:center; justify-content:center; flex-wrap:wrap; gap:12px; border-top:1px solid var(--line); padding-top:clamp(7px,1.2vh,12px); }
.order-footer .hint-btn,.order-footer .primary-btn { min-width:min(220px,42vw); justify-content:center; }
.order-complete { padding:clamp(7px,1.2vh,12px) 16px; border-radius:14px; background:#ecfbf5; color:#107654; text-align:center; font-size:clamp(.72rem,1.3vw,.95rem); }
.order-complete strong, .order-complete span { display:block; }
.incorrect-tube { animation:orderShake .42s ease; border-color:#f2a1aa; background:#fffafb; }
.correct-order .tube-card { border-color:#b8e8d4; background:#fbfffd; }
@keyframes orderShake { 25%{transform:translateX(-6px)} 50%{transform:translateX(6px)} 75%{transform:translateX(-3px)} }

@media (max-width:760px) {
  .activity-options { grid-template-columns:1fr; }
  .tube-picker { grid-template-columns:1fr; }
  .order-board { padding:8px; }
  .order-footer { justify-content:center; gap:8px; }
  .order-footer .hint-btn,.order-footer .primary-btn { min-width:min(150px,44vw); }
}
@media (max-height:700px) {
  .tube-order-list { padding-bottom:2px; }
  .order-tip { display:none; }
}

/* Portrait/mobile Order of Draw layout */
@media (orientation: portrait) {
  body.order-mode .app-shell {
    width: 100%;
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  }

  #orderDrawView.active {
    gap: 8px;
  }

  .order-toolbar {
    grid-template-columns: 48px 1fr 48px;
    min-height: 48px;
  }

  .order-toolbar .icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    font-size: 1.25rem;
  }

  .order-progress-track {
    height: 6px;
  }

  .order-board {
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    gap: clamp(8px, 1.2vh, 14px);
    padding: clamp(12px, 2vh, 20px) clamp(10px, 2.8vw, 18px) clamp(12px, 2vh, 18px);
    border-radius: 24px;
  }

  .order-board .match-kicker {
    justify-self: start;
    margin: 0;
    padding: 7px 13px;
    font-size: clamp(.68rem, 2.9vw, .84rem);
  }

  .order-instructions {
    align-self: start;
    padding-inline: 4px;
  }

  .order-instructions h2 {
    max-width: 330px;
    margin-inline: auto;
    font-size: clamp(1.15rem, 5vw, 1.45rem);
    line-height: 1.25;
  }

  .order-instructions p {
    margin-top: 8px;
    font-size: clamp(.88rem, 3.7vw, 1.02rem);
  }

  .tube-order-list {
    --tube-gap: clamp(2px, .7vw, 4px);
    align-self: center;
    align-items: center;
    padding: 0;
    min-height: 0;
  }

  .tube-card,
  .tube-drop-placeholder {
    max-width: none;
    max-height: min(43vh, 100px);
    height: min(43vh, 100px);
    min-height: 235px;
    border-radius: clamp(9px, 2.4vw, 14px);
  }

  .tube-card {
    grid-template-rows: 18px minmax(0, 1fr);
    gap: 3px;
    padding: 5px 1px 7px;
  }

  .drag-dots {
    font-size: clamp(.58rem, 2.3vw, .78rem);
  }

  .blood-tube {
    width: min(86%, 48px);
    padding-top: clamp(34px, 5.8vh, 48px);
  }

  .tube-cap {
    width: 94%;
    height: clamp(34px, 5.8vh, 48px);
    border-radius: 6px 6px 4px 4px;
  }

  .tube-neck {
    width: 68%;
    height: clamp(12px, 2.1vh, 19px);
  }

  .tube-label {
    width: 68%;
    gap: 2px;
  }

  .tube-label strong {
    font-size: clamp(.42rem, 1.5vw, .58rem);
  }

  .tube-label small {
    font-size: clamp(.36rem, 1.2vw, .48rem);
  }

  .tube-base {
    width: 68%;
    height: clamp(27px, 4.8vh, 40px);
  }

  .tube-drop-placeholder::after {
    font-size: clamp(.32rem, 1.45vw, .46rem);
  }

  .order-tip {
    font-size: clamp(.72rem, 3vw, .88rem);
    padding-inline: 8px;
    display:none;
  }

  .order-footer {
    display: flex;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    padding-top: 12px;
  }

  .order-footer .hint-btn,
  .order-footer .primary-btn {
    min-width: 0;
    width: 100%;
    min-height: 54px;
    border-radius: 18px;
  }

  .order-footer #doneOrderDrawBtn:not([hidden]) {
    grid-column: 1 / -1;
    width: min(100%, 300px);
    justify-self: center;
  }
}

@media (orientation: portrait) and (max-height: 720px) {
  .order-board {
    gap: 6px;
    padding-top: 9px;
    padding-bottom: 9px;
  }

  .order-instructions p,
  .order-tip {
    display: none;
  }

  .tube-card,
  .tube-drop-placeholder {
    height: min(39vh, 300px);
    min-height: 205px;
  }

  .order-footer .hint-btn,
  .order-footer .primary-btn {
    min-height: 46px;
  }
}


.order-round-size-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.order-round-size-control label {
  display: grid;
  gap: .2rem;
}

.order-round-size-control label span {
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
}

.order-round-size-control select {
  flex: 0 0 auto;
  min-width: 7.5rem;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--purple-soft);
  color: var(--text);
  font: inherit;
}

@media (max-width: 560px) {
  .order-round-size-control {
    align-items: stretch;
    flex-direction: column;
  }

  .order-round-size-control select {
    width: 100%;
  }
}


.order-hide-text-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: .75rem;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
}

.order-hide-text-control > span {
  display: grid;
  gap: .2rem;
}

.order-hide-text-control small {
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
}

.order-hide-text-control input {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  accent-color: var(--purple);
}

.tube-order-card.hide-tube-text .tube-copy,
.tube-order-card.hide-tube-text .tube-label,
.tube-order-card.hide-tube-text strong,
.tube-order-card.hide-tube-text p,
.tube-order-card.hide-tube-text span:not(.tube-cap):not(.tube-body):not(.tube-label-stripe) {
  display: none;
}

/* The hide-labels preference must suppress both the primary and secondary text. */
.tube-order-card.hide-tube-text strong,
.tube-order-card.hide-tube-text .tube-copy > span,
.tube-order-card.hide-tube-text .tube-copy > p {
  display: none !important;
}


/* Font Awesome Free Solid icons */
.fa-solid,
.fas {
  display: inline-block;
  flex: 0 0 auto;
  line-height: 1;
  color: currentColor;
}

button .fa-solid,
a .fa-solid,
.activity-icon .fa-solid,
.nav-icon .fa-solid {
}

.icon-only .fa-solid,
button[aria-label] > .fa-solid:only-child {
  margin-inline-end: 0;
}

.activity-card .fa-solid,
.activity-option .fa-solid {
  font-size: 1.35em;
}

.activity-icon i::before { font-size: .75em;
  vertical-align: center;
  margin: 0px;
  padding: 0px;}