:root {
  --ink: #2e1f16;
  --edge: #1e130c;
  --sand: #f6e6c3;
  --paper: #fbf0d6;
  --cream: #fff3dc;
  --red: #d63a2b;
  --red-hi: #e9563f;
  --red-dark: #8f2217;
  --brown: #4a3223;
  --plate: #5a3d2a;
  --plate-dark: #3a2619;
  --rivet: #d8b583;
  --muted: #7a6450;
  --teal: #2f8f8a;
  --gold: #e8b23a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  /* 四隅のびょう（背景に重ねる） */
  --rivets: radial-gradient(circle at 9px 9px, var(--rivet) 2.2px, rgba(0, 0, 0, 0.4) 3px, transparent 3.6px),
    radial-gradient(circle at calc(100% - 9px) 9px, var(--rivet) 2.2px, rgba(0, 0, 0, 0.4) 3px, transparent 3.6px),
    radial-gradient(circle at 9px calc(100% - 9px), var(--rivet) 2.2px, rgba(0, 0, 0, 0.4) 3px, transparent 3.6px),
    radial-gradient(circle at calc(100% - 9px) calc(100% - 9px), var(--rivet) 2.2px, rgba(0, 0, 0, 0.4) 3px, transparent 3.6px);
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e2c28b;
  color: var(--ink);
  font: 15px/1.3 system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Yu Gothic UI', 'Noto Sans JP', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
canvas#cv {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}
button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}
[hidden] {
  display: none !important;
}
/* アイコン（js/icons.js）。文字の大きさに合わせる */
.ic {
  display: inline-block;
  flex: none;
  width: 1.25em;
  height: 1.25em;
  vertical-align: -0.25em;
}
.ic svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 40px;
  font-weight: 900;
  color: var(--brown);
  background: #e2c28b;
  z-index: 50;
}

/* ---- 部品の共通の形 ---- */

