/* まるっとスライドパズル — play.css（あそぶ画面）
 * スマホ縦：上に札と手数／まん中に盤（正方形）／下にボタン4つ。
 * 横長でせまい（横向きスマホ）：左に札、まん中に盤、右にボタン（.play.is-side）。
 * 盤の一辺は play.js が --bs に入れる（残りの場所でいちばん大きい正方形）。
 */
#screen-play { padding-left: calc(10px + var(--safe-l)); padding-right: calc(10px + var(--safe-r)); }

.play {
  --bs: min(100%, 60vh);
  flex: 1 1 auto; min-height: 0; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0;
}
/* たて：あまった高さは 上 3 ： 下 5（上寄り。親指がとどくよう、下は少し残す）。
   すきまは gap ではなく margin（空きの部品に gap がつかないように） */
.play::before, .play::after { content: ""; display: block; min-height: 0; }
.play::before { flex: 3 1 0; }
.play::after { flex: 5 1 0; }
.play > .play-stage { margin: 10px 0; }
.play-hud, .play-btns { width: max(var(--bs), min(100%, 340px)); max-width: 100%; flex: 0 0 auto; }
.play-stage { position: relative; width: var(--bs); height: var(--bs); flex: 0 0 auto; }
.play-boardbox { position: absolute; inset: 0; }
.play-missing { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; }

