/* ==========================================================================
   GastroLingo — Duolingo Design System (REA Evidence-Backed Reconstruction)
   Observed Root Tokens from https://www.duolingo.com
   REA Evidence ID: ev_e48413d6df148e9f950b91c7c02a0b8bf2730f1d8b94d808d394af6582bc3926
   DOM SHA-256: 8697e27f5f86e7274e944513e447477312d8d81a11b0b943092dd6913fd78da9
   ========================================================================== */

:root {
  /* Observed Duolingo RGB triplets from REA DOM inspection */
  --color-owl: 88, 204, 2;
  --color-tree-frog: 88, 167, 0;
  --color-mask-green: 137, 226, 25;
  --color-sea-sponge: 215, 255, 184;
  --color-macaw: 28, 176, 246;
  --color-whale: 24, 153, 214;
  --color-iguana: 221, 244, 255;
  --color-cardinal: 255, 75, 75;
  --color-fire-ant: 234, 43, 43;
  --color-walking-fish: 255, 223, 224;
  --color-bee: 255, 200, 0;
  --color-camel: 231, 166, 1;
  --color-canary: 255, 245, 211;
  --color-fox: 255, 150, 0;
  --color-guinea-pig: 205, 121, 0;
  --color-beetle: 206, 130, 255;
  --color-butterfly: 111, 78, 161;
  --color-peacock: 0, 205, 156;

  /* Semantic Hex Tokens (Light Mode Default) */
  --duo-green: #58CC02;
  --duo-green-lip: #46A302;
  --duo-green-light: #D7FFB8;
  --duo-green-shine: #89E219;

  --duo-blue: #1CB0F6;
  --duo-blue-lip: #1899D6;
  --duo-blue-light: #DDF4FF;

  --duo-red: #FF4B4B;
  --duo-red-lip: #EA2B2B;
  --duo-red-light: #FFDFE0;

  --duo-yellow: #FFC800;
  --duo-yellow-lip: #CC9B00;
  --duo-yellow-light: #FFF5D1;

  --duo-orange: #FF9600;
  --duo-orange-lip: #CD7900;
  --duo-orange-light: #FFF0D6;

  --duo-purple: #CE82FF;
  --duo-purple-lip: #A560E8;
  --duo-purple-light: #F3E5FF;

  --duo-teal: #00CD9C;
  --duo-teal-lip: #00A47D;
  --duo-teal-light: #D6FFF5;

  /* Surfaces & Neutrals */
  --bg-page: #FFFFFF;
  --bg-secondary: #F7F7F7;
  --bg-card: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --border-color: #E5E5E5;
  --border-lip: #CECECE;
  --text-main: #3C3C3C;
  --text-secondary: #777777;
  --text-muted: #AFAFAF;
  --locked-bg: #E5E5E5;
  --locked-lip: #B7B7B7;

  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --sidebar-w: 256px;
  --rightbar-w: 340px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--duo-blue);
  outline-offset: 3px;
}

.gamepad-focus {
  outline: 3px solid var(--duo-blue) !important;
  outline-offset: 3px !important;
  scroll-margin: 72px;
}

.gamepad-status {
  position: fixed;
  z-index: 125;
  right: 14px;
  bottom: 14px;
  max-width: min(310px, calc(100vw - 28px));
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  box-shadow: 0 3px 14px rgba(0, 0, 0, .12);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.45;
  pointer-events: none;
}

.gamepad-status.is-connected {
  border-color: var(--duo-green);
  color: var(--duo-green-lip);
}

