:root {
  color-scheme: dark;
  --bg0: #0e1528;
  --bg1: #1a2744;
  --ink: #f5f0e6;
  --muted: #a8b4cc;
  --pass: #3dd68c;
  --fail: #ff6b7a;
  --accent: #ffd166;
  --paper: #fff8e8;
  --mine: #ff5c7a;
  --panel: rgba(14, 21, 40, 0.92);
  /* ノッチ・ホームインジケータ対応 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  /* ヘッダー＋余白の概算（ステージ高さを算出用。フッターヒントは廃止） */
  --chrome-h: 5.75rem;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  /* iOS のアドレスバー変動に強いビューポート高さ */
  height: 100%;
  height: -webkit-fill-available;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: radial-gradient(ellipse at 50% 0%, #24365f 0%, var(--bg0) 55%);
  color: var(--ink);
  overflow-x: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

#app {
  width: min(960px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 0.5rem 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: min(100dvh - var(--safe-top) - var(--safe-bottom), 100%);
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  padding: 0 0.15rem;
  flex-shrink: 0;
}

.title {
  margin: 0;
  font-size: clamp(1.15rem, 4.5vw, 1.7rem);
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: clamp(0.78rem, 2.8vw, 0.9rem);
  line-height: 1.3;
}

.hud-right {
  display: flex;
  gap: 0.45rem;
  flex-shrink: 0;
}

.stat {
  min-width: 3.1rem;
  text-align: center;
  padding: 0.3rem 0.45rem;
  border-radius: 0.65rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 0.08rem;
}

.stat span:last-child {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.95rem, 3.2vw, 1.05rem);
}

/*
 * ゲームステージ: 常に 900:560 を維持（歪み防止）
 * 幅 = min(親幅, 画面に収まる高さから逆算) にしてから aspect-ratio を適用する。
 * max-height だけ指定すると幅 100% のまま縦だけ縮み、キャンバスが潰れる。
 */
.stage-wrap {
  --stage-max-h: min(
    78dvh,
    calc(100dvh - var(--chrome-h) - var(--safe-top) - var(--safe-bottom))
  );
  position: relative;
  width: min(100%, calc(var(--stage-max-h) * 900 / 560));
  aspect-ratio: 900 / 560;
  margin-inline: auto;
  border-radius: clamp(0.65rem, 2vw, 1rem);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  background: var(--bg1);
  flex-shrink: 0;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  /* object-fit 相当: 親が aspect を保つので伸縮なし */
  cursor: crosshair;
  background: #1a2744;
  touch-action: none;
  /* iOS でキャンバスがぼやけないよう */
  image-rendering: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0.4rem;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: rgba(8, 12, 24, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s ease;
  z-index: 5;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(28rem, 100%);
  max-height: 100%;
  margin: auto 0;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: clamp(0.75rem, 2.5vw, 1rem);
  padding: 0.75rem 0.85rem 0.65rem;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.badge {
  display: inline-block;
  margin: 0 0 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: clamp(0.65rem, 2.4vw, 0.72rem);
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(255, 209, 102, 0.12);
  flex-shrink: 0;
}

.panel h2 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.05rem, 4vw, 1.35rem);
  flex-shrink: 0;
  line-height: 1.25;
}

/* 本文・難易度はスクロール、ボタンは下に固定 */
.panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0 0 0.45rem;
  padding-right: 0.1rem;
  text-align: left;
}

