/*
 * Liquid / Dynamic Material — CSS
 * ------------------------------------------------------------
 * Apple の Liquid Glass の考え方に倣い、「マテリアル」はナビゲーション／
 * コントロール層にのみ使う。読むためのコンテンツには絶対に使わない。
 *
 * .lq          : ガラス素材の土台クラス（フロートバー・パネルに付与）
 * .lq-seg      : セグメントコントロール（レンズ型インジケータが移動する）
 * .lq-pill-button : 主要アクション用の丸ピルボタン（ガラス）
 *
 * カスタムプロパティ:
 *   --lq-tint  : 素材の基調色。rgba() で指定。既定は暖色ホワイト。
 *                暗い背景の上では明るいテキスト、明るい背景では暗いテキストに
 *                自動追従させたい場合は --lq-on-dark を要素・祖先に付与する。
 *   --lx / --ly: ポインタ追従スペキュラーハイライトの位置（JSが設定）。
 */

:root {
  --lq-tint: rgba(255, 250, 240, 0.55);
  --lq-tint-strong: rgba(255, 250, 240, 0.78);
  --lq-text: #1c1c1e;
  --lq-text-dim: rgba(28, 28, 30, 0.62);
  --lq-border: rgba(255, 255, 255, 0.55);
  --lq-shadow-color: rgba(20, 20, 30, 0.28);
  --lq-radius: 22px;
}

/* 暗い背景に載せる想定のとき、祖先か要素自身に付ける */
.lq-on-dark {
  --lq-tint: rgba(30, 30, 36, 0.45);
  --lq-tint-strong: rgba(20, 20, 26, 0.68);
  --lq-text: #f5f5f7;
  --lq-text-dim: rgba(245, 245, 247, 0.72);
  --lq-border: rgba(255, 255, 255, 0.22);
  --lq-shadow-color: rgba(0, 0, 0, 0.45);
}

/* 隠しSVGフィルタのホスト（Liquid.init() が挿入） */
#lq-svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* .lq 基本ガラス素材                                                  */
/* ------------------------------------------------------------------ */
.lq {
  position: relative;
  isolation: isolate;
  border-radius: var(--lq-radius);
  color: var(--lq-text);
  background: var(--lq-tint);
  /* 既定（フォールバック）: ぼかし + 彩度強調のみ */
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  border: 1px solid var(--lq-border);
  box-shadow:
    0 1px 1px rgba(255, 255, 255, 0.4) inset,
    0 0 0 0.5px rgba(255, 255, 255, 0.3) inset,
    0 8px 24px -8px var(--lq-shadow-color),
    0 2px 8px -2px var(--lq-shadow-color);
  transition: box-shadow 220ms ease, background 220ms ease;
  will-change: transform;
  transform: translateZ(0) scale(var(--lq-scale, 1)) scaleX(var(--lq-scale-x, 1));
}

/* SVG屈折フィルタに対応するブラウザ（主にChromium）ではレンズ効果を追加 */
.lq-refract-supported .lq {
  backdrop-filter: url(#lq-refract) blur(6px) saturate(1.6);
  -webkit-backdrop-filter: url(#lq-refract) blur(6px) saturate(1.6);
}

/* 内側リムライト（1pxのグラデーション枠、上が明るく下が暗い） */
.lq::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  pointer-events: none;
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.85),
    rgba(255, 255, 255, 0.05) 35%,
    rgba(255, 255, 255, 0.05) 65%,
    rgba(255, 255, 255, 0.35)
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.9;
  z-index: 2;
}

/* ポインタ追従スペキュラーハイライト */
.lq::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(
    140px 140px at var(--lx, 50%) var(--ly, 0%),
    rgba(255, 255, 255, 0.55),
    rgba(255, 255, 255, 0) 70%
  );
  opacity: var(--lq-glow, 0);
  transition: opacity 260ms ease;
  z-index: 3;
  mix-blend-mode: overlay;
}

.lq:focus-within::after {
  --lq-glow: 1;
} @media (hover: hover) { .lq:hover::after {
  --lq-glow: 1;
} }

/* 持ち上げ状態（押下前のホバー等）で影を深くする */
.lq.lq-lifted {
  box-shadow:
    0 1px 1px rgba(255, 255, 255, 0.45) inset,
    0 0 0 0.5px rgba(255, 255, 255, 0.32) inset,
    0 16px 40px -12px var(--lq-shadow-color),
    0 6px 16px -4px var(--lq-shadow-color);
}

/* コンテンツは常にz-index最上位 */
.lq > * {
  position: relative;
  z-index: 4;
}

/* テキストのコントラストを確保する裏地（--lq-tint が薄いとき用） */
.lq-text-backing {
  background: var(--lq-tint-strong);
  border-radius: 999px;
  padding: 2px 8px;
}

/* ------------------------------------------------------------------ */
/* 押下フィジックス（transform は JS スプリングが --lq-scale* を更新）  */
/* ------------------------------------------------------------------ */
.lq-pressable {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* .lq 自身でなくても（セグメント項目・アバター等）スクイッシュを反映する */
  will-change: transform;
  transform: translateZ(0) scale(var(--lq-scale, 1)) scaleX(var(--lq-scale-x, 1));
}

/* ------------------------------------------------------------------ */
/* .lq-seg セグメントコントロール                                      */
/* ------------------------------------------------------------------ */
.lq-seg {
  display: inline-flex;
  position: relative;
  gap: 2px;
  padding: 4px;
  border-radius: calc(var(--lq-radius) - 2px);
}

.lq-seg-item {
  position: relative;
  z-index: 5;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--lq-text-dim);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 200ms ease;
}

.lq-seg-item[aria-current="page"],
.lq-seg-item[aria-selected="true"] {
  color: var(--lq-text);
}

.lq-seg-item:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: 2px;
}

/* レンズ型インジケータ（JSが transform / width を毎フレーム更新） */
.lq-seg-indicator {
  position: absolute;
  top: 4px;
  left: 0;
  height: calc(100% - 8px);
  border-radius: 999px;
  background: var(--lq-tint-strong);
  box-shadow:
    0 1px 1px rgba(255, 255, 255, 0.6) inset,
    0 4px 12px -4px rgba(0, 0, 0, 0.35);
  z-index: 3;
  pointer-events: none;
  will-change: transform, width;
  backdrop-filter: url(#lq-refract) blur(4px) saturate(1.4);
  -webkit-backdrop-filter: blur(4px) saturate(1.4);
}

.lq-refract-supported .lq-seg-indicator {
  backdrop-filter: url(#lq-refract) blur(4px) saturate(1.4);
}

/* ------------------------------------------------------------------ */
/* .lq-pill-button                                                     */
/* ------------------------------------------------------------------ */
.lq-pill-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  border: none;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  color: var(--lq-text);
  background: var(--lq-tint-strong);
}

.lq-pill-button:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: 3px;
}

/* ------------------------------------------------------------------ */
/* motion reduce                                                       */
/* ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .lq,
  .lq-seg-indicator {
    transition-duration: 1ms !important;
  }
}
