:root {
  --ink: #5a4532;
  --ink2: #8a6d52;
  --cream: #fff9ea;
  --cream2: #fbefd2;
  --leaf: #6f9f55;
  --sun: #ffd76a;
  --star: #f6b93b;
  --font: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #8db878; color: var(--ink); font-family: var(--font);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
canvas#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: var(--font); color: var(--ink); cursor: pointer; }

.pill {
  border: 2px solid #c9ad86; background: var(--cream); border-radius: 999px;
  padding: 7px 14px; font-size: 15px; font-weight: 700; letter-spacing: .02em;
  box-shadow: 0 3px 0 #d9c4a0; transition: transform .08s, box-shadow .08s;
  touch-action: manipulation;
}
.pill:active { transform: translateY(2px); box-shadow: 0 1px 0 #d9c4a0; }
.pill.big { font-size: 17px; padding: 10px 22px; }
.pill.huge { font-size: 22px; padding: 12px 44px; background: #fff3c9; border-color: #e0b85a; box-shadow: 0 4px 0 #e2c27a; }
.pill:disabled { opacity: .45; }

.mute { width: 44px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.mute svg { width: 22px; height: 22px; }

/* 上の帯 */
#hud {
  position: fixed; left: 0; right: 0; top: 0; height: 64px; padding: 10px 12px 0;
  padding-top: max(10px, env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 8px; pointer-events: none;
}
#hud > * { pointer-events: auto; }
#hudMid { display: flex; align-items: center; gap: 10px; background: rgba(255, 249, 234, .88); border: 2px solid #d8c29c; border-radius: 18px; padding: 4px 12px; }
#hudStage { font-size: 22px; font-weight: 800; color: #7a5a3c; min-width: 26px; text-align: center; }
#hudInfo { display: flex; flex-direction: column; font-size: 13px; line-height: 1.35; }
#hudInfo b { font-size: 15px; }
#hudMoves small { color: var(--ink2); font-size: 12px; }
#hudMoves.over b#mvNow { color: #c0703a; }
.chipbadge { display: inline-flex; align-items: center; gap: 3px; }
.chipicon { display: inline-block; width: 16px; height: 13px; border-radius: 50% 45% 55% 48%; background: radial-gradient(circle at 35% 35%, #fff2b0, #f2c24e 60%, #d99a2b); border: 1px solid #c58a28; transform: rotate(-12deg); }
/* 描いた ポテチ（2026-10-25〜） */
.chipicon { width: 19px; height: 16px; border: 0; border-radius: 0; background: url("../img/art/chip.webp") center / contain no-repeat; }
.chipbadge.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

/* 下の帯 */
#bottom {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 0 12px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
#bottom > * { pointer-events: auto; }
#hint {
  min-height: 20px; font-size: 14px; color: #fff; text-shadow: 0 1px 2px rgba(60, 80, 40, .55);
  text-align: center; max-width: 560px; line-height: 1.45; pointer-events: none;
}
#hint.ask {
  color: var(--ink); text-shadow: none; font-weight: 700; background: rgba(255, 253, 245, .95);
  border: 2px solid #d6bf98; border-radius: 14px; padding: 4px 12px;
}
#btns { display: flex; gap: 28px; }
/* やりなおし: 1回目の あと（2秒いないに もう一度で やりなおす） */
.pill.big.armed {
  font-size: 12px; line-height: 1.25; padding: 6px 12px; max-width: 140px; white-space: normal; word-break: keep-all;
  background: #fff0dc; border-color: #e0a46a; box-shadow: 0 3px 0 #e8c08e;
}
/* ちかみちで つながった とき「このまま いく」 */
.pill.go { background: #fff3c9; border-color: #e0b85a; box-shadow: 0 3px 0 #e2c27a; }

/* ふきだし */
#bubble {
  position: fixed; z-index: 5; transform: translate(-50%, -100%);
  background: #fffdf5; border: 2px solid #d6bf98; border-radius: 16px; padding: 6px 12px;
  font-size: 15px; font-weight: 700; white-space: nowrap; pointer-events: none;
  animation: bubin .35s ease-out;
}
#bubble::after { content: ""; position: absolute; left: calc(50% + var(--tail, 0px)); bottom: -9px; margin-left: -7px; border: 7px solid transparent; border-top-color: #d6bf98; border-bottom: 0; }
@keyframes bubin { from { opacity: 0; transform: translate(-50%, -80%); } to { opacity: 1; transform: translate(-50%, -100%); } }
#bubble.ask { white-space: pre-line; text-align: center; line-height: 1.45; width: max-content; max-width: calc(100vw - 16px); }
/* 上に 場所が ないときは ぽてむしの 下に 出す */
#bubble.below { transform: translate(-50%, 0); animation-name: bubinB; }
#bubble.below::after { bottom: auto; top: -9px; border: 7px solid transparent; border-bottom-color: #d6bf98; border-top: 0; }
@keyframes bubinB { from { opacity: 0; transform: translate(-50%, -20%); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 画面（タイトル・えらび・クリア） */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
#title { background: linear-gradient(rgba(255, 250, 225, .0), rgba(255, 250, 225, .0)); }
.tbox { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
h1 { margin: 0; line-height: 1.05; color: #fffdf3; text-shadow: 0 3px 0 #6f9152, 0 0 18px rgba(60, 100, 40, .45), 0 6px 14px rgba(60, 90, 40, .35); }
h1 .t1 { display: block; font-size: clamp(26px, 7vw, 40px); }
h1 .t2 { display: block; font-size: clamp(48px, 15vw, 82px); letter-spacing: .08em; }
.sub { margin: 4px 0 0; font-size: 15px; color: #fffbe8; text-shadow: 0 1px 3px rgba(50, 80, 40, .6); }
#titleImg { height: min(34vh, 300px); margin: 4px 0 6px; filter: drop-shadow(0 8px 6px rgba(50, 80, 30, .25)); animation: sway 3.2s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-5px) rotate(1deg); } }
.small-mute { margin-top: 4px; }
.howto { font-size: 13px; color: #fffbe8; text-shadow: 0 1px 3px rgba(50, 80, 40, .6); line-height: 1.6; margin: 6px 0 0; }

#select { background: rgba(120, 160, 100, .35); }
.sbox { width: min(560px, 100%); max-height: 100%; overflow-y: auto; background: rgba(255, 249, 234, .95); border: 3px solid #d8c29c; border-radius: 24px; padding: 14px; }
.shead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.shead h2 { word-break: keep-all; font-size: 16px; margin: 0; text-align: center; flex: 1; }
#selTotal { text-align: center; font-size: 14px; color: var(--ink2); margin: 8px 0 10px; }
#selTotal b { color: var(--star); }
#grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sbtn {
  aspect-ratio: 1 / 1; border-radius: 18px; border: 2px solid #cfe0b8; background: #f3f9e8;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 3px 0 #c5d9ab; font-weight: 800; font-size: 22px; color: #557a3c; padding: 0;
}
.sbtn .st { font-size: 13px; letter-spacing: 1px; color: #d8cdb5; }
.sbtn .st .on { color: var(--star); }
.sbtn .sz { font-size: 10px; font-weight: 600; color: #8aa575; }
.sbtn.locked { background: #ece6d8; border-color: #ddd3bf; box-shadow: 0 3px 0 #d6ccb6; color: #bfb39b; }
.sbtn.next { border-color: #e7c35f; background: #fff7d6; box-shadow: 0 3px 0 #e8d08a; }
#saveNote { margin: 12px 0 0; text-align: center; font-size: 12px; color: var(--ink2); }

#clear { background: rgba(255, 244, 200, .18); align-items: flex-end; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.cbox {
  width: min(420px, 100%); background: rgba(255, 250, 236, .97); border: 3px solid #e3cc98; border-radius: 26px;
  padding: 16px 18px 18px; text-align: center; animation: rise .5s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes rise { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
#cFace { width: 96px; height: 96px; margin: -60px auto 4px; border-radius: 50%; border: 4px solid #fff; background-color: #e9f3d8; background-image: url(../img/potemushi_faces.webp); background-size: 700% 100%; box-shadow: 0 4px 10px rgba(90, 70, 40, .25); }
#cStars { font-size: 42px; letter-spacing: 6px; height: 52px; }
#cStars span { color: #e6dcc6; display: inline-block; transform: scale(.6); transition: color .2s, transform .35s cubic-bezier(.2, 1.6, .4, 1); }
#cStars span.on { color: var(--star); transform: scale(1); text-shadow: 0 2px 0 #d9952a; }
#cStars span.dim { transform: scale(.9); }
#cLine { word-break: keep-all; overflow-wrap: anywhere; font-size: 18px; font-weight: 700; margin: 6px 0 4px; min-height: 26px; }
#cStat { font-size: 13px; color: var(--ink2); margin: 0 0 12px; }
#cStat .it { white-space: nowrap; }
#clear.top { align-items: flex-start; padding-top: max(76px, env(safe-area-inset-top)); padding-bottom: 16px; }
.cbtns { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cbtns .row { display: flex; gap: 12px; }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; background: #8db878; z-index: 50; }

@media (max-height: 640px) {
  #titleImg { height: 26vh; }
  h1 .t2 { font-size: 52px; }
}

/* 横長で 背が低い 画面（横向きの スマホなど）: 上と下の 帯を 盤面の 左右に よせる（game.js が body に side を つける。--col は 帯の はば） */
body.side #hud {
  top: 0; bottom: auto; left: 0; right: auto; width: var(--col, 140px); height: auto;
  padding: 8px 8px 0; padding-left: max(8px, env(safe-area-inset-left));
  flex-direction: column; align-items: center; justify-content: flex-start; gap: 10px;
}
body.side #hud .mute { position: fixed; top: 8px; right: max(8px, env(safe-area-inset-right)); }
body.side #hudMid { flex-direction: column; gap: 2px; padding: 6px 10px; max-width: 100%; }
body.side #hudInfo { align-items: center; text-align: center; }
body.side #hudMoves small { display: block; }
body.side #bottom {
  top: 56px; bottom: 0; left: auto; right: 0; width: var(--col, 140px);
  padding: 0 8px 10px; padding-right: max(8px, env(safe-area-inset-right)); padding-bottom: max(10px, env(safe-area-inset-bottom));
  justify-content: flex-end; gap: 10px;
}
body.side #hint { font-size: 12px; max-width: 100%; min-height: 0; word-break: keep-all; overflow-wrap: anywhere; }
body.side #btns { flex-direction: column; align-items: stretch; gap: 28px; width: 100%; max-width: 160px; }
body.side .pill.big { font-size: 14px; padding: 8px 6px; word-break: keep-all; overflow-wrap: anywhere; }
body.side .pill.big.armed { font-size: 12px; padding: 5px 8px; max-width: none; }

/* 背が低い 画面の クリア: 小さく して、入りきらなければ 中を スクロール */
@media (max-height: 479px) {
  #clear, #clear.top { align-items: center; padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .cbox { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 10px 14px 12px; }
  #cFace { width: 56px; height: 56px; margin: 0 auto 2px; border-width: 3px; }
  #cStars { font-size: 30px; height: 36px; }
  #cLine { font-size: 16px; margin: 2px 0; min-height: 0; }
  #cStat { margin: 0 0 8px; }
  .cbtns { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; }
  .cbtns .row { gap: 8px; }
  .cbtns .pill.huge { font-size: 18px; padding: 8px 28px; }
}
