/* Phone chrome. Desktop and tablet keep the study menu. */

html[data-motion="full"] { scroll-behavior: smooth; }
html[data-motion="full"] .reveal {
  opacity: 0;
  transform: translateY(18px);
}
html[data-motion="full"] .reveal.is-in {
  opacity: 1;
  transform: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.phone-bar { display: none; }
.phone-menu[hidden] { display: none; }
.phone-menu {
  position: fixed;
  inset: 0;
  z-index: 60;
  box-sizing: border-box;
  overflow: auto;
  background: var(--cc-bg);
  color: var(--cc-ink);
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 721px) {
  .phone-bar { display: none !important; }
  .quick-bar { display: none; }
}

@media (max-width: 720px) {
  html, body { overflow-x: clip; }
  main, .lesson-block, .lede, .sources-block, .source-list { overflow-wrap: anywhere; }
  .phone-links .menu-hint { white-space: normal; overflow: visible; text-overflow: unset; }
  .top,
  .rail { display: none; }
  .lab-bar {
    display: flex;
    top: calc(56px + env(safe-area-inset-top, 0px));
    z-index: 28;
  }
  .study-menu {
    display: flex;
    top: calc(116px + env(safe-area-inset-top, 0px));
    z-index: 27;
  }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .phone-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    box-sizing: border-box;
    height: calc(56px + env(safe-area-inset-top, 0px));
    max-height: calc(64px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0;
    background: color-mix(in srgb, var(--cc-bg) 92%, transparent);
    border-bottom: 1px solid var(--cc-line);
    backdrop-filter: blur(12px);
  }
  .phone-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
  }
  .phone-logo .mark {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--cc-accent-1);
    box-shadow: inset 0 0 0 4px var(--cc-accent-2);
    flex: none;
  }
  .menu-toggle, .quick-bar a, .quick-bar button, #close-menu {
    min-width: 48px;
    min-height: 48px;
  }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--cc-accent-1);
    background: var(--cc-surface);
    color: var(--cc-ink);
    font: inherit;
    font-weight: 700;
  }
  .menu-glyph {
    width: 18px;
    height: 12px;
    border-top: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
  }
  .quick-bar {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    box-sizing: border-box;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    background: var(--cc-surface);
    border-top: 1px solid var(--cc-line);
  }
  .quick-bar a, .quick-bar button, .bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    padding: 4px 2px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.68rem;
    text-decoration: none;
    text-align: center;
  }
  .quick-bar .menu-ico {
    width: 22px;
    height: 22px;
    font-size: 0.85rem;
    background: transparent;
  }
  .quick-bar [aria-current="page"], .quick-bar [aria-pressed="true"] {
    color: var(--cc-accent-1);
    font-weight: 700;
    box-shadow: inset 0 3px 0 var(--cc-accent-1);
    background: color-mix(in srgb, var(--cc-accent-1) 12%, transparent);
  }
  .phone-links .menu-item { width: 100%; }
  body { --bottom-h: calc(56px + env(safe-area-inset-bottom, 0px)); }
  main { padding-bottom: calc(var(--bottom-h) + 28px); }
  .lab-foot { margin-bottom: calc(var(--bottom-h) + 12px); }
  .mascot-dock { bottom: calc(var(--bottom-h) + 8px); }
  body .dock-stack {
    left: 8px;
    right: 8px;
    bottom: calc(var(--bottom-h) + 8px);
    z-index: 32;
    width: auto;
    max-width: none;
    min-width: 0;
  }
  .guide-panel { max-height: 46vh; width: 100%; min-width: 0; box-sizing: border-box; }
  .audio-dock { display: none; }
  .audio-dock.is-open {
    display: block;
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    max-height: 28vh;
    overflow: auto;
  }
  .phone-menu-bar, .menu-search, .phone-prefs {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .phone-menu-bar { justify-content: space-between; position: sticky; top: 0; background: var(--cc-bg); z-index: 1; padding-bottom: 8px; }
  .phone-menu-bar h2 { margin: 0; font-size: 1.25rem; }
  .menu-search { margin-bottom: 8px; }
  .menu-search input, .menu-search button { flex: 1; min-width: 48px; min-height: 48px; }
  .menu-search button { flex: none; padding: 0 16px; }
  .phone-links, .phone-else { display: grid; gap: 8px; margin: 8px 0 16px; }
  .phone-links a, .phone-else a, .phone-prefs button, .phone-prefs select, #phone-menu .theme-switch button {
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--cc-line);
    background: var(--cc-surface);
    color: inherit;
    text-decoration: none;
    font: inherit;
  }
  .phone-links a[aria-current="page"] {
    border-color: var(--cc-accent-1);
    color: var(--cc-link);
    box-shadow: inset 4px 0 0 var(--cc-accent-1);
  }
  .phone-prefs { flex-wrap: wrap; margin-bottom: 12px; }
  .phone-prefs label { display: grid; gap: 4px; flex: 1; min-width: 140px; }
  #phone-menu .theme-switch { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  body.menu-open { overflow: hidden; }
}

@media (max-width: 720px) and (max-height: 520px) {
  .dock-stack {
    max-height: calc(100dvh - var(--bottom-h) - 12px);
  }
  .guide-panel {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - var(--bottom-h) - 16px);
    overflow: hidden;
    padding: 8px;
    gap: 4px;
  }
  .guide-panel .guide-note,
  .guide-panel .py-chat-beta,
  .guide-panel .py-chat-try,
  .guide-panel .py-chat-examples,
  .guide-panel .py-chat-chips,
  .guide-panel [data-py-clear] { display: none; }
  .guide-chat-host {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
  }
  .guide-panel .py-chat {
    min-height: 0;
    flex: 1 1 auto;
    overflow: hidden;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
  .guide-panel .py-chat-log {
    flex: 1 1 auto;
    min-height: 36px;
    max-height: 64px;
    overflow: auto;
  }
  .guide-panel .py-chat-form { flex: 0 0 auto; width: 100%; min-width: 0; }
}

@media (max-width: 1100px) and (min-width: 721px) {
  .study-menu a, .study-menu summary, .study-menu button { min-height: 44px; }
}
.quick-bar a:focus-visible,
.quick-bar button:focus-visible,
.menu-toggle:focus-visible,
.phone-links a:focus-visible,
#close-menu:focus-visible {
  outline: 3px solid var(--cc-focus);
  outline-offset: 2px;
}
