/* ============================================================
   鉱物 協働投稿図鑑 — 標本箱 × 博物館ラベルの意匠
   暗い岩石地に、標本ラベルの真鍮金と結晶色のアクセント
   ============================================================ */

:root {
  /* --- 岩石・標本箱の色 --- */
  --bg: oklch(20% 0.012 270);
  --bg-deep: oklch(15% 0.012 270);
  --surface: oklch(26% 0.014 270);
  --surface-2: oklch(30% 0.016 270);
  --line: oklch(42% 0.02 270);
  --text: oklch(93% 0.008 90);
  --text-dim: oklch(73% 0.015 90);

  /* --- 標本ラベルの真鍮金 --- */
  --brass: oklch(82% 0.12 85);
  --brass-dim: oklch(66% 0.10 85);
  --label-paper: oklch(92% 0.03 85);
  --label-ink: oklch(26% 0.02 270);

  /* --- 成因グループの色（分類の意味を持つ） --- */
  --g-magma: oklch(66% 0.19 35);
  --g-sediment: oklch(74% 0.10 75);
  --g-meta: oklch(70% 0.12 195);
  --g-oxidized: oklch(68% 0.14 165);
  --g-life: oklch(72% 0.13 305);
  --g-unknown: oklch(64% 0.02 270);

  /* --- タイポグラフィ --- */
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "MS Mincho", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --text-hero: clamp(1.9rem, 1.2rem + 3vw, 3.4rem);
  --text-title: clamp(1.3rem, 1rem + 1.4vw, 2rem);
  --text-base: clamp(1rem, 0.95rem + 0.2vw, 1.1rem);
  --text-sm: 0.85rem;

  /* --- 余白・形・影 --- */
  --space-1: 0.4rem;
  --space-2: 0.8rem;
  --space-3: 1.2rem;
  --space-4: 2rem;
  --space-5: 3.2rem;
  --radius: 5px;
  --radius-lg: 10px;
  --shadow: 0 2px 6px oklch(0% 0 0 / 0.35), 0 8px 24px oklch(0% 0 0 / 0.25);
  --shadow-inset: inset 0 1px 0 oklch(100% 0 0 / 0.04);
  --duration: 220ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, oklch(30% 0.03 280 / 0.5), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, oklch(28% 0.04 200 / 0.4), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--brass); }

.wrap {
  width: min(1100px, 92vw);
  margin-inline: auto;
  padding-block: var(--space-4);
}
.wrap--narrow { width: min(640px, 92vw); }

/* ---------- ヘッダー ---------- */
.site-header {
  border-bottom: 1px solid var(--line);
  padding-block: var(--space-3);
  margin-bottom: var(--space-4);
}
.site-header__eyebrow {
  font-size: var(--text-sm);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--brass-dim);
  margin: 0 0 var(--space-1);
}
.site-header__title {
  font-family: var(--font-serif);
  font-size: var(--text-hero);
  font-weight: 600;
  line-height: 1.1;
  margin: 0;
  letter-spacing: 0.02em;
}
.site-header__sub {
  color: var(--text-dim);
  margin: var(--space-2) 0 0;
  max-width: 60ch;
}

/* ---------- ナビ ---------- */
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.nav a {
  text-decoration: none;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: var(--text-sm);
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease),
    background var(--duration) var(--ease);
}
.nav a:hover { color: var(--text); border-color: var(--brass-dim); background: var(--surface); }

/* ---------- 標本ラベル（和名タグ） ---------- */
.label-tag {
  display: inline-block;
  font-family: var(--font-serif);
  background: var(--label-paper);
  color: var(--label-ink);
  border: 1px solid var(--brass);
  border-radius: 2px;
  padding: 0.15rem 0.7rem;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-inset);
}

