:root {
  --bg: #fff5f7;
  --bg-card: #ffffff;
  --bg-hover: #fff0f3;
  --border: #f5d5dc;

  --text: #3d2040;
  --text-mid: #7a5a7e;
  --text-dim: #b094b4;

  /* 面・アイコン用のアクセント。文字には使わない（白地でコントラストが足りない） */
  --accent: #ff7eb3;
  --accent-light: #ffe4ef;
  /* 文字用のアクセント（白地で約 5:1） */
  --accent-ink: #c2377a;

  --teal: #5cdbd3;
  --amber: #ffc078;
  --amber-light: #fff5e6;
  /* ごほうび（星・トロフィー） */
  --gold: #ffb627;
  /* 病気・だめ（もちつきの手・もちくず） */
  --purple: #7a3fa0;

  /* スマホ幅のカラムの外側（PC で見たとき） */
  --outside: #1d1420;

  --font: "Zen Maru Gothic", "Hiragino Sans", sans-serif;
  --mono: "DM Mono", "SF Mono", "Menlo", monospace;

  --fs-title: 30px;
  --fs-num: 20px;
  --fs-head: 16px;
  --fs-body: 14px;
  --fs-label: 12px;
  --fs-badge: 0.65rem;

  /* 子どもが押す主なボタンの絵の大きさ */
  --act-icon: 40px;
  --round: 56px;
}

/* タブレットでは、要素ごとではなくトークンごと一段大きくする */
@media (min-width: 700px) {
  :root {
    --fs-title: 36px;
    --fs-num: 26px;
    --fs-head: 22px;
    --fs-body: 18px;
    --fs-label: 14px;
    --act-icon: 60px;
    --round: 64px;
  }
}

* {
  box-sizing: border-box;
}
/* display を指定した要素でも hidden 属性で確実に隠れるようにする */
[hidden] {
  /* biome-ignore lint/complexity/noImportantStyles: hidden 属性を各要素の display 指定より優先させるため */
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--outside);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#app {
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 16px);
}

/* ---- ヘッダー ---- */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.gen {
  font-size: var(--fs-label);
  color: var(--text-mid);
  font-weight: 700;
}
.icon-btn {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 9999px;
  background: var(--bg-card);
  box-shadow: 0 1px 2px rgb(61 32 64 / 0.08);
  display: grid;
  place-items: center;
  color: var(--text-mid);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
}

/* 長押しで実行するボタン。押しているあいだ、下から塗りつぶして進み具合を見せる */
.hold {
  position: relative;
  overflow: hidden;
  touch-action: none;
  /* iPad の長押しメニュー・文字選択が割り込んで、長押しが途中で切れないように */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
/* 短いタップへの合図（長押しが必要なことを伝える） */
.nudge {
  animation: nudge 0.4s ease-in-out;
}
@keyframes nudge {
  25% {
    rotate: -12deg;
  }
  75% {
    rotate: 12deg;
  }
}
.hold::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0.35;
  translate: 0 100%;
  pointer-events: none;
}
.hold.holding::after {
  animation: hold-fill var(--hold-ms, 2000ms) linear forwards;
}
@keyframes hold-fill {
  to {
    translate: 0 0;
  }
}

/* 丸いアイコンボタン（閉じる・もどる・やめる・もういっかい） */
.round-btn {
  width: var(--round);
  height: var(--round);
  flex: none;
  border: 2px solid var(--border);
  border-radius: 9999px;
  background: var(--bg-card);
  display: grid;
  place-items: center;
  color: var(--text-mid);
  padding: 0;
}
.round-btn svg {
  width: 50%;
  height: 50%;
}
.round-btn.big {
  --round: 88px;
}
.round-btn.main {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.round-btn.quit {
  margin-left: 8px;
}
/* 1 回押したら色が変わり、もう 1 回でやめる */
.round-btn.quit.armed {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: #fff;
}

/* ---- ペット ---- */
.pet-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgb(61 32 64 / 0.08);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pet-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pet-name {
  margin: 0;
  font-size: var(--fs-head);
  font-weight: 900;
}
.clock {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: var(--fs-label);
  color: var(--text-mid);
}
.clock-icon svg {
  width: calc(var(--fs-label) * 2);
  height: calc(var(--fs-label) * 2);
  color: var(--accent-ink);
}
.tag {
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: var(--fs-label);
  font-weight: 700;
  background: var(--accent-light);
  color: var(--accent-ink);
  white-space: nowrap;
}
.stage-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  flex: 1;
  min-height: 300px;
}
#stage,
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}
#game {
  touch-action: none;
}

