/* 色はすべてここのトークン経由で使う(直書きしない)。
   ライトとダークの値を light-dark() に並べて1か所で持ち、どちらを採用するかは
   color-scheme が決める。色の定義が1組しかないので「片方だけ直して忘れる」が起きない。
   新しい色を足すときも light-dark(ライト, ダーク) の形で書くこと。 */
:root {
  /* 既定は端末の設定に追従。data-theme が立つと下の2つが上書きする */
  color-scheme: light dark;

  --bg-1: light-dark(#fdf2f8, #241b27);
  --bg-2: light-dark(#eff6ff, #171a26);
  --card: light-dark(#ffffff, #2a2431);
  --text: light-dark(#3f3a45, #f0ebf3);
  /* 小さい文字にも使うため WCAG AA(4.5:1)を満たす濃さにしている */
  --text-sub: light-dark(#6e6878, #b9b0c4);
  --accent: light-dark(#f472b6, #f9a8d4);
  --accent-strong: light-dark(#db2777, #f472b6);
  /* --accent-strong を背景に敷いたときの文字色(チップの選択中・主ボタン)。
     暗い面のうえのピンクに白文字は 2.7:1 しかないので、ダークでは文字側を暗くする */
  --on-accent: light-dark(#ffffff, #241820);
  /* 半透明の面(チップ・空状態・読み込みスケルトン) */
  --surface: light-dark(rgb(255 255 255 / 0.7), rgb(255 255 255 / 0.08));
  /* 不透明の面(ボタン・バッジ) */
  --surface-solid: light-dark(#f3f0f7, #383043);
  /* アイコンピッカーのマス */
  --surface-soft: light-dark(#f7f4fb, #332c3d);
  --surface-soft-hover: light-dark(#f0eafa, #3d3448);
  --input-bg: light-dark(#ffffff, #221c29);
  --input-border: light-dark(#e5dff0, #4a4055);
  /* アイコンピッカーで「いま選んでいるマス」。周りより明るくして浮かせる */
  --surface-selected: light-dark(#ffffff, #463a52);
  /* 注意喚起(開発中バッジ・noscript・PIN リセット申請) */
  --warn-bg: light-dark(#fef3c7, #4a3a12);
  --warn-text: light-dark(#92400e, #fcd34d);
  /* 補足(外部サイトバッジ) */
  --info-bg: light-dark(#e0f2fe, #123044);
  --info-text: light-dark(#075985, #93c5fd);
  /* 限定アプリバッジ */
  --private-bg: light-dark(#ede9fe, #33265c);
  --private-text: light-dark(#5b21b6, #ddd0ff);
  --shadow: light-dark(
    0 4px 20px rgb(244 114 182 / 0.12),
    0 4px 20px rgb(0 0 0 / 0.35)
  );
  --shadow-hover: light-dark(
    0 8px 28px rgb(96 165 250 / 0.25),
    0 8px 28px rgb(0 0 0 / 0.5)
  );
  --backdrop: light-dark(rgb(63 58 69 / 0.35), rgb(10 8 12 / 0.6));
  --sheet-shadow: light-dark(
    0 12px 48px rgb(63 58 69 / 0.25),
    0 12px 48px rgb(0 0 0 / 0.6)
  );
  --radius: 18px;
}

/* みための手動切り替え。theme.ts が <html data-theme> を立てるので、ここでは
   color-scheme を固定するだけでよい(light-dark() の解決先がまとめて変わる)。
   端末の設定に戻したいときは data-theme を消す = :root の既定に戻る。 */
:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* display を持つクラスと hidden 属性が両立するように(UA スタイルは負けるため明示) */
[hidden] {
  /* biome-ignore lint/complexity/noImportantStyles: hidden 属性のリセットは定番の例外 */
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

/* リンクはサイト共通のアクセント色にする。ブラウザ既定の青は、ダークの面に
   置くと 2:1 前後しかなく読めない(404 ページの「ポータルに戻る」で実際に潰れていた)。
   カード全体がリンクの .card は自前で color: inherit を指定しているので影響しない。 */
a {
  color: var(--accent-strong);
}

/* 名前ボタン → 見出し → キャッチコピーの縦並び(絶対配置にすると狭い画面で h1 に重なる)。 */
header {
  display: flex;
  flex-direction: column;
  text-align: center;
  padding: 1.2rem 1rem 1.5rem;
}

header h1 {
  margin: 0.8rem 0 0;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  letter-spacing: 0.04em;
}

header p {
  margin: 0.5rem 0 0;
  color: var(--text-sub);
}

main {
  flex: 1;
  width: min(960px, 100% - 2rem);
  margin: 0 auto;
  padding-bottom: 3rem;
}

/* 起動中の表示(me() 応答までの空白を埋める)。応答が来たら hidden 属性で消える */
.boot {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-sub);
}

.boot-icon {
  display: block;
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 0.4rem;
  animation: pulse 1.2s ease-in-out infinite;
}

.boot p {
  margin: 0;
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  .boot-icon {
    animation: none;
  }
}

.noscript {
  margin: 1rem 0;
  padding: 1rem;
  text-align: center;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
}

.toolbar {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#search {
  font: inherit;
  width: 100%;
  padding: 0.7rem 1.1rem;
  border: none;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  /* --accent(#f472b6)は白背景で約2.65:1 と WCAG 1.4.11(3:1)未満のため、
     フォーカスリングには --accent-strong(約4.6:1)を使う */
  outline-color: var(--accent-strong);
}

#search::placeholder {
  color: var(--text-sub);
}

#tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* タグは「2アプリ以上にまたがるカテゴリ」だけに絞ってあるので数が少ない(いま6個)。
   小さめにして折り返しに任せ、スマホでも2行に収まるようにする。
   高さ 36px は WCAG 2.2 のタップ領域(24px)に対して十分な余裕があり、
   隣との間隔(gap 0.5rem)も確保している。 */
.chip {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.85rem;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: none;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-sub);
  cursor: pointer;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.chip[aria-pressed="true"] {
  background: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 700;
}

/* 空状態の「ぜんぶ見る」は押してほしいボタンなので、こちらは大きいまま */
.empty .chip {
  font-size: 0.85rem;
  padding: 0.55rem 1rem;
  min-height: 44px;
}

#apps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 1rem;
}

/* 読み込み中のスケルトン(aria-busy をフックに CSS だけで出す) */
#apps[aria-busy="true"]::before,
#apps[aria-busy="true"]::after {
  content: "";
  display: block;
  height: 96px;
  border-radius: var(--radius);
  background: var(--surface);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  #apps[aria-busy="true"]::before,
  #apps[aria-busy="true"]::after {
    animation: none;
  }

  .card,
  .card:hover {
    transition: none;
    transform: none;
  }
}

.card {
  position: relative;
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  padding: 1.1rem 1.2rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.card > div {
  min-width: 0; /* 長い英数字でもカード外にはみ出させない */
}

.card .emoji {
  font-size: 2rem;
  line-height: 1;
}

.card h2 {
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.card p {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--text-sub);
  overflow-wrap: anywhere;
}

.card .meta {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.72rem;
}

.badge {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--text-sub);
  overflow-wrap: anywhere;
  max-width: 100%;
}

.badge.draft {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge.external {
  background: var(--info-bg);
  color: var(--info-text);
}

.badge.archived {
  background: var(--surface-solid);
  color: var(--text);
}

.badge.private {
  background: var(--private-bg);
  color: var(--private-text);
}

/* カードの右上のメニューボタン(⋯)は、カードのリンクの外側の箱に重ねて置く */
.card-wrap {
  position: relative;
  display: grid;
}

.card-wrap.has-menu .card {
  padding-right: 3rem;
}

/* アーカイブ中のカードは、一覧に混ぜたときに目立ちすぎないよう板を薄くする */
.card-wrap.archived .card {
  background: var(--surface);
  box-shadow: none;
}

.card-menu-button {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 40px;
  height: 40px;
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-sub);
  cursor: pointer;
}

.card-menu-button:hover,
.card-menu-button:focus-visible,
.card-menu-button[aria-expanded="true"] {
  background: var(--surface-soft-hover);
}

.card-menu {
  position: absolute;
  top: 2.9rem;
  right: 0.4rem;
  z-index: 10;
  min-width: 11rem;
  padding: 0.35rem;
  border: 1px solid var(--input-border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--sheet-shadow);
}

.card-menu button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.card-menu button:hover,
.card-menu button:focus-visible {
  background: var(--surface-soft-hover);
}

.card-menu button:disabled {
  cursor: progress;
  opacity: 0.6;
}

/* 一覧の上の行。左にいま見ているもの・操作の結果、右に「アーカイブを表示」 */
.list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

/* どちらも出ていないときは行ごと消して、検索欄と一覧の間を空けない */
.list-head:not(:has(> :not([hidden], :empty))) {
  display: none;
}

.list-head #archive-toggle {
  margin-left: auto;
}

.list-title {
  margin: 0;
  font-weight: 700;
}

.home-message {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-sub);
}

.home-message:empty {
  display: none;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-sub);
  background: var(--surface);
  border-radius: var(--radius);
}

/* ---- しおしんID(ログインゲート・プロフィール) ---- */

.profile-button {
  align-self: flex-end;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.95rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border: none;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.profile-button:hover,
.profile-button:focus-visible {
  box-shadow: var(--shadow-hover);
}

.login-gate {
  text-align: center;
  padding: 1rem 0 2rem;
}

.login-gate h2 {
  margin: 0;
  font-size: 1.2rem;
}

.login-users {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 1rem;
  max-width: 560px;
  margin: 1.5rem auto 0;
}

.user-card {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.4rem 1rem;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  color: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.user-card:hover,
.user-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

@media (prefers-reduced-motion: reduce) {
  .user-card,
  .user-card:hover {
    transition: none;
    transform: none;
  }
}

.user-icon {
  font-size: 2.6rem;
  line-height: 1;
}

.user-name {
  font-weight: 700;
}

.user-note {
  font-size: 0.72rem;
  color: var(--text-sub);
}

.pin-form {
  max-width: 320px;
  margin: 1.5rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.4rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pin-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.pin-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-sub);
  text-align: left;
}

.pin-label input {
  font: inherit;
  font-size: 1.3rem;
  letter-spacing: 0.4em;
  text-align: center;
  padding: 0.5rem 0.8rem;
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text);
  /* 上の #search と同じ理由で --accent-strong を使う */
  outline-color: var(--accent-strong);
}

.pin-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.button {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 1.3rem;
  min-height: 44px;
  border: none;
  border-radius: 999px;
  background: var(--surface-solid);
  color: var(--text);
  cursor: pointer;
}

.button.primary {
  background: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 700;
}

.linkish {
  font: inherit;
  font-size: 0.8rem;
  min-height: 44px;
  border: none;
  background: none;
  /* --accent-2(#60a5fa)は白背景で約2.5:1 と WCAG AA(4.5:1)未達のため、
     PIN リセット導線には --accent-strong(約4.6:1)を使う */
  color: var(--accent-strong);
  cursor: pointer;
  text-decoration: underline;
}

.login-message {
  min-height: 1.4em;
  margin: 1rem auto 0;
  max-width: 420px;
  font-size: 0.9rem;
  color: var(--accent-strong);
}

.profile-sheet {
  border: none;
  border-radius: var(--radius);
  padding: 1.5rem;
  width: min(420px, calc(100% - 2rem));
  /* dialog の既定背景は UA 任せなので明示する(ダークで白い板が出るのを防ぐ) */
  background: var(--card);
  color: var(--text);
  box-shadow: var(--sheet-shadow);
}

.profile-sheet::backdrop {
  background: var(--backdrop);
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.sheet-icon {
  font-size: 2.6rem;
  line-height: 1;
}

.sheet-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.sheet-sub {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-sub);
}

.icon-picker {
  margin: 1.2rem 0 0;
  padding: 0;
  border: none;
  min-inline-size: 0; /* fieldset の既定で grid がはみ出すのを防ぐ */
}

.icon-picker-label {
  padding: 0;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--text-sub);
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.2rem;
  /* スクロールできることが伝わるよう、はみ出しを少しぼかす */
  -webkit-overflow-scrolling: touch;
}

.icon-choice {
  font-size: 1.5rem;
  line-height: 1;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1.5px solid transparent;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.08s ease,
    border-color 0.08s ease,
    background 0.08s ease;
}

.icon-choice:hover {
  background: var(--surface-soft-hover);
  transform: translateY(-1px);
}

.icon-choice.selected {
  border-color: var(--accent);
  background: var(--surface-selected);
  box-shadow: 0 0 0 2px rgb(244 114 182 / 0.25);
}

/* みための3択。タグのチップを流用しているが、置き場所がシート(白い面)なので
   2点だけ変える:
   - 面を不透明にする。既定の半透明の白だと、選んでいないほうがシートに溶けて
     ただの文字に見え、押せると分からない
   - 縦に並べて幅いっぱいにする。横並びだと狭い画面で「端末に合わせる」が
     途中で折り返して不格好になる */
.theme-choices {
  display: grid;
  gap: 0.4rem;
}

.theme-choices .chip {
  justify-content: center;
  min-height: 44px;
  background: var(--surface-solid);
}

/* .theme-choices .chip と詳細度が同じなので、選択中の色は明示的に上書きする */
.theme-choices .chip[aria-pressed="true"] {
  background: var(--accent-strong);
}

.reset-area {
  margin-top: 1.2rem;
  padding: 0.9rem 1rem;
  background: var(--warn-bg);
  border-radius: 12px;
}

.reset-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.reset-item p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--warn-text);
}

.sheet-actions {
  margin-top: 1.4rem;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
}

footer {
  text-align: center;
  padding: 1.2rem;
  font-size: 0.8rem;
  color: var(--text-sub);
}