/* ---------- 成因グループのチップ ---------- */
.group-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  color: var(--bg-deep);
  background: var(--g-unknown);
  white-space: nowrap;
}
.group-badge::before {
  content: "";
  width: 0.5em; height: 0.5em;
  border-radius: 50%;
  background: var(--bg-deep);
  opacity: 0.55;
}
.group-badge--magma { background: var(--g-magma); }
.group-badge--sediment { background: var(--g-sediment); }
.group-badge--meta { background: var(--g-meta); }
.group-badge--oxidized { background: var(--g-oxidized); }
.group-badge--life_fake { background: var(--g-life); }
.group-badge--unknown { background: var(--g-unknown); }

/* ふりがな（ruby.js が自動付与）。ルビは小さく控えめに */
rt { font-size: 0.56em; font-weight: 400; opacity: 0.82; letter-spacing: 0; user-select: none; }

/* ---------- ボタン ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--brass-dim);
  background: linear-gradient(oklch(34% 0.02 270), oklch(28% 0.02 270));
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.7rem 1.3rem;
  transition: transform var(--duration) var(--ease), border-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease);
  box-shadow: var(--shadow-inset);
}
.btn:hover { border-color: var(--brass); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn--primary {
  background: linear-gradient(oklch(78% 0.12 85), oklch(68% 0.12 85));
  color: var(--label-ink);
  border-color: var(--brass);
}
.btn--lg { padding: 0.9rem 1.6rem; font-size: 1.1rem; width: 100%; }
.btn--ghost { background: transparent; }

/* ---------- カード（標本箱の仕切り） ---------- */
.panel {
  background: linear-gradient(var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

/* ---------- 図鑑グリッド ---------- */
.specimen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
}
.specimen {
  background: linear-gradient(var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform var(--duration) var(--ease), border-color var(--duration) var(--ease);
  animation: specimen-in var(--duration) var(--ease);
}
.specimen:hover { transform: translateY(-3px); border-color: var(--brass-dim); }
@keyframes specimen-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.specimen__photo {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  background: var(--bg-deep);
  display: block;
}
.specimen__photo--empty {
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 2rem;
}
.specimen__body { padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.specimen__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.specimen__meta { font-size: var(--text-sm); color: var(--text-dim); }
.specimen__field { font-size: var(--text-sm); }
.specimen__field b { color: var(--brass-dim); font-weight: 600; }
.specimen__textures { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip-mini {
  font-size: 0.72rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  color: var(--text-dim);
}

/* ---------- フォーム ---------- */
.field { margin-bottom: var(--space-3); }
.field > label { display: block; font-weight: 600; margin-bottom: var(--space-1); }
.field .hint { font-size: var(--text-sm); color: var(--text-dim); font-weight: 400; }
input[type="text"], select, textarea {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brass-dim);
  outline-offset: 1px;
  border-color: var(--brass-dim);
}
textarea { resize: vertical; min-height: 3rem; }

/* チェックを「チップ」として押せるUI */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  position: relative;
  cursor: pointer;
  user-select: none;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: var(--text-sm);
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}
.chip input:checked + span {
  background: var(--brass);
  color: var(--label-ink);
  border-color: var(--brass);
  font-weight: 600;
}
.chip input:focus-visible + span { outline: 2px solid var(--brass); outline-offset: 2px; }

/* グループ選択（大きめのラジオ） */
.group-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.6rem; }
.group-opt { cursor: pointer; }
.group-opt input { position: absolute; opacity: 0; }
.group-opt span {
  display: block;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.5rem;
  font-weight: 600;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}
.group-opt input:checked + span { border-color: var(--brass); background: var(--surface-2); }
.group-opt input:focus-visible + span { outline: 2px solid var(--brass); outline-offset: 2px; }

/* 写真プレビュー */
.photo-input { display: grid; gap: var(--space-2); }
.photo-preview {
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg-deep);
  display: grid;
  place-items: center;
  color: var(--text-dim);
  overflow: hidden;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- メッセージ ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: var(--space-4);
  transform: translateX(-50%) translateY(120%);
  background: var(--surface-2);
  border: 1px solid var(--brass-dim);
  color: var(--text);
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: transform var(--duration) var(--ease);
  z-index: 50;
}
.toast--show { transform: translateX(-50%) translateY(0); }
.toast--error { border-color: var(--g-magma); }

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brass);
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}
.notice--warn { border-left-color: var(--g-magma); }