/* 舞台の上の吹き出し：絵が主役、文字は保護者向けに小さく */
.bubble {
  position: absolute;
  left: 50%;
  top: 12px;
  translate: -50% 0;
  max-width: 88%;
  padding: 8px 16px;
  border-radius: 16px;
  background: var(--bg-card);
  box-shadow: 0 1px 3px rgb(61 32 64 / 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.say-text {
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--text-mid);
}
.cue {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.cue img {
  height: calc(var(--act-icon) * 0.9);
  width: auto;
}
.cue-icon svg {
  width: calc(var(--act-icon) * 0.7);
  height: calc(var(--act-icon) * 0.7);
  color: var(--accent-ink);
}
.cue-hearts svg {
  width: 20px;
  height: 20px;
}
/* 「いらない」：絵に斜線 */
.cue-no {
  position: relative;
  display: inline-flex;
}
.cue-no::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -10%;
  width: 4px;
  height: 120%;
  background: var(--accent-ink);
  border-radius: 2px;
  rotate: 45deg;
}

/* ---- メーター（形で区別：おなか＝おもち、ごきげん＝ハート） ---- */
.meters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
body.playing .meters {
  display: none;
}
.meter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 9999px;
  background: var(--bg);
}
.meter-icon {
  width: calc(var(--act-icon) * 0.7);
  height: calc(var(--act-icon) * 0.7);
  object-fit: contain;
  color: var(--accent-ink);
}
.meter-icon svg {
  width: 100%;
  height: 100%;
}
/* 空っぽはいちばん大事な合図なので、背景の色を変える */
.meter.empty {
  background: var(--accent-light);
  outline: 2px solid var(--accent);
}
.gauge,
.hearts {
  display: inline-flex;
  gap: 2px;
}
.gauge svg,
.hearts svg {
  width: calc(var(--act-icon) * 0.5);
  height: calc(var(--act-icon) * 0.5);
}

/* ---- アクション ---- */
.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.act {
  position: relative;
  min-height: 80px;
  border: none;
  border-radius: 16px;
  background: var(--bg-card);
  box-shadow: 0 1px 2px rgb(61 32 64 / 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
}
/* grid だと行の高さが中身に合わせて伸び、画像の % 指定が効かないので flex にする */
.act-icon {
  width: var(--act-icon);
  height: var(--act-icon);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-ink);
}
.act-icon img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.act-icon svg {
  width: 70%;
  height: 70%;
}
.act-label {
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--text-mid);
  white-space: nowrap;
}
.act[aria-pressed="true"] {
  background: var(--text);
}
.act[aria-pressed="true"] .act-label {
  color: #fff;
}
/* いま意味のない操作：薄くする（押せば首ふりで返す） */
.act.dim {
  opacity: 0.45;
}
/* 呼ばれている：こたえるボタンに輪（大きさは変えず、明るさだけ点滅） */
.act.calling {
  opacity: 1;
  box-shadow: 0 0 0 4px var(--accent);
  animation: calling 1s ease-in-out infinite;
}
@keyframes calling {
  50% {
    box-shadow: 0 0 0 4px rgb(255 126 179 / 0.3);
  }
}
/* 新しく見つけたキャラがいる */
.has-new::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 14px;
  height: 14px;
  border-radius: 9999px;
  background: var(--accent);
  border: 2px solid #fff;
}