/* 枠付きの板（焦げ茶の板・明るい内側の線・四隅のびょう）。ゲームの中の距離の板と同じ作り */
.plate {
  background: var(--rivets), linear-gradient(#5f412d, var(--plate-dark));
  color: var(--cream);
  border: 3px solid var(--edge);
  border-radius: 16px;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0), inset 0 0 0 4.5px rgba(214, 170, 116, 0.45), inset 0 2px 0 6px rgba(255, 236, 200, 0.06),
    0 5px 0 var(--edge), 0 10px 18px rgba(30, 19, 12, 0.35);
}
/* 板の上に置く明るい札 */
.paper {
  background: linear-gradient(var(--paper), #f1dfb9);
  color: var(--ink);
  border: 2px solid var(--edge);
  border-radius: 12px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 3px 0 rgba(30, 19, 12, 0.55);
}
/* 押せる赤いボタン（上に光、下に厚み） */
.again,
.buy,
.mode.main {
  background: linear-gradient(var(--red-hi), var(--red) 55%, #c23224);
  color: #fff;
  border: 3px solid var(--edge);
  box-shadow: inset 0 3px 0 rgba(255, 220, 200, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.15), 0 4px 0 var(--edge);
  text-shadow: 0 2px 0 rgba(60, 10, 5, 0.45);
}
.again:active,
.buy:active,
.mode.main:active,
.mode.alt:active,
.menu:active,
.ridebtn:active,
#m-diff button:active,
.round:active,
.close:active {
  transform: translateY(3px);
  box-shadow: inset 0 3px 0 rgba(255, 220, 200, 0.2), 0 1px 0 var(--edge);
}

/* ---- 最初の画面: 題字と、大きなボタン2つ ---- */
#title {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  z-index: 10;
  pointer-events: none;
}
#title > * {
  pointer-events: auto;
}
/* 題字: 表紙と同じ（赤い文字・太い焦げ茶の縁・少し傾ける） */
h1 {
  margin: 0 0 6px;
  font-size: clamp(36px, 7.4vw, 76px);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--red);
  transform: rotate(-3deg);
  white-space: nowrap;
  /* 縁取り: 文字の形の影を4方向に重ね、最後に下へ落ちる影 */
  --o: 0.045em;
  filter: drop-shadow(var(--o) 0 0 var(--ink)) drop-shadow(calc(var(--o) * -1) 0 0 var(--ink)) drop-shadow(0 var(--o) 0 var(--ink))
    drop-shadow(0 calc(var(--o) * -1) 0 var(--ink)) drop-shadow(0 0.08em 0 rgba(46, 31, 22, 0.4));
  animation: bob 3.2s ease-in-out infinite;
}
h1 span {
  display: inline-block;
  background: linear-gradient(#f0745d 0 48%, var(--red) 52%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
@keyframes bob {
  50% {
    transform: rotate(-2deg) translateY(-3px);
  }
}
.modes {
  display: flex;
  gap: 14px;
  width: min(660px, 100%);
}
.mode {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 108px;
  padding: 14px 16px;
  border-radius: 16px;
  text-align: left;
}
/* カードの左のアイコン（丸い台に載せる） */
.mic {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(30, 19, 12, 0.3);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2);
}
.mic .ic {
  width: 38px;
  height: 38px;
}
.mt {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  gap: 4px;
  min-width: 0;
}
.mode b {
  font-size: 22px;
  font-weight: 900;
}
.mode .mt > span {
  font-size: 13px;
  opacity: 0.92;
  text-shadow: none;
}
.mode small {
  align-self: flex-start;
  margin-top: auto;
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
  text-shadow: none;
}
/* 遊ぶボタンの右下に、小さな ▶ の印 */
.mode::after {
  content: '';
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 0;
  height: 0;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  opacity: 0.85;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}
.mode.alt {
  background: var(--rivets), linear-gradient(#6a4a33, var(--plate-dark));
  color: var(--cream);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 4.5px rgba(214, 170, 116, 0.35), 0 4px 0 var(--edge);
}
.mode.main {
  background: var(--rivets), linear-gradient(var(--red-hi), var(--red) 55%, #c23224);
}
/* 拾って強化: カードの下に難しさ */
.wcol {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wcol .mode {
  flex: 1;
}
#m-diff {
  display: flex;
  gap: 6px;
}
#m-diff button {
  flex: 1;
  padding: 6px 4px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 800;
  background: linear-gradient(#4f3624, var(--plate-dark));
  color: rgba(255, 243, 220, 0.8);
  border: 2px solid var(--edge);
  box-shadow: 0 3px 0 var(--edge);
}
#m-diff button.on {
  background: linear-gradient(#fff6de, #f0dcb2);
  color: var(--brown);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12), 0 3px 0 var(--edge);
}
/* 前に遊んだモード: 明るい縁がゆっくり光る */
.mode.last {
  outline: 3px solid #fff6de;
  outline-offset: 3px;
  animation: glow 2.4s ease-in-out infinite;
}
@keyframes glow {
  50% {
    outline-color: rgba(255, 246, 222, 0.35);
  }
}
.subbtns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
/* 操作の説明。背の低い画面では地面に重なるので、明るい下地を敷いて読めるようにする */
#t-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0;
  max-width: 580px;
  padding: 4px 14px 4px 8px;
  border-radius: 10px;
  background: rgba(46, 31, 22, 0.72);
  border: 2px solid var(--edge);
  font-size: 14px;
  font-weight: 700;
  color: var(--cream);
}
#t-hint .ic {
  width: 30px;
  height: 30px;
}

