/* ==========================================================
   同じ形さがし - style.css
   スタート画面・結果画面の見た目は後出しじゃんけん(基準実装)に合わせる
   すべてのクラスに .sr- の接頭辞を付ける
   ========================================================== */

.sr-app [hidden] { display: none !important; }

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

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

.sr-app {
  /* ---- CSS 変数(共通要件 2.1) ---- */
  --sr-red: #E03131;
  --sr-blue: #1971C2;
  --sr-green: #2F9E44;
  --sr-yellow: #F59F00;
  --sr-bg: #f4f6fb;
  --sr-card: #ffffff;
  --sr-text: #212529;
  --sr-muted: #5c6670;
  --sr-primary: #3b5bdb;
  --sr-primary-dark: #2f49b3;
  --sr-border: #dee2e6;
  --sr-radius: 16px;
  /* ---- このゲームの色(SPEC 4.2 DS-22) ---- */
  --sr-ok: #257a35;
  --sr-ng: #c92a2a;

  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(--sr-bg);
  color: var(--sr-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(.sr-app) :is(h1, h2, p, dl, dd, ul, ol) { margin: 0; padding: 0; }
:where(.sr-app) :is(ul, ol) { list-style: none; }

/* ---------- トップバー(戻る／効果音) ---------- */
.sr-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}
.sr-app a.sr-back,
.sr-app .sr-sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sr-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;
}
.sr-app a.sr-back { color: var(--sr-primary); }
.sr-app .sr-sound-btn { color: var(--sr-primary); }
.sr-app .sr-sound-btn[aria-pressed="true"] { color: var(--sr-muted); }
.sr-app a.sr-back:hover { background: #edf2ff; color: var(--sr-primary-dark); }
.sr-app .sr-sound-btn:hover { background: #f1f3f5; }
.sr-app a.sr-back:active,
.sr-app .sr-sound-btn:active { transform: scale(0.94); }
.sr-back svg,
.sr-sound-btn svg { display: block; width: 22px; height: 22px; }
.sr-app a.sr-back:focus-visible,
.sr-app .sr-sound-btn:focus-visible,
.sr-app .sr-btn:focus-visible,
.sr-app .sr-choice:focus-visible,
.sr-app .sr-details summary:focus-visible { outline: 3px solid #ffd43b; outline-offset: 2px; }

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

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

/* ---------- ボタン ---------- */
.sr-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;
}
.sr-btn:active:not(:disabled) { transform: scale(0.97); }

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

/* ---------- 図形(見本・選択肢・図解・解説の複製で共通) ---------- */
.sr-board { display: block; overflow: visible; }
.sr-cell { fill: var(--sr-primary); stroke: #ffffff; stroke-width: 1; }

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

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

.sr-figure {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}
.sr-figure__item {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.sr-figure__board { width: 72px; height: 72px; }
.sr-figure__name { font-size: 0.85rem; font-weight: 700; }
.sr-figure__arrow { flex: none; display: block; width: 40px; height: 40px; color: var(--sr-primary); }
.sr-rule__example { margin-bottom: 12px; font-size: 0.85rem; text-align: center; }

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

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

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

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

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

.sr-sample { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px; }
.sr-sample__title { font-size: 0.95rem; font-weight: 800; color: var(--sr-muted); }
.sr-sample__board { width: 140px; height: 140px; }

.sr-question { text-align: center; font-size: 1.15rem; font-weight: 800; }

.sr-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.sr-choice {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  border: 3px solid #adb5bd;
  border-radius: 14px;
  background: var(--sr-card);
  color: var(--sr-text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #ced4da;
}
.sr-choice:active:not(:disabled) { transform: translateY(2px); }
.sr-choice:disabled { cursor: default; }
.sr-choice__board { width: 100%; height: 100%; max-width: 160px; max-height: 160px; }
/* 正誤: 色だけでなく、枠の太さ・線の形・印で見分ける(ボタンの大きさは変えない) */
.sr-choice[data-state="correct"] { border: 4px solid var(--sr-ok); background: #e6f4ea; }
.sr-choice[data-state="wrong"] { border: 4px dashed var(--sr-ng); background: #fff0f0; }
.sr-choice[data-fit="true"] { box-shadow: 0 0 0 4px var(--sr-ok), 0 3px 0 #ced4da; }
.sr-choice__mark {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}
.sr-choice__mark:empty { display: none; }
.sr-choice[data-state="correct"] .sr-choice__mark { color: var(--sr-ok); }
.sr-choice[data-state="wrong"] .sr-choice__mark { color: var(--sr-ng); }

/* 解説: 空のときも高さを確保する(選択肢の位置を動かさない) */
.sr-feedback {
  min-height: 6.5em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  text-align: center;
}
.sr-feedback__message { font-size: 1.2rem; font-weight: 800; line-height: 1.4; }
.sr-feedback__message[data-result="correct"] { color: var(--sr-ok); }
.sr-feedback__message[data-result="incorrect"] { color: var(--sr-ng); }
.sr-feedback__detail { font-size: 1rem; line-height: 1.5; }

/* 解説アニメーションの層と、見本の複製 */
.sr-fly-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.sr-fly { position: absolute; opacity: 0.85; transform-origin: 50% 50%; will-change: transform; }

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

.sr-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: sr-blink 0.9s ease-in-out infinite alternate;
}
@keyframes sr-blink { from { transform: scale(1); } to { transform: scale(1.08); } }

.sr-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: sr-pop 0.5s;
}
.sr-result__rank[data-rank="S"] { background: #b45309; }
.sr-result__rank[data-rank="A"] { background: var(--sr-red); }
.sr-result__rank[data-rank="B"] { background: var(--sr-blue); }
.sr-result__rank[data-rank="C"] { background: #257a35; }
.sr-result__rank[data-rank="D"] { background: #5c6670; }
@keyframes sr-pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
.sr-result__label { font-size: 1.1rem; font-weight: 800; }
.sr-result__note { font-weight: 700; color: var(--sr-muted); }
.sr-result__score { font-size: 2.6rem; font-weight: 900; line-height: 1.3; font-variant-numeric: tabular-nums; }
.sr-result__score small { margin-left: 2px; font-size: 1rem; }

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

/* ---------- レスポンシブ ---------- */
@media (min-width: 600px) {
  .sr-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) {
  .sr-app *, .sr-app *::before, .sr-app *::after {
    animation: none !important;
    transition: none !important;
  }
}