/* ---------- 進捗ダッシュボード（投影用） ---------- */
.dash { text-align: center; }
.dash__big {
  font-family: var(--font-serif);
  font-size: clamp(3rem, 1rem + 9vw, 8rem);
  line-height: 1;
  color: var(--brass);
  margin: var(--space-3) 0 0;
}
.dash__big small { font-size: 0.3em; color: var(--text-dim); }
.dash__caption { color: var(--text-dim); letter-spacing: 0.2em; text-transform: uppercase; font-size: var(--text-sm); }

.meter {
  height: 18px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: var(--space-3) 0;
}
.meter__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--g-meta), var(--brass));
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 600ms var(--ease);
}

/* 班対抗レース */
.race { display: grid; gap: var(--space-2); margin-top: var(--space-4); text-align: left; }
.race-row { display: grid; grid-template-columns: 7rem 1fr 3rem; align-items: center; gap: var(--space-2); }
.race-row__name { font-weight: 600; text-align: right; }
.race-row__track {
  height: 26px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.race-row__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--g-magma), var(--brass));
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 600ms var(--ease);
}
.race-row__num { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brass); }
.race-row--lead .race-row__bar { background: linear-gradient(90deg, var(--g-meta), var(--g-life)); }

/* グループ別カバー */
.group-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2); margin-top: var(--space-4); }
.group-stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-2); }
.group-stat__n { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- 管理画面の表 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--brass-dim); font-weight: 600; }
.token-pill { font-family: ui-monospace, monospace; background: var(--bg-deep); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.1rem 0.5rem; }

.qr-box { display: inline-block; background: #fff; padding: 8px; border-radius: var(--radius); }
.muted { color: var(--text-dim); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.spacer { flex: 1; }
.empty-state { text-align: center; color: var(--text-dim); padding: var(--space-5) var(--space-3); }

/* ---------- アクセシビリティ ---------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 図鑑のフィルタchip ---------- */
.nav-chip {
  font: inherit;
  cursor: pointer;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: var(--text-sm);
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease),
    background var(--duration) var(--ease);
}
.nav-chip:hover { color: var(--text); border-color: var(--brass-dim); }
.nav-chip.is-on { color: var(--label-ink); background: var(--brass); border-color: var(--brass); font-weight: 600; }
.nav-chip:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

code {
  font-family: ui-monospace, "SFMono-Regular", monospace;
  background: var(--bg-deep);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.9em;
}

/* ---------- 印刷（班QRの配布用） ---------- */
@media print {
  body { background: #fff; color: #000; }
  .no-print { display: none !important; }
  .specimen-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .specimen {
    break-inside: avoid;
    border: 1px solid #999;
    box-shadow: none;
    background: #fff;
    color: #000;
  }
  .label-tag { background: #fff; color: #000; border-color: #000; }
  .token-pill { color: #000; background: #fff; }
}

/* ---------- 鉱物カード（写真なし解説）／重要情報 ---------- */
.m-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-3);
}
.m-card {
  background: linear-gradient(var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow);
}
.m-card__name {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  margin: 0 0 var(--space-2);
  color: var(--text);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-1);
}
.m-card__name small { display: block; font-size: var(--text-sm); color: var(--text-dim); font-weight: 400; margin-top: 2px; }

/* キー・バリュー一覧（カードと投稿ヒントで共用） */
.kv { margin: 0; display: grid; gap: 0.4rem; }
.kv > div { display: grid; grid-template-columns: 5rem 1fr; gap: 0.5rem; font-size: var(--text-sm); }
.kv dt { color: var(--brass-dim); font-weight: 600; margin: 0; }
.kv dd { margin: 0; }

/* 投稿フォームの鉱物ヒントパネル */
.mineral-info {
  border: 1px solid var(--brass-dim);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-3);
}
.mineral-info__head { font-family: var(--font-serif); color: var(--brass); font-weight: 600; margin-bottom: var(--space-2); }
.mineral-info .hint { display: block; margin-top: var(--space-2); }

