/* わけわけ！おかしやさん — 見た目は mockup 準拠 + iOS Safari 対策 */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --cream: #FFF8EC;
  --brown: #7A5230;
  --pink: #FFB6C1;
  --peach: #FFDAB3;
  --mint: #BFE8D2;
  --sky: #BEE3F0;
  --accent: #FF8FA3;
  --ok: #5BB98C;
  --lavender: #E0D4F7;
}

html, body {
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDGothic", "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
  background: var(--cream);
  color: var(--brown);
  min-height: 100vh;
  min-height: 100dvh;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: pop 0.25s ease;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

header {
  text-align: center;
  padding: 10px 0 4px;
}

header h1 {
  font-size: 1.5rem;
  letter-spacing: 0.05em;
  line-height: 1.4;
}

header p.sub {
  font-size: 0.8rem;
  color: #a58a6b;
  margin-top: 4px;
  line-height: 1.5;
}

.cards {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.mode-card {
  border: none;
  border-radius: 24px;
  padding: 22px 20px;
  min-height: 72px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(122, 82, 48, 0.18);
  transition: transform 0.1s;
  font-family: inherit;
  width: 100%;
  touch-action: manipulation;
}

.mode-card:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(122, 82, 48, 0.18);
}

.mode-card .icon {
  font-size: 2.4rem;
  flex-shrink: 0;
}

.mode-card .t {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--brown);
}

.mode-card .d {
  font-size: 0.85rem;
  color: #8a6a48;
  margin-top: 4px;
  line-height: 1.4;
}

.c1 { background: var(--peach); }
.c2 { background: var(--sky); }
.c3 { background: var(--mint); }
.c4 { background: var(--lavender); }

.back {
  background: none;
  border: none;
  color: #a58a6b;
  font-size: 1rem;
  cursor: pointer;
  padding: 16px 12px;
  min-height: 60px;
  min-width: 60px;
  font-family: inherit;
  touch-action: manipulation;
}

.stage {
  background: #fff;
  border-radius: 24px;
  padding: 20px;
  margin-top: 8px;
  box-shadow: 0 3px 10px rgba(122, 82, 48, 0.08);
}

.game-stage {
  overscroll-behavior: none;
}

.prompt {
  font-size: 1.15rem;
  text-align: center;
  line-height: 1.7;
  margin-bottom: 14px;
}

.hint-line {
  text-align: center;
  font-size: 0.95rem;
  color: #8a6a48;
  min-height: 1.4em;
  margin-bottom: 8px;
}

/* --- わけわけ --- */
.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  min-height: 52px;
  background: var(--cream);
  border-radius: 16px;
  padding: 10px;
}

.cookie,
.box-item {
  font-size: 1.7rem;
  transition: transform 0.3s, filter 0.3s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
  user-select: none;
}

.cookie.left,
.box-item.left {
  filter: drop-shadow(0 0 6px #ff5a76);
  transform: scale(1.15);
  animation: pulse 1s ease infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1.1); }
  50% { transform: scale(1.2); }
}

.box-item.tappable {
  min-width: 60px;
  min-height: 60px;
  font-size: 2rem;
  border-radius: 14px;
  background: #fff;
  border: 2px dashed #e8d5b8;
}

.box-item.tappable:active {
  transform: scale(0.95);
  background: var(--mint);
}

.plates {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.plates.p2 { grid-template-columns: repeat(2, 1fr); }
.plates.p3 { grid-template-columns: repeat(3, 1fr); }
.plates.p4 { grid-template-columns: repeat(4, 1fr); }
.plates.p5 { grid-template-columns: repeat(3, 1fr); }

.plate {
  background: var(--cream);
  border: 3px dashed #e8d5b8;
  border-radius: 18px;
  min-height: 86px;
  min-width: 60px;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s, background 0.2s;
}

.plate.target {
  border-color: var(--accent);
  background: #fff5f7;
}

.plate .label {
  font-size: 0.75rem;
  color: #a58a6b;
}

.plate .got {
  font-size: 1.15rem;
  line-height: 1.3;
  word-break: break-all;
  margin-top: 4px;
}

.plate .count {
  font-size: 0.8rem;
  color: var(--brown);
  font-weight: bold;
  margin-top: 2px;
}

.bigbtn {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 18px;
  min-height: 60px;
  font-size: 1.2rem;
  font-weight: bold;
  border: none;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #d96a80;
  font-family: inherit;
  touch-action: manipulation;
}

.bigbtn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d96a80;
}

