/* Shared Mode Atlas navigation.
   All static page navigation is rendered from frontend_components.py. */
.ma-nav{
  --ma-nav-accent:var(--ma-collection-accent,var(--ma-writing));
  position:sticky;
  top:max(12px,env(safe-area-inset-top,0px));
  z-index:70;
  width:min(1240px,calc(100% - 32px));
  margin:14px auto 18px;
  padding:10px;
  display:flex;
  align-items:center;
  gap:var(--ma-space-3);
  box-sizing:border-box;
  border:1px solid var(--ma-border);
  border-radius:var(--ma-radius-nav);
  background:var(--ma-surface-strong);
  box-shadow:var(--ma-shadow-soft);
  backdrop-filter:blur(18px);
  -webkit-backdrop-filter:blur(18px);
}
.shell > .ma-nav,.wrap > .ma-nav{width:100%;}
.ma-nav--reading{--ma-nav-accent:var(--ma-collection-accent,var(--ma-reading));}
.ma-nav--writing{--ma-nav-accent:var(--ma-collection-accent,var(--ma-writing));}
.ma-nav--results{--ma-nav-accent:var(--ma-results);}
.ma-nav--kana{--ma-nav-accent:var(--ma-kana);}
.ma-nav--words{--ma-nav-accent:var(--ma-words);}