/* 最初の画面の「乗り物」ボタン */
.ridebtn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 4px 8px;
  border-radius: 12px;
  text-align: left;
}
.ridebtn canvas {
  border-radius: 8px;
  background: radial-gradient(circle at 50% 60%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 70%);
}
.ridebtn span {
  display: flex;
  flex-direction: column;
}
.ridebtn b {
  font-size: 15px;
  font-weight: 900;
}
.ridebtn small {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.ridebtn i:not(.ic) {
  position: absolute;
  top: -10px;
  right: -10px;
  padding: 2px 7px;
  border-radius: 7px;
  background: var(--red);
  border: 2px solid var(--edge);
  color: #fff;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
  transform: rotate(6deg);
  animation: nudge 1.2s ease-in-out infinite;
}
@keyframes nudge {
  50% {
    transform: rotate(6deg) scale(1.12);
  }
}

/* 乗り物の強み（＋）と弱み（−）。拾って強化のモードだけ効く */
.perk {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--muted);
}
.perk .pg {
  color: #2f6b3a;
}
.perk .pb {
  color: var(--red-dark);
}

/* ---- 板の中の見出し ---- */
.rhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.rhead b {
  font-size: 24px;
  font-weight: 900;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.close,
.round {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(#6a4a33, var(--plate-dark));
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 2px rgba(214, 170, 116, 0.35), 0 3px 0 var(--edge);
}
.close .ic,
.round .ic {
  width: 24px;
  height: 24px;
}

/* ---- チェックポイント: 強化して出発する ---- */
#cp {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 14px 18px 16px;
  z-index: 11;
  text-align: center;
  animation: pop 0.25s ease-out;
}
#cp-d {
  margin: 2px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 243, 220, 0.75);
  text-align: left;
}
/* 持っているスクラップ（ナットの印と数） */
.cps {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px 2px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.25);
  font-size: 20px;
  font-weight: 900;
  color: var(--cream);
}
.cps .ic {
  width: 26px;
  height: 26px;
}
/* 強化が多くて画面に入らないときも「出発」は見えるように、下に貼り付ける */
#b-go {
  position: sticky;
  bottom: 0;
  z-index: 1;
  width: 100%;
  margin: 4px 0 4px;
}
/* 次のチェックポイントで増える強化 */
#cp-n {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
  text-align: left;
}
/* 強化の札: 左に絵、名前と説明と段階、右に値段 */
.up {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  text-align: left;
  background: linear-gradient(var(--paper), #f1dfb9);
  color: var(--ink);
  border: 2px solid var(--edge);
  border-radius: 12px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 3px 0 rgba(30, 19, 12, 0.55);
}
.uic {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, #6a4a33, var(--plate-dark));
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 2px rgba(214, 170, 116, 0.3);
}
.uic .ic {
  width: 32px;
  height: 32px;
}
.up > div {
  flex: 1;
  min-width: 0;
}
.up b {
  font-size: 16px;
  font-weight: 900;
}
.up p {
  margin: 2px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.lv {
  display: flex;
  gap: 4px;
}
.lv i {
  width: 16px;
  height: 9px;
  border-radius: 3px;
  background: rgba(74, 50, 35, 0.18);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}
.lv i.on {
  background: linear-gradient(var(--red-hi), var(--red-dark));
  box-shadow: 0 0 0 1px var(--edge);
}
.buy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 84px;
  padding: 8px 8px;
  border-radius: 10px;
  font-weight: 900;
  font-size: 16px;
}
.buy .ic {
  width: 20px;
  height: 20px;
}
.buy:disabled {
  background: rgba(74, 50, 35, 0.18);
  border-color: rgba(30, 19, 12, 0.35);
  color: var(--muted);
  text-shadow: none;
  box-shadow: none;
  cursor: default;
  transform: none;
}
.buy:disabled .ic {
  opacity: 0.55;
}
#cp .up.no {
  opacity: 0.5;
}
/* チェックポイント: 今の乗り物の名前・強み・弱みを1行に */
.cpperk {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin: -4px 0 8px;
  font-size: 12px;
  text-align: left;
  color: rgba(255, 243, 220, 0.7);
}
.cpperk b {
  color: var(--cream);
}
.cpperk .pg {
  color: #9fd59a;
}
.cpperk .pb {
  color: #ff9d86;
}
/* 乗り物の弱みで、このチェックポイントでは買えない */
#cp-lock {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(214, 58, 43, 0.25);
  border: 2px solid rgba(214, 58, 43, 0.6);
  font-size: 13px;
  font-weight: 800;
  color: #ffd9cf;
  text-align: left;
}

