/* App-wide sizing follows the viewport, including the embedded course viewport. */
html, body { min-width: 0; }
#app, #view, #app-header { min-width: 0; }
#view { scroll-padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }
#view :is(audio, video, input, select, textarea) { max-width: 100%; }
.quest-header-copy, .quest-card-top > div { min-width: 0; }
.quest-header h1 { overflow-wrap: anywhere; }
.quest-card-top { flex-wrap: wrap; }

/* The wide-phone compatibility font scale also catches 16:10 Android tablets.
   Use the normal readable type scale for tablet-shaped Home viewports. */
@media (min-width: 720px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5) {
  html:has(body[data-route="home"]) { font-size: 100%; }
}

@media (min-width: 720px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5), (min-width: 1024px) {
  body #app, body #bottom-nav { max-width: min(100%, 76rem); }
  body[data-route="home"] .quest-header { max-width: none; }
  body[data-route="home"] #view > .quest-home { max-width: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
  .quest-home > .quest-install-slot, .quest-home > .quest-habit-row { grid-column: 1 / -1; }
  .quest-home > .quest-habit-row { grid-row: 1; }
  /* A continuous dashboard: quest, paired summaries, then tools. Independent
     columns left a hole below the shorter quest card. */
  .quest-home > .quest-card { grid-column: 1 / -1; grid-row: 2; }
  .quest-home > .quest-section:has(.quest-quick-strip) { grid-column: 1; grid-row: 3; }
  .quest-home > .quest-section:has(.quest-course-card) { grid-column: 2; grid-row: 3; }
  .quest-home > .quest-section:has(.quest-tools) { grid-column: 1 / -1; grid-row: 4; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-install-slot { grid-row: 1; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-habit-row { grid-row: 2; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-card { grid-row: 3; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-quick-strip) { grid-row: 4; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-course-card) { grid-row: 4; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-tools) { grid-row: 5; }
  .quest-home .quest-count { margin-block: 16px 24px; }
  .quest-home .quest-count strong { font-size: 96px; }
  .quest-home .quest-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  /* Size panels from their contents. Viewport height must not become empty
     padding around the progress number or inside the supporting cards. */
  body[data-route="home"] #app { min-height: 100dvh; }
  body[data-route="home"] #view { display: block; flex: 1; padding-bottom: 104px; }
  body[data-route="home"] #view > .quest-home { padding-bottom: 24px; }
  body[data-route="home"] #bottom-nav { position: fixed; inset: auto auto max(20px, calc(env(safe-area-inset-bottom) + 8px)) 50%; transform: translateX(-50%); }
  body[data-route="home"] #view > .quest-home { align-content: start; grid-template-rows: max-content repeat(3, max-content); }
  body[data-route="home"] #view > .quest-home:has(.quest-install-slot:not(:empty)) { grid-template-rows: max-content max-content repeat(3, max-content); }
  .quest-home > .quest-card { display: flex; flex-direction: column; align-self: start; }
  .quest-home .quest-count { flex: none; display: flex; align-items: baseline; margin-block: 12px; }
  .quest-home .quest-actions { margin-top: 0; }
  .quest-home .quest-count strong { font-size: clamp(96px, 9vw, 128px); }
  .quest-home .quest-count span { font-size: clamp(48px, 5vw, 64px); }
  .quest-home > .quest-section { display: flex; flex-direction: column; align-self: start; }
  .quest-home .quest-quick-strip, .quest-home .quest-course-card, .quest-home .quest-tools { flex: none; }
  .quest-home .quest-quick-strip, .quest-home .quest-tools { align-items: center; }
  .quest-home .quest-course-card { display: flex; flex-direction: column; justify-content: center; }
  .quest-home .quest-tool { font-size: 13px; }
  .quest-home .quest-tool-icon { width: 60px; height: 60px; }
  .quest-home .quest-tool-icon .material-symbols-outlined { font-size: 26px; }
}

/* Portrait tablets get the same layout with controls sized for their columns.
   Short phone landscape viewports retain the existing phone layout. */
@media (min-width: 720px) and (max-width: 1023px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5) {
  body[data-route="home"] #app-header > .quest-header { padding-inline: 32px !important; }
  body[data-route="home"] #view > .quest-home { gap: 16px; padding-inline: 16px !important; }
  .quest-home > .quest-card { padding: 22px; }
  .quest-home .quest-card h2 { font-size: clamp(24px, 3vw, 30px); }
  .quest-home .quest-count strong { font-size: clamp(80px, 12vw, 112px); }
  .quest-home .quest-count span { font-size: clamp(40px, 5.5vw, 56px); }
  .quest-home .quest-action { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; }
  .quest-home .quest-action-icon { width: 32px; height: 32px; }
  .quest-home .quest-action strong { font-size: 12px; }
  .quest-home .quest-action small { font-size: 10px; }
}
/* Portrait tablets use a compact full-width quest above the supporting panels. */
@media (min-width: 720px) and (max-width: 1199px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5) and (orientation: portrait) {
  body[data-route="home"] #view > .quest-home { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quest-home > .quest-card { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 24px; }
  .quest-home .quest-card-top { grid-column: 1; grid-row: 1; align-content: center; }
  .quest-home .quest-count { grid-column: 2; grid-row: 1; align-self: center; margin: 0; }
  .quest-home .quest-actions { grid-column: 1 / -1; grid-row: 2; margin: 0; }
  .quest-home .quest-action { grid-template-columns: 32px minmax(0, 1fr); justify-items: start; text-align: left; }
  .quest-home .quest-action-icon { width: 32px; height: 32px; }
  .quest-home .quest-progress { grid-column: 1 / -1; grid-row: 3; margin: 0; }
  .quest-home .quest-primary-button { grid-column: 1 / -1; grid-row: 4; margin: 0; }
  .quest-home > .quest-section:has(.quest-quick-strip) { grid-column: 1; grid-row: 3; }
  .quest-home > .quest-section:has(.quest-course-card) { grid-column: 2; grid-row: 3; }
  .quest-home > .quest-section:has(.quest-tools) { grid-column: 1 / -1; grid-row: 4; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-card { grid-row: 3; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-quick-strip),
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-course-card) { grid-row: 4; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-tools) { grid-row: 5; }
}
@media (min-width: 720px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5) and (max-height: 800px), (min-width: 1024px) and (max-height: 800px) {
  body[data-route="home"] #app-header > .quest-header { padding-block: 12px !important; }
  body[data-route="home"] #view { padding-bottom: 104px; }
  body[data-route="home"] #view > .quest-home { gap: 16px; padding-bottom: 24px; }
}
@media (max-width: 380px) {
  .quest-header { gap: 8px; }
  .quest-header-actions { flex-shrink: 1; }
  .quest-home .quest-card { padding: 16px; }
  .quest-card .quest-time { white-space: normal; }
}
@media (max-height: 500px) {
  .quest-home .quest-count strong { font-size: 64px; }
  .quest-home .quest-count { margin-block: 12px; }
  body #bottom-nav > div { height: 3.5rem; }
  #bottom-nav .nav-label { font-size: 10px; }
}

/* Compact glass navigation is shared by every viewport size. */
body #bottom-nav { position: fixed; inset: auto auto max(20px, calc(env(safe-area-inset-bottom) + 8px)) 50%; transform: translateX(-50%); box-sizing: border-box; width: min(368px, calc(100% - 32px)); max-width: 368px; min-height: 64px; margin: 0; padding: 5px; background: linear-gradient(180deg, rgb(255 255 255 / 30%), rgb(255 255 255 / 8%)), rgb(220 247 188 / 64%); border: 1px solid rgb(255 255 255 / 72%); border-radius: 999px; box-shadow: inset 0 1px 0 rgb(255 255 255 / 55%), 0 8px 24px rgb(46 75 35 / 15%); -webkit-backdrop-filter: blur(24px) saturate(150%); backdrop-filter: blur(24px) saturate(150%); }
  .theme-dark #bottom-nav { background: linear-gradient(180deg, rgb(255 255 255 / 30%), rgb(255 255 255 / 8%)), rgb(220 247 188 / 64%) !important; border-color: rgb(255 255 255 / 72%) !important; }
  body #bottom-nav > div { height: 52px; padding: 0; gap: 2px; }
  #bottom-nav .nav-item { min-width: 0; min-height: 52px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 3px; padding: 5px 3px; border: 0; border-radius: 999px; background: transparent; color: #203823; text-align: center; text-decoration: none; font-size: 11px; font-weight: 500; line-height: 1.2; }
  #bottom-nav .nav-item.active { background: linear-gradient(145deg, rgb(164 220 104 / 70%), rgb(186 235 135 / 50%)); color: #152d1c; box-shadow: inset 0 1px 0 rgb(255 255 255 / 50%), 0 2px 6px rgb(46 75 35 / 8%); }
  #bottom-nav .nav-item > .material-symbols-outlined { display: grid; place-items: center; width: 22px; min-height: 20px; height: 20px; margin: 0; padding: 0; border-radius: 0; background: transparent; color: inherit; font-size: 20px; line-height: 1; transform: none; }
  #bottom-nav .nav-label { color: inherit; font-size: 11px; font-weight: 500; letter-spacing: 0; }
  #bottom-nav .nav-item:focus-visible { outline: 2px solid #305936; outline-offset: -3px; }


/* Approved pistachio-glass quest card. Keep the phone card and all learning
   state/links intact; content determines the height at every supported width. */
@media (min-width: 720px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5), (min-width: 1024px) {
  .quest-home > .quest-card {
    container: quest-card / inline-size;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    min-width: 0;
    padding: 26px;
    border: 1px solid rgb(255 255 255 / 88%);
    border-radius: 26px;
    background: linear-gradient(135deg, rgb(255 255 255 / 20%), rgb(255 255 255 / 6%)), rgb(235 243 226 / 88%);
    color: #202830;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 60%), 0 8px 24px rgb(49 61 38 / 9%);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
  }
  .quest-home .quest-card-top,
  .quest-home .quest-card-top > div { display: contents; }
  .quest-home .quest-eyebrow { grid-column: 1; grid-row: 1; align-self: center; margin: 0; color: #69736a; font-size: 11px; font-weight: 600; letter-spacing: .08em; line-height: 1.5; }
  .quest-home .quest-eyebrow > span { display: none; }
  .quest-home .quest-time { grid-column: 2; grid-row: 1; justify-self: end; min-height: 0; padding: 0; gap: 6px; border: 0; background: transparent; color: #69736a; font-size: 13px; font-weight: 400; line-height: 1.5; }
  .quest-home .quest-time .material-symbols-outlined { font-size: 18px; }
  .quest-home .quest-card h2 { grid-column: 1; grid-row: 2; min-width: 0; margin: 0; color: inherit; font-family: inherit; font-size: clamp(22px, 4.5cqi, 28px); font-weight: 600; letter-spacing: -.035em; line-height: 1.2; overflow-wrap: anywhere; }
  .quest-home .quest-count { grid-column: 2; grid-row: 2; align-self: center; justify-self: end; display: flex; align-items: baseline; gap: 5px; margin: 0; font-family: inherit; white-space: nowrap; }
  .quest-home .quest-count strong,
  .quest-home .quest-count span { color: #303a40; font-size: 22px; font-weight: 400; letter-spacing: -.025em; line-height: 1.2; font-variant-numeric: tabular-nums; }
  .quest-home .quest-progress { grid-column: 1 / -1; grid-row: 3; height: 7px; margin: -2px 0 2px; background: rgb(104 124 93 / 12%); }
  .quest-home .quest-progress span { background: #79a84a; }
  .quest-home .quest-actions { grid-column: 1 / -1; grid-row: 4; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0; overflow: visible; border: 0; border-radius: 0; background: transparent; }
  .quest-home .quest-action { grid-template-columns: 40px minmax(0, 1fr); justify-items: start; align-items: center; gap: 12px; min-height: 70px; padding: 12px; border: 1px solid rgb(255 255 255 / 28%); border-radius: 17px; background: rgb(255 255 255 / 48%); color: #202830; text-align: left; }
  .quest-home .quest-action + .quest-action { border-left: 1px solid rgb(255 255 255 / 28%); }
  .quest-home .quest-action-icon { width: 40px; height: 40px; border-radius: 13px; background: rgb(135 162 107 / 10%); color: #303a40; }
  .quest-home .quest-action-icon .material-symbols-outlined { font-size: 24px; font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24; }
  .quest-home .quest-action > span:last-child { min-width: 0; }
  .quest-home .quest-action strong { font-size: 14px; font-weight: 500; line-height: 1.35; }
  .quest-home .quest-action small { margin-top: 4px; color: #69736f; font-size: 12px; font-weight: 400; line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }
  .quest-home .quest-primary-button { grid-column: 1 / -1; grid-row: 5; justify-self: end; width: fit-content; min-width: min(230px, 100%); max-width: 100%; min-height: 44px; margin: 0; padding: 11px 18px; gap: 20px; border-radius: 999px; background: #b6ff38; color: #18251a; font-size: 14px; font-weight: 500; line-height: 1.4; box-shadow: inset 0 1px 0 rgb(255 255 255 / 35%); }
  .quest-home .quest-primary-button > span:first-child { min-width: 0; overflow-wrap: anywhere; }
  .quest-home .quest-primary-button .material-symbols-outlined { flex: 0 0 auto; font-size: 22px; }
  .quest-home .quest-action:hover { background: rgb(255 255 255 / 75%); }
  .quest-home .quest-primary-button:hover { background: #c3ff61; }
  .quest-home .quest-card a:focus-visible { outline: 2px solid #3e6929; outline-offset: 3px; }
  .theme-dark .quest-home > .quest-card { background: linear-gradient(135deg, rgb(255 255 255 / 14%), transparent), rgb(235 243 226 / 96%); border-color: rgb(255 255 255 / 70%); box-shadow: inset 0 1px 0 rgb(255 255 255 / 50%), 0 8px 24px rgb(0 0 0 / 18%); }

  /* Narrow landscape columns keep readable labels instead of squeezing the
     desktop icon-and-text layout. Container width also covers embedded views. */
  @container quest-card (max-width: 460px) {
    .quest-home .quest-actions { gap: 8px; }
    .quest-home .quest-action { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 8px; padding: 12px 8px; text-align: center; }
    .quest-home .quest-action-icon { width: 34px; height: 34px; border-radius: 11px; }
    .quest-home .quest-action-icon .material-symbols-outlined { font-size: 22px; }
  }
  @container quest-card (max-width: 360px) {
    .quest-home .quest-card h2 { grid-column: 1 / -1; }
    .quest-home .quest-count { grid-column: 1 / -1; grid-row: 3; }
    .quest-home .quest-progress { grid-row: 4; }
    .quest-home .quest-actions { grid-row: 5; }
    .quest-home .quest-primary-button { grid-row: 6; }
  }
  @media (prefers-reduced-motion: reduce) {
    .quest-home .quest-card a, .quest-home .quest-progress span { transition: none; }
    .quest-home .quest-primary-button:hover { transform: none; }
  }
}

/* Treat Home as one composed dashboard, with readable controls and a clear
   final row above the pinned navigation rather than scattered tool circles. */
@media (min-width: 720px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5), (min-width: 1024px) {
  body[data-route="home"] #app { max-width: 1040px; }
  body[data-route="home"] #view { padding-bottom: 100px; }
  body[data-route="home"] #app-header > .quest-header { padding: 16px 32px 8px !important; }
  body[data-route="home"] .quest-header h1 { margin-top: 8px; font-size: 24px; }
  body[data-route="home"] #view > .quest-home { padding: 4px 32px 0 !important; gap: 16px; }
  .quest-home .quest-habit-chip, .quest-home .quest-level-chip { min-height: 32px; padding-block: 6px; }
  .quest-home > .quest-section:has(.quest-quick-strip),
  .quest-home > .quest-section:has(.quest-course-card) { align-self: stretch; }
  .quest-home .quest-quick-strip, .quest-home .quest-course-card { flex: 1; min-height: 148px; }
  .quest-home .quest-tools { gap: 12px; }
  .quest-home .quest-tool { display: grid; grid-template-columns: 60px minmax(0, 1fr) auto; align-items: center; gap: 14px; min-height: 86px; padding: 12px 16px; border: 1px solid #e9e4dc; border-radius: 22px; background: rgb(255 254 251 / 85%); font-size: 15px; font-weight: 600; text-align: left; box-shadow: 0 5px 16px rgb(37 34 29 / 4%); }
  .quest-home .quest-tool::after { content: "\2192"; justify-self: end; color: #69736f; font-size: 22px; font-weight: 400; }
  .quest-home .quest-tool-icon { box-shadow: none; }
  .quest-home .quest-tool:focus-visible { outline: 2px solid #3e6929; outline-offset: 3px; }
  .theme-dark .quest-home .quest-tool { border-color: #2b302d; background: #191d1b; box-shadow: 0 5px 16px rgb(0 0 0 / 12%); }
  .theme-dark .quest-home .quest-tool::after { color: #aeb3ae; }
}

/* Short computers/tablets use tighter spacing, not smaller text or hidden
   content. Shorter still can scroll with clearance above the fixed pill. */
@media (min-width: 720px) and (min-height: 600px) and (min-aspect-ratio: 3 / 5) and (max-height: 850px), (min-width: 1024px) and (max-height: 850px) {
  body[data-route="home"] #app-header > .quest-header { padding-block: 10px 6px !important; }
  body[data-route="home"] .quest-header h1 { margin-top: 6px; font-size: 22px; }
  body[data-route="home"] #view > .quest-home { gap: 12px; }
  .quest-home .quest-habit-chip, .quest-home .quest-level-chip { min-height: 30px; padding-block: 5px; }
  .quest-home > .quest-card { padding: 20px; gap: 12px; }
  .quest-home .quest-action { min-height: 60px; padding-block: 9px; }
  .quest-home .quest-section-label { margin-bottom: 6px; }
  .quest-home .quest-quick-strip, .quest-home .quest-course-card { min-height: 128px; }
  .quest-home .quest-course-card { padding: 12px 16px; }
  .quest-home .quest-course-progress { margin-top: 10px; }
  .quest-home .quest-course-link { margin-top: 10px; padding-top: 10px; }
  .quest-home .quest-tool { grid-template-columns: 48px minmax(0, 1fr) auto; min-height: 70px; padding-block: 10px; }
  .quest-home .quest-tool-icon { width: 48px; height: 48px; }
}

/* Tall portrait tablets read naturally as a vertical dashboard. */
@media (min-width: 720px) and (max-width: 1199px) and (min-height: 1000px) and (min-aspect-ratio: 3 / 5) and (orientation: portrait) {
  .quest-home .quest-tools { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quest-home .quest-tool:first-child { grid-column: 1 / -1; }
  .quest-home > .quest-section:has(.quest-quick-strip) { grid-column: 1 / -1; grid-row: 3; }
  .quest-home > .quest-section:has(.quest-course-card) { grid-column: 1 / -1; grid-row: 4; }
  .quest-home > .quest-section:has(.quest-tools) { grid-row: 5; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-quick-strip) { grid-row: 4; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-course-card) { grid-row: 5; }
  .quest-home:has(.quest-install-slot:not(:empty)) > .quest-section:has(.quest-tools) { grid-row: 6; }
}

/* Leave content and final actions clear of the floating capsule and home indicator. */
body #view, body[data-route="home"] #view { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