.bigbtn:disabled {
  background: #e0cdb4;
  box-shadow: none;
  color: #fff;
  transform: none;
}

.bigbtn.soft {
  background: var(--sky);
  color: var(--brown);
  box-shadow: 0 4px 0 #8fc3d6;
  font-size: 1.05rem;
}

.bigbtn.soft:active {
  box-shadow: 0 1px 0 #8fc3d6;
}

.bigbtn.secondary {
  background: var(--mint);
  color: var(--brown);
  box-shadow: 0 4px 0 #8ec9a8;
  margin-top: 10px;
}

.bigbtn.secondary:active {
  box-shadow: 0 1px 0 #8ec9a8;
}

.action-row {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.equation {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 1.5rem;
  font-weight: bold;
  margin-top: 18px;
  flex-wrap: wrap;
}

.slot {
  min-width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--cream);
  border: 3px solid #e8d5b8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.slot.filled {
  background: var(--mint);
  border-color: var(--ok);
  animation: pop 0.3s;
}

.slot small {
  font-size: 0.7rem;
  color: #a58a6b;
  font-weight: normal;
}

.amari-tag {
  font-size: 1rem;
}

/* --- アレイ --- */
.array-grid {
  display: grid;
  gap: 6px;
  justify-content: center;
  margin: 14px auto;
  width: max-content;
  max-width: 100%;
  transition: transform 0.5s;
}

.donut {
  font-size: 1.5rem;
  animation: pop 0.25s;
  text-align: center;
  line-height: 1;
}

.donut.tens {
  filter: hue-rotate(-30deg) saturate(1.3);
  background: #ffe8c8;
  border-radius: 8px;
}

.donut.ones {
  background: #e8f6ff;
  border-radius: 8px;
}

.ctrl-row {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border-radius: 16px;
  padding: 8px 12px;
}

.ctrl b {
  font-size: 1.15rem;
  min-width: 1.5em;
  text-align: center;
}

.pm {
  width: 60px;
  height: 60px;
  font-size: 1.5rem;
  border: none;
  border-radius: 14px;
  background: var(--sky);
  cursor: pointer;
  font-weight: bold;
  color: var(--brown);
  box-shadow: 0 3px 0 #8fc3d6;
  font-family: inherit;
  touch-action: manipulation;
}

.pm:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8fc3d6;
}

.rotate-btn {
  margin-top: 14px;
  width: 100%;
  padding: 16px;
  min-height: 60px;
  font-size: 1rem;
  border: none;
  border-radius: 16px;
  background: var(--sky);
  cursor: pointer;
  color: var(--brown);
  font-weight: bold;
  box-shadow: 0 3px 0 #8fc3d6;
  font-family: inherit;
  touch-action: manipulation;
}

.rotate-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8fc3d6;
}