/* ---- 乗り物の一覧 ---- */
#rides {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 14px 18px 16px;
  z-index: 10;
  text-align: center;
  animation: pop 0.25s ease-out;
}
#rides-d {
  margin: 2px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 243, 220, 0.75);
  text-align: left;
}
#rides-g {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px 8px;
  background: linear-gradient(var(--paper), #f1dfb9);
  color: var(--ink);
  border: 2px solid var(--edge);
  border-radius: 12px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 3px 0 rgba(30, 19, 12, 0.55);
}
.cell:not(.locked):active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(30, 19, 12, 0.55);
}
.cell b {
  font-size: 13px;
  font-weight: 800;
}
.cell small {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.cell.sel {
  background: linear-gradient(#fffaf0, #fbe9c4);
  outline: 3px solid var(--gold);
  outline-offset: 1px;
}
.cell.locked {
  cursor: default;
  background: linear-gradient(#d9c39b, #ccb185);
}
.cell.locked b {
  color: var(--muted);
}

/* ---- 結果 ---- */
#result {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 32px));
  padding: 16px 18px 18px;
  text-align: center;
  z-index: 10;
  animation: pop 0.25s ease-out;
}
@keyframes pop {
  from {
    transform: translate(-50%, -50%) scale(0.85);
    opacity: 0;
  }
}
/* 距離: 板に彫った大きな数字 */
#r-dist {
  margin: 0 auto;
  padding: 2px 18px 4px;
  width: fit-content;
  min-width: 60%;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.12);
  font-size: 54px;
  font-weight: 900;
  line-height: 1.1;
  color: var(--cream);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
}
#r-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 14px;
  font-weight: 800;
  color: rgba(255, 243, 220, 0.75);
}
#r-sub .ic {
  width: 26px;
  height: 26px;
}
#r-sub:not(.best) .tro {
  display: none;
}
#r-sub.best {
  color: var(--gold);
  font-size: 18px;
  animation: cheer 0.6s ease-out 0.2s both;
}
@keyframes cheer {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  60% {
    transform: scale(1.15);
  }
}
#r-cp {
  margin: -8px 0 12px;
  font-size: 13px;
  font-weight: 800;
  color: rgba(255, 243, 220, 0.75);
}
#r-ride {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -4px 0 14px;
  padding: 4px 10px 4px 6px;
  text-align: left;
  background: linear-gradient(var(--paper), #f1dfb9);
  color: var(--ink);
  border: 2px solid var(--edge);
  border-radius: 12px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 3px 0 rgba(30, 19, 12, 0.55);
}
#r-ride .rr {
  flex: 1;
}
#r-ride b {
  display: block;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}
#r-ride b.new {
  white-space: pre-line;
  font-size: 15px;
  color: var(--red);
}
.bar {
  height: 10px;
  margin-top: 4px;
  border-radius: 5px;
  background: rgba(74, 50, 35, 0.2);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.18) 0 4px, transparent 4px 8px), linear-gradient(var(--red-hi), var(--red-dark));
  border-radius: 5px;
}
.rbtns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.again {
  flex: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  font-size: 20px;
  font-weight: 900;
}
.again .ic {
  width: 22px;
  height: 22px;
}
.again small {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.22);
  text-shadow: none;
}
.menu {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px;
  border-radius: 12px;
  font-weight: 800;
  background: linear-gradient(#6a4a33, var(--plate-dark));
  color: var(--cream);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 2px rgba(214, 170, 116, 0.3), 0 4px 0 var(--edge);
}
.menu .ic {
  width: 20px;
  height: 20px;
}

/* 音のボタン（遊んでいる間は隠す） */
.round {
  position: fixed;
  right: 12px;
  top: calc(12px + var(--safe-t));
  width: 44px;
  height: 44px;
  z-index: 12;
}
.round.off {
  opacity: 0.75;
}

/* 一時停止 */
#pause {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(46, 31, 22, 0.55);
  color: #fff6de;
  z-index: 30;
}
#pause b {
  font-size: 40px;
  font-weight: 900;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(46, 31, 22, 0.92);
  border: 2px solid var(--edge);
  color: #fff6de;
  font-weight: 700;
  z-index: 40;
}