.panel-body {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: clamp(0.8rem, 2.8vw, 0.88rem);
  text-align: left;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.panel-body strong {
  color: var(--ink);
}

/* オーバーレイ本文: ルール / ヒント / メタ をブロックで整理（PC・スマホ共通） */
.msg-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.msg-block {
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.msg-block > p {
  margin: 0;
}

.msg-block > p + p {
  margin-top: 0.4rem;
}

.msg-block--accent {
  background: rgba(255, 209, 102, 0.08);
  border-color: rgba(255, 209, 102, 0.28);
}

.msg-block--muted {
  background: transparent;
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.1);
  padding: 0.4rem 0.55rem;
}

.msg-block--ok {
  background: rgba(61, 214, 140, 0.08);
  border-color: rgba(61, 214, 140, 0.3);
}

.msg-block--ng {
  background: rgba(255, 107, 122, 0.08);
  border-color: rgba(255, 107, 122, 0.3);
}

.msg-label {
  display: inline-block;
  margin: 0 0 0.35rem !important;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(255, 209, 102, 0.12);
  line-height: 1.3;
}

.msg-block--ok .msg-label {
  color: var(--pass);
  background: rgba(61, 214, 140, 0.14);
}

.msg-block--ng .msg-label {
  color: var(--fail);
  background: rgba(255, 107, 122, 0.14);
}

.msg-meta {
  font-size: 0.9em;
  opacity: 0.9;
}

.msg-kind {
  font-size: 0.85em;
  opacity: 0.75;
}

.msg-steps {
  font-size: 0.88em;
  line-height: 1.45;
  color: var(--ink);
  opacity: 0.92;
}

.msg-note {
  font-size: 0.88em;
  opacity: 0.8;
}

.msg-feature {
  margin: 0.15rem 0 0;
  font-size: 1.12em;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.35;
}

.msg-list {
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
}

.msg-list li {
  position: relative;
  padding: 0.2rem 0 0.2rem 1rem;
  color: var(--ink);
  font-weight: 600;
}

.msg-list li::before {
  content: "·";
  position: absolute;
  left: 0.15rem;
  color: var(--accent);
  font-weight: 800;
}

.msg-detail {
  margin-top: 0.35rem;
  color: var(--muted);
  line-height: 1.55;
}

.msg-detail strong {
  color: var(--ink);
}

.panel-actions {
  flex-shrink: 0;
  padding-top: 0.3rem;
  background: linear-gradient(180deg, transparent, rgba(14, 21, 40, 0.98) 28%);
}

.memo-preview {
  display: flex;
  justify-content: center;
  margin: 0 auto 0.85rem;
}

.memo-preview.hidden {
  display: none;
}

.diff-picker {
  margin: 0.65rem 0 0;
  text-align: left;
}

.diff-picker.hidden {
  display: none;
}

.diff-label {
  margin: 0 0 0.4rem;
  font-size: clamp(0.72rem, 2.5vw, 0.78rem);
  color: var(--muted);
  letter-spacing: 0.04em;
}

.diff-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.diff-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  padding: 0.55rem 0.35rem;
  /* スマホで押しやすい最低タッチ領域 */
  min-height: 2.75rem;
  cursor: pointer;
  text-align: center;
  line-height: 1.25;
  transition: border-color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.diff-btn:hover {
  border-color: rgba(255, 209, 102, 0.45);
}

.diff-btn:active {
  transform: scale(0.98);
}

.diff-btn.active {
  border-color: var(--accent);
  background: rgba(255, 209, 102, 0.12);
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.2);
}

.diff-n {
  display: block;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
}

.diff-name {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  margin: 0.15rem 0 0.1rem;
}

.diff-desc {
  display: block;
  font-size: 0.62rem;
  color: var(--muted);
}

.memo-card {
  width: 5.2rem;
  height: 6.6rem;
  border-radius: 0.35rem;
  background: linear-gradient(160deg, #fffaf0, #f3e6c8);
  color: #2a2430;
  border: 2px solid #d9c49a;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  position: relative;
  transform: rotate(-4deg);
}

.memo-card::after {
  content: "ME";
  position: absolute;
  top: 0.35rem;
  right: 0.3rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--mine);
  color: white;
  font-size: 0.55rem;
  display: grid;
  place-items: center;
  letter-spacing: 0;
}

#start-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.5rem;
  min-height: 2.85rem;
  font-size: clamp(0.9rem, 3.2vw, 0.98rem);
  font-weight: 700;
  color: #1a1520;
  background: linear-gradient(180deg, #ffe08a, var(--accent));
  box-shadow: 0 10px 22px rgba(255, 209, 102, 0.28);
  cursor: pointer;
  width: min(100%, 20rem);
  max-width: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#start-btn:hover {
  filter: brightness(1.05);
}

#start-btn:active {
  transform: scale(0.98);
}

.btn-secondary {
  appearance: none;
  display: block;
  margin: 0.45rem auto 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
  min-height: 2.55rem;
  font-size: clamp(0.82rem, 2.8vw, 0.9rem);
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  width: min(100%, 20rem);
  max-width: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-secondary:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.1);
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-secondary.hidden {
  display: none;
}

.msg-record {
  margin: 0.45rem 0 0 !important;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #1a1520;
  background: linear-gradient(90deg, #ffe08a, #ffd166, #ffb347);
  box-shadow: 0 4px 12px rgba(255, 209, 102, 0.35);
}

.panel-hint {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: clamp(0.65rem, 2.4vw, 0.72rem);
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  align-items: center;
}

.panel-hint-row {
  display: block;
}

/* 画面最下部のヒント行は廃止（PC / スマホとも。内容はパネル内に集約） */
.help {
  display: none !important;
}

/* スマホ用タッチパッド（既定は非表示。縦プレイ中のみ表示） */
.touch-pad {
  display: none;
  flex-shrink: 0;
  width: 100%;
  margin-top: 0.35rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-pad-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  /* ヒント行なしのためパディングをやや詰める */
  padding: 0.65rem 0.7rem;
  border-radius: 1.1rem;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(14, 21, 40, 0.92) 100%
  );
  border: 1px solid rgba(255, 209, 102, 0.28);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.touch-pad-track {
  position: relative;
  /* 3.4rem × 1.5 ≈ 5.1rem */
  height: 5.1rem;
  border-radius: 1.2rem;
  background:
    linear-gradient(
      90deg,
      rgba(255, 209, 102, 0.12) 0%,
      rgba(255, 255, 255, 0.06) 50%,
      rgba(61, 214, 140, 0.12) 100%
    );
  border: 1px dashed rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.touch-pad-track::before {
  content: "教授";
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.68rem;
  color: rgba(168, 180, 204, 0.7);
  pointer-events: none;
}

.touch-pad-track::after {
  content: "合格";
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.68rem;
  color: rgba(61, 214, 140, 0.8);
  pointer-events: none;
}

.touch-pad-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  /* 2.6rem × 1.5 ≈ 3.9rem はやや大きすぎるので 3.2rem */
  width: 3.2rem;
  height: 3.2rem;
  margin: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--accent) 55%, #d4a017);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 4px 12px rgba(255, 209, 102, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
  will-change: left;
  transition: left 0.06s linear;
}

