/* Safe-area-aware phone layout and compact modal navigation. */
.mobile-menu-toggle,
.mobile-brand {
  display: none;
}
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
@media (max-width: 850px), (max-height: 620px) {
  .sidebar,
  .chat-active .sidebar,
  .topbar-breadcrumb {
    display: none;
  }
  .workspace {
    margin-left: 0;
    min-width: 0;
  }
  .topbar,
  .chat-active .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: calc(52px + var(--safe-top));
    flex: 0 0 calc(52px + var(--safe-top));
    padding: var(--safe-top) max(12px, var(--safe-right)) 0 max(12px, var(--safe-left));
    gap: 8px;
  }
  #account-button {
    flex: 0 0 44px;
    width: 56px;
    height: 56px;
    padding: 4px;
    justify-content: center;
  }
  #account-button > span:not(#avatar) {
    display: none;
  }
  main {
    padding-inline: max(16px, var(--safe-left)) max(16px, var(--safe-right));
    padding-bottom: max(16px, var(--safe-bottom));
  }
  .chat-active main {
    padding: 8px max(10px, var(--safe-right)) max(8px, var(--safe-bottom)) max(10px, var(--safe-left));
  }
  input,
  select,
  textarea,
  .chat-active .practice-control select {
    font-size: 16px;
    min-height: 44px;
  }
  button,
  .chat-active #new-chat,
  .chat-mode-switch button,
  #attachment-selection {
    min-height: 44px;
    min-width: 44px;
  }
  .chat-active #attach-button,
  .chat-active #send-button {
    min-width: 44px;
  }
  #attachment-selection {
    height: auto;
    text-overflow: ellipsis;
    justify-content: flex-start;
  }
  .chat-active .practice-settings:has(#book-options:not([hidden])) #book-options,
  .chat-active .practice-settings:has(#book-options:not([hidden])) #unit-options {
    grid-column: span 3;
  }
  .chat-active .page-heading h1 {
    overflow-wrap: anywhere;
  }
  .list-row > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .text-button {
    margin-left: 0;
  }
  dialog,
  #account-dialog,
  #password-dialog {
    position: fixed;
    top: var(--chat-top, 0px);
    bottom: calc(100% - var(--chat-top, 0px) - var(--chat-height, 100dvh));
    max-height: calc(var(--chat-height, 100dvh) - 24px - var(--safe-top) - var(--safe-bottom));
    max-width: calc(100% - 24px - var(--safe-left) - var(--safe-right));
    padding: 24px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 16px;
  }
  .dialog-close {
    top: 12px;
    right: 12px;
  }
  dialog h2 {
    padding-right: 28px;
    font-size: 22px;
  }
  dialog label {
    margin-top: 12px;
  }
  .chat-active #voice-transcript {
    min-height: 0;
  }
  #voice-screen {
    container: voice / size;
    display: grid;
    grid-template-columns: 60px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  .voice-stage {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  #voice-transcript {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
  }
  .voice-controls {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}
