/* ===== Backdrop & base ===== */
.mh-modal{
  position: fixed; inset: 0; z-index: 9999;
  display: grid; place-items: center;
  background: rgb(0 0 0 / .45);
  transition: opacity .18s ease;
}
.mh-modal[aria-hidden="true"]{ opacity:0; pointer-events:none; }
.mh-modal__backdrop{ position:absolute; inset:0; }

/* ===== Dialog (共通の最小枠) ===== */
.mh-modal__dialog{
  position: relative;
  width: min(900px, 90vw);
  max-height: min(88vh, 88dvh);
  margin: 0 auto;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 14px 40px rgb(0 0 0 / .35);
  overflow: hidden;
}
.mh-modal__x{ display:none; }      /* 右上×は使わない */
.mh-modal__title{ display:none; }  /* タイトルも非表示 */

/* ===== Content base: 1カラム（画像 → コントロール） ===== */
.mh-modal__content{
  display: grid;
  grid-template-columns: 1fr;
  row-gap: 14px;
  padding: 16px;
  box-sizing: border-box;
  max-height: min(86vh, 86dvh);
  overflow: auto;
}

/* Image block（角丸） */
.mh-modal__image{
  display: grid;
  place-items: center;
  min-width: 0;
}
.mh-modal__image img,
.mh-modal__image svg,
.mh-modal__image canvas{
  display:block;
  max-width:100%;
  height:auto;
  border-radius: 14px;           /* 角丸 */
  max-height: 60dvh;             /* ベースは控えめに、スクロール回避 */
}

/* Controls block（スピーカー＋ボタン） */
.mh-modal__control{
  display:grid;
  grid-template-rows:auto auto;
  justify-items:center;
  row-gap:12px;
  min-height:0;
}

.mh-modal__speaker{
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.mh-modal--no-image .mh-modal__image{ display:none !important; }

.mh-speaker__label{ display:none; }
#mh-speaker-toggle{
  appearance:none;
  width:42px; height:42px;
  border:0; border-radius:10px;
  background:#f1f1f1;
  font-size:20px; line-height:1;
  cursor:pointer;
}

.mh-modal__actions{
  display:flex;
  gap:12px;
  flex-wrap:nowrap;
  justify-content:center;
}
.mh-btn{
  appearance:none;
  border:0; border-radius:14px;
  padding:12px 18px;
  font-weight:800; font-size:16px;
  background:#111; color:#fff;
  cursor:pointer;
}
.mh-btn--ghost{ background:#fff; color:#111; outline:2px solid #111; }

/* ===== PC：小さめ・1カラム固定・スクロール無し ===== */
@media (min-width:1024px){
  .mh-modal__dialog{
    width: min(360px, 70vw);     /* さらにコンパクト */
    max-height: 80vh;
  }
  .mh-modal__content{
    grid-template-columns:1fr;   /* 1カラム固定 */
    max-height: 78vh;
  }
  .mh-modal__image img,
  .mh-modal__image svg,
  .mh-modal__image canvas{
    max-height: 48vh;            /* 画像控えめ＝全体が収まる */
  }
  .mh-modal__actions{ flex-direction:row; }
}

/* ===== スマホ縦（そのまま1カラム） ===== */
@media (max-width:1023px) and (orientation:portrait){
  .mh-modal__dialog{ width:min(680px, 92vw); }
  .mh-modal__image img,
  .mh-modal__image svg,
  .mh-modal__image canvas{ max-height: 64dvh; }
}

/* ===== スマホ横：余白を極小化する細身2カラム＋ボタン縦並び ===== */
@media (max-width:1023px) and (orientation:landscape){
  .mh-modal__dialog{
    width: min(500px, 70vw);     /* モーダル自体を細くして左右余白を削る */
    max-height: min(88vh, 88dvh);
  }
  .mh-modal__content{
    grid-template-columns: minmax(0,1fr) 100px; /* 左=画像 / 右=操作（細幅） */
    column-gap: 8px;
    padding: 10px;
    align-items: center;
    max-height: min(86vh, 86dvh);
  }
  .mh-modal__image{ grid-column:1/2; }
  .mh-modal__image img,
  .mh-modal__image svg,
  .mh-modal__image canvas{
    max-height: 70dvh;           /* 低背でも収まる上限 */
  }
  .mh-modal__control{
    grid-column:2/3;
    grid-template-rows:auto 1fr auto; /* 上:スピーカー / 伸縮 / 下:ボタン */
    align-content:stretch;
    height:100%;
    justify-items:end;
  }
  .mh-modal__speaker{ align-self:start; }
  .mh-modal__actions{
    align-self:end; justify-self:end;
    flex-direction:column;        /* ボタン縦並びで横幅節約 */
    gap:8px; width:100%;
  }
  .mh-btn{
    width:100%;
    padding:9px 12px;
    font-size:14px;
    border-radius:12px;
  }
  #mh-speaker-toggle{
    width:38px; height:38px; border-radius:9px; font-size:19px;
  }

  .mh-modal--no-image .mh-modal__content{
    grid-template-columns:1fr;
    align-items:start;
    justify-items:center;
    max-height: min(86vh, 86dvh);
  }
  .mh-modal--no-image .mh-modal__body{
    grid-column:1/2;
    width:100%;
  }
  .mh-modal--no-image .mh-modal__control{
    grid-column:1/2;
    grid-template-rows:auto auto;
    align-content:start;
    justify-items:center;
    height:auto;
    width:100%;
  }
  .mh-modal--no-image .mh-modal__speaker{
    align-self:center;
  }
  .mh-modal--no-image .mh-modal__actions{
    align-self:auto;
    justify-self:center;
    flex-direction:row;
    gap:10px;
    width:auto;
  }
}