/* --- おみせやさん --- */
.order {
  background: var(--cream);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.order .face {
  font-size: 2.2rem;
  flex-shrink: 0;
}

.order .say {
  font-size: 1.05rem;
  line-height: 1.7;
}

.chips {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.chip {
  width: 60px;
  height: 60px;
  font-size: 1.4rem;
  font-weight: bold;
  border: none;
  border-radius: 50%;
  background: var(--peach);
  cursor: pointer;
  color: var(--brown);
  box-shadow: 0 3px 0 #e8b98a;
  font-family: inherit;
  touch-action: manipulation;
}

.chip.op {
  background: var(--sky);
  box-shadow: 0 3px 0 #8fc3d6;
  font-size: 1.5rem;
}

.chip:active {
  transform: translateY(2px);
}

.chip.used {
  opacity: 0.35;
  pointer-events: none;
}

.reset-chips {
  display: block;
  margin: 12px auto 0;
  background: none;
  border: 2px solid #e8d5b8;
  border-radius: 14px;
  padding: 14px 20px;
  min-height: 60px;
  font-size: 0.95rem;
  color: #8a6a48;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
}

.boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
  min-height: 40px;
}

.box {
  background: var(--cream);
  border-radius: 12px;
  padding: 6px 10px;
  font-size: 1.2rem;
  animation: pop 0.3s;
}

/* --- 言語化 --- */
.lang-choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lang-choice {
  width: 100%;
  text-align: left;
  padding: 16px 18px;
  min-height: 64px;
  font-size: 1.05rem;
  line-height: 1.5;
  border: 3px solid #e8d5b8;
  border-radius: 18px;
  background: var(--cream);
  color: var(--brown);
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
}

.lang-choice:active {
  background: var(--mint);
  border-color: var(--ok);
}

.or-line {
  text-align: center;
  color: #c0a98c;
  margin: 16px 0 4px;
  font-size: 0.9rem;
}

/* --- 図鑑 --- */
.zukan-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.zukan-item {
  background: var(--cream);
  border-radius: 16px;
  padding: 12px 6px;
  text-align: center;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.zukan-item .em {
  font-size: 1.8rem;
  line-height: 1;
}

.zukan-item.locked .em {
  filter: grayscale(1) contrast(0.2) brightness(1.4);
  opacity: 0.55;
}

.zukan-item .nm {
  font-size: 0.7rem;
  color: #8a6a48;
  line-height: 1.3;
}

.zukan-item.locked .nm {
  color: #c0a98c;
}

/* --- 報酬 --- */
.reward-stage {
  text-align: center;
}

.reward-emoji {
  font-size: 4.5rem;
  margin: 12px 0;
  animation: pop 0.4s ease;
}

.reward-name {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 8px;
}

.done-text {
  text-align: center;
  font-size: 1.1rem;
  line-height: 1.8;
  margin: 12px 0 8px;
}

/* --- レベル選択 --- */
.level-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.level-btn {
  width: 100%;
  text-align: left;
  padding: 18px 20px;
  min-height: 72px;
  border: none;
  border-radius: 20px;
  background: var(--mint);
  color: var(--brown);
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 3px 0 rgba(122, 82, 48, 0.15);
  touch-action: manipulation;
}

.level-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(122, 82, 48, 0.15);
}

.level-btn.locked {
  background: #eee4d6;
  color: #a58a6b;
  box-shadow: none;
  opacity: 0.75;
}

.level-btn .lv {
  font-size: 1.15rem;
  font-weight: bold;
  display: block;
}

.level-btn .ld {
  font-size: 0.85rem;
  margin-top: 4px;
  opacity: 0.85;
}

/* --- 進捗ドット --- */
.progress-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.progress-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e8d5b8;
}

.progress-dots span.on {
  background: var(--accent);
}

.progress-dots span.done {
  background: var(--ok);
}

/* --- 共通 --- */
.parent-tip {
  margin-top: 16px;
  background: #F4EBDD;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: #8a6a48;
  line-height: 1.6;
}

.parent-tip b {
  color: var(--brown);
}

.celebrate {
  text-align: center;
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--ok);
  margin-top: 12px;
  min-height: 1.6em;
  line-height: 1.5;
}

.celebrate.warn {
  color: #c07840;
}

footer {
  text-align: center;
  font-size: 0.7rem;
  color: #c0a98c;
  padding: 18px 0 8px;
}

/* iPhone / 狭い画面 */
@media (max-width: 400px) {
  header h1 { font-size: 1.25rem; }
  .mode-card .t { font-size: 1.1rem; }
  .equation { font-size: 1.25rem; gap: 5px; }
  .plates.p4 { grid-template-columns: repeat(2, 1fr); }
  .plates.p5 { grid-template-columns: repeat(2, 1fr); }
  .donut { font-size: 1.25rem; }
  .zukan-grid { grid-template-columns: repeat(3, 1fr); }
}

/* iPad 縦など */
@media (min-width: 700px) {
  .wrap { padding: 24px 32px; }
  header h1 { font-size: 1.8rem; }
  .prompt { font-size: 1.3rem; }
  .zukan-grid { grid-template-columns: repeat(6, 1fr); }
}

/* 横向きのコンパクト対応 */
@media (max-height: 500px) and (orientation: landscape) {
  .stage { padding: 12px; }
  .prompt { font-size: 1rem; margin-bottom: 8px; }
  .plate { min-height: 64px; }
}