@container voice (max-height: 440px) {
  .voice-stage {
    flex-direction: row;
    gap: 14px;
    padding: 12px;
    text-align: left;
  }
  .voice-orb {
    width: 88px;
    height: 88px;
  }
  .voice-stage h2 {
    font-size: 14px;
  }
  .voice-stage p,
  #voice-hint {
    display: none;
  }
  .voice-controls {
    padding: 8px;
  }
  #record-button {
    min-height: 44px;
  }
}
@container voice (max-height: 260px) {
  .voice-stage {
    grid-column: 1;
    grid-row: 3;
    padding: 8px;
    border-top: 1px solid var(--line);
  }
  .voice-stage > div,
  #record-status {
    display: none;
  }
  .voice-orb {
    width: 56px;
    height: 56px;
  }
  #voice-transcript {
    grid-row: 1 / 3;
  }
  .voice-controls {
    grid-column: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px;
  }
  #record-button {
    width: 100%;
    gap: 6px;
    padding: 6px;
    font-size: 12px;
  }
}
/* Older Safari keeps captions and actions visible without container queries. */
@supports not (container-type: size) {
  @media (max-width: 850px), (max-height: 620px) {
    #voice-screen .voice-stage {
      grid-column: 1;
      grid-row: 3;
      padding: 8px;
      border-top: 1px solid var(--line);
    }
    #voice-screen .voice-stage > div,
    #voice-screen #record-status,
    #voice-screen #voice-hint {
      display: none;
    }
    #voice-screen .voice-orb {
      width: 56px;
      height: 56px;
    }
    #voice-screen #voice-transcript {
      grid-row: 1 / 3;
    }
    #voice-screen .voice-controls {
      grid-column: 2;
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 4px;
      padding: 8px;
    }
    #voice-screen #record-button {
      width: 100%;
      min-height: 44px;
      gap: 6px;
      padding: 6px;
      font-size: 12px;
    }
  }
}
/* Keyboard resize on iOS does not necessarily change CSS media-query height. */
.compact-composer .chat-active .page-heading,
.compact-composer body.chat-active #chat-view .practice-settings,
.compact-composer .chat-active .chat-toolbar {
  display: none;
}
.compact-composer .chat-active .chat-panel {
  grid-template-rows: minmax(0, 1fr) auto;
}
.compact-composer.minimal-viewport .chat-active .chat-mode-switch {
  display: none;
}
.compact-composer .chat-active .notice {
  max-height: 44px;
  overflow-y: auto;
}
@media (max-height: 450px) {
  .chat-active #chat-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 4px 8px;
  }
  .chat-active .chat-mode-switch {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
  }
  .chat-active .page-heading {
    grid-column: 2;
    grid-row: 1;
  }
  .chat-active .page-heading > div:not(.heading-level) {
    display: none;
  }
  .chat-active #new-chat {
    width: 44px;
    font-size: 0;
    gap: 0;
  }
  .chat-active .chat-layout {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .chat-active .page-heading {
    margin-bottom: 4px;
  }
  .chat-active .practice-control label {
    display: none;
  }
  .chat-active .practice-settings:has(#book-options:not([hidden])) {
    display: flex;
    flex-wrap: nowrap;
  }
  .chat-active .chat-layout {
    gap: 4px;
  }
  .chat-active .chat-mode-switch {
    margin-bottom: 4px;
  }
}

/* Course selection stays reachable from the beginning and during practice. */
#course-language {
  width: 118px;
  flex: 0 0 118px;
  min-height: 44px;
  margin: 0;
  font-size: 16px;
  padding: 8px;
}
.topbar-breadcrumb {
  flex: 1;
}
body[data-course='en'] .small-flag {
  visibility: hidden;
}
.card-meta > [data-course-meta] {
  margin: 0;
  color: inherit;
}
@media (max-width: 850px), (max-height: 620px) {
  #course-language {
    display: none;
  }
}

