/* ==========================================================
   後出しじゃんけん - style.css
   見た目は number-memory / letter-trace(基準実装)に合わせる
   すべてのクラスに .aj- プレフィックスを付与(WP 干渉防止)
   ========================================================== */

[hidden] { display: none !important; }

.aj-body {
  margin: 0;
  background: #e9ecef;
}

.aj-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.aj-app,
.aj-app *,
.aj-app *::before,
.aj-app *::after {
  box-sizing: border-box;
}

.aj-app {
  /* ---- CSS 変数(基準実装と共通) ---- */
  --aj-red: #E03131;
  --aj-blue: #1971C2;
  --aj-green: #2F9E44;
  --aj-bg: #f4f6fb;
  --aj-card: #ffffff;
  --aj-text: #212529;
  --aj-muted: #5c6670;
  --aj-primary: #3b5bdb;
  --aj-primary-dark: #2f49b3;
  --aj-border: #dee2e6;
  --aj-radius: 16px;

  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  min-height: 640px;
  margin: 0 auto;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: var(--aj-bg);
  color: var(--aj-text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* 詳細度 0 のリセット(個別クラスの margin 等を邪魔しない) */
:where(.aj-app) :is(h1, h2, p, dl, dd, ul, ol) { margin: 0; padding: 0; }
:where(.aj-app) :is(ul, ol) { list-style: none; }

/* ---------- トップバー(戻る／効果音) ---------- */
.aj-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}
.aj-app a.aj-back,
.aj-app .aj-sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--aj-card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background-color 0.15s ease;
}
.aj-app a.aj-back { color: var(--aj-primary); }
.aj-app .aj-sound-btn { color: var(--aj-primary); }
.aj-app .aj-sound-btn[aria-pressed="true"] { color: var(--aj-muted); }
.aj-app a.aj-back:hover { background: #edf2ff; color: var(--aj-primary-dark); }
.aj-app .aj-sound-btn:hover { background: #f1f3f5; }
.aj-app a.aj-back:active,
.aj-app .aj-sound-btn:active { transform: scale(0.94); }
.aj-back svg,
.aj-sound-btn svg { display: block; width: 22px; height: 22px; }
.aj-app a.aj-back:focus-visible,
.aj-app .aj-sound-btn:focus-visible,
.aj-app .aj-btn:focus-visible,
.aj-app .aj-choice:focus-visible,
.aj-app .aj-details summary:focus-visible { outline: 3px solid #ffd43b; outline-offset: 2px; }

/* ---------- 画面共通 ---------- */
.aj-screen {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 16px;
}

.aj-card {
  background: var(--aj-card);
  border-radius: var(--aj-radius);
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ---------- ボタン ---------- */
.aj-btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.aj-btn:active:not(:disabled) { transform: scale(0.97); }

.aj-btn--primary { background: var(--aj-primary); color: #fff; box-shadow: 0 4px 0 var(--aj-primary-dark); }
.aj-btn--primary:hover:not(:disabled) { background: #4263eb; }
.aj-btn--cta { min-height: 64px; font-size: 1.25rem; }
.aj-app a.aj-btn--x {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  background: #111; color: #fff; text-decoration: none;
}
.aj-app a.aj-btn--x:hover { background: #333; color: #fff; }
.aj-btn--ghost { background: transparent; color: #495057; border: 1px solid var(--aj-border); min-height: 44px; }

/* ---------- 指示バナー(プレイ画面と、スタート画面の図解で共通) ---------- */
.aj-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  font-weight: 800;
}
.aj-banner__icon { flex: none; display: block; width: 1.4em; height: 1.4em; }
.aj-banner[data-instruction="win"]  { background: #1d4ed8; color: #ffffff; }
.aj-banner[data-instruction="lose"] { background: #b91c1c; color: #ffffff; }
.aj-banner[data-instruction="draw"] { background: #facc15; color: #111827; }

/* ---------- ① スタート画面 ---------- */
.aj-title-area {
  font-size: clamp(1.4rem, 5.5vw, 1.8rem);
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}
.aj-title { padding-top: 4px; font-size: 1em; }
.aj-subtitle { font-size: 0.7em; color: var(--aj-primary); }

.aj-rule__lead { text-align: center; font-size: 1.05rem; margin-bottom: 12px; }
.aj-rule__lead strong { color: var(--aj-primary); }

.aj-figure {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: 8px;
}
.aj-figure__hand {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.aj-figure__art { display: block; width: 56px; height: 56px; }
.aj-figure__name { font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.aj-figure__banner {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 6px;
  font-size: 0.75rem;
  line-height: 1.3;
  text-align: center;
}
.aj-figure__banner .aj-banner__icon { width: 1.2em; height: 1.2em; }
.aj-figure__arrow { flex: none; display: block; width: 20px; height: 20px; color: var(--aj-primary); }
.aj-rule__example { margin-bottom: 12px; font-size: 0.85rem; text-align: center; }

.aj-rule__list { font-size: 0.85rem; display: grid; gap: 4px; }
.aj-rule__list li { padding-left: 1.1em; position: relative; }
.aj-rule__list li::before { content: "●"; position: absolute; left: 0; color: var(--aj-primary); font-size: 0.6em; top: 0.5em; }

.aj-stats { display: flex; justify-content: space-around; text-align: center; gap: 8px; }
.aj-stats__item { flex: 1; min-width: 0; }
.aj-stats__item dt { font-size: 0.75rem; color: var(--aj-muted); }
.aj-stats__item dd { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.aj-details { padding: 8px 16px; font-size: 0.85rem; color: #495057; }
.aj-details summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 700; touch-action: manipulation; }
.aj-table { width: 100%; margin: 4px 0 8px; border-collapse: collapse; }
.aj-table th, .aj-table td { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--aj-border); }
.aj-table td:first-child { font-weight: 800; color: var(--aj-primary); }

/* スポンサー枠(スタート画面は余白・枠線・背景を持たない) */
.aj-sponsor { text-align: center; }
.aj-sponsor--result { margin-top: 40px; } /* 操作ボタンから 35px 以上離す */

/* ---------- ② プレイ画面 ---------- */
.aj-screen--play {
  flex: none;
  gap: 12px;
  /* 長押しメニュー・テキスト選択の抑止(プレイ画面だけ) */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.aj-progress { text-align: center; font-size: 1.1rem; font-weight: 800; }

.aj-opponent { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.aj-opponent__title { font-size: 0.9rem; font-weight: 700; color: var(--aj-muted); }
.aj-hand-art { display: block; width: 120px; height: 120px; }
.aj-opponent__name { font-size: 1.5rem; font-weight: 800; line-height: 1.3; }

.aj-banner--play {
  min-height: 64px;
  padding: 12px;
  font-size: 1.5rem;
  line-height: 1.3;
  white-space: nowrap;
}

/* 正誤表示: 空のときも高さを確保する(回答ボタンの位置を動かさない) */
.aj-feedback {
  min-height: 3.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
}
.aj-feedback[data-result="correct"] { color: #1b7a34; }
.aj-feedback[data-result="incorrect"] { color: #c92a2a; }

.aj-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.aj-choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 96px;
  padding: 8px 4px;
  border: 3px solid #adb5bd;
  border-radius: 14px;
  background: var(--aj-card);
  color: var(--aj-text);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #ced4da;
}
.aj-choice:active:not(:disabled) { transform: translateY(2px); }
.aj-choice:disabled { cursor: default; color: var(--aj-text); }
.aj-choice__art { display: block; width: 48px; height: 48px; }
/* 正誤の印: 色だけでなく、枠の線の形・外側の輪・文字の札でも区別する(位置は動かさない) */
.aj-choice[data-state="correct"] { border-color: #1b7a34; background: #e6f4ea; box-shadow: 0 0 0 3px #1b7a34; }
.aj-choice[data-state="wrong"] { border-style: dashed; border-color: #c92a2a; background: #fff0f0; box-shadow: 0 0 0 3px #c92a2a; }
.aj-choice[data-state]::after {
  position: absolute;
  top: -10px;
  left: 50%;
  padding: 0 8px;
  transform: translateX(-50%);
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.75rem;
  line-height: 1.6;
}
.aj-choice[data-state="correct"]::after { content: "正解"; background: #1b7a34; }
.aj-choice[data-state="wrong"]::after { content: "不正解"; background: #c92a2a; }

/* ---------- ③ 結果画面 ---------- */
.aj-result__title { text-align: center; font-size: 1.4rem; font-weight: 800; }
.aj-result__main { position: relative; text-align: center; padding-top: 24px; }

.aj-new-record {
  display: inline-block; margin: 0 auto 8px; padding: 2px 14px;
  background: #c92a2a; color: #ffffff;
  font-weight: 900; letter-spacing: 0.08em; border-radius: 999px;
  animation: aj-blink 0.9s ease-in-out infinite alternate;
}
@keyframes aj-blink { from { transform: scale(1); } to { transform: scale(1.08); } }

.aj-result__rank {
  width: 96px; height: 96px; margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #ffffff;
  font-size: 3.4rem; font-weight: 900; line-height: 1;
  background: #5c6670;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: aj-pop 0.5s;
}
.aj-result__rank[data-rank="S"] { background: #b45309; }
.aj-result__rank[data-rank="A"] { background: var(--aj-red); }
.aj-result__rank[data-rank="B"] { background: var(--aj-blue); }
.aj-result__rank[data-rank="C"] { background: #257a35; }
.aj-result__rank[data-rank="D"] { background: #5c6670; }
@keyframes aj-pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
.aj-result__label { font-size: 1.1rem; font-weight: 800; }
.aj-result__note { font-weight: 700; color: var(--aj-muted); }
.aj-result__score { font-size: 2.6rem; font-weight: 900; line-height: 1.3; font-variant-numeric: tabular-nums; }
.aj-result__score small { margin-left: 2px; font-size: 1rem; }

.aj-actions { display: grid; gap: 12px; }

/* ---------- レスポンシブ ---------- */
@media (max-width: 380px) {
  .aj-app { padding-left: 16px; padding-right: 16px; }
}
@media (min-width: 600px) {
  .aj-app { margin-top: 16px; margin-bottom: 16px; border-radius: 20px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); }
}

/* 動きを減らす設定への配慮(アニメーションと遷移を無効にする。表示は変えない) */
@media (prefers-reduced-motion: reduce) {
  .aj-app *, .aj-app *::before, .aj-app *::after {
    animation: none !important;
    transition: none !important;
  }
}