@media (max-width: 760px) {
  .gamepad-status {
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    max-width: min(280px, calc(100vw - 20px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Exercise formats: ordering, classification, numeric input and image recognition. */
.order-board,
.classify-board {
  display: grid;
  gap: 12px;
  margin: 14px 0;
}

.order-slot-list,
.order-tile-list {
  display: grid;
  gap: 8px;
}

.order-slot,
.order-tile,
.classify-item,
.classify-choice,
.numeric-answer-input,
.lesson-image-card {
  border: 2px solid var(--border-color);
  border-bottom-width: 4px;
  border-radius: 13px;
  background: var(--bg-card);
  color: var(--text-main);
}

.order-slot {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
}

.order-slot:not(.filled) > span:last-child {
  min-height: 20px;
  flex: 1;
  border-bottom: 1px dashed var(--border-lip);
}

.order-tile-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.order-tile,
.classify-choice {
  min-width: 0;
  padding: 11px 12px;
  text-align: left;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
  cursor: pointer;
}

.order-tile:hover,
.classify-choice:hover {
  border-color: var(--duo-blue);
  background: var(--duo-blue-light);
}

.classify-item {
  padding: 13px;
}

.classify-item > p {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
  white-space: pre-wrap;
}

.classify-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.classify-choice.selected {
  border-color: var(--duo-blue);
  background: var(--duo-blue-light);
}

.classify-choice:disabled {
  cursor: default;
  opacity: 0.8;
}

.classify-item.answer-correct,
.order-board.answer-correct .order-slot {
  border-color: var(--duo-green);
  background: var(--duo-green-light);
}

.classify-item.answer-wrong,
.order-board.answer-wrong .order-slot {
  border-color: var(--duo-red);
  background: var(--duo-red-light);
}

.numeric-answer-label {
  display: block;
  margin: 12px 0 7px;
  font-size: 13px;
  font-weight: 900;
  color: var(--text-secondary);
}

.numeric-answer-input {
  display: block;
  width: min(100%, 320px);
  min-height: 58px;
  padding: 12px 16px;
  font: inherit;
  font-size: 24px;
  font-weight: 900;
  text-align: center;
}

.lesson-image-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 10px auto 15px;
  padding: 8px;
  max-width: 460px;
  overflow: hidden;
}

.lesson-image-card img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
}

.lesson-image-card figcaption {
  padding: 3px 6px 5px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.4;
  text-align: center;
}

.clinical-image-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px auto 18px;
  max-width: 700px;
}

.duo-card-option.clinical-image-option {
  min-width: 0;
  display: grid;
  width: 100%;
  justify-items: center;
  gap: 7px;
  padding: 9px;
  text-align: center;
}

.duo-card-option.clinical-image-option:focus-visible {
  outline: 3px solid var(--duo-blue);
  outline-offset: 2px;
}

.clinical-image-option img {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg-secondary);
}

.clinical-image-option-label {
  font-size: 12px;
  font-weight: 900;
}

.clinical-image-disclaimer {
  margin: -8px auto 16px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
}

.lesson-stage.has-visual-explanation {
  justify-content: flex-start;
}

.clinical-visual-explanation {
  width: 100%;
  margin: 18px auto 8px;
  padding: 16px;
  border: 2px solid var(--duo-blue);
  border-radius: 18px;
  background: var(--bg-secondary);
  color: var(--text-main);
  text-align: left;
  box-shadow: 0 4px 0 rgba(28, 176, 246, 0.28);
}

.clinical-visual-explanation h3 {
  margin: 0 0 6px;
  color: var(--duo-blue);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
}

.clinical-visual-summary {
  margin: 0 0 12px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.clinical-visual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.clinical-visual-figure {
  min-width: 0;
  margin: 0;
}

.clinical-annotated-image {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: #08152f;
}

.clinical-annotated-image.chicago {
  aspect-ratio: 900 / 560;
}

.clinical-annotated-image.forrest {
  aspect-ratio: 1;
  background: #100d0d;
}

.clinical-annotated-image img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.clinical-image-marker,
.clinical-explanation-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 29px;
  height: 29px;
  border: 3px solid #FFFFFF;
  border-radius: 50%;
  background: var(--duo-blue);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 1px 7px rgba(0, 0, 0, 0.5);
}

.clinical-image-marker {
  position: absolute;
  z-index: 1;
  transform: translate(-50%, -50%);
}

.clinical-explanation-figure figcaption {
  margin-top: 5px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.3;
  text-align: center;
}

.clinical-explanation-marker-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.clinical-explanation-marker-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.clinical-explanation-marker-item strong {
  display: block;
  margin: 1px 0 2px;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 900;
}

.clinical-explanation-marker-item p {
  margin: 0;
  color: var(--text-secondary);
  font-weight: 700;
}

.clinical-explanation-number {
  width: 23px;
  height: 23px;
  border-width: 2px;
  font-size: 11px;
}

.clinical-visual-example,
.clinical-visual-caution {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.45;
}

.clinical-visual-example {
  border-left: 4px solid var(--duo-green);
  background: var(--duo-green-light);
}

.clinical-visual-example p {
  margin: 4px 0 0;
  color: var(--text-main);
  font-weight: 750;
}

.clinical-visual-caution {
  border-left: 4px solid var(--duo-yellow);
  background: var(--duo-yellow-light);
  color: var(--text-main);
  font-weight: 700;
}

@media (max-width: 560px) {
  .order-tile-list,
  .classify-options {
    grid-template-columns: 1fr;
  }

  .clinical-visual-explanation {
    padding: 12px;
  }

  .clinical-visual-grid {
    grid-template-columns: 1fr;
  }

  .clinical-explanation-marker-list {
    grid-template-columns: 1fr;
  }
}