@media (max-width: 850px), (max-height: 620px) {
  .mobile-menu-toggle,
  .mobile-brand {
    display: flex;
    align-items: center;
    border: 0;
    background: transparent;
    color: var(--navy);
  }
  .mobile-menu-toggle {
    flex: 0 0 44px;
    justify-content: center;
    padding: 10px;
    border-radius: 12px;
  }
  .mobile-menu-toggle .icon {
    width: 24px;
    height: 24px;
  }
  .mobile-brand {
    min-width: 0;
    flex: 1;
    gap: 9px;
    padding: 0;
    text-align: left;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
  }
  /* The navy symbol fills most of its white square, as in the app icon. */
  .mobile-brand img {
    width: 38px;
    height: 38px;
    padding: 1px;
    border-radius: 11px;
    background: var(--white);
    object-fit: contain;
  }
  .mobile-brand small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
  }
  body.mobile-menu-open {
    overflow: hidden;
  }
}
#mobile-menu {
  inset: var(--safe-top) auto auto var(--safe-left);
  margin: 0;
  width: min(400px, calc(100% - var(--safe-left) - var(--safe-right)));
  height: calc(var(--chat-height, 100dvh) - var(--safe-top) - var(--safe-bottom));
  max-width: none;
  max-height: none;
  padding: 12px 18px max(16px, var(--safe-bottom));
  border: 0;
  border-radius: 0 24px 24px 0;
  color: var(--navy);
  background: #fcfcff;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 12px 0 48px #1c244b24;
}
#mobile-menu[open] {
  animation: mobile-menu-in 220ms var(--motion-ease) both;
}
#mobile-menu::backdrop {
  background: #121a38a6;
}
.mobile-menu-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#mobile-menu h2 {
  padding: 0;
  margin: 0;
  font-size: 20px;
}
#close-mobile-menu {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: var(--navy);
  background: var(--paper);
}
.mobile-course-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  margin: 12px 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f1f3f9;
}
.mobile-course-picker > span {
  flex: 1;
  padding-left: 8px;
  color: var(--muted);
  font-size: 12px;
}
.mobile-course-picker button {
  min-width: 76px;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--blue);
  font-size: 14px;
}
.mobile-course-picker button[aria-pressed='true'] {
  background: var(--navy);
  color: white;
  box-shadow: 0 2px 8px #1c244b20;
}
.mobile-menu-sections {
  display: grid;
  gap: 18px;
}
#mobile-menu nav {
  display: grid;
  gap: 4px;
}
#mobile-menu h3 {
  grid-column: 1 / -1;
  margin: 0 0 4px;
  padding-left: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
}
#mobile-menu nav button,
#mobile-menu nav a {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  gap: 10px;
  padding: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--navy);
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
}
#mobile-menu nav button > span {
  flex: 1;
}
#mobile-menu nav button > .icon:last-child:not(:first-child) {
  width: 14px;
  height: 14px;
  color: var(--muted);
}
#mobile-menu nav button[aria-current='page'] {
  background: #e9edf8;
  color: #354d83;
}
#mobile-menu .mobile-practice,
#mobile-menu .mobile-personal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
#mobile-menu .mobile-practice button {
  border: 1px solid var(--line);
  background: white;
  gap: 8px;
}
#mobile-menu .mobile-practice button:last-child {
  grid-column: 1 / -1;
}
#mobile-menu .mobile-practice button > .icon:last-child:not(:first-child) {
  display: none;
}
#mobile-menu .mobile-personal button {
  font-size: 12px;
  gap: 7px;
}
@media (max-height: 620px) and (min-width: 500px) {
  #mobile-menu {
    width: min(760px, calc(100% - var(--safe-left) - var(--safe-right)));
    padding: 8px 16px;
  }
  #mobile-menu[open] {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr) 44px;
    grid-template-areas: 'heading course close' 'sections sections sections';
    gap: 10px;
    align-content: start;
    align-items: center;
  }
  .mobile-menu-heading {
    display: contents;
  }
  #mobile-menu h2 {
    grid-area: heading;
    font-size: 17px;
  }
  #close-mobile-menu {
    grid-area: close;
  }
  .mobile-course-picker {
    grid-area: course;
    margin: 0;
  }
  .mobile-course-picker > span {
    display: none;
  }
  .mobile-course-picker button {
    flex: 1;
  }
  .mobile-menu-sections {
    grid-area: sections;
    grid-template-columns: 1.25fr 1fr;
    gap: 12px;
  }
  #mobile-menu nav button,
  #mobile-menu nav a {
    padding: 8px;
    font-size: 12px;
    gap: 6px;
  }
}
@keyframes mobile-menu-in {
  from {
    opacity: 0;
    transform: translateX(-18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
/* Phone menu: practice options as a single list, account at the bottom. */
#mobile-menu .mobile-practice {
  grid-template-columns: 1fr;
}
#mobile-menu .mobile-practice button > .icon:last-child:not(:first-child) {
  display: block;
}
#mobile-menu .mobile-account {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  color: var(--navy);
  font-size: 13px;
  text-align: left;
}
#mobile-avatar {
  flex: 0 0 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #edeef5;
  font-size: 11px;
  font-weight: 700;
}
#mobile-account-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#mobile-account > .icon {
  width: 14px;
  height: 14px;
  color: var(--muted);
}
/* Phone menu header: the Método EA logo in navy (the white logo file is used as a mask). */
.mobile-menu-logo {
  display: block;
  width: 150px;
  max-width: 100%;
  aspect-ratio: 1414 / 410;
  background: var(--navy);
  -webkit-mask: url('/static/logo-ea.png?v=2') no-repeat left center / contain;
  mask: url('/static/logo-ea.png?v=2') no-repeat left center / contain;
}
.mobile-menu-heading {
  margin-bottom: 14px;
}
/* Phone menu: Início on top, then Praticar, Meu espaço and Minha conta as single-column lists. */
#mobile-menu .mobile-home,
#mobile-menu .mobile-personal,
#mobile-menu .mobile-external,
#mobile-menu .mobile-account-section {
  grid-template-columns: 1fr;
}
#mobile-menu nav button:disabled {
  opacity: 0.6;
}
#mobile-menu nav .soon-badge {
  flex: 0 0 auto;
}
#mobile-menu .mobile-account .account-text {
  flex: 1;
  display: grid;
  min-width: 0;
  line-height: 1.3;
}
#mobile-account-state {
  color: #2f8a5f;
  font-size: 11px;
}
/* Portrait phone menu: the account card sits at the bottom, apart from "Configurações" (like the desktop sidebar). */
@media (min-height: 621px) {
  #mobile-menu[open] {
    display: flex;
    flex-direction: column;
  }
  #mobile-menu .mobile-menu-sections {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  #mobile-menu .mobile-account {
    margin-top: 12px;
  }
}
/* Phones a little too short for the roomy menu: trim only the space between sections. */
@media (max-width: 850px) and (min-height: 656px) and (max-height: 799px) {
  #mobile-menu .mobile-menu-heading {
    margin-bottom: 8px;
  }
  #mobile-menu .mobile-menu-sections {
    gap: 12px;
  }
  #mobile-menu .mobile-account {
    margin-top: 8px;
  }
}
/* Shorter phones (iPhone 13, 14): a tighter list, same touch targets, still one wide column. */
@media (max-width: 850px) and (min-height: 656px) and (max-height: 743px) {
  #mobile-menu .mobile-menu-heading {
    margin-bottom: 2px;
  }
  #mobile-menu .mobile-menu-sections {
    gap: 6px;
  }
  #mobile-menu nav {
    gap: 0;
  }
  #mobile-menu .mobile-practice {
    gap: 4px;
  }
  #mobile-menu h3 {
    margin-bottom: 0;
  }
  #mobile-menu .mobile-account {
    margin-top: 4px;
    min-height: 44px;
    padding-block: 4px;
  }
  .mobile-menu-logo {
    width: 128px;
  }
}
/* Landscape phones: "Praticar" on the left; Início, Meu espaço, Minha conta and the account card on the right. */
@media (max-height: 620px) and (min-width: 500px) {
  #mobile-menu .mobile-menu-sections {
    grid-template-columns: 1.15fr 1fr;
    grid-template-areas:
      'practice home'
      'practice personal'
      'practice external'
      'practice config'
      'practice account';
    align-content: start;
    column-gap: 16px;
    row-gap: 6px;
  }
  #mobile-menu .mobile-home {
    grid-area: home;
  }
  #mobile-menu .mobile-practice {
    grid-area: practice;
    align-self: start;
  }
  #mobile-menu .mobile-personal {
    grid-area: personal;
  }
  #mobile-menu .mobile-external {
    grid-area: external;
  }
  #mobile-menu .mobile-account-section {
    grid-area: config;
  }
  #mobile-menu .mobile-account {
    grid-area: account;
    min-height: 44px;
  }
  #mobile-menu .mobile-personal h3,
  #mobile-menu .mobile-external h3,
  #mobile-menu .mobile-account-section h3 {
    margin-bottom: 0;
  }
  #mobile-menu .mobile-personal button,
  #mobile-menu .mobile-external a,
  #mobile-menu .mobile-account-section button,
  #mobile-menu .mobile-home button {
    min-height: 44px;
    padding-block: 4px;
  }
  #mobile-menu .mobile-menu-sections nav {
    gap: 0;
  }
}