/* ---------- でき方の選択肢 ---------- */
.how-picker { display: grid; gap: 0.5rem; }
.how-opt { cursor: pointer; }
.how-opt input { position: absolute; opacity: 0; pointer-events: none; }
.how-opt span {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}
.how-opt input:checked + span { border-color: var(--brass); background: var(--surface-2); font-weight: 600; }
.how-opt input:focus-visible + span { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ---------- 穴埋め説明 ---------- */
.fill-blank {
  background: var(--surface-2);
  border: 1px dashed var(--brass-dim);
  border-radius: var(--radius);
  padding: var(--space-3);
}
.fill-sentence { margin: 0; line-height: 2.2; }
.fill-input {
  font: inherit;
  width: 8em;
  max-width: 62%;
  color: var(--text);
  background: var(--bg-deep);
  border: none;
  border-bottom: 2px solid var(--brass);
  border-radius: 4px 4px 0 0;
  padding: 0.2rem 0.5rem;
  margin: 0 0.15rem;
}
.fill-input:focus { outline: none; background: var(--surface); }

/* ---------- スマホ最適化 ---------- */
@media (max-width: 540px) {
  .wrap { padding-block: var(--space-3); }
  /* iOS が input を勝手に拡大するのを防ぐ（16px以上必須） */
  input[type="text"], textarea, select, .fill-input { font-size: 16px; }
  .btn--lg { padding: 1rem; font-size: 1.05rem; }
  .specimen-grid { grid-template-columns: 1fr 1fr; gap: var(--space-2); }
  .photo-preview { aspect-ratio: 1 / 1; }
}

/* ---------- 図鑑：自分の投稿の編集・削除 ---------- */
.btn--sm { padding: 0.35rem 0.75rem; font-size: var(--text-sm); }
.specimen--mine { border-color: var(--brass-dim); box-shadow: 0 0 0 1px var(--brass-dim), var(--shadow); }
.specimen__mine {
  display: flex;
  gap: 0.5rem;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px dashed var(--line);
}
.specimen__mine .btn { flex: 1; text-align: center; text-decoration: none; }

/* ============================================================
   クラフト層：資源チップ・工房・製品カード
   ============================================================ */

/* ---------- 図鑑カードの「取れる資源」 ---------- */
.specimen__resources { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }
.specimen__reslabel { font-size: 0.72rem; color: var(--brass-dim); font-weight: 600; margin-right: 0.15rem; }
.res-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: 0.72rem;
  background: var(--bg-deep);
  border: 1px solid var(--brass-dim);
  border-radius: 999px;
  padding: 0.1rem 0.55rem 0.1rem 0.1rem;
  color: var(--text);
}
.res-chip__sym {
  display: inline-grid;
  place-items: center;
  min-width: 1.5em; height: 1.5em;
  border-radius: 50%;
  background: var(--brass);
  color: var(--label-ink);
  font-weight: 700;
  font-size: 0.78em;
}