[data-theme="dark"] {
  --bg-page: #131F24;
  --bg-secondary: #1B2B32;
  --bg-card: #18272E;
  --bg-elevated: #20343D;
  --border-color: #37464F;
  --border-lip: #28353D;
  --text-main: #F1F7FB;
  --text-secondary: #99B0BC;
  --text-muted: #657D89;
  --locked-bg: #2A3B44;
  --locked-lip: #1D2A31;
  --duo-blue-light: rgba(28, 176, 246, 0.18);
  --duo-green-light: rgba(88, 204, 2, 0.18);
  --duo-red-light: rgba(255, 75, 75, 0.18);
  --duo-yellow-light: rgba(255, 200, 0, 0.16);
  --duo-orange-light: rgba(255, 150, 0, 0.16);
  --duo-purple-light: rgba(206, 130, 255, 0.16);
}

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

html, body {
  height: 100%;
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ==========================================================================
   APP SHELL LAYOUT (3-Column Duolingo Web Layout)
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--rightbar-w);
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
}

/* Left Navigation Sidebar */
.left-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 2px solid var(--border-color);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-page);
  z-index: 20;
  overflow-y: auto;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px 20px;
  cursor: pointer;
  user-select: none;
}

.brand-mascot {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  object-fit: cover;
  border: 2px solid var(--duo-green);
  border-bottom: 4px solid var(--duo-green-lip);
  background: #131F24;
}

.brand-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--duo-green);
  line-height: 1;
}

.brand-subtitle {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s ease;
}

.nav-item:hover {
  background: var(--bg-secondary);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--duo-blue-light);
  border-color: #84D8FF;
  color: var(--duo-blue);
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
  width: 28px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  background: var(--duo-red);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
}

.sidebar-footer {
  border-top: 2px solid var(--border-color);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rea-verified-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-color);
  font-size: 11px;
  font-weight: 800;
  color: var(--text-secondary);
}

.rea-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--duo-green);
  box-shadow: 0 0 0 3px rgba(88, 204, 2, 0.25);
  flex-shrink: 0;
}

/* ==========================================================================
   CENTER MAIN VIEWPORT
   ========================================================================== */

.center-main {
  padding: 24px 36px 80px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

/* Unit Filter Pills Bar */
.unit-filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 14px;
  margin-bottom: 18px;
  scrollbar-width: none;
}
.unit-filter-bar::-webkit-scrollbar {
  display: none;
}

.unit-pill {
  padding: 8px 14px;
  border-radius: 12px;
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.1s ease;
}

.unit-pill:hover {
  background: var(--bg-secondary);
}

.unit-pill.active {
  background: var(--duo-green);
  border-color: var(--duo-green);
  border-bottom-color: var(--duo-green-lip);
  color: #FFFFFF;
}

/* Unit Banner Header (Duolingo Style) */
.unit-section {
  margin-bottom: 44px;
}

.unit-banner {
  border-radius: 18px;
  padding: 20px 24px;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
  border-bottom: 6px solid rgba(0, 0, 0, 0.22);
  position: relative;
  overflow: hidden;
}

.unit-banner-info {
  flex: 1;
}

.unit-banner-eyebrow {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  opacity: 0.88;
  margin-bottom: 4px;
}

.unit-banner-title {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
  margin-bottom: 4px;
}

.unit-banner-subtitle {
  font-size: 14px;
  font-weight: 700;
  opacity: 0.92;
}

.unit-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-unit-guide {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-bottom: 4px solid rgba(0, 0, 0, 0.22);
  color: #FFFFFF;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 16px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-unit-guide:hover {
  background: rgba(255, 255, 255, 0.28);
}

.btn-unit-guide:active {
  transform: translateY(3px);
  border-bottom-width: 1px;
}

/* ==========================================================================
   WINDING S-CURVE SKILL PATH ("IL PERCORSO")
   ========================================================================== */

.skill-path-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  position: relative;
  padding: 12px 0 20px;
}

.path-node-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 2;
  transition: transform 0.2s ease;
}

/* Outer Crown / Mastery Ring */
.path-node-ring {
  position: relative;
  width: 92px;
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.path-node-ring svg.ring-svg {
  position: absolute;
  inset: -6px;
  width: 104px;
  height: 98px;
  pointer-events: none;
  transform: rotate(-90deg);
}

/* 3D Oval Path Node Button */
.path-node-btn {
  width: 76px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: var(--node-color, var(--duo-green));
  border-bottom: 8px solid var(--node-lip, var(--duo-green-lip));
  color: #FFFFFF;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, filter 0.15s ease;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.06);
}

.path-node-btn::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 14px;
  width: 22px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  transform: rotate(-20deg);
  pointer-events: none;
}

.path-node-btn:hover {
  filter: brightness(1.06);
}

.path-node-btn:active {
  transform: translateY(5px);
  border-bottom-width: 3px;
}

.path-node-btn.mastered {
  background: var(--duo-yellow);
  border-bottom-color: var(--duo-yellow-lip);
}

.path-node-btn.in-progress {
  box-shadow: 0 0 0 6px rgba(88, 204, 2, 0.2);
}

.node-crown-badge {
  position: absolute;
  right: -4px;
  bottom: -2px;
  background: var(--duo-yellow);
  border: 2px solid var(--bg-page);
  border-bottom: 3px solid var(--duo-yellow-lip);
  color: #5C4300;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 4;
}

