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

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

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

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

.sqt-app {
  /* ---- CSS 変数(共通要件 2.1) ---- */
  --sqt-red: #E03131;
  --sqt-blue: #1971C2;
  --sqt-green: #2F9E44;
  --sqt-yellow: #F59F00;
  --sqt-bg: #f4f6fb;
  --sqt-card: #ffffff;
  --sqt-text: #212529;
  --sqt-muted: #5c6670;
  --sqt-primary: #3b5bdb;
  --sqt-primary-dark: #2f49b3;
  --sqt-border: #dee2e6;
  --sqt-radius: 16px;
  /* ---- マスの色(SPEC 4.2 DS-22) ---- */
  --sqt-cell: #4c6ef5;
  --sqt-cell-border: #364fc7;
  --sqt-lit: #ffd43b;
  --sqt-lit-border: #e67700;
  --sqt-wrong: #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(--sqt-bg);
  color: var(--sqt-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(.sqt-app) :is(h1, h2, p, dl, dd, ul, ol) { margin: 0; padding: 0; }
:where(.sqt-app) :is(ul, ol) { list-style: none; }

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

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

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

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

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

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

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

/* 図解: 3×3 のマスと、光る順番の数字 */
.sqt-figure { display: flex; justify-content: center; margin-bottom: 8px; }
.sqt-figure__svg { display: block; width: 112px; height: 112px; }
.sqt-figure__cell { fill: var(--sqt-cell); stroke: var(--sqt-cell-border); stroke-width: 2; }
.sqt-figure__cell--lit { fill: var(--sqt-lit); stroke: var(--sqt-lit-border); stroke-width: 3; }
.sqt-figure__order {
  fill: var(--sqt-text);
  font-size: 22px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
}
.sqt-rule__example { margin-bottom: 12px; font-size: 0.85rem; text-align: center; }

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

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

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

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

/* ---------- ② プレイ画面 ---------- */
.sqt-screen--play {
  flex: none;
  gap: 12px;
  /* 長押しメニュー・テキスト選択の抑止(プレイ画面だけ) */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.sqt-status { display: flex; justify-content: space-between; gap: 8px; font-size: 1.05rem; font-weight: 800; }

/* 案内: 文言が変わっても高さを変えない(NFR-004) */
.sqt-message {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3em;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
}

/* 盤面: 3 列 × 3 行。縦が短い画面(横向き)では盤面を小さくする(NFR-002) */
.sqt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 330px, max(160px, calc(100vh - 190px)));
  margin: 0 auto;
}
.sqt-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 3px solid var(--sqt-cell-border);
  border-radius: 14px;
  background: var(--sqt-cell);
  color: var(--sqt-text);
  font: inherit;
  opacity: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms ease, border-color 150ms ease;
}
/* 提示中も盤面を暗くしない(DS-22) */
.sqt-cell:disabled { opacity: 1; cursor: default; }
/* 点灯・タップの光: 色に加えて枠を太くする(色だけで見分けさせない。NFR-003) */
.sqt-cell[data-lit="true"],
.sqt-cell[data-tap="true"] { background: var(--sqt-lit); border: 6px solid var(--sqt-lit-border); }
.sqt-cell[data-state="wrong"] { background: var(--sqt-wrong); border-color: var(--sqt-wrong); }
.sqt-cell[data-state="answer"] { background: var(--sqt-lit); border: 6px solid var(--sqt-lit-border); }
/* 印(○・×)はマスの中に重ねる(マスの大きさ・位置を変えない) */
.sqt-cell__mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}
.sqt-cell__mark:empty { display: none; }
.sqt-cell[data-state="wrong"] .sqt-cell__mark { color: #ffffff; }
.sqt-cell[data-state="answer"] .sqt-cell__mark { color: var(--sqt-text); }

.sqt-replay { min-height: 52px; width: min(100%, 330px); margin: 0 auto; font-size: 1.05rem; }
.sqt-replay:disabled { cursor: default; color: var(--sqt-muted); }

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

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

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

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

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