/* ---------- 工房：サマリー ---------- */
.craft-summary {
  display: flex;
  align-items: baseline;
  gap: var(--space-3) var(--space-4);
  flex-wrap: wrap;
  background: linear-gradient(var(--surface-2), var(--surface));
  border: 1px solid var(--brass-dim);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow);
}
.craft-score { font-family: var(--font-serif); line-height: 1; color: var(--brass); }
.craft-score span { font-size: clamp(2.4rem, 1rem + 6vw, 4rem); font-variant-numeric: tabular-nums; }
.craft-score small { font-size: 0.4em; color: var(--text-dim); margin-left: 0.2em; }
.craft-substat { color: var(--text-dim); }
.craft-substat b { color: var(--text); font-size: 1.3em; font-variant-numeric: tabular-nums; }
.craft-h2 { font-family: var(--font-serif); margin: var(--space-5) 0 var(--space-1); }
.craft-note { color: var(--text-dim); font-size: var(--text-sm); margin: 0 0 var(--space-3); }
.craft-note b { color: var(--brass-dim); }

/* ---------- 工房：資源インベントリ ---------- */
.inventory {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.5rem;
}
.inv-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.5rem;
  background: var(--bg-deep);
  opacity: 0.36;
  filter: saturate(0.35);
  transition: opacity var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.inv-chip.is-on { opacity: 1; filter: none; border-color: var(--brass); background: var(--surface-2); }
.inv-chip__sym {
  display: inline-grid; place-items: center;
  min-width: 1.8em; height: 1.8em;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 700; font-size: 0.82rem;
}
.inv-chip.is-on .inv-chip__sym { background: var(--brass); color: var(--label-ink); }
.inv-chip__name { font-size: 0.76rem; }

/* ---------- 工房：製品カード ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-2);
}
.product-card {
  position: relative;
  background: linear-gradient(var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  display: flex; flex-direction: column; gap: 0.5rem;
  box-shadow: var(--shadow);
  transition: transform var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.product-card.is-locked { opacity: 0.6; }
.product-card.is-made { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass-dim), var(--shadow); }
.product-card.is-made:hover { transform: translateY(-2px); }
.product-card__top { display: flex; align-items: center; justify-content: space-between; }
.product-card__icon { font-size: 1.6rem; line-height: 1; }
.product-card__pts { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brass); font-size: 0.9rem; }
.product-card__name { font-family: var(--font-serif); font-size: 1rem; margin: 0; }
.product-card__check { color: var(--g-meta); }
.product-card__recipe { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.recipe-res {
  display: inline-grid; place-items: center;
  min-width: 1.7em; height: 1.7em; padding: 0 0.2em;
  border-radius: 50%;
  font-size: 0.72rem; font-weight: 700;
  border: 1px solid var(--line);
}
.recipe-res.have { background: var(--brass); color: var(--label-ink); border-color: var(--brass); }
.recipe-res.miss { background: var(--bg-deep); color: var(--text-dim); border-style: dashed; }
.product-card__missing { font-size: 0.74rem; color: var(--g-sediment); margin: 0; font-weight: 600; }
.product-card__blurb { font-size: 0.74rem; color: var(--text-dim); margin: 0; line-height: 1.45; }
/* 目玉（ティア3）の達成は特別感を出す */
.product-card.tier-3.is-made {
  border-color: var(--g-life);
  box-shadow: 0 0 0 1px var(--g-life), 0 0 24px oklch(72% 0.13 305 / 0.25), var(--shadow);
}
.product-card.tier-3 .product-card__pts { color: var(--g-life); }

/* ダッシュボード：班スコアの製品数サブ表示 */
.race-row__sub { font-size: 0.62em; color: var(--text-dim); font-weight: 600; }

/* 資源の点数（レア度）バッジ・スコア内訳 */
.inventory { grid-template-columns: repeat(auto-fill, minmax(106px, 1fr)); }
.inv-chip__pts { margin-left: auto; font-size: 0.68rem; font-weight: 700; color: var(--text-dim); }
.inv-chip.is-on .inv-chip__pts { color: var(--brass); }
.craft-substat__main b { color: var(--text); font-size: 1.15em; font-variant-numeric: tabular-nums; }
.craft-substat__sub { font-size: var(--text-sm); color: var(--text-dim); margin-top: 3px; }

