:root {
  --outline: #7A4545;
  --accent: #E0577A;
  --ink: #4A3A33;
  --ink-soft: #8C7A70;
  --cream: #FFF8EE;
  --mold: #EDE3DA;
  --mint: #7FD1AE;
  --font: ui-rounded, "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "Arial Rounded MT Bold", "Yu Gothic", "Meiryo", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #FFF7EC;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

/* お菓子屋さんの背景：ピンク→クリーム→ミント＋水玉 */
#bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(circle at 12% 18%, #F7A8BE88 0 7px, transparent 8px),
    radial-gradient(circle at 78% 9%, #FFD97A88 0 9px, transparent 10px),
    radial-gradient(circle at 88% 42%, #A8E2C888 0 6px, transparent 7px),
    radial-gradient(circle at 6% 62%, #C5B8F588 0 8px, transparent 9px),
    radial-gradient(circle at 70% 78%, #A8DBF788 0 7px, transparent 8px),
    radial-gradient(circle at 30% 92%, #FFC09A88 0 9px, transparent 10px),
    radial-gradient(circle, #ffffffaa 0 2px, transparent 3px) 0 0 / 28px 28px,
    linear-gradient(#FFEFF4, #FFF7EC 50%, #EEF9F3);
}

.screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}

/* お店のひさし */
.awning {
  align-self: stretch;
  height: calc(40px + env(safe-area-inset-top));
  background: repeating-linear-gradient(90deg, #F27A9B 0 36px, #fff 36px 72px);
  -webkit-mask: radial-gradient(18px at 18px calc(100% - 18px), #000 98%, transparent) 0 0 / 36px 100% repeat-x,
                linear-gradient(#000, #000) 0 0 / 100% calc(100% - 18px) no-repeat;
  mask: radial-gradient(18px at 18px calc(100% - 18px), #000 98%, transparent) 0 0 / 36px 100% repeat-x,
        linear-gradient(#000, #000) 0 0 / 100% calc(100% - 18px) no-repeat;
  filter: drop-shadow(0 2px 2px #C9566F40);
}

.home-body {
  flex: 1; width: 100%; max-width: 480px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  padding: 12px 28px 16px;
}
.title-block { display: flex; flex-direction: column; align-items: center; }
.logo { margin: 0; font-size: clamp(42px, 13vw, 58px); font-weight: 900; letter-spacing: -0.04em; white-space: nowrap; }
.logo span {
  display: inline-block; color: var(--c);
  text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 0 5px 0 #7A454599;
  transform: rotate(-6deg);
}
.logo span:nth-child(even) { transform: rotate(5deg); }
.subtitle {
  margin: 4px 0 0; padding: 6px 16px; border-radius: 99px;
  background: linear-gradient(#EA7593, var(--accent)); color: #fff; font-weight: 800; font-size: 15px;
}
.bobs { display: flex; gap: 14px; margin: 18px 0 8px; }
.bobs canvas { animation: bob 1.2s ease-in-out infinite alternate; }
.bobs canvas:nth-child(even) { animation-delay: -1.2s; }
@keyframes bob { from { transform: translateY(5px); } to { transform: translateY(-7px); } }

.menu { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; }
.row .candy:first-child { flex: 1; }

/* 時間あり／時間なし */
.mode { display: flex; gap: 6px; padding: 5px; background: #fff; border-radius: 99px; box-shadow: 0 3px 8px #E58BA533; }
.mode button {
  flex: 1; border: 0; padding: 9px 0; border-radius: 99px; background: transparent;
  font-weight: 700; font-size: 15px; color: var(--ink-soft);
}
.mode button[aria-pressed="true"] { background: linear-gradient(#EA7593, var(--accent)); color: #fff; }

/* キャンディのボタン */
.candy {
  --fill: var(--accent); --text: #fff; --edge: #B8466A;
  width: 100%; min-height: 52px; padding: 10px 18px;
  border: 2.5px solid var(--outline); border-radius: 99px;
  background: linear-gradient(color-mix(in srgb, var(--fill) 75%, #fff), var(--fill));
  color: var(--text); font-size: 18px; font-weight: 900;
  box-shadow: 0 5px 0 var(--edge), 0 5px 0 2.5px var(--outline);
  margin-bottom: 7px;
  transition: transform .08s, box-shadow .08s;
}
.candy:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--edge), 0 1px 0 2.5px var(--outline); }
.candy:disabled { opacity: .5; cursor: default; }
.candy.mint { --fill: var(--mint); --edge: #5FA98A; }
.candy.white { --fill: #fff; --text: var(--ink); --edge: #D9CFC8; }
.candy.soft { --fill: #FFF1F4; --text: var(--ink); --edge: #E5C9D1; }
.candy.square { width: 64px; flex: none; padding: 0; font-size: 22px; }

.credit { margin-top: 10px; font-size: 12px; color: var(--ink-soft); text-align: center; line-height: 1.7; }
.credit a { color: var(--ink-soft); }

/* 画面上の帯（もどる・題名・設定） */
.bar {
  align-self: stretch; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 6px;
}
.bar h2 { margin: 0; font-size: 17px; font-weight: 800; }
.round {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  border: 2.5px solid var(--outline); border-radius: 50%; background: var(--cream);
  color: var(--outline); font-size: 24px; font-weight: 900; line-height: 1; padding: 0 0 2px;
}
.round.ghost { visibility: hidden; }
.stage-tag {
  display: flex; align-items: center; gap: 6px; padding: 7px 16px;
  border: 2.5px solid var(--outline); border-radius: 18px; background: var(--cream);
  color: var(--outline); font-weight: 900; font-size: 17px;
}
.stage-tag .star { color: #FFD045; }

/* ステージ一覧 */
.stage-list { width: 100%; max-width: 720px; padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 18px; }
.shelf { background: #fff; border-radius: 18px; padding: 14px; box-shadow: 0 3px 8px #E58BA526; }
.shelf h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 17px; font-weight: 800; }
.shelf h3 small { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.stage-btn {
  height: 56px; border: 0; border-radius: 16px; position: relative;
  background: linear-gradient(color-mix(in srgb, var(--c) 70%, #fff), var(--c));
  box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 82%, #000);
  color: #fff; font-weight: 900; font-size: 18px; line-height: 1.1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-shadow: 0 1px 0 #0003;
}
.stage-btn::before { content: ""; position: absolute; left: 8px; top: 6px; width: 16px; height: 5px; border-radius: 3px; background: #fff8; }
.stage-btn .stars { font-size: 9px; letter-spacing: 1px; color: #ffffff73; text-shadow: none; }
.stage-btn .stars b { color: #FFE07A; font-weight: 400; }
.stage-btn:disabled { background: #EDE3DA80; box-shadow: none; color: #DCCFC4; cursor: default; font-size: 15px; }
.stage-btn:disabled::before { display: none; }

/* ゲーム画面 */
#game { height: 100vh; height: 100dvh; overflow: hidden; }
.game-body {
  flex: 1; min-height: 0; width: 100%; max-width: 640px;
  display: flex; flex-direction: column; gap: 10px; padding: 4px 16px 8px;
}
.order {
  background: #fff; border: 2.5px solid var(--outline); border-radius: 26px;
  box-shadow: 0 4px 0 #7A454526; padding: 12px 18px 14px;
}
.order.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.04); } }
.order-head { display: flex; align-items: center; justify-content: center; position: relative; color: var(--outline); }
.order-head strong { font-size: 17px; font-weight: 900; }
#order-count { position: absolute; right: 0; display: flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 800; }
#order-count i { width: 9px; height: 9px; border-radius: 50%; border: 1.2px solid var(--outline); background: #fff; }
#order-count i.on { background: var(--accent); }
.order-items { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-top: 8px; }
.item { display: flex; align-items: center; gap: 8px; min-width: 0; }
.item .txt { min-width: 0; }
.item b { display: block; font-size: 15px; font-weight: 900; color: var(--outline); white-space: nowrap; }
.dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.2px solid #7A4545cc; background: #fff; }
.dots i.on { border-color: transparent; background: var(--c); }
.item .ok { color: #3DB36B; font-size: 18px; font-weight: 900; }

.timebar { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.timebar .label { font-weight: 900; font-size: 14px; color: var(--outline); white-space: nowrap; }
.track {
  flex: 1; height: 30px; position: relative; border-radius: 99px;
  background: #B9A19C; border: 2.5px solid var(--outline);
}
.track .fill {
  position: absolute; left: 3px; top: 3px; bottom: 3px; border-radius: 99px; max-width: calc(100% - 6px);
  background: repeating-linear-gradient(-45deg, #fff5 0 5px, transparent 5px 12px), var(--bar, #FFC53D);
}
#time-text { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; font-size: 14px; color: var(--outline); font-variant-numeric: tabular-nums; }
.mascot {
  position: absolute; top: -12px; width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(#FFD27A, #F5A93A); border: 1.5px solid var(--outline);
  background-image: radial-gradient(circle at 35% 45%, var(--outline) 0 1.6px, transparent 2px),
                    radial-gradient(circle at 65% 45%, var(--outline) 0 1.6px, transparent 2px),
                    radial-gradient(ellipse at 25% 62%, #F27A6B80 0 3px, transparent 4px),
                    radial-gradient(ellipse at 75% 62%, #F27A6B80 0 3px, transparent 4px),
                    linear-gradient(#FFD27A, #F5A93A);
}

.board-area { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; }
.plate { position: relative; }
.plate::before {
  content: ""; position: absolute; left: -18px; right: -18px; top: 26px; bottom: 26px; z-index: -1;
  border-radius: 50%; background: #CDEDE3; border: 2.5px solid #7A4545cc;
}
.tray {
  padding: 14px; border-radius: 26px; border: 3px solid var(--outline);
  background: #F7F1E8; box-shadow: inset 0 0 0 7px #FFFDF8, 0 5px 0 #7A454533;
}
#board { display: block; }
.board-area { touch-action: none; }
/* ゲーム中はページを固定（引っぱりスクロール・ゴムのような戻りをさせない） */
html.playing, html.playing body { overflow: hidden; overscroll-behavior: none; height: 100%; }
html.playing body { position: fixed; inset: 0; }
#game { touch-action: none; }
#game button { touch-action: manipulation; }

.note {
  align-self: center; margin: 0; padding: 8px 14px; border-radius: 99px; background: #fff;
  font-size: 14px; font-weight: 700; text-align: center;
}
.note.warn { color: var(--accent); }
.actions { display: flex; gap: 12px; }

/* クリア・時間切れ・設定 */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px;
  background: #5A3A4440; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.panel {
  position: relative; width: 100%; max-width: 330px; padding: 24px;
  background: var(--cream); border: 3px solid var(--outline); border-radius: 28px;
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  animation: pop .35s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.panel h2 { margin: 0; font-size: 21px; color: var(--outline); }
.panel .small { margin: 0; font-size: 13px; color: var(--ink-soft); line-height: 1.6; white-space: pre-line; }
.panel .candy { font-size: 16px; min-height: 48px; }
.big-stars { display: flex; gap: 6px; font-size: 42px; line-height: 1; }
.big-stars span { color: var(--mold); transform: scale(.2) rotate(-40deg); animation: star .45s cubic-bezier(.3, 1.8, .5, 1) forwards; }
.big-stars span.on { color: #F2B21B; text-shadow: 0 2px 0 #E09A0066; }
@keyframes star { to { transform: none; } }
.timeup-icon { font-size: 40px; }

.sheet { max-width: 420px; text-align: left; align-items: stretch; max-height: calc(100dvh - 48px); overflow-y: auto; }
.sheet h2 { text-align: center; }
.sheet h3 { margin: 6px 0 0; font-size: 15px; }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: #fff; border-radius: 14px; font-weight: 700; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

/* クリアで降るスプリンクル */
.rain { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.rain i { position: absolute; top: -30px; width: 5px; height: 14px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(calc(100dvh + 60px)) rotate(240deg); } }

@media (max-height: 700px) {
  .order { padding: 8px 14px 10px; }
  .order-items { margin-top: 4px; gap: 4px 10px; }
  .candy { min-height: 46px; font-size: 16px; }
  .game-body { gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .big-stars span { transform: none; }
}
#shelves { display: flex; flex-direction: column; gap: 16px; }
