:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --text: #1f1f24;
  --text-muted: #6b6b76;
  --accent: #5b5bd6;
  --accent-soft: #eeedfb;
  --accent-contrast: #ffffff;
  --border: #e4e2dd;
  --radius: 12px;
  --mismatch-soft: #f2f0ec;
}

* {
  box-sizing: border-box;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: contain;
  overflow-x: hidden;
}

/* JS読み込み完了までの一瞬の白画面を防ぐスプラッシュ(Native#9)。アイコン(www/icons/)と
   同じ「インディゴ背景に平」を踏襲し、新しい配色判断は増やさない。app.js側のmount()の
   初回呼び出しで削除する。 */
#splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
}

#splash span {
  color: var(--accent-contrast);
  font-size: 3rem;
  font-weight: 700;
}

.app-header {
  padding: 24px 20px 8px;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 20px calc(48px + env(safe-area-inset-bottom));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

/* 画面遷移に方向性を持たせる(Native#3)。進む(pushState)は右から、戻る(popstate)は
   左からスライドインさせ、階層のどちら向きに動いたかを体感できるようにする。 */
.screen-enter-forward {
  animation: screen-enter-forward 0.25s ease both;
}

.screen-enter-back {
  animation: screen-enter-back 0.25s ease both;
}

@keyframes screen-enter-forward {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes screen-enter-back {
  from {
    opacity: 0;
    transform: translateX(-24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(31, 31, 36, 0.06);
}

/* 結果画面・履歴詳細のスコアカードは最重要情報なので、余白を広げて強弱をつける */
.card-hero {
  padding: 28px 20px;
  margin-bottom: 24px;
}

/* クイズカードの後ろに次のカードが透けて見える「積み重ね」表現(B1)。 */
.quiz-card-stack {
  position: relative;
  margin-bottom: 28px;
}

.quiz-card-stack .card {
  position: relative;
  z-index: 1;
  margin-bottom: 0;
}

.quiz-card-stack-shadow {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.quiz-card-stack-shadow-1 {
  transform: translateY(8px) scale(0.97);
  opacity: 0.7;
  z-index: 0;
}

.quiz-card-stack-shadow-2 {
  transform: translateY(16px) scale(0.94);
  opacity: 0.4;
  z-index: -1;
}

/* ページ見出し(Home/カテゴリ選択/履歴等)は控えめに、クイズの質問文(.question-heading)は
   回答者の意識をその1問に集中させるため、あえて大きく・重くする(Typeform的な重み付け)。 */
h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 700;
}

.question-heading {
  font-size: 1.35rem;
  line-height: 1.4;
}

button {
  font: inherit;
  cursor: pointer;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font-size: 1rem;
  transition: transform 0.08s ease;
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.1);
  transform: scale(0);
  animation: ripple-expand 0.5s ease-out;
  pointer-events: none;
}

@keyframes ripple-expand {
  to {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* デスクトップ/審査ブラウザでは、カーソルを乗せても変化がなく押せる要素だと
   伝わりにくいとUIレビューで指摘(2026-08-17)。タッチには影響しない軽い変化を足す。
   hoverが効かないタッチデバイスに副作用を出さないよう(hover: hover)で限定する。 */
@media (hover: hover) {
  .btn:hover {
    border-color: var(--accent);
  }
  .btn-primary:hover {
    filter: brightness(1.05);
  }
  .btn-outline:hover {
    background: var(--accent-soft);
  }
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.5;
  transform: scale(0.98);
  border-color: var(--bg);
}

.btn.btn-selected:disabled {
  opacity: 1;
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  text-align: center;
  font-weight: 600;
}

.btn-outline {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  text-align: center;
}

/* 選択肢の一覧として使うbtn-outline(属性の値・カテゴリ)は、単独のCTAと違い左揃えのまま */
.attribute-option,
.category-option {
  text-align: left;
}

/* カテゴリボタンの「挑戦済み」バッジ(2026-08-18、CX指摘の継続利用シグナル) */
.category-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.category-option.is-played {
  opacity: 0.72;
}
.played-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
}

.btn-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: auto;
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 12px 0;
  min-height: 44px;
}

.btn-link .icon {
  flex-shrink: 0;
}

.btn-link-emphasis {
  font-weight: 700;
  text-decoration: none;
}

.progress {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.result-score {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
}

.result-tier {
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 8px;
}

.tier-meter {
  margin: 0 0 16px;
}

.tier-meter-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent), var(--accent-soft) 50%, var(--border));
}

.tier-meter-marker {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  background: var(--text);
  border: 2px solid var(--surface);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: left 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.tier-meter-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--text-muted);
  /* 0.65rem(実測10.4px)は判読しづらいとa11yレビューで指摘、0.75remに引き上げ(2026-08-17)。
     ただし320px幅で5ラベルが詰まるため0.7remに微調整し、両端は内側に寄せて端の余白を確保
     (2026-08-18、UI指摘)。 */
  font-size: 0.7rem;
}

.tier-meter-labels span:first-child {
  text-align: left;
}

.tier-meter-labels span:last-child {
  text-align: right;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.8rem;
  font-weight: 600;
}

/* 通算称号は単色ピル固定だとランクが上がっても差が出なかったため、ランクごとに
   色調を変える(UI#15)。低ランクほど落ち着いた色、最高ランクは金色でひときわ目立つように。 */
.badge-tier-1 {
  background: #e8dcc8;
  color: #7a5c2e;
}

.badge-tier-2 {
  background: #dfe1ea;
  color: #4b5170;
}