/* 工房のスマホ最適化 */
@media (max-width: 540px) {
  .inventory { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .product-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   獲得モーダル・資源/製品の画像
   ============================================================ */
.gain-modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: oklch(12% 0.02 270 / 0.78);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  padding: var(--space-3);
  animation: gain-fade var(--duration) var(--ease);
}
@keyframes gain-fade { from { opacity: 0 } to { opacity: 1 } }
.gain-modal__box {
  background: linear-gradient(var(--surface-2), var(--surface));
  border: 1px solid var(--brass);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 40px oklch(82% 0.12 85 / 0.25), var(--shadow);
  padding: var(--space-4); width: min(440px, 92vw); text-align: center;
  animation: gain-pop 320ms var(--ease);
  /* 獲得が多くてもボタンに届くよう、画面高さに収め、中身だけスクロールさせる */
  max-height: calc(100dvh - 2 * var(--space-3));
  display: flex; flex-direction: column;
}
@keyframes gain-pop { from { transform: scale(0.9); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.gain-modal__eyebrow { color: var(--brass); letter-spacing: 0.3em; font-size: var(--text-sm); font-weight: 700; margin: 0; flex: 0 0 auto; }
.gain-modal__title { font-family: var(--font-serif); font-size: 1.5rem; margin: var(--space-1) 0 var(--space-3); flex: 0 0 auto; }
.gain-modal__items {
  display: grid; gap: var(--space-2); margin-bottom: var(--space-3);
  /* 中身が多い場合はここだけスクロール（ボタンと見出しは常に見える） */
  overflow-y: auto; min-height: 0; flex: 1 1 auto;
  /* 内側の余白を保ちつつ、スクロールバーが項目に被らないよう少しゆとり */
  padding-right: 4px;
}
.gain-modal__box > .btn { flex: 0 0 auto; }
.gain-item {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--bg-deep); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--space-2); text-align: left;
}
.gain-item.is-product { border-color: var(--g-life); box-shadow: 0 0 16px oklch(72% 0.13 305 / 0.2); }
.gain-item__img { display: grid; place-items: center; width: 64px; height: 64px; flex: 0 0 auto; }
.gain-img { width: 64px; height: 64px; object-fit: contain; }
.gain-img-fb { font-size: 2rem; }
.gain-item__meta { display: flex; flex-direction: column; gap: 1px; }
.gain-item__tag { font-size: 0.7rem; color: var(--brass-dim); font-weight: 700; }
.gain-item__name { font-family: var(--font-serif); font-size: 1.1rem; }
.gain-item__pts { font-size: 0.8rem; color: var(--brass); font-weight: 700; }

/* 資源インベントリの画像（fallback=元素記号の丸） */
.inv-chip__icon { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 auto; }
.inv-img { width: 30px; height: 30px; object-fit: contain; }
.inv-img-fb {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; background: var(--surface); color: var(--text-dim);
  font-weight: 700; font-size: 0.82rem;
}
.inv-chip.is-on .inv-img-fb { background: var(--brass); color: var(--label-ink); }

/* 製品カードの画像（fallback=絵文字） */
.product-card__icon { display: inline-grid; place-items: center; min-height: 48px; }
.prod-img { width: 48px; height: 48px; object-fit: contain; }
.prod-img-fb { font-size: 1.6rem; line-height: 1; }

/* 図鑑カードの資源チップの画像（fallback=元素記号の丸） */
.res-chip__icon { display: inline-grid; place-items: center; width: 1.7em; height: 1.7em; }
.res-img { width: 1.7em; height: 1.7em; object-fit: contain; }
.res-img-fb {
  display: inline-grid; place-items: center; width: 1.5em; height: 1.5em;
  border-radius: 50%; background: var(--brass); color: var(--label-ink);
  font-weight: 700; font-size: 0.78em;
}

/* 画像が読めたら fallback を、読めなければ画像を、確実に隠す（display指定が hidden属性に勝つのを防ぐ） */
.inv-img[hidden], .inv-img-fb[hidden],
.res-img[hidden], .res-img-fb[hidden],
.prod-img[hidden], .prod-img-fb[hidden],
.gain-img[hidden], .gain-img-fb[hidden] { display: none !important; }
/* モーダル本体も display 指定が hidden 属性に勝つので明示的に隠す（出っぱなし防止） */
.gain-modal[hidden] { display: none !important; }

/* 未獲得の製品＝正体（名前・得点・画像）を隠し、作り方だけ見せる */
.product-card.is-secret { opacity: 0.95; border-style: dashed; }
.product-card__icon--secret {
  display: inline-grid; place-items: center;
  width: 48px; height: 48px; border-radius: 12px;
  border: 2px dashed var(--line); color: var(--text-dim);
  font-size: 1.5rem; font-weight: 700;
}
.product-card__pts--secret { color: var(--text-dim); }
.product-card__name--secret { color: var(--text-dim); letter-spacing: 0.1em; }

/* ============================================================
   MINERALIA タイトル画面（ブランド）
   ============================================================ */
.brand-logo { display: block; max-width: min(440px, 82%); height: auto; margin: 0 auto var(--space-2); }
.brand-title {
  text-align: center; letter-spacing: 0.14em;
  font-size: clamp(2.6rem, 1rem + 7vw, 5rem); margin: 0;
  background: linear-gradient(160deg, var(--brass), var(--brass-dim) 70%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-kana {
  text-align: center; color: var(--brass);
  font-family: var(--font-serif); font-weight: 600;
  letter-spacing: 0.5em; font-size: clamp(1.2rem, 1rem + 1.2vw, 1.7rem);
  margin: var(--space-1) 0 0; padding-left: 0.5em;
}
.brand-sub {
  text-align: center; color: var(--brass-dim);
  letter-spacing: 0.24em; font-size: var(--text-base);
  margin: 2px 0 var(--space-3);
}
.site-header:has(.brand-title) { text-align: center; border-bottom: none; }
.site-header:has(.brand-title) .site-header__sub { margin-inline: auto; }
.site-header:has(.brand-title) .nav { justify-content: center; }

/* 投稿フォームの採点（問題・エラー表示） */
.quiz-note {
  background: var(--surface-2); border: 1px solid var(--brass-dim);
  border-radius: var(--radius); padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm); margin: 0 0 var(--space-3);
}
.quiz-note b { color: var(--brass); }
.field-error { color: var(--g-magma); font-size: var(--text-sm); font-weight: 700; margin: var(--space-1) 0 0; }
.chip span small { opacity: 0.6; margin-left: 0.35em; font-size: 0.82em; font-weight: 400; }

/* BGM の ON/OFF トグル（右下フローティング） */
.bgm-toggle {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
  width: 3rem; height: 3rem; border-radius: 50%;
  border: 1px solid var(--brass-dim); background: var(--surface-2);
  color: var(--text); font-size: 1.3rem; cursor: pointer;
  box-shadow: var(--shadow); display: grid; place-items: center;
  transition: border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}
.bgm-toggle:hover { border-color: var(--brass); transform: scale(1.05); }
.bgm-toggle.is-off { opacity: 0.55; }

/* 「♪タップしてはじめる」イントロ（自動再生がブロックされた入口で確実に鳴らす） */
.bgm-intro {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center; cursor: pointer;
  background: oklch(12% 0.02 270 / 0.82);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: gain-fade var(--duration) var(--ease);
}
.bgm-intro__inner {
  display: grid; place-items: center; gap: 0.5rem;
  color: var(--brass); font-family: var(--font-serif); font-size: 3rem;
  animation: gain-pop 320ms var(--ease);
}
.bgm-intro__inner span { font-size: 1.05rem; letter-spacing: 0.3em; color: var(--text); }