/* Floating "STUDIA ORA" / "INIZIA" Tooltip */
.duo-start-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  background: var(--bg-card);
  color: var(--node-color, var(--duo-green));
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  padding: 7px 14px;
  border-radius: 12px;
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
  animation: duoBounce 1.6s ease-in-out infinite;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  z-index: 5;
  pointer-events: none;
}

.duo-start-tooltip::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--bg-card);
  border-right: 2px solid var(--border-color);
  border-bottom: 2px solid var(--border-color);
}

@keyframes duoBounce {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}

.path-node-label {
  margin-top: 8px;
  text-align: center;
  max-width: 210px;
}

.path-node-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.25;
}

.path-node-category {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Quick Action Mini Buttons under Node */
.node-quick-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.btn-node-mini {
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border-color);
  border-bottom: 3px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.1s ease;
}

.btn-node-mini:hover {
  border-color: var(--duo-blue);
  color: var(--duo-blue);
  background: var(--duo-blue-light);
}

/* ==========================================================================
   RIGHT SIDEBAR (HUD Stats, Daily Quests, League, Weak Classifications)
   ========================================================================== */

.right-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-left: 2px solid var(--border-color);
  padding: 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--bg-page);
  overflow-y: auto;
}

/* Top Gamification HUD Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
}

.hud-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease;
}

.hud-stat:hover {
  background: var(--bg-secondary);
}

.hud-stat.streak { color: var(--duo-orange); }
.hud-stat.gems   { color: var(--duo-blue); }
.hud-stat.hearts { color: var(--duo-red); }
.hud-stat.xp     { color: var(--duo-yellow-lip); }

/* Sidebar Widget Cards */
.widget-card {
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  border-radius: 16px;
  padding: 16px 18px;
  background: var(--bg-card);
}

.gem-shop {
  margin: 0 0 24px;
}

.gem-shop-overview {
  display: grid;
  grid-template-columns: minmax(170px, .7fr) minmax(230px, 1.3fr);
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  margin-bottom: 20px;
  border: 2px solid var(--border-color);
  border-bottom-width: 4px;
  border-radius: 18px;
  background: linear-gradient(115deg, var(--duo-blue-light), var(--bg-card) 70%);
}

.gem-shop-balance,
.gem-shop-goal {
  display: grid;
  gap: 4px;
}

.gem-shop-balance strong {
  color: var(--duo-blue);
  font-size: 34px;
  font-weight: 950;
  line-height: 1.1;
}

.gem-shop-kicker,
.gem-shop-item-tag {
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.gem-shop-caption {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 750;
}

.gem-shop-goal-copy strong {
  color: var(--text-main);
  font-size: 14px;
  font-weight: 900;
}

.gem-shop-progress {
  height: 11px;
  margin-top: 5px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-card);
}

.gem-shop-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--duo-blue), var(--duo-purple));
  transition: width .25s ease;
}

.gem-shop-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.gem-shop-heading h2 {
  margin: 4px 0 0;
  color: var(--text-main);
  font-size: 20px;
  font-weight: 950;
}

.gem-shop-heading p {
  max-width: 390px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.gem-shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.gem-shop-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
}

.gem-shop-item-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  font-size: 25px;
}

.gem-shop-item-icon--heart { background: var(--duo-red-light); }
.gem-shop-item-icon--refill { background: var(--duo-purple-light); }
.gem-shop-item-icon--xp { background: var(--duo-orange-light); }

.gem-shop-item-copy h3 {
  margin: 3px 0 5px;
  color: var(--text-main);
  font-size: 17px;
  font-weight: 950;
}

.gem-shop-item-copy p {
  min-height: 54px;
  margin: 0 0 7px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.gem-shop-item-stock {
  display: block;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 850;
  line-height: 1.45;
}

.gem-shop-buy {
  width: 100%;
  min-height: 46px;
  margin-top: auto;
  padding: 9px 10px;
  font-size: 12px;
}

.gem-shop-earning-note {
  margin: 12px 2px 0;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
}

@media (max-width: 560px) {
  .gem-shop-overview {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 15px;
  }

  .gem-shop-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .gem-shop-grid {
    grid-template-columns: 1fr;
  }

  .gem-shop-item-copy p {
    min-height: 0;
  }
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.widget-title {
  font-size: 16px;
  font-weight: 900;
  color: var(--text-main);
}

.widget-link {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--duo-blue);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
}

/* Progress Bar inside Widgets */
.duo-progress-track {
  width: 100%;
  height: 16px;
  background: var(--border-color);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.duo-progress-fill {
  height: 100%;
  background: var(--duo-green);
  border-radius: 999px;
  position: relative;
  transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.duo-progress-fill::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 8px;
  right: 8px;
  height: 4px;
  background: var(--duo-green-shine);
  border-radius: 999px;
  opacity: 0.85;
}

/* ==========================================================================
   3D TACTILE BUTTONS (Global Utility Classes)
   ========================================================================== */

.duo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-main);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 13px 24px;
  border-radius: 16px;
  border: 2px solid transparent;
  border-bottom: 4px solid var(--btn-lip, var(--duo-green-lip));
  background-color: var(--btn-bg, var(--duo-green));
  color: #FFFFFF;
  cursor: pointer;
  user-select: none;
  transition: filter 0.12s ease, transform 0.06s ease, border-bottom-width 0.06s ease;
}