.badge-tier-3 {
  background: linear-gradient(135deg, #f5d47a, #d9a94a);
  color: #5c3d0a;
  box-shadow: 0 0 0 1px rgba(217, 169, 74, 0.4), 0 2px 6px rgba(217, 169, 74, 0.35);
}

.question-row {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.question-row:last-child {
  border-bottom: none;
}

.question-row .question-text {
  margin: 0 0 4px;
  font-weight: 600;
}

.question-row .match {
  color: var(--accent);
  font-weight: 600;
}

.question-row .mismatch {
  color: var(--text-muted);
}

.breakdown-attr-heading {
  margin: 24px 0 10px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 1rem;
}

.topic-list-category {
  margin: 20px 0 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* カテゴリ/内訳の折りたたみ(details/summary)。summaryをタップ可能な見出し行に(2026-08-18) */
.topic-list-cat,
.breakdown-accordion {
  border-top: 1px solid var(--border);
}
.topic-list-cat > summary,
.breakdown-accordion > summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 4px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topic-list-cat > summary::-webkit-details-marker,
.breakdown-accordion > summary::-webkit-details-marker {
  display: none;
}
.topic-list-cat > summary::before,
.breakdown-accordion > summary::before {
  content: '▸';
  color: var(--text-muted);
  transition: transform 0.15s ease;
}
.topic-list-cat[open] > summary::before,
.breakdown-accordion[open] > summary::before {
  transform: rotate(90deg);
}

.topic-list-category:first-child {
  margin-top: 0;
}

/* 一覧項目はネイティブbuttonにして、キーボード操作・スクリーンリーダーから
   「押せる要素」として認識されるようにする(2026-08-17、a11y/UI/初回ユーザーの
   3ペルソナが「divのままでタップ可能と気づかれない/操作不能」と指摘)。
   button既定の見た目(中央寄せ・枠・背景)を打ち消し、行リンク風に整える。 */
.session-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 14px 4px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.session-list-item:last-child {
  border-bottom: none;
}

.session-list-item-main {
  flex: 1;
}

/* タップ可能であることを示す矢印(初回ユーザーが「ただの一覧テキストに見える」と指摘) */
.session-list-item-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
}

.session-list-item:hover {
  background: var(--accent-soft);
}

.session-list-item:active {
  transform: scale(0.99);
}

.field {
  margin-bottom: 16px;
}

.field label,
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* プロフィール設定をnative selectからタップ式の選択肢チップへ(D3)。 */
.attribute-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attribute-option {
  width: auto;
  margin-bottom: 0;
  padding: 10px 16px;
}

.attribute-option.is-selected {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

select {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 1rem;
  background: var(--surface);
}

/* textarea/input はブラウザ既定だと13.3px・monospaceになり、iOS Safariは
   font-size<16pxのフォーカスで画面を強制ズームインする(2026-08-18、UI担当ペルソナ指摘)。
   16px以上＋フォント継承で、iOSの自動ズームと他画面からの浮きを防ぐ。 */
textarea,
input,
input[type='text'] {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  box-sizing: border-box;
}

.error {
  color: #c0392b;
  font-size: 0.9rem;
}

.bar-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.bar-row:last-child {
  border-bottom: none;
}

.bar-row-label {
  margin: 0 0 8px;
  font-weight: 600;
}

.bar-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  row-gap: 4px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  border-radius: 8px;
}

/* 自分の一票が反映された行だけ、着地の瞬間に一度だけ淡くハイライトする */
.bar-line-you {
  animation: pulse-you 0.8s ease;
}

@keyframes pulse-you {
  from {
    background: var(--accent-soft);
  }
  to {
    background: transparent;
  }
}

/* ラベルは固定幅で横に置くのをやめ、バーの上の独立した行にする(flex-basis:100%)。
   6.5em固定だと「(あなた・多数派)」タグ付きの長いラベルが2行に折り返し、その行だけ
   高くなってバーの縦位置がずれていた(2026-08-17、UIレビューで再発を指摘)。
   独立行にすることで、ラベル長に関係なくバーの左端・高さが常に揃う。 */
.bar-option-label {
  flex: 1 1 100%;
  color: var(--text-muted);
}

.bar-track {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 内訳バーで「あなたが選んだ選択肢」以外を落ち着かせ、自分の一票の行方が
   一目で追えるようにする(常にインディゴ1色だと意味づけが伝わらなかったため)。 */
.bar-muted {
  background: var(--text-muted);
  opacity: 0.35;
}

.bar-count {
  width: 3em;
  flex-shrink: 0;
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.quiz-progress-track {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.quiz-progress-segment {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  transition: background-color 0.3s ease;
}

.quiz-progress-segment.is-filled {
  background: var(--accent);
}

.feedback-banner {
  display: flex;
  /* 文言が2行に折り返す小型端末でも、アイコンが縦中央に浮かず先頭行に揃うようにする
     (2026-08-18、UI指摘)。 */
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 1.05rem;
  animation: banner-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.feedback-banner.is-match {
  background: var(--accent-soft);
  color: var(--accent);
}

.feedback-banner.is-mismatch {
  background: var(--mismatch-soft);
  color: var(--text-muted);
}

.feedback-banner .feedback-icon {
  font-size: 1.6rem;
  line-height: 1;
}

/* クイズの「中断する」逃げ道リンクは、目立たせすぎず控えめに(2026-08-18) */
.quiz-quit {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

@keyframes banner-pop {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.loading-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  align-items: center;
  min-height: 120px;
}

.loading-text {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar,
  .quiz-progress-segment,
  .feedback-banner,
  .screen-enter-forward,
  .screen-enter-back,
  .spinner,
  .bar-line-you {
    animation: none !important;
    transition: none !important;
  }
}
