/* ==========================================================
   間違い探し - style.css
   すべてのクラス名に sfd- の接頭辞を付ける(WordPress 埋め込み時にテーマの CSS と干渉させない)。
   状態は data-* / aria-* 属性で表す。
   ========================================================== */

/* hidden 属性で確実に隠す(display を指定した要素でも隠れるように) */
[hidden] { display: none !important; }

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

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

.sfd-app {
  --sfd-bg: #f4f6fb;
  --sfd-card: #ffffff;
  --sfd-text: #212529;
  --sfd-muted: #5c6670;
  --sfd-primary: #3b5bdb;
  --sfd-primary-dark: #2f49b3;
  --sfd-primary-soft: #edf2ff;
  --sfd-border: #dee2e6;
  --sfd-red: #E03131;
  --sfd-blue: #1971C2;
  --sfd-green: #2F9E44;
  --sfd-yellow: #F59F00;
  /* ランクバッジ用(白文字で 4.5:1 以上を保つため、判定色より濃くする) */
  --sfd-rank-s: #b45309;
  --sfd-rank-a: #c92a2a;
  --sfd-rank-b: #1864ab;
  --sfd-rank-c: #237a36;
  --sfd-rank-d: #5c6670;
  --sfd-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-x: clip;
  background: var(--sfd-bg);
  color: var(--sfd-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(.sfd-app) :is(h1, h2, p, dl, dd, ul, ol, figure) { margin: 0; padding: 0; }
:where(.sfd-app) :is(ul, ol) { list-style: none; }

.sfd-app a,
.sfd-app button,
.sfd-app summary { touch-action: manipulation; }

/* ---------- トップバー ---------- */
.sfd-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 4px;
}
/* 戻るリンクが隠れている間も、音のボタンは右端に置く */
.sfd-topbar .sfd-sound-btn { margin-left: auto; }
.sfd-app a.sfd-back,
.sfd-app .sfd-sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sfd-card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  cursor: pointer;
}
.sfd-app a.sfd-back { color: var(--sfd-primary); }
.sfd-app .sfd-sound-btn { color: var(--sfd-text); }
.sfd-back svg,
.sfd-sound-btn svg { display: block; width: 22px; height: 22px; }
.sfd-app a.sfd-back:focus-visible,
.sfd-sound-btn:focus-visible,
.sfd-btn:focus-visible,
.sfd-details summary:focus-visible { outline: 3px solid #ffd43b; outline-offset: 2px; }

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

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

/* ---------- ボタン ---------- */
.sfd-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;
}
.sfd-btn:active:not(:disabled) { transform: scale(0.97); }
.sfd-btn:disabled { opacity: 1; background: #6c757d; color: #ffffff; box-shadow: none; cursor: not-allowed; }
.sfd-btn-primary { background: var(--sfd-primary); color: #ffffff; box-shadow: 0 4px 0 var(--sfd-primary-dark); }
.sfd-btn-primary:hover:not(:disabled) { background: var(--sfd-primary-dark); }
.sfd-btn-cta { min-height: 64px; font-size: 1.25rem; }
.sfd-app a.sfd-btn-x {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #111111; color: #ffffff; text-decoration: none;
}
.sfd-btn-ghost { background: transparent; color: var(--sfd-muted); border: 1px solid var(--sfd-border); min-height: 44px; }

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

.sfd-howto { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 14px; }
.sfd-howto svg { display: block; width: 100%; max-width: 320px; height: auto; }
.sfd-howto-caption { font-size: 0.95rem; font-weight: 800; color: var(--sfd-primary); }

.sfd-rule-list { font-size: 0.95rem; display: grid; gap: 6px; }
.sfd-rule-list li { padding-left: 1.1em; position: relative; }
.sfd-rule-list li::before { content: "●"; position: absolute; left: 0; color: var(--sfd-primary); font-size: 0.6em; top: 0.55em; }

.sfd-record { display: flex; justify-content: space-around; text-align: center; gap: 8px; }
.sfd-record-cell { flex: 1; min-width: 0; }
.sfd-record-cell dt { font-size: 0.8rem; color: var(--sfd-muted); }
.sfd-record-cell dd { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sfd-record-cell:last-child dd { color: var(--sfd-primary); }

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

/* ---------- プレイ画面(長押しメニュー・テキスト選択を抑止する) ---------- */
.sfd-play {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.sfd-hud {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--sfd-card);
  border-radius: var(--sfd-radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.sfd-hud-remaining { flex: 1; font-size: 1.25rem; font-weight: 800; }
.sfd-hud-elapsed { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--sfd-primary); }
.sfd-btn-hint { width: auto; min-width: 88px; min-height: 48px; padding: 8px 16px; }

.sfd-boards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 12px;
}

/* 盤面は正方形。一辺は 176 px 以上 480 px 以下。2 枚は同じ大きさ */
.sfd-board {
  display: block;
  width: 100%;
  min-width: 176px;
  max-width: 480px;
  height: auto;
  aspect-ratio: 1 / 1;
  overflow: visible;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sfd-cell { cursor: pointer; }
.sfd-cell-bg { fill: #FFFFFF; stroke: #999999; stroke-width: 1.5; }
.sfd-cell[data-found="true"] .sfd-cell-bg { fill: #FFF3C4; }
.sfd-shape { stroke: #333333; stroke-width: 3; stroke-linejoin: round; pointer-events: none; }
.sfd-ring { fill: none; stroke: #E60033; stroke-width: 6; pointer-events: none; }
.sfd-hint { fill: rgba(255, 200, 0, 0.35); stroke: #8a6100; stroke-width: 3; stroke-dasharray: 10 7; pointer-events: none; }
.sfd-miss {
  fill: #666666;
  stroke: #FFFFFF;
  stroke-width: 6;
  paint-order: stroke;
  font-size: 72px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* ---------- 結果画面 ---------- */
.sfd-result-title { text-align: center; font-size: 1.4rem; font-weight: 800; }
.sfd-result-main { text-align: center; padding-top: 24px; }
.sfd-new-record {
  display: inline-block; margin-bottom: 8px; padding: 2px 14px;
  background: var(--sfd-rank-a); color: #ffffff;
  font-weight: 900; letter-spacing: 0.08em; border-radius: 999px;
}
.sfd-rank-badge {
  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: var(--sfd-rank-d);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.sfd-rank-badge[data-rank="S"] { background: var(--sfd-rank-s); }
.sfd-rank-badge[data-rank="A"] { background: var(--sfd-rank-a); }
.sfd-rank-badge[data-rank="B"] { background: var(--sfd-rank-b); }
.sfd-rank-badge[data-rank="C"] { background: var(--sfd-rank-c); }
.sfd-rank-badge[data-rank="D"] { background: var(--sfd-rank-d); }
.sfd-result-label { font-size: 1.2rem; font-weight: 800; }
.sfd-result-score { font-size: 2.6rem; font-weight: 900; line-height: 1.3; font-variant-numeric: tabular-nums; }
.sfd-result-score small { font-size: 1rem; margin-left: 2px; }

.sfd-breakdown { display: flex; flex-direction: column; gap: 8px; }
.sfd-breakdown-item { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; min-width: 0; }
.sfd-breakdown-item dt { font-size: 0.95rem; color: var(--sfd-muted); }
.sfd-breakdown-item dd { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }

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

/* ---------- レスポンシブ ---------- */
@media (max-width: 380px) {
  .sfd-app { padding-left: 12px; padding-right: 12px; }
}
/* 横向きで幅 600 px 以上のときだけ、盤面を左右に並べる(A が左、B が右) */
@media (orientation: landscape) and (min-width: 600px) {
  .sfd-boards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 600px) {
  .sfd-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) {
  .sfd-app *, .sfd-app *::before, .sfd-app *::after {
    animation: none !important;
    transition: none !important;
  }
}