/* 縦長の画面: ボタンを縦に並べる */
@media (max-aspect-ratio: 1/1) {
  .modes {
    flex-direction: column;
  }
  .mode {
    min-height: 88px;
  }
}
/* 背の低い横長（スマホの横向き・800×450） */
@media (max-height: 480px) {
  #title {
    gap: 8px;
  }
  h1 {
    font-size: 40px;
    margin-bottom: 2px;
  }
  .mode {
    min-height: 84px;
    padding: 10px 14px;
    gap: 10px;
  }
  .mode b {
    font-size: 19px;
  }
  .mic {
    width: 42px;
    height: 42px;
  }
  .mic .ic {
    width: 30px;
    height: 30px;
  }
  #t-hint {
    margin: 0;
    font-size: 12px;
  }
  #t-hint .ic {
    width: 24px;
    height: 24px;
  }
  #rides-g {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }
}

/* 背の低い横長: チェックポイントの強化を横に並べ（4つずつ）、「出発」まで1画面に収める */
@media (max-height: 480px) {
  #cp {
    width: min(780px, calc(100vw - 32px));
    padding: 10px 14px 12px;
  }
  #cp-d {
    margin-bottom: 6px;
  }
  #cp-g {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  #cp-n {
    margin: 6px 0 0;
    font-size: 12px;
  }
  /* 絵と値段は名前の左右に小さく置いて、札を低くする */
  #cp .up {
    position: relative;
    display: block;
    margin: 0;
    padding: 8px;
  }
  #cp .uic {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }
  #cp .uic .ic {
    width: 22px;
    height: 22px;
  }
  #cp .up b {
    display: block;
    min-height: 24px;
    padding: 2px 0 0 32px;
    font-size: 14px;
  }
  #cp .up p {
    font-size: 11px;
    margin: 6px 0 4px;
  }
  #cp .buy {
    position: absolute;
    bottom: 6px;
    right: 6px;
    min-width: 0;
    padding: 2px 6px;
    font-size: 13px;
    box-shadow: 0 2px 0 var(--edge);
    border-width: 2px;
  }
  #cp .buy .ic {
    width: 15px;
    height: 15px;
  }
  #cp .lv {
    min-height: 22px;
    align-items: center;
  }
  #b-go {
    margin: 8px 0 6px;
    padding: 8px;
  }
}

/* ---- 初めての人の練習（js/tut.js）。触れても下のゲームの画面に届く ---- */
#tut {
  position: fixed;
  left: 0;
  right: 0;
  top: max(calc(96px + var(--safe-t)), 24vh);
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
  z-index: 9;
}
#tut[hidden] {
  display: none;
}
#tut-c {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  padding: 10px 18px 10px 12px;
  border-radius: 16px;
  background: var(--rivets), linear-gradient(#5f412d, var(--plate-dark));
  color: var(--cream);
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 4.5px rgba(214, 170, 116, 0.45), 0 5px 0 var(--edge), 0 10px 18px rgba(30, 19, 12, 0.35);
  animation: tutIn 0.18s ease-out;
}
#tut-i {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(#3a2619, #24170f);
  border: 2px solid rgba(214, 170, 116, 0.55);
  font-size: 36px;
}
#tut-i[hidden] {
  display: none;
}
#tut .tt {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#tut-t {
  font-size: clamp(26px, 5vw, 40px);
  font-weight: 900;
  line-height: 1;
  color: #ffd23a;
  letter-spacing: 0.03em;
}
#tut-s {
  font-size: clamp(14px, 2.4vw, 18px);
  font-weight: 700;
}
#tut-s:empty {
  display: none;
}
#tut-s.bad {
  color: #ff9c86;
}
/* 止まって押すのを待つ: 札がゆっくり脈を打つ */
#tut.wait #tut-c {
  animation: tutIn 0.18s ease-out, tutPulse 0.9s ease-in-out 0.2s infinite;
}
/* ほめる・やり直しの一言: 札なしの大きな文字 */
#tut.big #tut-c {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
  animation: tutPop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}