.duo-btn:hover:not(:disabled) {
  filter: brightness(1.06);
}

.duo-btn:active:not(:disabled) {
  transform: translateY(4px);
  border-bottom-width: 0px;
  margin-bottom: 4px;
}

.duo-btn:disabled {
  background-color: var(--locked-bg);
  border-bottom-color: var(--locked-lip);
  color: var(--text-muted);
  cursor: not-allowed;
}

.duo-btn.blue {
  --btn-bg: var(--duo-blue);
  --btn-lip: var(--duo-blue-lip);
}

.duo-btn.orange {
  --btn-bg: var(--duo-orange);
  --btn-lip: var(--duo-orange-lip);
}

.duo-btn.purple {
  --btn-bg: var(--duo-purple);
  --btn-lip: var(--duo-purple-lip);
}

.duo-btn.red {
  --btn-bg: var(--duo-red);
  --btn-lip: var(--duo-red-lip);
}

.duo-btn.outline {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
}

.duo-btn.outline:hover:not(:disabled) {
  background-color: var(--bg-secondary);
}

/* ==========================================================================
   COMPENDIO / SCHEDE RIFERIMENTO ESAME VIEW
   ========================================================================== */

.search-input-wrap {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.duo-search-input {
  flex: 1;
  padding: 13px 18px;
  border-radius: 14px;
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 700;
  outline: none;
}

.duo-search-input:focus {
  border-color: var(--duo-blue);
  border-bottom-color: var(--duo-blue-lip);
}

.compendio-card {
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  border-radius: 18px;
  padding: 20px 22px;
  background: var(--bg-card);
  margin-bottom: 18px;
}

.compendio-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.compendio-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--duo-blue-light);
  color: var(--duo-blue);
  margin-bottom: 6px;
}

.compendio-title {
  font-size: 20px;
  font-weight: 900;
  color: var(--text-main);
}

.compendio-summary {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 14px;
  line-height: 1.45;
}

.ref-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 14px;
  font-size: 13.5px;
}

.ref-table th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 900;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.7px;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border-color);
}

.ref-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
  line-height: 1.4;
}

.ref-table tr:last-child td {
  border-bottom: none;
}

.ref-code-badge {
  display: inline-block;
  font-weight: 900;
  color: var(--duo-blue);
  background: var(--duo-blue-light);
  padding: 2px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

.pearl-box, .mnemonic-box {
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.45;
  margin-top: 8px;
}

.pearl-box {
  background: var(--duo-yellow-light);
  border-left: 4px solid var(--duo-yellow);
  color: var(--text-main);
}

.mnemonic-box {
  background: var(--duo-purple-light);
  border-left: 4px solid var(--duo-purple);
  color: var(--text-main);
}

/* ==========================================================================
   FULL-SCREEN DUOLINGO LESSON & QUIZ MODAL
   ========================================================================== */

.lesson-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-page);
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
}

.lesson-overlay.hidden {
  display: none !important;
}

.lesson-top-bar {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 28px 12px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.btn-close-lesson {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  font-weight: 900;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 10px;
}

.btn-close-lesson:hover {
  color: var(--text-main);
  background: var(--bg-secondary);
}

.lesson-combo-pill {
  background: var(--duo-orange-light);
  color: var(--duo-orange);
  border: 2px solid var(--duo-orange);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.lesson-hearts-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  font-weight: 900;
  color: var(--duo-red);
  white-space: nowrap;
}

.lesson-theory-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom: 5px solid var(--border-color);
  border-radius: 20px;
  padding: 22px 24px;
  margin-bottom: 20px;
  animation: slideInTheory 0.25s ease-out;
}

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

.theory-guide-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--border-color);
}

.theory-badge-pill {
  display: inline-block;
  background: var(--duo-blue-light);
  color: var(--duo-blue);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.lesson-hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--duo-yellow-light);
  border: 2px solid var(--duo-yellow);
  border-bottom: 3px solid var(--duo-yellow-lip);
  color: #7A5700;
  font-family: var(--font-main);
  font-size: 12.5px;
  font-weight: 900;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 14px;
  transition: all 0.12s ease;
}

.lesson-hint-btn:hover {
  filter: brightness(1.05);
}

