/* Mobile Experience 2.0 — isolated from the approved desktop layout. */
.touch-help,
.mobile-more-trigger,
.mobile-more-layer {
  display: none;
}

/* Recent searches use stable columns at every desktop width. */
.recent-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(92px, 112px) 44px;
  align-items: center;
  gap: 14px;
}
.recent-main,
.recent-word,
.recent-meaning {
  min-width: 0;
}
.recent-word,
.recent-meaning {
  overflow-wrap: anywhere;
}
.recent-meta {
  width: 100%;
  color: color-mix(in srgb, var(--muted) 78%, var(--text));
  font-size: max(.76rem, 12px);
  font-weight: 650;
  line-height: 1.35;
  text-align: right;
  white-space: nowrap;
}
.recent-row > .icon-btn {
  justify-self: end;
}

/* Fifth theme: slightly stronger action color without tinting every control. */
html[data-theme="premium"] .btn-primary {
  background: #8b5cf6;
  border-color: #8b5cf6;
  color: #fff;
}
html[data-theme="premium"] .btn-primary:hover {
  background: #986cf8;
  border-color: #a78bfa;
}
html[data-theme="premium"] :focus-visible {
  outline-color: #b6c5fa;
}
html[data-theme="premium"][data-background="grid"] body::before {
  opacity: calc(var(--background-intensity, .25) * .62);
}

/* Settings icons now follow the same neutral Lucide language as the main nav. */
.settings-nav .settings-category-icon {
  width: 20px !important;
  height: 20px !important;
  color: var(--muted);
  filter: none !important;
  opacity: 1;
}
.settings-nav button {
  min-height: 44px;
  gap: 10px;
}
.settings-nav button:hover .settings-category-icon,
.settings-nav button.active .settings-category-icon {
  color: var(--accent);
}
.settings-nav button.active {
  color: var(--text);
}
.theme-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

@media (max-width: 850px) {
  :root {
    --mobile-nav-height: 74px;
  }
  body {
    overflow-x: clip;
  }
  .app-main {
    padding-bottom: calc(var(--mobile-nav-height) + 28px + env(safe-area-inset-bottom));
  }
  .sidebar {
    min-height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    height: auto;
    z-index: 70;
  }
  #mainNav {
    display: grid;
    grid-template-columns: repeat(5, minmax(52px, 1fr));
    gap: 3px;
    overflow: visible;
    max-width: 620px;
    padding: 0;
  }
  #mainNav > .nav-item {
    display: none;
    width: auto;
    min-width: 0;
    height: 55px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 4px 2px;
    border-radius: 13px;
  }
  #mainNav > [data-page="home"],
  #mainNav > [data-page="translate"],
  #mainNav > [data-page="study"],
  #mainNav > [data-page="review"],
  #mainNav > .mobile-more-trigger {
    display: flex;
  }
  #mainNav > .nav-item span {
    display: block;
    max-width: 100%;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #mainNav > .nav-item.active span {
    color: var(--accent-ink);
  }
  .mobile-more-layer:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 69;
  }
  .mobile-more-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    border: 0;
    background: rgba(4, 5, 8, .58);
    backdrop-filter: blur(3px);
  }
  .mobile-more-panel {
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    max-width: 620px;
    max-height: min(68vh, 540px);
    margin-inline: auto;
    overflow: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: color-mix(in srgb, var(--surface) 97%, transparent);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .38);
    overscroll-behavior: contain;
  }
  .mobile-more-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }
  .mobile-more-head span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
  }
  .mobile-more-head h2 {
    margin: 1px 0 0;
    font-size: 1.16rem;
  }
  .mobile-more-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .mobile-more-item {
    min-width: 0;
    min-height: 50px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: .82rem;
    font-weight: 700;
    text-align: left;
  }
  .mobile-more-item span {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .mobile-more-item[aria-current="page"] {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
    background: var(--accent-soft);
    color: var(--accent-ink);
  }
  body.mobile-menu-open {
    overflow: hidden;
  }

  /* Settings becomes a touch-friendly wrapped selector with no x-scroll. */
  .settings-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    overflow: visible;
    padding: 8px;
  }
  .settings-nav button {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    justify-content: flex-start;
    padding: 9px 10px;
    white-space: normal;
  }
  .settings-nav button span {
    min-width: 0;
    font-size: .72rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }
  .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* All two-column learning layouts collapse before becoming cramped. */
  .translator-layout,
  .study-layout,
  .challenge-content-grid,
  .challenge-game-grid,
  .story-layout,
  .review-layout,
  .progress-columns,
  .settings-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .surface,
  .page-content,
  .page-heading,
  .toolbar,
  .result-actions {
    min-width: 0;
  }
  .btn,
  .icon-btn,
  .swap-btn,
  .study-tab,
  .challenge-answer,
  .story-choice,
  .answer-option {
    touch-action: manipulation;
  }
}