/* Compact menus keep the account reachable on short phones without shrinking touch targets. */
@media (max-height: 620px) {
  #mobile-menu .mobile-menu-heading {
    margin-bottom: 4px;
  }
  #mobile-menu .mobile-menu-sections {
    gap: 8px;
  }
  #mobile-menu nav button:disabled:has(.soon-badge) {
    display: none;
  }
}

/* Portrait phones: switches, level and "Nova conversa" share one row; the title moves to the top bar. */
/* Only during a conversation; ".mobile-brand small" would otherwise show it on every screen. */
.mobile-brand .mobile-page-title {
  display: none;
}
@media (max-width: 850px) and (min-height: 451px) {
  /* The text column may shrink, so a long title ends in "…" instead of pushing the flag aside. */
  .chat-active .mobile-brand > span {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .chat-active .mobile-brand .mobile-page-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-active #chat-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0 8px;
    align-items: center;
  }
  .chat-active .chat-mode-switch {
    grid-column: 1;
    grid-row: 1;
    flex-wrap: nowrap;
    gap: 6px;
    width: auto;
    margin: 0 0 8px;
  }
  .chat-active .chat-mode-switch .mode-toggle {
    gap: 6px;
    padding: 6px 8px;
  }
  .chat-active .page-heading {
    grid-column: 2;
    grid-row: 1;
    gap: 6px;
    margin: 0 0 8px;
  }
  .chat-active .page-heading > div:not(.heading-level) {
    display: none;
  }
  .chat-active .heading-level label {
    display: none;
  }
  /* Safari draws its own shorter select; drawing it here makes it match the "+" button beside it. */
  .chat-active .heading-level select {
    -webkit-appearance: none;
    appearance: none;
    width: 64px;
    height: 44px;
    min-height: 44px;
    padding: 0 24px 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%231c244b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
      no-repeat right 10px center / 10px 7px;
    line-height: 42px;
  }
  .chat-active #new-chat {
    width: 44px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    gap: 0;
  }
  .chat-active .chat-layout {
    grid-column: 1 / -1;
    grid-row: 2;
    align-self: stretch;
  }
  .chat-active .chat-toolbar.with-controls {
    gap: 8px;
    padding: 8px 8px 8px 12px;
  }
  .chat-active .chat-toolbar.with-controls .pill {
    display: none;
  }
  .chat-active .chat-toolbar.with-controls > div:not(.heading-level) {
    flex: 1;
    min-width: 0;
  }
  .chat-active .chat-toolbar.with-controls .heading-level {
    flex: 0 0 auto;
    margin-left: 0;
  }
  .chat-active #chat-view:has(.chat-toolbar.with-controls) .page-heading {
    display: none;
  }
}
@media (max-width: 380px) and (min-height: 451px) {
  .chat-active .chat-mode-switch .mode-toggle > .icon,
  .chat-active .chat-mode-switch .mode-toggle > .toggle-icon {
    display: none;
  }
}

