/* The app shell: sidebar, top bar with search and the account menu ("You" sheet on phones), bottom tab bar (phones), and the shortcuts and sign-in dialogs. */

.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

/* ------------------------------------------------------------------ sidebar (desktop) */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
  transition: width .18s ease, padding .18s ease;
}
.brand { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 8px; margin-bottom: 10px; color: var(--text); white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand-mark {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: transparent; color: var(--brand);
}
.brand-mark svg { width: 28px; height: 28px; display: block; }
.brand-text { font-size: 15px; font-weight: 600; letter-spacing: -.1px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}
.nav-item .i { color: var(--text-3); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active .i { color: var(--brand); }

/* Syllabus, Pricing, then a row of icon buttons (theme, help by email, Telegram, YouTube, shortcuts) */
.sidebar-foot {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.sidebar-tools { display: flex; align-items: center; gap: 2px; padding: 6px 2px 0; }
.sidebar-tools .icon-btn { position: relative; }

/* Collapsed: icon rail with hover tooltips */
html.nav-collapsed { --sidebar-w: var(--rail-w); }
html.nav-collapsed .sidebar { padding: 12px 10px; }
html.nav-collapsed .brand { justify-content: center; padding: 0; }
html.nav-collapsed .brand-text,
html.nav-collapsed .sidebar .label { display: none; }
html.nav-collapsed .nav-item { justify-content: center; padding: 0; }
html.nav-collapsed .sidebar-tools { flex-direction: column; align-items: stretch; padding: 4px 0 0; }
html.nav-collapsed .sidebar-tools .icon-btn { width: 100%; }
html.nav-collapsed .sidebar [data-tip]:hover::after,
html.nav-collapsed .sidebar [data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 12px); top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px;
  font-size: 12.5px; font-weight: 500; line-height: 1.4;
  color: var(--tip-text); background: var(--tip-bg);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-pop);
}

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); transition: margin-left .18s ease; }

/* ------------------------------------------------------------------ top bar: [toggle] [search] [account] */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 560px) minmax(0, 1fr);
  align-items: center; gap: 12px;
  padding: 0 20px 0 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.nav-toggle { flex: none; }
.topbar .back-btn, .topbar-mark { display: none; flex: none; }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }

.search { position: relative; min-width: 0; width: 100%; }
.search > svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%; height: 36px;
  padding: 0 12px 0 34px;
  font: inherit; font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
.search input:hover { border-color: var(--border-strong); }
.search input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 420px; overflow: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.search-results a { display: flex; flex-direction: column; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text); }
.search-results a small { color: var(--text-3); font-size: 12.5px; }
.search-results a.on, .search-results a:hover { background: var(--surface-2); }
.search-results .none { padding: 10px; color: var(--text-3); font-size: 14px; }
.search-cat-header {
  padding: 8px 10px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  border-top: 1px solid var(--border);
}
.search-cat-header:first-child { border-top: none; }
.search-match-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-2);
  margin-right: 6px;
  vertical-align: 1px;
}

/* overflow-x: clip is a last guard: nothing may make the page wider than the screen
   (phones would zoom the whole page out). Wide maths and code scroll inside their box. */
.content { max-width: 1000px; margin: 0 auto; padding: 28px 28px 80px; overflow-x: clip; }

/* Studio wide layout: utilize full desktop screen width */
html[data-view="studio"] .content,
.content:has(#view-studio:not([hidden])) {
  max-width: 100% !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 20px 28px 80px !important;
}

/* ------------------------------------------------------------------ account button and menu (modules/account.js) */
.account { position: relative; display: flex; }
.account-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  font-size: 14px; font-weight: 500;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
}
.account-btn:hover { background: var(--surface-2); }
.account-btn.is-pending { visibility: hidden; }
.account-btn .i { width: 16px; height: 16px; }
.account-signin { display: inline-flex; align-items: center; }
.account-btn .avatar-guest { display: none; }
.account-btn.is-signed-in { width: 34px; padding: 0; justify-content: center; border-color: transparent; background: none; border-radius: 50%; }
.account-btn.is-signed-in:hover { background: var(--surface-2); }
.avatar {
  flex: none;
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 13px; font-weight: 600; line-height: 1;
  color: var(--brand); background: color-mix(in srgb, var(--brand) 16%, var(--surface));
  object-fit: cover;
}
.account-btn[aria-expanded="true"].is-signed-in .avatar { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand); }
.account-menu { width: 272px; }
.account-menu .menu-head { padding: 8px 8px 10px; }
.menu-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-user .avatar { width: 32px; height: 32px; font-size: 14px; }
.menu-user > div { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.menu-user b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-user .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#account-premium > .i { color: var(--brand); }
.account-menu .menu-head .btn-block { height: 40px; }

/* Phones: the menu is the "You" sheet and adds the sidebar's extras (.you-only) */
.account-menu .you-only { display: none; }
.you-theme { min-height: 48px; }
.you-theme .segmented button { display: inline-flex; align-items: center; gap: 6px; }
.you-theme .segmented .i { width: 16px; height: 16px; }
.you-legal {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 8px -6px -2px; padding: 12px 10px 4px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-3);
}
.you-legal a { color: var(--text-3); }
.you-legal a:hover { color: var(--text); }