.ma-nav__brand{
  align-self:center;
  display:flex;
  align-items:center;
  gap:var(--ma-space-3);
  min-width:0;
  flex:0 1 auto;
  color:var(--ma-text);
  text-decoration:none;
}
.ma-nav__mark{
  width:44px;
  height:44px;
  flex:0 0 44px;
  display:grid;
  place-items:center;
  border:1px solid color-mix(in srgb,var(--ma-nav-accent) 44%,var(--ma-border));
  border-radius:15px;
  background:color-mix(in srgb,var(--ma-nav-accent) 14%,var(--ma-card-2));
  color:var(--ma-text-strong);
  font-family:var(--ma-font-jp);
  font-size:.98rem;
  font-weight:900;
  line-height:1;
  box-shadow:inset 0 1px 0 color-mix(in srgb,var(--ma-text) 8%,transparent);
}
.ma-nav__brand-copy{display:grid;gap:2px;min-width:0;}
.ma-nav__kicker{
  color:var(--ma-muted);
  font-size:.66rem;
  font-weight:900;
  letter-spacing:.12em;
  line-height:1;
  text-transform:uppercase;
}
.ma-nav__title{
  overflow:hidden;
  color:var(--ma-text-strong);
  font-family:var(--ma-font-display);
  font-size:.92rem;
  font-weight:850;
  line-height:1.15;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.ma-nav__content{
  min-width:0;
  flex:1 1 auto;
  display:grid;
  gap:8px;
}
.ma-nav__primary{
  min-width:0;
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:var(--ma-space-2);
}
.ma-nav__links,.ma-nav__actions{
  display:flex;
  align-items:center;
  gap:var(--ma-space-2);
}
.ma-nav__links{min-width:0;overflow:visible;}
.ma-nav__link,.ma-nav__action{
  appearance:none;
  flex:0 0 auto;
  min-height:42px;
  padding:0 13px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  box-sizing:border-box;
  border:1px solid transparent;
  border-radius:var(--ma-radius-control);
  background:transparent;
  color:var(--ma-muted);
  font:inherit;
  font-size:.82rem;
  font-weight:800;
  line-height:1;
  text-decoration:none;
  cursor:pointer;
  transition:background var(--ma-motion-fast) ease,border-color var(--ma-motion-fast) ease,color var(--ma-motion-fast) ease,transform var(--ma-motion-fast) ease;
}
.ma-nav__link:hover,.ma-nav__action:hover{
  border-color:var(--ma-border);
  background:var(--ma-control-hover);
  color:var(--ma-text);
}
.ma-nav__link:focus-visible,.ma-nav__action:focus-visible,.ma-nav-handle:focus-visible{outline:3px solid var(--ma-focus-ring);outline-offset:2px;}
.ma-nav__link.is-active{
  border-color:color-mix(in srgb,var(--ma-nav-accent) 48%,var(--ma-border));
  background:color-mix(in srgb,var(--ma-nav-accent) 15%,var(--ma-card-2));
  color:var(--ma-text-strong);
}
.ma-nav__actions{flex:0 0 auto;}
.ma-nav__action{border-color:var(--ma-border);background:var(--ma-control);color:var(--ma-control-text);}
.ma-nav__action--quiet{background:transparent;color:var(--ma-muted);}
.ma-nav__settings{width:44px;min-width:44px;padding:0;}
.ma-nav__settings .ma-nav__action-label{display:none;}
.ma-nav__profile{--ma-atlas-rank:color-mix(in srgb,var(--ma-results) 70%,var(--ma-card-3));min-width:0;padding:0 9px 0 6px;gap:7px;}
.ma-nav__profile[data-ma-atlas-rank="silver"]{--ma-atlas-rank:color-mix(in srgb,var(--ma-muted) 75%,var(--ma-card));}
.ma-nav__profile[data-ma-atlas-rank="gold"]{--ma-atlas-rank:var(--ma-warning);}
.ma-nav__profile[data-ma-atlas-rank="violet"]{--ma-atlas-rank:var(--ma-kana);}
.ma-nav__profile[data-ma-atlas-rank="teal"]{--ma-atlas-rank:color-mix(in srgb,var(--ma-writing) 45%,var(--ma-reading));}
.ma-nav__profile .ma-nav__action-label{min-width:40px;padding:5px 7px;display:inline-flex;align-items:center;justify-content:center;border:1px solid color-mix(in srgb,var(--ma-atlas-rank) 58%,var(--ma-border));border-radius:var(--ma-radius-pill);background:color-mix(in srgb,var(--ma-atlas-rank) 14%,transparent);color:var(--ma-text-strong);font-size:.72rem;font-weight:900;font-variant-numeric:tabular-nums;letter-spacing:.01em;}
.ma-nav__avatar{
  width:30px;
  height:30px;
  min-width:30px;
  display:grid;
  place-items:center;
  overflow:hidden;
  border-radius:999px;
  background:color-mix(in srgb,var(--ma-nav-accent) 20%,var(--ma-card-2));
  color:var(--ma-text-strong);
  font-size:.76rem;
  font-weight:900;
}
.ma-nav__avatar img{width:100%;height:100%;display:block;object-fit:cover;}
.ma-nav__settings-icon{font-size:1.1rem;line-height:1;}

.ma-nav-handle{
  display:none;
  position:fixed;
  right:18px;
  top:auto;
  bottom:max(18px,calc(env(safe-area-inset-bottom,0px) + 8px));
  z-index:10020;
  min-height:46px;
  padding:0 16px;
  border:1px solid var(--ma-border-strong);
  border-radius:var(--ma-radius-pill);
  background:var(--ma-surface-strong);
  color:var(--ma-text);
  box-shadow:var(--ma-shadow-soft);
  font:inherit;
  font-size:.82rem;
  font-weight:850;
  cursor:pointer;
}
body.study-nav-hidden .ma-nav{
  display:flex;
  position:fixed;
  top:max(12px,env(safe-area-inset-top,0px));
  right:max(12px,env(safe-area-inset-right,0px));
  left:auto;
  width:auto;
  margin:0;
  padding:0;
  border:0;
  background:transparent;
  box-shadow:none;
  z-index:1200;
}
body.study-nav-hidden .ma-nav__brand,
body.study-nav-hidden .ma-nav__links,
body.study-nav-hidden .ma-nav__profile,
body.study-nav-hidden .ma-nav__settings{display:none;}
body.study-nav-hidden .ma-nav__content,
body.study-nav-hidden .ma-nav__primary,
body.study-nav-hidden .ma-nav__actions{display:flex;width:auto;}
body.study-nav-hidden .ma-nav__primary,
body.study-nav-hidden .ma-nav__actions{gap:0;}
body.study-nav-hidden .ma-nav__focus{
  display:inline-flex;
  width:auto;
  min-width:44px;
  padding:0 12px;
}
body.study-nav-hidden .ma-nav__focus .ma-nav__action-label{display:inline-flex;}
body.study-nav-hidden .ma-nav-handle{display:none;}

@media(max-width:1080px){
  .ma-nav{width:min(100% - 24px,1240px);}
  .ma-nav__brand{max-width:210px;}
  .ma-nav__action-label{display:none;}
  .ma-nav__profile{width:auto;min-width:0;padding:0 8px 0 6px;}
  .ma-nav__profile .ma-nav__action-label{display:inline-flex;}
  .ma-nav__settings{width:44px;min-width:44px;padding:0;}
}

@media(max-width:760px), (max-width:900px) and (orientation:portrait){
  .ma-nav{
    width:calc(100% - 20px);
    margin:10px auto 16px;
    padding:10px;
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    gap:10px;
    border-radius:22px;
  }
  .ma-nav__brand{grid-column:1;max-width:none;}
  .ma-nav__mark{width:40px;height:40px;flex-basis:40px;border-radius:13px;}
  .ma-nav__content{grid-column:1 / -1;width:100%;gap:8px;}
  .ma-nav__primary{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;}
  .ma-nav__links{width:100%;gap:6px;}
  .ma-nav__link{min-height:40px;padding:0 11px;font-size:.78rem;}
  .ma-nav__actions{gap:6px;}
  .ma-nav__profile{width:auto;min-width:0;min-height:42px;padding:0 7px 0 5px;}
  .ma-nav__profile .ma-nav__action-label{display:inline-flex;}
  .ma-nav__settings{width:42px;min-width:42px;min-height:42px;padding:0;}
  .ma-nav__avatar{width:30px;height:30px;min-width:30px;}
  .ma-nav__action--quiet{padding:0 10px;font-size:.76rem;}
}

@media(max-width:520px){
  .ma-nav__kicker{display:none;}
  .ma-nav__title{font-size:.84rem;}
  .ma-nav__content,.ma-nav__primary{display:contents;}
  .ma-nav__links{grid-column:1 / -1;grid-row:2;width:100%;justify-content:space-between;gap:4px;}
  .ma-nav__actions{grid-column:2;grid-row:1;justify-self:end;gap:5px;}
  .ma-nav__link{padding:0 8px;font-size:.75rem;}
  .ma-nav__action--quiet{display:none;}
}

/* Explicit display modes own their navigation composition independently of
   pointer type or physical viewport width. Tablet stays a compact single row;
   Phone uses a denser two-row product navigation. */
body[data-effective-display-mode="tablet"] .ma-nav{
  position:sticky;
  top:max(10px,env(safe-area-inset-top,0px));
  width:min(1120px,calc(100% - 24px));
  margin:12px auto 18px;
  padding:8px 10px;
  display:flex;
  grid-template-columns:none;
  align-items:center;
  gap:10px;
  border-radius:20px;
}
body[data-effective-display-mode="tablet"] .ma-nav__brand{grid-column:auto;max-width:174px;flex:0 1 174px;gap:9px;}
body[data-effective-display-mode="tablet"] .ma-nav__mark{width:40px;height:40px;flex-basis:40px;border-radius:13px;}
body[data-effective-display-mode="tablet"] .ma-nav__kicker{display:none;}
body[data-effective-display-mode="tablet"] .ma-nav__title{font-size:.84rem;}
body[data-effective-display-mode="tablet"] .ma-nav__content{display:grid;min-width:0;flex:1 1 auto;gap:0;}
body[data-effective-display-mode="tablet"] .ma-nav__primary{display:flex;min-width:0;align-items:center;justify-content:flex-end;gap:6px;}
body[data-effective-display-mode="tablet"] .ma-nav__links{width:auto;gap:4px;}
body[data-effective-display-mode="tablet"] .ma-nav__link{min-height:40px;padding:0 10px;font-size:.77rem;}
body[data-effective-display-mode="tablet"] .ma-nav__actions{gap:5px;}
body[data-effective-display-mode="tablet"] .ma-nav__profile{width:auto;min-width:0;min-height:40px;padding:0 7px 0 5px;}
body[data-effective-display-mode="tablet"] .ma-nav__profile .ma-nav__action-label{display:inline-flex;}
body[data-effective-display-mode="tablet"] .ma-nav__settings{width:40px;min-width:40px;min-height:40px;padding:0;}
body[data-effective-display-mode="tablet"] .ma-nav__avatar{width:28px;height:28px;min-width:28px;}
body[data-effective-display-mode="tablet"] .ma-nav__focus{display:inline-flex;width:auto;min-width:40px;min-height:40px;padding:0 10px;}
body[data-effective-display-mode="tablet"] .ma-nav__focus .ma-nav__action-label{display:inline-flex;}

body[data-effective-display-mode="phone"] .ma-nav{
  position:fixed;
  top:max(6px,env(safe-area-inset-top,0px));
  left:max(6px,env(safe-area-inset-left,0px));
  right:max(6px,env(safe-area-inset-right,0px));
  width:auto;
  margin:0;
  padding:8px;
  display:grid;
  grid-template-columns:minmax(0,1fr) max-content;
  grid-template-rows:auto auto;
  column-gap:6px;
  row-gap:8px;
  border-radius:20px;
  transition:transform var(--ma-motion-medium) ease,opacity var(--ma-motion-fast) ease,box-shadow var(--ma-motion-fast) ease;
  will-change:transform;
}
body[data-effective-display-mode="phone"] .ma-nav__brand{grid-column:1;grid-row:1;min-width:0;max-width:none;gap:8px;}
body[data-effective-display-mode="phone"] .ma-nav__mark{width:36px;height:36px;flex-basis:36px;border-radius:12px;}
body[data-effective-display-mode="phone"] .ma-nav__kicker{display:none;}
body[data-effective-display-mode="phone"] .ma-nav__title{font-size:.8rem;}
body[data-effective-display-mode="phone"] .ma-nav__content,
body[data-effective-display-mode="phone"] .ma-nav__primary{display:contents;}
body[data-effective-display-mode="phone"] .ma-nav__links{grid-column:1 / -1;grid-row:2;width:100%;min-width:0;justify-content:space-between;gap:3px;}
body[data-effective-display-mode="phone"] .ma-nav__actions{grid-column:2;grid-row:1;align-self:center;justify-self:end;gap:4px;}
body[data-effective-display-mode="phone"] .ma-nav__link{min-height:36px;padding:0 7px;font-size:.72rem;}
body[data-effective-display-mode="phone"] .ma-nav__profile{width:auto;min-width:0;min-height:38px;padding:0 6px 0 4px;}
body[data-effective-display-mode="phone"] .ma-nav__profile .ma-nav__action-label{display:inline-flex;}
body[data-effective-display-mode="phone"] .ma-nav__settings{width:38px;min-width:38px;min-height:38px;padding:0;}
body[data-effective-display-mode="phone"] .ma-nav__avatar{width:28px;height:28px;min-width:28px;}
body[data-effective-display-mode="phone"] .ma-nav__focus{display:inline-flex;width:44px;min-width:44px;min-height:44px;padding:0;}
body[data-effective-display-mode="phone"] .ma-nav__focus .ma-nav__action-label{display:none;}
.ma-nav-spacer{display:none;}
body[data-effective-display-mode="phone"] .ma-nav-spacer{
  display:block;
  width:100%;
  min-height:0;
}
body[data-effective-display-mode="phone"].study-nav-hidden .ma-nav-spacer{display:none;}
body[data-effective-display-mode="phone"].study-nav-hidden .ma-nav{
  left:auto;
  right:max(12px,env(safe-area-inset-right,0px));
  width:auto;
  margin:0;
}
body[data-effective-display-mode="phone"]:not(.study-nav-hidden) .ma-nav.ma-nav--scroll-hidden{
  transform:translateY(calc(-100% - max(12px,env(safe-area-inset-top,0px))));
  opacity:0;
  pointer-events:none;
}
body[data-effective-display-mode="phone"].ma-phone-keyboard-open .ma-nav-handle{display:none!important;}
body[data-effective-display-mode="phone"].study-nav-hidden .ma-nav__focus{width:44px;min-width:44px;padding:0;}
body[data-effective-display-mode="phone"].study-nav-hidden .ma-nav__focus .ma-nav__action-label{display:none;}
body[data-effective-display-mode="phone"].study-nav-hidden .ma-nav-handle{display:inline-flex;align-items:center;justify-content:center;}

html[data-ma-theme="light"]:where(:not([data-ma-runtime="ios"])) .ma-nav__action{
  background:var(--ma-control);
  color:var(--ma-control-text);
  -webkit-text-fill-color:var(--ma-control-text);
  border-color:var(--ma-border);
}
html[data-ma-theme="light"]:where(:not([data-ma-runtime="ios"])) .ma-nav__link{color:var(--ma-muted);-webkit-text-fill-color:var(--ma-muted);}
html[data-ma-theme="light"]:where(:not([data-ma-runtime="ios"])) .ma-nav__link.is-active{color:var(--ma-text-strong);-webkit-text-fill-color:var(--ma-text-strong);}

@media(prefers-reduced-motion:reduce){
  .ma-nav,.ma-nav__link,.ma-nav__action{transition:none;}
}

/* 2.31 utility actions use the shared icon vocabulary. */
.ma-nav__settings-icon{width:18px;height:18px;font-size:inherit;}
.ma-nav__focus{gap:7px;}
.ma-nav-handle{gap:8px;}
@media(max-width:1080px){
  .ma-nav__focus{width:auto;min-width:44px;padding:0 10px;}
  .ma-nav__focus .ma-nav__action-label{display:inline-flex;}
  body[data-effective-display-mode="phone"] .ma-nav__focus{width:44px;min-width:44px;padding:0;}
  body[data-effective-display-mode="phone"] .ma-nav__focus .ma-nav__action-label{display:none;}
}
@media(max-width:520px){
  .ma-nav__focus{display:inline-flex;}
}


/* Keyboard bypass link stays out of the visual shell until focused. */
.ma-skip-link{
  position:fixed;
  top:max(12px,env(safe-area-inset-top));
  left:max(12px,env(safe-area-inset-left));
  z-index:12050;
  min-height:44px;
  display:inline-flex;
  align-items:center;
  padding:0 16px;
  border:1px solid var(--ma-border-strong);
  border-radius:var(--ma-radius-control);
  background:var(--ma-surface-strong);
  color:var(--ma-text-strong);
  box-shadow:var(--ma-shadow-soft);
  font-weight:850;
  text-decoration:none;
  opacity:0;
  transform:translateY(calc(-100% - 24px));
  pointer-events:none;
}
.ma-skip-link:focus-visible{
  opacity:1;
  transform:none;
  pointer-events:auto;
  outline:3px solid var(--ma-focus-ring);
  outline-offset:2px;
}

@media(pointer:coarse){
  .ma-nav__link,.ma-nav__action{min-height:44px;}
  .ma-nav__profile{width:auto;min-width:0;min-height:44px;}
  .ma-nav__settings{width:44px;min-width:44px;min-height:44px;}
}

/* Branch navigation stays in the page; primary destinations never change. */
.ma-kana-navigation{display:flex;flex-wrap:wrap;gap:4px;margin:8px 0 16px;}
body:is(.ma-reading-page,.ma-writing-page)>.ma-kana-navigation{width:min(540px,100%);margin-inline:auto;align-self:center;flex:none;}
.ma-kana-navigation a{flex:1 1 auto;display:flex;align-items:center;justify-content:center;min-height:44px;padding:8px 12px;border-radius:12px;text-decoration:none;color:var(--ma-muted);font-weight:750;font-size:.8rem;}
.ma-kana-navigation a[aria-current="page"]{color:var(--ma-text-strong);background:var(--ma-control);}
body.trainer-session-active .ma-kana-navigation,body.study-nav-hidden .ma-kana-navigation{display:none;}