/* Short phones (iPhone SE, 12 Mini): one wide column cannot fit, so the menu splits into two columns. */
@media (max-width: 850px) and (max-height: 655px) and (min-height: 451px) {
  #mobile-menu .mobile-menu-heading {
    margin-bottom: 8px;
  }
  #mobile-menu .mobile-menu-sections {
    display: grid;
    flex: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: 'home home' 'practice personal' 'external config' 'account account';
    gap: 8px;
    align-items: start;
  }
  #mobile-menu .mobile-home {
    grid-area: home;
  }
  #mobile-menu .mobile-practice {
    grid-area: practice;
  }
  #mobile-menu .mobile-personal {
    grid-area: personal;
  }
  #mobile-menu .mobile-external {
    grid-area: external;
  }
  #mobile-menu .mobile-account-section {
    grid-area: config;
  }
  #mobile-menu .mobile-account {
    grid-area: account;
    margin-top: 0;
  }
  #mobile-menu nav button,
  #mobile-menu nav a {
    padding: 6px;
    gap: 6px;
    font-size: 12px;
  }
  #mobile-menu nav button > .icon:last-child:not(:first-child) {
    display: none;
  }
}
/* Landscape phones: the menu is too short for one column, so it spreads across three. */
@media (min-width: 500px) and (max-height: 450px) {
  #mobile-menu .mobile-menu-sections {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(44px, auto));
    grid-template-areas: none;
    gap: 6px 10px;
  }
  #mobile-menu .mobile-menu-sections nav {
    display: contents;
  }
  #mobile-menu .mobile-menu-sections h3 {
    display: none;
  }
  #mobile-menu .mobile-home button {
    grid-column: 1;
    grid-row: 1;
  }
  #mobile-menu .mobile-practice button {
    grid-column: 2;
    padding-block: 4px;
  }
  #mobile-menu .mobile-practice button:nth-of-type(1) {
    grid-row: 1;
  }
  #mobile-menu .mobile-practice button:nth-of-type(2) {
    grid-row: 2;
  }
  #mobile-menu .mobile-practice button:nth-of-type(3) {
    grid-row: 3;
  }
  #mobile-menu .mobile-practice button:nth-of-type(4) {
    grid-column: 2;
    grid-row: 4;
  }
  #mobile-menu .mobile-personal button {
    grid-column: 3;
  }
  #mobile-menu .mobile-personal button[data-view='plan'] {
    grid-row: 1;
  }
  #mobile-menu .mobile-personal button[data-view='errors'] {
    grid-row: 2;
  }
  #mobile-menu .mobile-personal button[data-view='history'] {
    grid-row: 3;
  }
  #mobile-menu .mobile-external a {
    grid-column: 1;
    grid-row: 2;
  }
  #mobile-menu .mobile-account-section button {
    grid-column: 3;
    grid-row: 4;
  }
  #mobile-menu .mobile-account {
    grid-area: auto;
    grid-column: 1;
    grid-row: 4;
  }
}

