/* ==========================================================
   時計よみクイズ - style.css
   見た目は atodashi-janken(基準実装)に合わせる
   すべてのクラス・CSS 変数に clk- プレフィックスを付与
   ========================================================== */

[hidden] { display: none !important; }

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

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

.clk-app {
  /* ---- CSS 変数(基準実装と共通 + 正解・不正解の色) ---- */
  --clk-bg: #f4f6fb;
  --clk-card: #ffffff;
  --clk-text: #212529;
  --clk-muted: #5c6670;
  --clk-primary: #3b5bdb;
  --clk-primary-dark: #2f49b3;
  --clk-border: #dee2e6;
  --clk-red: #E03131;
  --clk-blue: #1971C2;
  --clk-ok: #1e7b34;
  --clk-ng: #c92a2a;
  --clk-radius: 16px;
  --clk-anim-ms: 1200ms;

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

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

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

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

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

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

/* ---------- 時計(SVG) ---------- */
.clk-clock { display: block; width: 100%; height: auto; }
.clk-clock__face { fill: #ffffff; stroke: #1f2933; stroke-width: 3; }
.clk-clock__tick { stroke: #1f2933; stroke-width: 2; stroke-linecap: round; }
.clk-clock__numeral { fill: #1f2933; font-size: 17px; font-weight: 700; font-family: inherit; }
.clk-clock__hand {
  /* 針は原点(0,0)を中心に、CSS の transform で回す。累積角度を指定するので、逆回転しない */
  transform-origin: 0 0;
  stroke-linecap: round;
  transition: transform var(--clk-anim-ms) ease-in-out;
}
.clk-clock__hand--hour { stroke: #1f2933; stroke-width: 8; }
.clk-clock__hand--minute { stroke: var(--clk-primary); stroke-width: 5; }
.clk-clock__center { fill: #1f2933; }

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

.clk-rule__lead { text-align: center; font-size: 1.05rem; margin-bottom: 12px; }

/* ルールの図解: 時計 1 台と、針の凡例 */
.clk-diagram {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.clk-diagram__clock { flex: none; width: 120px; }
.clk-legend { display: grid; gap: 8px; font-size: 0.95rem; font-weight: 700; }
.clk-legend__item { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.clk-legend__swatch { display: block; flex: none; width: 24px; border-radius: 999px; }
.clk-legend__swatch--hour { height: 8px; background: #1f2933; }
.clk-legend__swatch--minute { height: 5px; background: var(--clk-primary); }

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

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

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

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

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

.clk-question { display: grid; gap: 12px; text-align: center; }
.clk-question__text { font-size: 1.25rem; font-weight: 800; line-height: 1.4; }

/* 時計のコンテナ: 1 台のときは幅 min(100%, 200px)、2 台のときは 2 列で均等に並べる */
.clk-clocks { display: flex; justify-content: center; gap: 12px; }
.clk-clocks__item { flex: 0 1 auto; width: min(100%, 200px); min-width: 0; }
.clk-clocks[data-count="2"] .clk-clocks__item { flex: 1 1 0; width: auto; max-width: 200px; }
.clk-clocks__caption { margin-top: 4px; font-size: 0.9rem; font-weight: 800; text-align: center; }

.clk-choices { display: grid; gap: 8px; }
.clk-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 3px solid #adb5bd;
  border-radius: 14px;
  background: var(--clk-card);
  color: var(--clk-text);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.3;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #ced4da;
}
.clk-choice:active:not(:disabled) { transform: translateY(2px); }
/* 回答後も文字を薄くしない(DS-22) */
.clk-choice:disabled { cursor: default; color: var(--clk-text); }
/* ○ ×の印の場所は、回答前から確保する(ボタンの大きさと位置を動かさない) */
.clk-choice__mark { display: inline-block; min-width: 1.2em; text-align: center; }
/* 正誤の印: 色だけでなく、○ ×・枠の線の形・外側の輪でも区別する */
.clk-choice[data-state="correct"] { border-color: var(--clk-ok); background: #e6f4ea; box-shadow: 0 0 0 3px var(--clk-ok); }
.clk-choice[data-state="incorrect"] { border-style: dashed; border-color: var(--clk-ng); background: #fff0f0; box-shadow: 0 0 0 3px var(--clk-ng); }

/* 正誤バッジ: 空のときも高さを確保する(解説カードが出ても選択肢の位置を動かさない) */
.clk-badge {
  min-height: 2em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 900;
  text-align: center;
}
.clk-badge[data-result="correct"] { color: var(--clk-ok); }
.clk-badge[data-result="incorrect"] { color: var(--clk-ng); }

.clk-explanation { display: grid; gap: 12px; }
.clk-explanation__text { font-size: 1.05rem; font-weight: 700; line-height: 1.6; }

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

.clk-new-record-wrap { min-height: 0; }
.clk-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: clk-blink 0.9s ease-in-out infinite alternate;
}
@keyframes clk-blink { from { transform: scale(1); } to { transform: scale(1.08); } }

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

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

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