.mh-results{
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.mh-results__level{
  font-weight: 600;
  margin: 5px 0;
}
.mh-results__score{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
}
.mh-results__score-main{ font-weight: 600; }
.mh-results__cleared{
  display: inline-flex;
  align-items: center;
}
.mh-results__cleared[hidden]{
  display: none !important;
}
.mh-results__oops{
  margin: 2px 0 6px;
  font-size: 15px;
  color: #b91c1c;
  font-weight: 600;
}
.mh-results__rank-btn{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffff00;
  color: #111;
  border: 2px solid#FFFF00;
  border-radius: 14px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: background-color .15s ease;
}
.mh-results__rank-btn span{ display: inline-flex; align-items: center; }
.mh-results__rank-btn:focus-visible,
.mh-results__rank-btn:hover{
  background: #ffeb3b;
}
.mh-results__rank-btn[hidden]{
  display: none;
}
.mh-results__rank-label{ font-weight: 600; }
.mh-results__rank-icon{ font-size: 20px; }
.mh-results__actions{
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.mh-results__share{
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.mh-results__share[hidden]{
  display: none !important;
}
.mh-share__btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #111;
  background: #111;
  color: #fff;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.mh-share__btn img,
.mh-share__btn span{
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mh-share__btn--facebook{
  background: none;
  border: none;
  border-radius: 50%;
  padding: 0;
  width: 42px;
  height: 42px;
}
.mh-share__btn--x{
  background: #111;
  border-color: #111;
}
.mh-share__btn--facebook img{
  width: 42px;
  height: 42px;
}
.mh-share__btn:focus-visible,
.mh-share__btn:hover{
  transform: translateY(-1px);
  opacity: 0.88;
}
.mh-results .mh-cleared-icon{
  width: 32px;
  height: 32px;
  font-size: 48x;
  line-height: 1;
  margin-left: 8px;
}
/* ===== 超低背Landscapeの保険 ===== */
@media (max-height:380px) and (orientation:landscape){
  .mh-modal__content{ grid-template-columns:minmax(0,1fr) 130px; }
  .mh-btn{ font-size:13px; padding:8px 10px; }
  .mh-modal--no-image .mh-modal__content{
    grid-template-columns:1fr;
    max-height: min(82vh, 82dvh);
  }
  .mh-modal--no-image .mh-modal__actions{
    flex-direction:row;
    gap:8px;
  }
}
/* 3,2,1,GO オーバーレイ */
#mh-countdown{
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: none;                   /* ← 初期は非表示 */
  place-items: center;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: clamp(48px, 14vw, 140px);
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0,0,0,.4);
}
#mh-countdown.is-on{ display: grid; }