.lesson-hint-box {
  background: var(--duo-yellow-light);
  border: 2px solid var(--duo-yellow);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 700;
  color: #4A3500;
  line-height: 1.45;
  animation: slideInTheory 0.2s ease-out;
}

.btn-node-learn {
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 900;
  padding: 6px 12px;
  border-radius: 12px;
  border: 2px solid var(--duo-green);
  border-bottom: 3px solid var(--duo-green-lip);
  background: var(--duo-green);
  color: #FFFFFF;
  cursor: pointer;
  transition: all 0.1s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-node-learn:hover {
  filter: brightness(1.06);
}

.btn-node-learn:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

/* Lesson Stage Body */
.lesson-stage {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 28px 32px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.lesson-topic-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--duo-purple);
  margin-bottom: 10px;
}

.lesson-prompt {
  font-size: 25px;
  font-weight: 900;
  color: var(--text-main);
  line-height: 1.3;
  margin-bottom: 20px;
}

/*Mascot Speech Bubble for Clinical Case */
.mascot-case-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}

.mascot-avatar-lg {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: cover;
  border: 2px solid var(--duo-green);
  border-bottom: 4px solid var(--duo-green-lip);
  flex-shrink: 0;
}

.speech-bubble {
  position: relative;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  border-radius: 18px;
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.45;
  flex: 1;
}

.speech-bubble-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--duo-orange);
  margin-bottom: 4px;
}

/* Interactive Option Cards */
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.options-grid.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.duo-card-option {
  display: flex;
  align-items: center;
  gap: 14px;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  border-radius: 16px;
  padding: 15px 18px;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 15.5px;
  font-weight: 800;
  line-height: 1.38;
  word-break: break-word;
  overflow-wrap: break-word;
  text-align: left;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.1s ease, border-color 0.1s ease, transform 0.06s ease;
}

.duo-card-option:hover:not(.disabled) {
  background-color: var(--bg-secondary);
}