/* Combined voice/text shares a narrow row: never let the record pill cover Cancel. */
@media (max-width: 850px), (max-height: 620px) {
  .chat-active .voice-and-text #voice-screen .voice-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-width: 0;
    gap: 4px;
    width: 100%;
  }
  .voice-and-text #record-button {
    min-width: 0;
    width: 100%;
    min-height: 44px;
    padding: 6px 6px 6px 42px;
    font-size: 12px;
  }
  .voice-and-text #record-button > .icon {
    width: 32px;
    height: 32px;
    padding: 7px;
    left: 4px;
  }
  .voice-and-text .voice-control-status {
    min-width: 0;
    gap: 0;
  }
  .voice-and-text #cancel-recording {
    min-width: 44px;
    min-height: 44px;
  }
}
@media (max-height: 450px) {
  .chat-active .voice-and-text #voice-screen {
    height: 64px;
    grid-template-columns: 60px minmax(0, 1fr);
  }
  .chat-active .voice-and-text #voice-screen .voice-orb {
    width: 56px;
    height: 56px;
  }
}
/* The close button gets focus when the menu opens; keep its focus ring clear of the rounded corner. */
#mobile-menu #close-mobile-menu {
  /* Offset without margin, so the menu keeps fitting short phones without scrolling. */
  position: relative;
  top: 2px;
  right: 6px;
}
/* Touch screens: a dialog focuses its close button on opening, and the gold ring then crowded the
   corner and the first item. Fingers don't need it; keyboards still get the ring. */
@media (hover: none) and (pointer: coarse) {
  .dialog-close:focus-visible,
  #close-mobile-menu:focus-visible {
    outline: none;
  }
}
