/* Only the main scrolls. The grid follows the visible viewport when the keyboard opens. */
:root {
  --navigation-height: 64px;
  --navigation-selected: rgb(32 84 71 / 14%);
  --sidebar-width: 184px;
  --page-gutter: clamp(16px, 3.1vw, 56px);
}
html { height: 100%; overflow: hidden; }
body {
  position: fixed;
  top: var(--app-top, 0px);
  inset-inline: 0;
  height: 100vh;
  height: var(--app-height, 100dvh);
  margin: 0;
  overflow: hidden;
}
.app-shell {
  display: grid;
  grid-template: "header" auto "content" minmax(0, 1fr) "navigation" auto / minmax(0, 1fr);
  width: 100%;
  height: 100%;
}
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(5px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 5px max(16px, env(safe-area-inset-left, 0px));
  background: var(--frame);
  border-bottom: 1px solid var(--frame-line);
}
.app-header .brand { font-size: 23px; }
.app-header .brand-mark { width: 32px; height: 32px; }
.page-location { display: none; color: var(--secondary); font-size: 14px; }
.header-account {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  padding: 4px 0 4px 8px;
  border: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 13px;
}
.header-account > [data-icon] {
  display: grid;
  flex: none;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--navigation-selected);
  color: var(--primary);
}
#header-user { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-content {
  grid-area: content;
  min-width: 0;
  min-height: 0;
  padding: 20px max(var(--page-gutter), env(safe-area-inset-right, 0px)) 36px max(var(--page-gutter), env(safe-area-inset-left, 0px));
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-padding-block: 20px;
}
.app-content:focus { outline: 0; }
.page-content { width: 100%; max-width: 768px; min-width: 0; margin-inline: auto; }
.app-content:is([data-page=home], [data-page=examples], [data-page=history]) .page-content { max-width: 1184px; }
.app-content:is([data-page=ask], [data-page=birth], [data-page=account], [data-page=feedback], [data-page=privacy], [data-page=share]) .page-content {
  max-width: 656px;
}
.page-content:has(.auth-view) { max-width: 456px !important; }
.app-content :is(input, textarea, select) { font-size: 16px; scroll-margin-block: 20px; }
.app-navigation {
  grid-area: navigation;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  min-height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding: 5px max(10px, env(safe-area-inset-right, 0px)) calc(5px + env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
  background: var(--frame);
  border-top: 1px solid var(--frame-line);
}
.app-navigation button {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 48px;
  padding: 5px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.app-navigation button[aria-current=page] { color: var(--primary); background: var(--navigation-selected); font-weight: 600; }
.app-navigation svg { width: 21px; height: 21px; }
.app-navigation :is(.desktop-route, .nav-divider) { display: none; }
.app-navigation [data-icon], .header-account [data-icon] { line-height: 1; }
.reading-overview, .reading-body { min-width: 0; }
#notice {
  position: fixed;
  z-index: 4;
  bottom: calc(var(--navigation-height) + 12px);
  left: 50%;
  width: max-content;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 18px;
  transform: translateX(-50%);
  border-radius: var(--radius);
  background: #233f36;
  color: white;
  box-shadow: 0 4px 16px #152c2321;
  pointer-events: none;
  font-size: 14px;
}
@media screen and (min-width: 700px) {
  .app-content { padding-block: 32px 48px; }
}
@media screen and (min-width: 1024px) {
  .app-shell {
    grid-template: "header header" 68px "navigation content" minmax(0, 1fr) / var(--sidebar-width) minmax(0, 1fr);
  }
  .app-header { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr) auto; gap: 0; padding: 0 var(--page-gutter) 0 0; }
  .app-header .brand { align-self: stretch; padding-inline: 24px; border-right: 1px solid var(--frame-line); font-size: 25px; }
  .app-header .brand-mark { width: 38px; height: 38px; }
  .page-location { display: block; margin-left: var(--page-gutter); }
  .app-content { padding-block: 32px 56px; scrollbar-gutter: stable; }
  .page-content { max-width: 1280px; }
  .app-navigation {
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    min-height: 0;
    gap: 5px;
    padding: 24px 12px;
    border-top: 0;
    border-right: 1px solid var(--frame-line);
    overflow-y: auto;
  }
  .app-navigation button, .app-navigation button.desktop-route {
    flex: 0 0 auto;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    gap: 13px;
    min-height: 46px;
    padding: 10px 16px;
    font-size: 14px;
  }
  .app-navigation .nav-divider { display: block; height: 1px; background: var(--frame-line); margin: 14px 10px; }
  .reading-layout { display: grid; grid-template-columns: minmax(238px, 30%) minmax(0, 1fr); align-items: start; gap: 24px; }
  .reading-overview { position: sticky; top: 0; max-height: calc(var(--app-height, 100dvh) - 136px); overflow-y: auto; overscroll-behavior-y: contain; }
  #notice { bottom: 24px; left: calc(50% + var(--sidebar-width)/2); }
}
@media (hover: hover) {
  .app-navigation button:not([aria-current=page]):hover { background: rgb(32 84 71 / 8%); color: var(--primary); }
  .header-account:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
}
@media screen and (max-height: 520px) and (max-width: 1023px) {
  .app-header { padding-block: 0; }
  .app-navigation { min-height: 48px; padding-block: 1px; }
  .app-navigation button { flex-direction: row; gap: 6px; min-height: 44px; }
}
@media print {
  html, body, .app-shell, .app-content, .reading-overview { position: static; height: auto; max-height: none; overflow: visible; background: white; }
  .app-shell, .reading-layout { display: block; }
  .app-content { padding: 0; }
  .page-content { max-width: none; }
  .app-header, .app-navigation, #notice { display: none; }
}

.language-switch { display: flex; align-items: center; gap: 5px; margin-inline-start: auto; white-space: nowrap; color: var(--muted); font-size: 13px; }
.language-switch a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 3px; color: inherit; text-decoration: none; }
.language-switch a[aria-current] { color: var(--primary); font-weight: 650; text-decoration: underline; text-underline-offset: 4px; }
html:lang(en) .hero h1 { letter-spacing: -.025em; line-height: 1.06; }
html:lang(en) .hero-copy { max-width: 460px; }
html:lang(en) .card-title { line-height: 1.23; }
@media (max-width: 460px) {
  .app-header { gap: 8px; }
  .app-header #header-user { max-width: 8ch; }
  html:lang(en) .hero::after { background: linear-gradient(0deg, #f6eddb 0%, #f6eddbed 49%, #f6edda60 79%, transparent); }
}
@media (max-width: 360px) {
  .app-header { padding-inline: 10px; }
  .app-header .brand { gap: 5px; font-size: 19px; }
  .language-switch { gap: 2px; }
}
@media (min-width: 1024px) {
  .app-header { grid-template-columns: var(--sidebar-width) minmax(0, 1fr) auto auto; }
  .language-switch { margin-inline-end: 18px; }
}