.duo-card-option:active:not(.disabled) {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

.option-key-badge {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.duo-card-option.selected {
  background-color: var(--duo-blue-light);
  border-color: var(--duo-blue);
  border-bottom-color: var(--duo-blue-lip);
  color: var(--duo-blue);
}

.duo-card-option.selected .option-key-badge {
  border-color: var(--duo-blue);
  color: var(--duo-blue);
}

.duo-card-option.correct {
  background-color: var(--duo-green-light);
  border-color: var(--duo-green);
  border-bottom-color: var(--duo-green-lip);
  color: var(--duo-green-lip);
}

.duo-card-option.wrong {
  background-color: var(--duo-red-light);
  border-color: var(--duo-red);
  border-bottom-color: var(--duo-red-lip);
  color: var(--duo-red-lip);
  animation: duoShake 0.35s ease;
}

/* Pair Matching ("Abbina le Coppie") Grid */
.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.match-tile {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 14px;
  border-radius: 16px;
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: break-word;
  cursor: pointer;
  transition: all 0.12s ease;
}

.match-tile-right {
  text-align: left;
  justify-content: flex-start;
  font-size: 13.5px;
  font-weight: 700;
}

.match-tile:hover:not(:disabled) {
  background: var(--bg-secondary);
}

.match-tile.selected {
  background: var(--duo-blue-light);
  border-color: var(--duo-blue);
  border-bottom-color: var(--duo-blue-lip);
  color: var(--duo-blue);
}

.match-tile.matched {
  background: var(--duo-green-light);
  border-color: var(--duo-green);
  color: var(--duo-green-lip);
  opacity: 0.45;
  cursor: default;
  transform: scale(0.98);
}

.match-tile.mismatch {
  background: var(--duo-red-light);
  border-color: var(--duo-red);
  color: var(--duo-red);
  animation: duoShake 0.35s ease;
}

@keyframes duoShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Bottom Lesson Footer & Slide-Up Feedback Banner */
.lesson-footer {
  border-top: 2px solid var(--border-color);
  padding: 22px 32px;
  background: var(--bg-page);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.lesson-footer-inner {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.lesson-footer.correct-banner {
  background: var(--duo-green-light);
  border-top-color: var(--duo-green);
}

.lesson-footer.wrong-banner {
  background: var(--duo-red-light);
  border-top-color: var(--duo-red);
}

.feedback-status {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex: 1;
}

.feedback-icon-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  flex-shrink: 0;
}

.feedback-title {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 4px;
}

.feedback-explanation {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.4;
}

.correct-banner .feedback-title,
.correct-banner .feedback-explanation,
.correct-banner .feedback-icon-circle {
  color: var(--duo-green-lip);
}

.wrong-banner .feedback-title,
.wrong-banner .feedback-explanation,
.wrong-banner .feedback-icon-circle {
  color: var(--duo-red-lip);
}

/* Modal Dialog (Theory Sheet & Victory Screen) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(19, 31, 36, 0.72);
  backdrop-filter: blur(4px);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-dialog {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom: 6px solid var(--border-color);
  border-radius: 22px;
  max-width: 740px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 26px 28px;
}

/* Victory Celebration Card */
.victory-screen {
  text-align: center;
  padding: 20px 10px;
}

.victory-trophy {
  width: 118px;
  height: 118px;
  border-radius: 26px;
  object-fit: cover;
  border: 3px solid var(--duo-yellow);
  border-bottom: 6px solid var(--duo-yellow-lip);
  margin-bottom: 18px;
}

.victory-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-width: 520px;
  margin: 24px auto;
}

.victory-stat-box {
  border-radius: 16px;
  border: 2px solid var(--duo-yellow);
  border-bottom: 4px solid var(--duo-yellow-lip);
  overflow: hidden;
  background: var(--bg-card);
}

.victory-stat-box.accuracy {
  border-color: var(--duo-green);
  border-bottom-color: var(--duo-green-lip);
}

.victory-stat-box.gems {
  border-color: var(--duo-blue);
  border-bottom-color: var(--duo-blue-lip);
}

.victory-stat-header {
  background: var(--duo-yellow);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 6px;
}

.victory-stat-box.accuracy .victory-stat-header { background: var(--duo-green); }
.victory-stat-box.gems .victory-stat-header { background: var(--duo-blue); }

.victory-stat-val {
  font-size: 24px;
  font-weight: 900;
  padding: 14px 8px;
  color: var(--text-main);
}

/* Responsive Breakpoints */
@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 84px minmax(0, 1fr) 300px;
  }
  .brand-title, .brand-subtitle, .nav-item span:not(.nav-icon):not(.nav-badge) {
    display: none;
  }
  .nav-item {
    justify-content: center;
    padding: 12px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .left-sidebar {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    height: 66px;
    border-right: none;
    border-top: 2px solid var(--border-color);
    flex-direction: row;
    padding: 6px 12px;
  }
  .brand-header, .sidebar-footer {
    display: none;
  }
  .nav-menu {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
  }
  .right-sidebar {
    position: static;
    height: auto;
    border-left: none;
    border-top: 2px solid var(--border-color);
    padding-bottom: 90px;
  }
  .options-grid.two-cols, .match-board {
    grid-template-columns: 1fr;
  }
}

/* Phone and tablet layouts: reserve safe areas, keep controls touchable, and
   let lesson content scroll above the fixed mobile navigation. */
@media (max-width: 900px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overscroll-behavior-x: none;
  }

  .app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
    max-width: none;
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }

  .left-sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 90;
    width: 100%;
    height: calc(66px + env(safe-area-inset-bottom));
    padding: 5px 8px calc(5px + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    box-shadow: 0 -4px 18px rgba(19, 31, 36, .08);
  }

  .brand-header,
  .sidebar-footer {
    display: none;
  }

  .nav-menu {
    display: flex;
    width: 100%;
    min-width: 0;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: 3px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .nav-menu::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    position: relative;
    display: flex;
    flex: 1 1 0;
    min-width: 44px;
    max-width: 104px;
    min-height: 48px;
    justify-content: center;
    gap: 0;
    padding: 7px 3px;
    border-width: 1px;
    border-radius: 12px;
  }

  .nav-icon {
    width: auto;
    font-size: 21px;
  }

  .nav-badge {
    position: absolute;
    top: 0;
    right: 1px;
    margin: 0;
    padding: 1px 5px;
    font-size: 9px;
  }

  .center-main {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 20px clamp(16px, 4vw, 32px) 28px;
  }

  .right-sidebar {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    width: 100%;
    height: auto;
    gap: 12px;
    overflow: visible;
    padding: 14px clamp(16px, 4vw, 32px) 20px;
    border: 0;
    border-top: 1px solid var(--border-color);
  }

  .right-sidebar > .hud-bar,
  .right-sidebar > .widget-card:last-child {
    grid-column: 1 / -1;
  }

  .hud-bar {
    flex-wrap: wrap;
    justify-content: space-around;
  }

  .lesson-overlay {
    height: 100vh;
    height: 100dvh;
    justify-content: flex-start;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .lesson-top-bar {
    position: sticky;
    top: 0;
    z-index: 3;
    max-width: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    background: var(--bg-page);
  }

  .lesson-top-bar .duo-progress-track {
    min-width: 48px;
  }

  .lesson-stage {
    min-width: 0;
    justify-content: flex-start;
    padding: 18px clamp(16px, 4vw, 32px) 24px;
  }

  .lesson-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    flex-shrink: 0;
    padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
  }

  .lesson-footer-inner {
    width: 100%;
    gap: 12px;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .modal-dialog {
    max-height: 92vh;
    max-height: 92dvh;
    padding: 20px clamp(16px, 4vw, 26px);
    border-radius: 18px;
    -webkit-overflow-scrolling: touch;
  }

  .ref-table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ref-table th,
  .ref-table td {
    min-width: 112px;
  }
}