/* ---- 上の札・手数・時間 ---- */
.play-hud { display: flex; align-items: stretch; gap: 8px; }
.play-hud > div {
  background: var(--white); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm), inset 0 0 0 2px rgba(74, 52, 38, .08);
  padding: 6px 10px; position: relative; display: flex; flex-direction: column; justify-content: center; min-height: 58px;
}
.play-badge { flex: 0 1 auto; min-width: 0; border-left: 6px solid var(--wood); padding-right: 12px; }
.play-badge[data-mode="daily"] { border-left-color: var(--keika); }
.play-badge[data-mode="free"] { border-left-color: var(--miso); }
.play-label-row { min-width: 0; }
/* あそぶ画面の札では、コース名は左上にのせる（「ステージ」の字をけずらない） */
.play-label-row > .play-course { position: absolute; top: -13px; left: 2px; z-index: 1; box-shadow: var(--shadow-sm); }
/* コース名の小さな札（やさしい＝みどり／ふつう＝オレンジ／むずかしい＝こい青むらさき） */
.play-course {
  --course: var(--fumi);
  display: inline-block; flex: 0 0 auto; font-size: 13px; font-weight: 900; line-height: 1; padding: 4px 8px; border-radius: 999px;
  background: var(--course); color: #fff; white-space: nowrap; vertical-align: middle;
}
.play-course[data-course="easy"] { --course: var(--ok); }
.play-course[data-course="normal"] { --course: var(--fumi); }
.play-course[data-course="hard"] { --course: #4B3F9E; }
.play-badge[data-course="easy"] { border-left-color: var(--ok); }
.play-badge[data-course="hard"] { border-left-color: #4B3F9E; }
.play-res-picwho .play-course, .play-modal-where .play-course { margin-right: 6px; }
.play-modal-where { margin: 0 0 6px; font-size: 16px; color: var(--ink-soft); }
.play-note.is-course { background: var(--wood-dark, #6B4A32); }
.play-note.is-course[data-course="easy"] { background: var(--ok); }
.play-note.is-course[data-course="hard"] { background: #4B3F9E; }
.play-label { font-size: 14px; line-height: 1.2; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-badge-main { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.play-big { font-size: 22px; font-weight: 900; line-height: 1.15; }
.play-size { font-size: 16px; color: var(--ink-soft); }
.play-tag {
  position: absolute; top: -14px; right: -6px; font-size: 14px; line-height: 1; padding: 4px 9px; border-radius: 999px;
  background: var(--ok); color: #fff; box-shadow: var(--shadow-sm); white-space: nowrap;
}

.play-moves { flex: 1 0 auto; min-width: 0; }
.play-moves-row { display: flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.play-moves-row > * { flex: 0 0 auto; }
.play-moves-cap { font-size: 14px; color: var(--ink-soft); }
/* 数字は inline-block で幅をとり、「手」とのあいだに少しすきま（3けた・太字の字でも重ならない） */
.play-moves-num { display: inline-block; font-size: 28px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: 0; min-width: 1.4em; text-align: right; padding-right: 2px; transition: color .2s ease; }
.play-moves-num.is-3 { font-size: 25px; }
.play-moves-unit { font-size: 16px; margin-left: 2px; }
.play-ext {
  position: absolute; top: -14px; right: 6px; font-size: 14px; line-height: 1; padding: 4px 9px; border-radius: 999px;
  background: var(--miso); color: #fff; box-shadow: var(--shadow-sm);
}
.play-gauge { height: 7px; margin-top: 5px; border-radius: 999px; background: rgba(74, 52, 38, .1); overflow: hidden; }
.play-gauge-bar { height: 100%; border-radius: inherit; background: var(--ok); transform-origin: left center; transition: transform .25s ease-out, background-color .3s ease; }
.play-moves[data-level="low"] .play-gauge-bar { background: var(--fumi); }
.play-moves[data-level="low"] .play-moves-num { color: #C9701A; }
.play-moves[data-level="very"] .play-gauge-bar { background: var(--keika); }
.play-moves[data-level="very"] .play-moves-num { color: #C4416E; }

.play-time { flex: 0 0 auto; align-items: center; min-width: 62px; }
.play-time-cap { font-size: 14px; color: var(--ink-soft); line-height: 1.2; }
.play-time-num { font-size: 21px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.2; }
.play-time.is-idle .play-time-num { color: var(--ink-soft); opacity: .7; }

/* ---- 盤の上の札（ステージ名・まぜます・スタート！） ---- */
.play-cap {
  position: absolute; left: 50%; top: 50%; z-index: 3; pointer-events: none;
  transform: translate(-50%, -50%) scale(.9); opacity: 0; transition: opacity .22s ease, transform .3s cubic-bezier(.2, 1.4, .4, 1);
  background: rgba(74, 52, 38, .86); color: #fff; border-radius: 22px; padding: 12px 26px; text-align: center;
  box-shadow: 0 8px 26px rgba(40, 24, 14, .3); max-width: 86%;
}
.play-cap.is-show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
/* 題名と「まぜます」は上のほうに（完成の絵をかくさない） */
.play-cap[data-kind="title"], .play-cap[data-kind="shuffle"] { top: 15%; }
.play-cap-main { font-size: 24px; font-weight: 900; line-height: 1.3; white-space: nowrap; }
.play-cap-sub { font-size: 16px; font-weight: 700; opacity: .9; margin-top: 2px; }
.play-cap[data-kind="shuffle"] { background: rgba(74, 52, 38, .7); padding: 8px 22px; }
.play-cap[data-kind="shuffle"] .play-cap-main { font-size: 20px; }
.play-cap[data-kind="go"] { background: var(--fumi); }
.play-cap[data-kind="go"] .play-cap-main { font-size: 28px; letter-spacing: 2px; }

/* ---- ひとこと（吹き出し） ---- */
.play-say {
  position: absolute; left: 50%; bottom: 6%; z-index: 3; pointer-events: none; width: max-content; max-width: 92%;
  transform: translate(-50%, 10px); opacity: 0; transition: opacity .25s ease, transform .25s ease;
}
.play-say.is-show { opacity: 1; transform: translate(-50%, 0); }
.play-line { display: flex; align-items: center; gap: 8px; text-align: left; }
.play-line-who {
  flex: 0 0 auto; font-size: 14px; line-height: 1; padding: 6px 10px; border-radius: 999px;
  background: var(--who, var(--ink-soft)); color: #fff; font-weight: 900;
}
.play-line-text { font-size: 16px; line-height: 1.45; }
.play-line.is-bubble {
  background: var(--white); border-radius: 18px; padding: 8px 14px 8px 8px; box-shadow: 0 6px 18px rgba(74, 52, 38, .22);
}
.play-line.is-modal {
  margin: 14px auto 0; padding: 10px 12px; border-radius: 14px; background: var(--paper); width: fit-content; max-width: 100%;
}

/* ---- 下のボタン ---- */
.play-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.play-btn {
  appearance: none; border: 0; cursor: pointer; position: relative; min-height: 62px; padding: 6px 2px;
  border-radius: 16px; background: var(--white); color: var(--ink);
  box-shadow: var(--shadow-sm), inset 0 0 0 2px rgba(74, 52, 38, .1);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .08s ease, box-shadow .08s ease, background-color .15s ease, opacity .15s ease;
  touch-action: manipulation;
}
.play-btn:active:not([disabled]) { transform: translateY(3px); box-shadow: inset 0 0 0 2px rgba(74, 52, 38, .1); }
.play-btn:focus-visible { outline: 3px solid var(--miso); outline-offset: 2px; }
.play-btn[disabled] { opacity: .45; cursor: default; }
.play-btn-icon { font-size: 21px; line-height: 1.1; }
.play-btn-label { font-size: 16px; font-weight: 800; line-height: 1.2; white-space: nowrap; }
.play-btn-count {
  position: absolute; top: 4px; right: 6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--star); color: var(--ink); font-size: 14px; font-weight: 900; line-height: 22px; text-align: center;
}
.play-btn.is-on { background: #DDEEFB; box-shadow: inset 0 0 0 3px var(--miso); }
.play-b-peek.is-on { background: #FFF0D9; box-shadow: inset 0 0 0 3px var(--fumi); }

/* ---- 横長でせまいとき（横向きのスマホなど）：左・まん中・右 ---- */
.play.is-side { flex-direction: row; justify-content: center; gap: 14px; }
.play.is-side::before, .play.is-side::after { display: none; }
.play.is-side > .play-stage { margin: 0; }
.play.is-side .play-hud { width: 168px; flex-direction: column; gap: 8px; }
.play.is-side .play-hud > div { min-height: 0; }
.play.is-side .play-badge { padding: 8px 12px; }
.play.is-side .play-time { flex-direction: row; justify-content: space-between; align-items: baseline; }
.play.is-side .play-btns { width: 168px; grid-template-columns: 1fr; grid-auto-rows: 1fr; max-height: var(--bs); }
.play.is-side .play-btn { flex-direction: row; gap: 8px; min-height: 48px; justify-content: flex-start; padding: 4px 14px; }
.play.is-side .play-btn-count { top: 50%; transform: translateY(-50%); right: 10px; }

/* ---- 窓（共通） ---- */
.play-modal h2 { font-size: 24px; }
.play-modal .btn { width: 100%; word-break: keep-all; overflow-wrap: anywhere; }
/* 2行のボタン（名前＋小さい説明） */
.play-modal .btn.has-sub { flex-direction: column; gap: 0; line-height: 1.25; padding-top: 8px; padding-bottom: 8px; }
.btn.has-sub .btn-main { display: block; }
.btn.has-sub .btn-sub { display: block; font-size: 16px; font-weight: 700; opacity: .85; }
.btn-big.has-sub .btn-sub { font-size: 16px; }

/* とちゅうの保存があるとき */
.play-ask h2 { font-size: 22px; }
.play-ask .play-res-pic { margin: 6px 0 4px; }
.play-ask-text { margin: 6px 0 14px; font-size: 16px; color: var(--ink-soft); }

/* メニュー */
.play-menu-info { margin: 0 0 12px; font-size: 16px; }
.play-menu-list, .play-fail-list { display: flex; flex-direction: column; gap: 10px; }
.play-menu-note { margin: 12px 0 0; font-size: 15px; }

/* おしい！ */
.play-fail-mark { font-size: 34px; line-height: 1; color: var(--fumi); font-weight: 900; margin-bottom: 4px; }
.play-fail-text { margin: 0; font-size: 17px; }
.play-fail .play-line.is-modal { margin-bottom: 16px; }
.play-fail .btn-ghost { box-shadow: inset 0 0 0 2px rgba(74, 52, 38, .12); }

/* けっか */
.modal-back.is-result { background: rgba(60, 40, 28, .3); }
.play-result { padding-top: 16px; max-height: 96%; }
.play-res-title { color: var(--wood-dark); letter-spacing: 1px; }
.play-res-pic { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 4px 0 6px; text-align: left; }
.play-res-thumb {
  width: 64px; height: 64px; flex: 0 0 auto; border-radius: 12px; background-size: cover; background-position: center;
  background-color: var(--paper-2); box-shadow: 0 0 0 3px var(--wood-light), var(--shadow-sm);
}
.play-res-pictxt { min-width: 0; }
/* けっかの絵（大きく・角丸）。高さが足りない画面では、ボタンまで入るように小さくなる */
.play-res-hero {
  width: 100%; max-width: 100%; cursor: zoom-in; aspect-ratio: 1 / 1; margin: 0 auto 10px; border-radius: 18px;
  background-size: cover; background-position: center; background-color: var(--paper-2);
  box-shadow: 0 0 0 3px var(--wood-light), 0 6px 16px rgba(74, 52, 38, .18);
}
.play-res-title { margin-bottom: 2px; }
.play-res-cap { margin: 0 0 4px; }
/* とても低い画面：小さい絵の横に題名（play.js が is-compact をつける） */
.play-result.is-compact .play-res-a { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 12px; align-items: center; }
.play-result.is-compact .play-res-a > * { grid-column: 1 / -1; }
.play-result.is-compact .play-res-hero { grid-column: 1; grid-row: 1 / span 2; width: 76px !important; margin: 0; border-radius: 12px; }
.play-result.is-compact .play-res-title, .play-result.is-compact .play-res-cap { grid-column: 2; text-align: left; margin: 0; }
.play-result.is-compact .play-res-title { align-self: end; }
.play-result.is-compact .play-res-cap { align-self: start; }
.play-res-pictitle { font-size: 18px; font-weight: 900; line-height: 1.3; }
.play-res-picwho { font-size: 15px; }

.play-stars { display: flex; justify-content: center; gap: 10px; margin: 6px 0 4px; }
.play-star { font-size: 44px; line-height: 1; color: rgba(74, 52, 38, .16); transition: color .15s ease; }
.play-star.is-on { color: var(--star); animation: play-star-in .42s cubic-bezier(.2, 1.6, .4, 1) both; text-shadow: 0 3px 0 rgba(201, 140, 0, .35); }
@keyframes play-star-in { 0% { transform: scale(.3) rotate(-30deg); } 70% { transform: scale(1.25) rotate(6deg); } 100% { transform: scale(1) rotate(0); } }

.play-res-stats { display: flex; justify-content: center; gap: 10px; margin-top: 6px; }
.play-stat { flex: 1 1 0; max-width: 150px; background: var(--paper); border-radius: 14px; padding: 4px 8px; display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.play-stat-cap { font-size: 14px; color: var(--ink-soft); }
.play-stat-num { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.2; }
.play-res-tip { margin: 8px auto 0; font-size: 16px; padding: 4px 14px; border-radius: 999px; background: #FFF6D6; color: var(--wood-dark); width: fit-content; max-width: 100%; }
.play-res-best { margin-top: 6px; font-size: 15px; }
.play-notes { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; }
.play-note { font-size: 15px; padding: 4px 12px; border-radius: 999px; color: #fff; background: var(--ok); }
.play-note.is-album { background: var(--keika); }
.play-note.is-stamp { background: var(--miso); }
.play-note.is-best { background: var(--fumi); }

.play-res-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.play-res-sub { display: flex; gap: 10px; }
.play-res-sub .btn { flex: 1 1 0; }
.play-res-view {
  appearance: none; border: 0; background: none; cursor: pointer; margin-top: 2px; min-height: 48px; padding: 4px 16px;
  font-size: 15px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px;
}

/* 「絵を ながめる」：窓をよけて、さわると戻る */
.modal-back.is-viewing { background: transparent; cursor: pointer; }
.modal-back.is-viewing .modal { opacity: 0; transform: translateY(40px); pointer-events: none; transition: opacity .2s ease, transform .25s ease; animation: none; }
.modal-back.is-viewing::after {
  content: "さわると けっかに もどります"; position: absolute; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(74, 52, 38, .85); color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 15px; white-space: nowrap;
}

/* 小さい画面：窓の中を少しつめる */
@media (max-height: 700px) {
  .modal-back.play-modal-back { padding: 10px; }
  .play-modal { padding: 14px 16px; }
  .play-modal h2 { font-size: 21px; margin-bottom: 4px; }
  .play-res-thumb { width: 52px; height: 52px; }
  .play-star { font-size: 34px; }
  .play-stars { margin: 2px 0; }
  .play-stat { padding: 4px 8px; }
  .play-stat-num { font-size: 21px; }
  .play-res-tip { margin-top: 8px; }
  .play-notes { margin-top: 8px; }
  .play-res-btns { margin-top: 10px; gap: 8px; }
  .play-line.is-modal { margin-top: 8px; padding: 8px 10px; }
  .play-modal .btn-big { min-height: 54px; font-size: 19px; }
  .play-res-view { margin-top: 2px; }
  .play-fail-mark { display: none; }
}
/* 横長でせまい画面：けっかを左右2つに */
@media (max-height: 500px) and (min-aspect-ratio: 5/4) {
  .play-result { width: min(720px, 100%); }
  .play-res-info { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: center; }
  .play-res-b .play-line.is-modal:first-child { margin-top: 0; }
  .play-fail, .play-menu { width: min(520px, 100%); }
  .play-fail .play-line.is-modal { margin-bottom: 10px; }
}

/* 広い画面（PC）：けっかは 左に大きな絵・右に けっか */
@media (min-width: 860px) and (min-height: 501px) and (min-aspect-ratio: 5/4) {
  .play-result:not(.is-compact) { width: min(900px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; align-items: center; padding: 24px; }
  .play-result:not(.is-compact) .play-res-hero { margin: 0; justify-self: center; border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .play-cap, .play-say, .play-gauge-bar, .play-btn { transition: none; }
  .play-star.is-on { animation: none; }
}