.touch-pad-knob.is-active {
  background: radial-gradient(circle at 35% 30%, #ffc2d1, #ff8fab 55%, #c44569);
  border-color: rgba(255, 255, 255, 0.7);
  box-shadow:
    0 0 0 3px rgba(255, 143, 171, 0.35),
    0 4px 14px rgba(255, 92, 122, 0.4);
}

/* touch-pad-hint はスマホでは表示しない（削除済み） */

/* ========== タブレット以下 ========== */
@media (max-width: 768px) {
  :root {
    --chrome-h: 6.5rem;
  }

  #app {
    padding: 0.4rem 0.5rem 0.7rem;
  }

  .hud {
    gap: 0.5rem;
  }

  .stat {
    min-width: 2.9rem;
    padding: 0.28rem 0.4rem;
  }
}

/* ========== スマホ（縦） ========== */
@media (max-width: 640px) {
  :root {
    --chrome-h: 6.75rem;
  }

  #app {
    padding: 0.35rem 0.4rem 0.6rem;
  }

  .hud {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
  }

  .hud-left {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .hud-left .subtitle {
    margin: 0;
    text-align: right;
    flex-shrink: 0;
  }

  .hud-right {
    justify-content: stretch;
    gap: 0.35rem;
  }

  .stat {
    flex: 1 1 0;
    min-width: 0;
  }

  .diff-options {
    grid-template-columns: 1fr;
  }

  .diff-btn {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 0.55rem;
    text-align: left;
    padding: 0.6rem 0.75rem;
    min-height: 3.1rem;
  }

  .diff-n {
    grid-row: 1 / 3;
    align-self: center;
    font-size: 1.4rem;
  }

  .diff-name {
    margin-top: 0;
  }

  .panel {
    padding: 0.7rem 0.7rem 0.55rem;
  }

  .panel-body {
    font-size: 0.84rem;
  }

  .msg-block {
    padding: 0.5rem 0.55rem;
  }

  #game {
    cursor: auto;
  }

  .memo-card {
    width: 4.6rem;
    height: 5.9rem;
    font-size: 0.88rem;
  }
}

/*
 * スマホ縦向き: 縦長画面を活かす
 * - 開始前: ステージ高さ制限なし（残り高さをフル使用）
 * - プレイ中: 高さいっぱいに拡大し、横スクロールで全域を表示
 * - 操作は下部タッチパッド（団扇を指で隠さない）
 */