/* iPad and compact tablets keep side-by-side exercise choices. */
@media (min-width: 561px) and (max-width: 900px) {
  .options-grid.two-cols,
  .match-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .right-sidebar > .widget-card {
    min-width: 0;
  }

  .unit-banner {
    padding: 18px;
  }
}

/* Narrow phones. */
@media (max-width: 560px) {
  .app-shell {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .left-sidebar {
    height: calc(64px + env(safe-area-inset-bottom));
    padding-inline: 5px;
  }

  .nav-menu {
    gap: 1px;
  }

  .nav-item {
    min-width: 42px;
    min-height: 46px;
    padding-inline: 1px;
    border-radius: 10px;
  }

  .nav-icon {
    font-size: 20px;
  }

  .center-main {
    padding: 16px 12px 24px;
  }

  .right-sidebar {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 12px 12px 18px;
  }

  .right-sidebar > .hud-bar,
  .right-sidebar > .widget-card:last-child {
    grid-column: auto;
  }

  .hud-bar {
    justify-content: space-between;
    gap: 2px;
    padding: 6px;
  }

  .hud-stat {
    gap: 4px;
    padding: 6px 4px;
    font-size: 13px;
  }

  .widget-card,
  .compendio-card {
    padding: 14px;
    border-radius: 15px;
  }

  .unit-banner {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: 16px;
  }

  .unit-banner-title {
    font-size: 19px;
  }

  .unit-banner-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 7px;
  }

  .btn-unit-guide {
    min-width: 0;
    justify-content: center;
    padding: 9px 7px;
    font-size: 10px;
  }

  .search-input-wrap,
  .compendio-card-top {
    flex-direction: column;
    align-items: stretch;
  }

  .duo-search-input {
    min-width: 0;
    padding: 11px 13px;
    font-size: 16px;
  }

  .ref-table {
    font-size: 12px;
  }

  .ref-table th,
  .ref-table td {
    min-width: 128px;
    padding: 8px;
  }

  .lesson-top-bar {
    gap: 6px;
    padding-inline: 10px;
  }

  .lesson-top-bar .btn-node-mini {
    padding: 6px 8px;
    font-size: 10px;
  }

  .lesson-combo-pill {
    display: none !important;
  }

  .lesson-hearts-display {
    gap: 4px;
    font-size: 15px;
  }

  .lesson-stage {
    padding: 14px 14px 20px;
  }

  .lesson-topic-tag {
    gap: 5px;
    font-size: 10px;
    letter-spacing: .35px;
  }

  .lesson-prompt {
    font-size: clamp(20px, 5.8vw, 24px);
    margin-bottom: 14px;
  }

  .mascot-case-row {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
  }

  .mascot-avatar-lg {
    width: 52px;
    height: 52px;
    border-radius: 14px;
  }

  .speech-bubble {
    width: 100%;
    padding: 13px 14px;
    font-size: 14px;
  }

  .options-grid.two-cols,
  .clinical-image-options,
  .order-tile-list,
  .classify-options,
  .match-board {
    grid-template-columns: minmax(0, 1fr);
  }

  .clinical-image-options {
    gap: 8px;
  }

  .duo-card-option {
    min-height: 54px;
    gap: 10px;
    padding: 12px 13px;
    font-size: 14px;
  }

  .match-tile {
    min-height: 52px;
    padding: 10px 12px;
    font-size: 13px;
  }

  .numeric-answer-input {
    width: 100%;
  }

  .lesson-footer {
    padding-inline: 14px;
  }

  .lesson-footer-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .lesson-footer-inner > button {
    width: 100%;
    min-height: 48px;
  }

  .feedback-status {
    gap: 10px;
  }

  .feedback-icon-circle {
    width: 40px;
    height: 40px;
    font-size: 21px;
  }

  .feedback-title {
    font-size: 17px;
  }

  .feedback-explanation {
    font-size: 13px;
  }

  .victory-stats-grid {
    gap: 7px;
    margin: 16px auto;
  }

  .victory-stat-header {
    font-size: 9px;
    letter-spacing: .2px;
  }

  .victory-stat-val {
    padding: 10px 4px;
    font-size: 17px;
  }

  .modal-backdrop {
    padding-inline: 6px;
  }

  .modal-dialog {
    padding: 16px 12px;
    border-radius: 16px;
  }
}

@media (max-width: 370px) {
  .nav-badge {
    display: none;
  }

  .victory-stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (pointer: coarse) {
  button,
  select,
  input[type="checkbox"],
  input[type="radio"] {
    touch-action: manipulation;
  }

  button:not(.nav-item) {
    min-height: 42px;
  }
}
