/* ============================================================================
   My Success — Layout
   アプリシェル（ヘッダー / 本文 / タブバー）と安全領域の扱い。

   ここに置くのは「画面の骨格」だけ。中身の見た目は持たない。
   Step 3 の layout.js がこの構造を組み立てる。
   ============================================================================ */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  /* 各領域が独立したスタッキング文脈を持ち、z-index が衝突しない */
  isolation: isolate;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.app-header {
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: var(--z-sticky);
  padding-top: var(--safe-top);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  transition:
    background-color var(--duration-slow) var(--ease-inout),
    border-color     var(--duration-slow) var(--ease-inout);
}

/* 固定ヘッダーの高さを本文側で確保し、表示順・上端を維持する。 */
.app-header:not([hidden]) + .app-main {
  padding-top: calc(var(--safe-top) + var(--header-h) + 1px);
}

.app-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--header-h);
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--page-x);
}

.app-header__title {
  font-size: var(--text-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  min-width: 0;
}

/* ── ワードマーク ─────────────────────────────────────────────
   タブの根（戻り先を持たない画面）ではブランドを中央に出す。
   下層では画面の名前に戻る。「いまどのアプリか」と「いまどこか」を
   同じ場所で言い分ける。 */
/* 幅は中身のぶんだけ。左右が同じ幅で残りを分け合うので、真ん中に来る。
   伸ばすと左右と三等分になり、狭い画面で折れてしまう。 */
.app-header__title--mark {
  flex: 0 1 auto;
  width: clamp(128px, 46vw, 190px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header__logo {
  display: block;
  width: 100%;
  height: auto;
  max-height: 44px;
  object-fit: contain;
}

/* 中央に置いたワードマークが、左右のボタンの数で動かないようにする。
   :has() を分けて書くのは、未対応のブラウザで規則ごと捨てられないため。 */
/* ワードマークを真ん中に置くため、左右を同じ幅で分け合う。
   右はベルと設定の2つ、左はマイページの1つなので、固定幅だと中心がずれる。 */
.app-header__title--mark + .app-header__trail {
  flex: 1 1 0;
  justify-content: flex-end;
}

.app-header__lead:has(+ .app-header__title--mark) {
  flex: 1 1 0;
}

.app-header__lead,
.app-header__trail {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.app-header__trail {
  margin-inline-start: auto;
}

/* ============================================================================
   MAIN
   ============================================================================ */

.app-main {
  flex: 1 1 auto;
  /* ページ本体は横スクロールさせない。はみ出す要素は .u-scroll-x で包む */
  overflow-x: clip;
}

.page {
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--page-x);
  padding-top: var(--space-5);
  /* タブバーと安全領域のぶんだけ下に逃がす */
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--space-8));
}

.page--flush {
  padding-inline: 0;
}

.page--no-nav {
  padding-bottom: calc(var(--safe-bottom) + var(--space-12));
}

/* セクションの縦リズム。画面ごとに余白を発明させない */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.stack--tight { gap: var(--space-3); }
.stack--loose { gap: var(--space-10); }

.section__heading {
  font-size: var(--text-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-3);
}

.section__caption {
  font-size: var(--text-label);
  color: var(--color-text-secondary);
  margin-top: calc(var(--space-1) * -1);
  margin-bottom: var(--space-3);
}

/* 英字マイクロ見出しは .eyebrow（base.css）。
   カードの中では createCard の eyebrow がその役目を持つ。
   地の上に節を立てるときは .eyebrow を見出しの直前に置く。 */

/* ============================================================================
   TAB BAR
   ============================================================================ */

.app-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-nav);
  display: flex;
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  border-top: 1px solid var(--color-border);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  transition:
    background-color var(--duration-slow) var(--ease-inout),
    border-color     var(--duration-slow) var(--ease-inout);
}

.app-nav__inner {
  display: flex;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

.app-nav__item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  color: var(--color-text-tertiary);
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
  transition: color var(--duration-fast) var(--ease-out);
}

.app-nav__item[aria-current="page"] {
  color: var(--color-primary-text);
  font-weight: var(--weight-bold);
}

.app-nav__icon {
  width: 24px;
  height: 24px;
  stroke-width: 1.75;
  transition: transform var(--duration-fast) var(--ease-spring);
}

.app-nav__item[aria-current="page"] .app-nav__icon {
  transform: translateY(-1px) scale(1.06);
}

/* ============================================================================
   HEADER ACTIONS
   ============================================================================ */

.app-header__icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  color: var(--color-text-secondary);
  transition: background-color var(--duration-fast) var(--ease-out);
}

.app-header__icon-btn:hover {
  background: var(--color-surface-sunken);
}

/* ============================================================================
   ROUTE FEEDBACK
   250ms を超えた遷移だけ、前の画面を隠さずに重ねる。
   ============================================================================ */

.route-indicator {
  position: fixed;
  z-index: var(--z-indicator);
  top: calc(var(--safe-top) + var(--header-h) + var(--space-3));
  left: 50%;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
  box-shadow: var(--elevation-floating);
}

.route-failure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-16) var(--space-5);
  text-align: center;
}

.route-failure__text {
  font-size: var(--text-body);
  color: var(--color-text-secondary);
}

/* 失敗した理由。原因が見えないと直せないので、そのまま出す */
.route-failure__detail {
  max-width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  color: var(--color-negative);
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  line-height: var(--leading-normal);
  text-align: start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.route-failure__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.route-failure__copy {
  min-height: var(--tap-min);
  padding-inline: var(--space-4);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
}

.route-failure__retry {
  min-height: var(--tap-min);
  padding-inline: var(--space-6);
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
}

/* ============================================================================
   汎用の並べ方
   画面ごとに flex の設定を書き直させないための最小限。
   ============================================================================ */

.wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* ベルの数字。数えるのは未対応だけなので、たいてい1桁で収まる */
.app-header__icon-btn {
  position: relative;
}

/* まだ見ていない数。ベルの右上に、少しだけ重ねて置く。
   赤い丸にはしない。刺し色の金で、読める大きさにする。 */
.app-header__badge {
  position: absolute;
  top: 2px;
  right: 0;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border-radius: var(--radius-full);
  background: var(--color-highlight);
  color: var(--color-text-inverse);
  font-size: 11px;
  font-weight: var(--weight-bold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  /* ベルの線から浮かせる。地の色で細く縁取ると、重なっても読める */
  box-shadow: 0 0 0 2px var(--color-surface);
}

/* 最初の画面が描画されるまでの起動表示。ルーターの描画で取り除かれる。 */
.app-splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
}
.app-splash img {
  display: block;
  width: 132px;
  height: 132px;
  object-fit: contain;
}