/* ---- あそび ---- */
.play {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgb(61 32 64 / 0.08);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.play-hint {
  color: var(--accent-ink);
  display: flex;
  justify-content: center;
}
.play-hint svg {
  width: 160px;
  height: 80px;
}
.play-hint.big svg {
  width: 240px;
  height: 120px;
}
/* あんこキャッチ：ここを左右になぞっても動かせる */
.drag-pad {
  width: 100%;
  min-height: 140px;
  align-items: center;
  border-radius: 16px;
  background: var(--bg);
  touch-action: none;
}
.btn.pound {
  width: 100%;
  min-height: 140px;
  padding: 8px;
  display: grid;
  place-items: center;
}
.btn.pound img {
  height: 120px;
  width: auto;
}
.result-line {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
}
.result-hearts svg {
  width: 40px;
  height: 40px;
}
.result-new svg {
  width: 40px;
  height: 40px;
  color: var(--gold);
}
.result-buttons {
  justify-content: center;
}

.row {
  display: flex;
  gap: 12px;
  width: 100%;
}

/* ---- ボタン ---- */
.btn {
  flex: 1;
  min-height: 48px;
  padding: 12px 24px;
  border-radius: 9999px;
  border: none;
  background: var(--accent-ink);
  color: #fff;
  font-size: var(--fs-body);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgb(61 32 64 / 0.1);
}
.btn.sub {
  background: var(--accent-light);
  color: var(--accent-ink);
  box-shadow: none;
}
.btn.ghost {
  background: transparent;
  color: var(--text-mid);
  box-shadow: none;
  border: 1px solid var(--border);
}
.btn.danger {
  background: var(--text);
}
.play > .btn {
  flex: none;
}

.pill {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-mid);
  font-size: var(--fs-body);
  font-weight: 700;
}
.pill[aria-pressed="true"] {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: #fff;
}

/* ---- シート ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(29 20 32 / 0.45);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 100%;
  max-width: 430px;
  max-height: 88dvh;
  overflow-y: auto;
  translate: -50% calc(100% + 32px);
  transition: translate 200ms ease-out;
  background: var(--bg-card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 24px rgb(61 32 64 / 0.15);
  padding: 0 16px calc(env(safe-area-inset-bottom) + 24px);
  z-index: 50;
}
.sheet.open {
  translate: -50% 0;
}
/* 上の帯（つまみ＋閉じる）。スクロールしても上に残る */
.sheet-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 32px;
  margin: 0 -16px 8px;
  padding: 8px 16px 0;
  background: var(--bg-card);
}
.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 9999px;
  background: var(--border);
}
.sheet-close {
  position: absolute;
  right: 12px;
  top: 8px;
}
.round-btn.back {
  position: sticky;
  top: 8px;
  z-index: 2;
  margin-top: -40px;
  margin-bottom: 8px;
}
.sheet h2 {
  margin: 0 0 12px;
  font-size: var(--fs-head);
  font-weight: 900;
}
.sheet h3 {
  margin: 16px 0 8px;
  font-size: var(--fs-body);
  font-weight: 900;
  color: var(--text-mid);
}
.sheet p {
  margin: 0 0 8px;
  font-size: var(--fs-body);
  line-height: 1.8;
}
.muted {
  color: var(--text-mid);
}
.small {
  font-size: var(--fs-label);
}
.mt {
  margin-top: 12px;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0;
  font-size: var(--fs-body);
}
.kv dt {
  color: var(--text-mid);
  font-size: var(--fs-label);
  font-weight: 700;
  padding-top: 2px;
}
.kv dd {
  margin: 0;
}
.num {
  font-family: var(--mono);
  font-size: var(--fs-num);
  font-weight: 500;
}

.bar {
  height: 10px;
  border-radius: 9999px;
  background: var(--bg-hover);
  overflow: hidden;
  margin-top: 6px;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--teal);
  border-radius: 9999px;
}