#tut.big #tut-t {
  font-size: clamp(34px, 7vw, 60px);
  --o: 0.05em;
  filter: drop-shadow(var(--o) 0 0 var(--ink)) drop-shadow(calc(var(--o) * -1) 0 0 var(--ink)) drop-shadow(0 var(--o) 0 var(--ink))
    drop-shadow(0 calc(var(--o) * -1) 0 var(--ink)) drop-shadow(0 0.08em 0 rgba(46, 31, 22, 0.4));
  transform: rotate(-3deg);
}
#tut.big.bad #tut-t {
  color: #ff7a5c;
}
@keyframes tutIn {
  from {
    transform: translateY(-8px) scale(0.92);
    opacity: 0;
  }
}
@keyframes tutPulse {
  50% {
    transform: scale(1.05);
  }
}
@keyframes tutPop {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}
/* 開いた直後の題字（初めての人だけ。少しで消える） */
#logo {
  position: fixed;
  left: 0;
  right: 0;
  top: 22vh;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 8;
  animation: logoOut 2.2s ease-in forwards;
}
#logo[hidden] {
  display: none;
}
@keyframes logoOut {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  12%,
  70% {
    opacity: 1;
    transform: none;
  }
  100% {
    opacity: 0;
    transform: translateY(-20px);
  }
}
/* 操作の絵（マウスと Space のキー、さわる画面では指）。押す: キーが押し込まれる、長押し: 押されたまま目盛りがたまる */
#tut .tk {
  display: flex;
  align-items: center;
  gap: 8px;
}
#tut-k {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 26px;
}
#tut-k:empty {
  display: none;
}
#tut-k kbd {
  position: relative;
  overflow: hidden;
  padding: 3px 12px 4px;
  border-radius: 6px;
  background: linear-gradient(#fff6de, #e6d2a8);
  color: var(--ink);
  border: 2px solid var(--edge);
  box-shadow: 0 3px 0 var(--edge);
  font: 900 13px system-ui, sans-serif;
  letter-spacing: 0.08em;
}
#tut-k.tap kbd,
#tut-k.tap .ic {
  animation: keyTap 0.9s ease-in-out infinite;
}
#tut-k.hold kbd {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--edge);
}
#tut-k.hold kbd::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 100%;
  background: var(--red);
  transform-origin: left;
  animation: keyHold 1.1s linear infinite;
}
@keyframes keyTap {
  0%,
  55%,
  100% {
    transform: none;
  }
  65%,
  80% {
    transform: translateY(2px);
  }
}
@keyframes keyHold {
  from {
    transform: scaleX(0);
  }
}
/* 練習をとばす（練習の間だけ、右下） */
#tut-skip {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-b));
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(46, 31, 22, 0.78);
  color: #fff6de;
  border: 2px solid var(--edge);
  font: 700 14px system-ui, sans-serif;
  z-index: 12;
  cursor: pointer;
}
#tut-skip::after {
  content: ' ›';
}
#tut-skip[hidden] {
  display: none;
}
/* 出発のボタン: 止まってすぐの押せない間（0.5 秒）は薄く */
#b-go:disabled {
  opacity: 0.55;
  filter: saturate(0.5);
}