@media (max-width: 640px) and (orientation: portrait) {
  :root {
    /* タッチパッド分（ヒント行なし） */
    --touch-pad-h: 7.5rem;
  }

  html,
  body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    /* 縦スクロールはアプリ内オーバーレイに任せる */
    overscroll-behavior: none;
  }

  #app {
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    padding: 0.3rem 0.35rem 0.45rem;
    box-sizing: border-box;
  }

  /* 開始前・結果: 残りの縦スペースをすべて使う（高さ制限なし） */
  .stage-wrap {
    --stage-max-h: none;
    width: 100%;
    max-width: none;
    aspect-ratio: auto;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    margin-inline: 0;
    border-radius: 0.75rem;
  }

  /* オーバーレイはステージ全体（縦いっぱい）を使う */
  .overlay {
    padding: 0.45rem 0.35rem;
    justify-content: stretch;
    align-items: stretch;
    overflow: hidden;
  }

  .panel {
    width: 100%;
    max-width: 28rem;
    /* ステージ高さ制限は撤廃。パネルは縦スペースを使いつつボタンを固定 */
    max-height: none;
    height: 100%;
    margin: 0 auto;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .panel-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel-actions {
    flex-shrink: 0;
  }

  /*
   * プレイ中: 高さを最大活用し、幅はアスペクト比から決まる
   * → 画面より広くなるので横スクロール
   */
  .stage-wrap.is-play {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    /* 操作は下部パッド。キャンバス上の誤タッチは無視 */
    touch-action: none;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 209, 102, 0.45) transparent;
  }

  .stage-wrap.is-play::-webkit-scrollbar {
    height: 4px;
  }

  .stage-wrap.is-play::-webkit-scrollbar-thumb {
    background: rgba(255, 209, 102, 0.4);
    border-radius: 999px;
  }

  .stage-wrap.is-play #game {
    display: block;
    width: auto;
    height: 100%;
    max-width: none;
    /* 高さ 100% を基準に 900:560 で幅を決定 → 画面より広くなり横スクロール */
    aspect-ratio: 900 / 560;
  }

  /* プレイ中はオーバーレイ非表示のためキャンバスのみ */
  .stage-wrap:not(.is-play) #game {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  body.game-play {
    /* プレイ中はページ全体のスクロール・バウンスを止める */
    touch-action: none;
    overflow: hidden;
  }

  /* 下部に指置き領域（団扇はキャンバス側で見える） */
  body.game-play .touch-pad {
    display: block;
    margin-top: 0.4rem;
    margin-bottom: 0.1rem;
    order: 2;
  }

  /* レイアウト順: HUD → ステージ → タッチパッド（ヒントなし） */
  body.game-play #app {
    display: flex;
    flex-direction: column;
  }

  body.game-play .stage-wrap {
    order: 1;
  }

  body.game-play .hud {
    order: 0;
  }
}

/* ========== 極小画面（〜360px） ========== */
@media (max-width: 360px) {
  :root {
    --chrome-h: 7rem;
  }

  .title {
    font-size: 1.05rem;
  }

  .stat-label {
    font-size: 0.6rem;
  }

  .stat span:last-child {
    font-size: 0.9rem;
  }

  .panel-body {
    font-size: 0.8rem;
    line-height: 1.5;
  }

  #start-btn {
    padding: 0.75rem 1.1rem;
    font-size: 0.88rem;
  }
}

/* ========== 横向き（短い高さ） ========== */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --chrome-h: 4.25rem;
  }

  #app {
    padding: 0.25rem 0.5rem 0.4rem;
  }

  .stage-wrap {
    --stage-max-h: calc(100dvh - var(--chrome-h) - var(--safe-top) - var(--safe-bottom));
  }

  .hud {
    flex-direction: row;
    align-items: center;
    margin-bottom: 0.25rem;
    gap: 0.5rem;
  }

  .hud-left {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
  }

  .title {
    font-size: 1rem;
  }

  .subtitle {
    font-size: 0.72rem;
    margin: 0;
  }

  .stat {
    min-width: 2.6rem;
    padding: 0.15rem 0.35rem;
  }

  .stat-label {
    font-size: 0.58rem;
  }

  .stat span:last-child {
    font-size: 0.88rem;
  }

  .panel {
    padding: 0.45rem 0.65rem 0.4rem;
    border-radius: 0.65rem;
  }

  .panel h2 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
  }

  .badge {
    margin-bottom: 0.15rem;
    font-size: 0.62rem;
  }

  .panel-body {
    font-size: 0.78rem;
    line-height: 1.4;
  }

  .diff-options {
    grid-template-columns: repeat(3, 1fr);
  }

  .diff-btn {
    display: block;
    min-height: 2.4rem;
    padding: 0.35rem 0.25rem;
    text-align: center;
  }

  .diff-n {
    grid-row: auto;
    font-size: 1rem;
  }

  .diff-desc {
    display: none;
  }

  #start-btn {
    min-height: 2.4rem;
    padding: 0.5rem 1.2rem;
    font-size: 0.85rem;
  }

  .panel-hint {
    font-size: 0.62rem;
    margin-top: 0.3rem;
  }

  .msg-block {
    padding: 0.35rem 0.45rem;
  }

  .msg-label {
    font-size: 0.62rem;
    margin-bottom: 0.25rem !important;
  }

  .memo-card {
    width: 3.6rem;
    height: 4.6rem;
    font-size: 0.75rem;
  }
}

/* ========== 横向き + スマホ幅 ========== */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .hud-left .subtitle {
    display: none;
  }

  .panel-scroll {
    margin-bottom: 0.3rem;
  }
}

/* ホバーが使えないタッチ端末 */
@media (hover: none) {
  .diff-btn:hover {
    border-color: rgba(255, 255, 255, 0.12);
  }

  .diff-btn.active:hover {
    border-color: var(--accent);
  }

  #start-btn:hover {
    filter: none;
  }

  #game {
    cursor: auto;
  }
}

/* 入力フォーカス時の拡大防止（iOS）: 16px 以上推奨だが本アプリはボタン中心 */
/* prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .overlay,
  .diff-btn,
  #start-btn {
    transition: none;
  }
}