@media (max-width: 620px) {
  .app-main {
    padding-inline: clamp(12px, 4vw, 18px);
  }
  .page-content {
    padding-top: 16px;
  }
  .page-heading {
    gap: 10px;
    margin-bottom: 15px;
  }
  .page-heading h2 {
    font-size: clamp(1.34rem, 6vw, 1.62rem);
    line-height: 1.17;
  }
  .page-heading p,
  .settings-desc,
  .muted,
  .small {
    line-height: 1.5;
  }
  input,
  textarea,
  select,
  .form-control {
    font-size: 16px;
  }
  .btn {
    min-height: 44px;
    padding-block: 10px;
  }
  .icon-btn,
  .swap-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Home */
  .welcome-card {
    min-height: 0;
    padding: 19px;
  }
  .welcome-card .welcome-title {
    max-width: 15ch;
    margin-top: 5px;
    font-size: clamp(1.68rem, 8vw, 2.05rem);
    line-height: 1.08;
    letter-spacing: -.025em;
  }
  .welcome-copy {
    margin-top: 10px;
    font-size: .9rem;
  }
  .welcome-actions {
    gap: 8px;
    margin-top: 15px;
  }
  .welcome-actions .btn {
    width: auto;
    flex: 1 1 150px;
    justify-content: center;
  }
  .welcome-luma {
    position: static;
    width: min(46%, 168px);
    height: auto;
    min-height: 118px;
    margin: 12px auto -8px;
  }
  .welcome-luma img {
    width: 100%;
    height: auto;
    max-height: 160px;
    object-fit: contain;
    object-position: center bottom;
  }
  .home-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat-card {
    min-height: 126px;
  }

  /* Translator */
  .translator-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
    align-items: end;
    gap: 7px;
    padding: 12px;
  }
  .language-field,
  .language-field select {
    min-width: 0;
    width: 100%;
  }
  .language-field label {
    margin-bottom: 4px;
  }
  .language-field select {
    height: 46px;
    padding: 8px 28px 8px 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .language-field .lumen-lang-trigger {
    min-width: 0;
    min-height: 46px;
    padding: 8px 9px;
    overflow: hidden;
    font-size: clamp(13px, 3.4vw, 15px);
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .language-field .lumen-lang-menu {
    min-width: min(220px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
  }
  /* Destination control sits on the right: anchor its list to the control's
     right edge so even the closed, absolutely positioned menu stays in view. */
  .language-field:last-child .lumen-lang-menu {
    left: auto;
    right: 0;
  }
  .translator-input {
    padding: 14px;
  }
  .translator-input textarea {
    min-height: clamp(112px, 28vh, 180px);
    padding: 12px;
  }
  .translate-bottom {
    align-items: stretch;
    gap: 10px;
  }
  .translate-bottom .btn {
    justify-content: center;
  }
  .result-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .result-actions .btn {
    width: 100%;
    justify-content: center;
    white-space: normal;
    text-align: center;
  }
  .desktop-shortcut {
    display: none;
  }
  .touch-help {
    display: inline;
  }

  /* Recent searches */
  .recent-row {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px 10px;
    padding: 13px 12px;
  }
  .recent-main {
    grid-column: 1;
  }
  .recent-meta {
    display: block;
    grid-column: 1;
    grid-row: 2;
    text-align: left;
    white-space: normal;
  }
  .recent-row > .icon-btn {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
  }

  /* Content-heavy pages */
  .vocab-item,
  .history-item,
  .mistake-row,
  .setting-row {
    overflow-wrap: anywhere;
  }
  .vocab-actions,
  .history-actions,
  .mistake-actions {
    gap: 7px;
  }
  .vocab-actions .btn,
  .mistake-actions .btn {
    min-height: 42px;
  }
  .study-tabs {
    overflow: visible;
    flex-wrap: wrap;
  }
  .study-tab {
    min-width: 92px;
  }
  .challenge-progress-top,
  .challenge-bottom-stats,
  .story-scene-header,
  .review-card-top {
    flex-wrap: wrap;
  }
  .challenge-bottom-stats {
    gap: 6px;
  }
  .challenge-bottom-stats span {
    flex: 1 1 120px;
    justify-content: center;
  }
  .story-choice,
  .answer-option,
  .challenge-answer {
    min-height: 50px;
    text-align: left;
  }
  .cosmetic-grid,
  .review-summary-grid,
  .plan-steps,
  .activity-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .modal {
    width: min(100% - 20px, 620px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-bottom));
    overflow: auto;
  }

  .settings-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .theme-option {
    min-width: 0;
    padding: 11px;
  }
  .theme-option-name,
  .theme-option .tiny {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 370px) {
  #mainNav > .nav-item span {
    font-size: 9px;
  }
  .mobile-more-grid,
  .settings-nav,
  .theme-grid,
  .result-actions,
  .home-stats {
    grid-template-columns: minmax(0, 1fr);
  }
  .translator-controls {
    grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
    gap: 4px;
    padding-inline: 9px;
  }
  .language-field select {
    padding-left: 6px;
    font-size: 15px;
  }
  .welcome-actions {
    flex-direction: column;
  }
  .welcome-actions .btn {
    width: 100%;
    flex-basis: auto;
  }
}

@media (max-width: 620px) and (pointer: fine) {
  .desktop-shortcut {
    display: inline;
  }
  .touch-help {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 1024px) {
  .mobile-more-panel {
    max-height: calc(100dvh - var(--mobile-nav-height) - 24px);
  }
  .welcome-luma {
    max-width: 120px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-more-panel,
  .mobile-more-backdrop {
    scroll-behavior: auto;
    transition: none;
  }
}