/* ------------------------------------------------------------------ keyboard shortcuts dialog */
.modal-shortcuts { width: min(460px, calc(100vw - 32px)); }
.shortcut-list { display: flex; flex-direction: column; }
.sc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.sc-row:last-child { border-bottom: 0; }
.sc-keys {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.sc-row > span:last-child {
  margin-left: auto;
  color: var(--text-2);
  text-align: right;
  font-size: 13px;
}

/* ------------------------------------------------------------------ sign-in dialog (account.js openSignIn)
   One card, three steps on .signin-card[data-step]: start (Google, or an email link), sent ("Check
   your inbox"), confirm (back from the link on another device: the address again). */
.signin-card {
  position: relative;
  width: min(400px, calc(100vw - 32px));
  padding: 36px 32px 24px;
  text-align: center;
  overflow-y: auto;
}
.signin-close { position: absolute; top: 10px; right: 10px; }
.signin-title { margin: 0 0 6px; font-size: 20px; font-weight: 600; letter-spacing: -.2px; color: var(--text); }
.signin-lede { margin: 0 0 22px; color: var(--text-2); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.signin-lede b { color: var(--text); font-weight: 600; }
.signin-mark {
  display: none;
  width: 44px; height: 44px; margin: 0 auto 14px;
  place-items: center;
  border-radius: 50%;
  color: var(--brand); background: var(--brand-soft);
}
.signin-mark .i { width: 22px; height: 22px; }
.signin-google, .signin-form .btn { height: 40px; }
.signin-google .i { width: 18px; height: 18px; }
.signin-or {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0;
  color: var(--text-3); font-size: 12.5px;
}
.signin-or::before, .signin-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.signin-form { display: flex; flex-direction: column; gap: 10px; }
.signin-form .input { width: 100%; height: 40px; }
.signin-error { margin: 0; color: var(--bad); font-size: 13px; text-align: left; }
.signin-again { display: none; margin: 0 auto; font-size: 14px; }
.signin-terms { margin: 20px 0 0; color: var(--text-3); font-size: 12.5px; line-height: 1.5; }
.signin-terms a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.signin-terms a:hover { color: var(--text); }
.signin-card[data-step="confirm"] .signin-google-part,
.signin-card[data-step="sent"] .signin-google-part,
.signin-card[data-step="sent"] .signin-form { display: none; }
.signin-card[data-step="sent"] .signin-mark { display: grid; }
.signin-card[data-step="sent"] .signin-again { display: inline; }
@media (max-width: 640px) {
  .signin-card { width: 100%; padding: 32px 20px max(20px, env(safe-area-inset-bottom)); }
  .signin-form .input { font-size: 16px; }   /* no iOS zoom */
}

/* ------------------------------------------------------------------ bottom tabs (phones) + the practice page's footer */
.tabbar { display: none; }
.mobile-foot { display: none; }

@media (max-width: 900px), (pointer: coarse) and (max-height: 500px) {
  .sidebar, .nav-toggle { display: none; }
  .main { margin-left: 0; }
  /* [back on deep pages] [search] [avatar]. Solid bar: a blurred backdrop repaints on every scroll frame on low-end phones */
  .topbar {
    display: flex;
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
    gap: 8px;
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .topbar-left { display: contents; }
  .topbar-right { flex: none; gap: 2px; }
  .search { flex: 1; max-width: none; }
  /* Top-level pages: the logo (to Practice); topic pages: a back arrow (installed apps have no browser Back) */
  .topbar-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; margin-left: -4px; }
  html[data-view="topic"] .topbar-mark { display: none; }
  html[data-view="topic"] .back-btn { display: inline-grid; margin-left: -6px; }
  .back-btn svg { width: 22px; height: 22px; }
  .account-btn:not(.is-signed-in) { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 50%; border-color: var(--border); }
  .account-btn:not(.is-signed-in) .account-signin { display: none; }
  .account-btn .avatar-guest { display: inline-grid; color: var(--text-2); background: none; }
  .account-btn .avatar-guest .i { width: 18px; height: 18px; }
  .account-menu { width: 320px; }
  .account-menu .you-only { display: block; }
  .account-menu .you-legal { display: flex; }
  /* While typing a search, the field takes the whole bar */
  .topbar:has(#search:focus) .back-btn,
  .topbar:has(#search:focus) .topbar-mark,
  .topbar:has(#search:focus) .topbar-right { display: none; }
  .search-results { max-height: min(420px, 60vh); }
  .content {
    padding: 18px max(14px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px) max(14px, env(safe-area-inset-left));
  }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 0 max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tabbar a {
    flex: 1 1 0;
    min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 11px; font-weight: 500;
    color: var(--text-3);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    padding: 4px 2px;
  }
  .tab-icon { display: grid; place-items: center; width: 44px; height: 24px; }
  .tab-icon svg { width: 20px; height: 20px; }
  .tabbar a.active { color: var(--text); }
  .tabbar a.active .tab-icon { color: var(--brand); }
  .mobile-foot { display: flex; justify-content: center; padding: 26px 0 0; }
  .mobile-foot a { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text-3); }
  .mobile-foot svg { width: 16px; height: 16px; }
  /* 16px stops iOS zooming into focused fields */
  .search input { font-size: 16px; }
}

/* Phones held sideways: slimmer bars leave room for the problems */
@media (max-width: 900px) and (max-height: 500px), (pointer: coarse) and (max-height: 500px) {
  .tabbar a { flex-direction: row; gap: 4px; font-size: 13px; }
  .tab-icon { width: 32px; height: 24px; }
  .content { padding-top: 14px; }
}

/* Phones: no physical keyboard, so no shortcuts */
@media (max-width: 640px) {
  #btn-shortcuts { display: none !important; }
}

@media (pointer: coarse) {
  .topbar .icon-btn { width: 40px; height: 40px; }
  .mobile-foot a { padding: 10px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .main { transition: none; }
}