/* ---- ごはん ---- */
.food {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.food button {
  min-height: 160px;
  border: none;
  border-radius: 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
}
.food button.dim {
  opacity: 0.45;
}
.food img {
  height: 96px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
.food-effect {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-num);
  color: var(--accent-ink);
}
.food-effect svg {
  width: 28px;
  height: 28px;
}
.food .small {
  color: var(--text-mid);
}

/* ---- あそび：えらぶ ---- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.game-card {
  position: relative;
  border: none;
  border-radius: 16px;
  background: var(--bg);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.game-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}
.game-name {
  font-size: var(--fs-label);
  font-weight: 900;
  white-space: nowrap;
}
.game-hint {
  color: var(--accent-ink);
}
.game-hint svg {
  width: 80px;
  height: 40px;
}
.game-best {
  display: inline-flex;
  gap: 2px;
}
.game-best svg {
  width: 20px;
  height: 20px;
}

/* ---- 図鑑 ---- */
.dex-progress {
  font-size: var(--fs-label);
  color: var(--text-mid);
  font-weight: 700;
  margin-bottom: 12px;
}
.dex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.dex-cell {
  position: relative;
  border: none;
  border-radius: 16px;
  background: var(--bg);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-label);
  font-weight: 700;
  min-height: 44px;
}
.dex-cell img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}
.dex-cell .no {
  position: absolute;
  top: 6px;
  left: 8px;
  font-family: var(--mono);
  font-size: var(--fs-badge);
  color: var(--text-mid);
}
.dex-cell.unknown {
  color: var(--text-mid);
}
.preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  background: var(--bg);
  display: block;
}
.detail-head {
  margin: 12px 0 8px;
}
.detail-head h2 {
  margin: 0;
}
.catch {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--amber-light);
  font-size: var(--fs-body);
  font-weight: 700;
}
.memory {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 16px;
  background: var(--bg);
}
.memory img {
  width: 56px;
  height: 56px;
}
.memory .what {
  font-size: var(--fs-body);
  font-weight: 700;
}
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* ---- お別れ ---- */
.farewell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.farewell-pic {
  width: 120px;
  height: 120px;
}
.farewell-thanks {
  font-size: var(--fs-head);
  font-weight: 900;
  color: var(--accent-ink);
}
.small-kv {
  font-size: var(--fs-label);
  text-align: left;
}
.next-egg {
  flex: none;
  width: 100%;
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.next-egg img {
  height: 64px;
}
.next-egg svg {
  width: 40px;
  height: 40px;
}

:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

/* ---- iPad（タブレット）縦 ---- */
@media (min-width: 700px) {
  #app {
    max-width: 820px;
    padding-left: 24px;
    padding-right: 24px;
    gap: 16px;
  }
  .act {
    min-height: 120px;
  }
  .sheet {
    max-width: 760px;
    padding-left: 24px;
    padding-right: 24px;
  }
  .food button {
    min-height: 220px;
  }
  .food img {
    height: 140px;
  }
  .dex-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }
}

/* ---- iPad 横：左に舞台、右に操作 ---- */
@media (min-width: 900px) and (orientation: landscape) {
  #app {
    max-width: none;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr clamp(360px, 34vw, 440px);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "card top"
      "card side";
    padding-top: calc(env(safe-area-inset-top) + 16px);
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  }
  .top {
    grid-area: top;
  }
  .pet-card {
    grid-area: card;
    min-height: 0;
  }
  .actions,
  .play {
    grid-area: side;
  }
  /* 右の列を縦いっぱいに使う */
  .actions {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 1fr;
    align-self: stretch;
  }
  .act {
    min-height: 0;
  }
  .play {
    justify-content: center;
  }
  .btn.pound {
    flex: 1;
  }
  .btn.pound img {
    height: 200px;
  }
  /* 短い選択（ごはん・あそび・ようす）は右の列に出し、舞台のおもちを隠さない */
  .sheet.side {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: clamp(360px, 34vw, 440px);
    max-width: none;
    max-height: none;
    border-radius: 24px 0 0 24px;
    translate: calc(100% + 32px) 0;
  }
  .sheet.side.open {
    translate: 0 0;
  }
  .sheet.side .game-grid {
    grid-template-columns: 1fr;
  }
  .sheet.side .game-card {
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .sheet.side .game-card img {
    width: 120px;
  }
  /* 図鑑・設定は中央の広いシート */
  .sheet:not(.side) {
    max-width: 960px;
  }
}
