:root {
  --hud-h: 48px;
  --bg: #2f3e46;
  --panel: #fdf6e3;
  --text: #2b2b2b;
  --accent: #f5c842;
  /* プッシャー 360x300 と庭 360x260 を縦に並べた比率。画面の高さに収まる幅にする */
  --stage-w: min(100vw, 480px, calc((100dvh - var(--hud-h)) * 360 / 560));
  --progress-w: 260px;
}

/* 広い画面（PC）：すすみぐあいの欄を右に出し、プッシャーと庭は 480px の上限なしで画面の高さいっぱいまで大きくする。
   この幅は js/progress.js の WIDE と同じにする */
@media (min-width: 820px) {
  :root {
    --stage-w: min(calc(100vw - var(--progress-w) - 72px), calc((100dvh - var(--hud-h)) * 360 / 560));
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

#play {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

@media (min-width: 820px) {
  #app {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 24px;
  }

  /* 横並びのときは横に広がらず、縦は画面いっぱい（庭を下まで伸ばすため） */
  #play {
    flex: 0 0 auto;
    align-self: stretch;
  }
}

#hud {
  display: flex;
  align-items: center;
  gap: 16px;
  width: var(--stage-w);
  height: var(--hud-h);
  padding: 0 12px;
  flex-shrink: 0;
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.hud-coin {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: inset 0 0 0 3px #d9a820;
}

/* お金。いちばん大きく出す（目標の数字）。ヘッダーからはみ出すときだけ 12.3K のように短くなる */
#hud-coin-box {
  gap: 5px;
  min-width: 0;
  font-size: 20px;
  line-height: 1;
}

#hud-coins {
  color: #ffe9a3;
}

.hud-unit {
  font-size: 12px;
  opacity: 0.75;
}

.hud-label {
  font-size: 13px;
  opacity: 0.8;
}

/* 図鑑への入口（本の印と「図鑑」）。押すと図鑑が開く。新しく載ったら弾む。達成率は図鑑の中にだけ出す */
#codex-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

#codex-button .hud-label {
  opacity: 1;
}

.codex-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

#codex-button.is-nudged {
  animation: codex-nudge 0.9s ease-out;
}

@keyframes codex-nudge {
  20% { transform: scale(1.18); background: rgba(245, 200, 66, 0.55); }
  100% { transform: scale(1); }
}

/* すすみぐあいのボタン（狭い画面だけ。広い画面では欄が右に出ているので隠す） */
#progress-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  margin-left: -8px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

#progress-button[aria-expanded="true"] {
  background: rgba(245, 200, 66, 0.45);
}

#progress-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
}

@media (min-width: 820px) {
  #progress-button {
    display: none;
  }
}

/* 友だちと遊ぶ（同席）。見た目はミュートと同じ 36px の丸で、押せる範囲は 44px。
   同じ庭に人がいるときだけ横に伸びて人数と倍率を出し、庭をひらいている間は右上に緑の印 */
#friends-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
  margin-right: -10px;
  min-width: 44px;
  height: 44px;
  padding: 4px;
  border: none;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.15);
  background-clip: content-box;
  color: #fff;
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease-out;
}

#friends-button:active {
  transform: scale(0.9);
}

#friends-button svg {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  fill: currentColor;
}

#friends-button .friends-back {
  opacity: 0.6;
}

#friends-button.has-friends {
  padding-right: 4px;
  background-color: rgba(255, 207, 138, 0.25);
  color: #ffe2b8;
}

#friends-button.has-friends svg {
  margin-left: 6px;
}

#hud-friends {
  padding-right: 10px;
  font-size: 14px;
}

#hud-friends[hidden] {
  display: none;
}

#friends-button.is-joined::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: #7fd67a;
}

#friends-button.has-friends::after {
  display: none;
}

.hud-item {
  white-space: nowrap;
}

/* 同じ庭に人がいてボタンが伸びたときは、ミュートと ⚙ が画面からはみ出さないように間隔を詰める */
#hud:has(#friends-button.has-friends) {
  gap: 10px;
}

/* 狭い画面で友だちのボタンが伸びても HUD が折り返さないように詰める */
@media (max-width: 374px) {
  #hud,
  #hud:has(#friends-button.has-friends) {
    gap: 6px;
    padding: 0 6px;
  }

  #codex-button {
    padding: 4px 8px;
  }

  #progress-button {
    margin-left: -2px;
  }

  #friends-button.has-friends svg {
    display: none;
  }

  #hud-friends {
    padding: 0 8px;
  }

  #friends-button,
  #mute-button {
    margin-right: -4px;
  }
}

/* ミュート。見た目は ⚙ と同じ 36px の丸で、押せる範囲は 44px（まわりの 4px は透明） */
#mute-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: -10px;
  width: 44px;
  height: 44px;
  padding: 4px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  background-clip: content-box;
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s ease-out;
}

#mute-button:active {
  transform: scale(0.9);
}

#mute-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#mute-button .mute-speaker {
  fill: currentColor;
}

#mute-button .mute-slash,
#mute-button[aria-pressed="true"] .mute-waves {
  display: none;
}

#mute-button[aria-pressed="true"] .mute-slash {
  display: inline;
}

#mute-button[aria-pressed="true"] {
  color: rgba(255, 255, 255, 0.75);
}

#settings-button {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

#stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: var(--stage-w);
  min-height: 0;
}

#stage canvas {
  display: block;
  width: 100%;
  touch-action: manipulation;
}

#pusher-canvas {
  flex-shrink: 0;
  aspect-ratio: 360 / 300;
  cursor: pointer;
}

/* 落とし口を指で横に動かせるように、横のスワイプはページに渡さない（#stage canvas より強くする） */
#stage #pusher-canvas {
  touch-action: pan-y;
}

/* 庭は画面の下まで伸ばす（縦に長いスマホで下にすきまを残さない）。区画などは上の 360x260 の中で、伸びた分は芝生（garden.js の drawLawn）。
   canvas の解像度が高さに跳ね返らないよう、高さは flex で決めて最低の高さを決め打ちする */
#garden-canvas {
  flex: 1 1 0;
  min-height: calc(var(--stage-w) * 260 / 360);
  cursor: pointer;
}

/* 眺めるモード：コインが0のあいだ、プッシャーを少し暗く静かにする。罰や催促は出さない */
#pusher-canvas {
  transition: filter 1.2s ease;
}

#stage.is-resting #pusher-canvas {
  filter: saturate(0.45) brightness(0.72);
  cursor: default;
}

#rest-note {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  margin: 0;
  color: #fdf6e3;
  font-size: 14px;
  letter-spacing: 0.1em;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 1.2s ease, visibility 0s linear 1.2s;
}

#stage.is-resting #rest-note {
  opacity: 1;
  visibility: visible;
  transition: opacity 1.2s ease, visibility 0s;
  animation: rest-breathe 4s ease-in-out 1.2s infinite;
}

@keyframes rest-breathe {
  50% { opacity: 0.6; }
}

/* 戻ったときの「おかえりなさい」。庭の上に小さく出して消える。操作は下へ通す */
#welcome-note {
  position: absolute;
  top: calc(var(--stage-w) * 300 / 360 + 10px);
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0;
  padding: 6px 16px;
  border-radius: 14px;
  background: rgba(253, 246, 227, 0.92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  color: #4a3b2a;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -6px);
  transition: opacity 0.8s ease, transform 0.8s ease, visibility 0s linear 0.8s;
}

#welcome-note.is-shown {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity 0.8s ease, transform 0.8s ease, visibility 0s;
}

.welcome-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.welcome-detail {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* 図鑑に初めて載ったとき・報酬が届いたときの帯。プッシャーの上に出して消える。操作は下へ通す */
#codex-toast {
  position: absolute;
  top: 44px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 6px 18px 6px 8px;
  border-radius: 16px;
  background: rgba(253, 246, 227, 0.96);
  box-shadow: 0 0 0 2px #f5c842, 0 4px 14px rgba(0, 0, 0, 0.3);
  color: #4a3b2a;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -8px) scale(0.9);
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s linear 0.35s;
}

#codex-toast.is-shown {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0) scale(1);
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1), visibility 0s;
}

#codex-toast.is-reward {
  background: rgba(255, 245, 205, 0.97);
}

/* めずらしいペットが孵ったときの帯（D47）。光る卵と同じ紫（きらり）・金色（まぼろし）で縁取って光らせる。まぼろしは光が脈打つ */
#codex-toast.is-rare {
  background: rgba(250, 242, 255, 0.97);
  box-shadow: 0 0 0 2px #b36ad9, 0 0 16px rgba(200, 150, 245, 0.85), 0 4px 14px rgba(0, 0, 0, 0.3);
}

#codex-toast.is-mythic {
  background: rgba(255, 246, 210, 0.97);
  box-shadow: 0 0 0 2px #e0a820, 0 0 22px rgba(255, 210, 80, 0.95), 0 4px 14px rgba(0, 0, 0, 0.3);
}

#codex-toast.is-mythic.is-shown {
  animation: toast-mythic-glow 1.1s ease-in-out infinite alternate;
}

@keyframes toast-mythic-glow {
  from { box-shadow: 0 0 0 2px #e0a820, 0 0 14px rgba(255, 210, 80, 0.7), 0 4px 14px rgba(0, 0, 0, 0.3); }
  to { box-shadow: 0 0 0 2px #e0a820, 0 0 30px rgba(255, 210, 80, 1), 0 4px 14px rgba(0, 0, 0, 0.3); }
}

#codex-toast.is-rare .toast-stars i {
  background: #c98ae8;
}

#codex-toast.is-mythic .toast-stars i {
  background: #ffcf40;
}

/* #stage canvas（幅いっぱい）より強くする */
#codex-toast .toast-art {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 10px;
  background: #efe3c4;
}

.toast-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.toast-title {
  font-size: 12px;
  letter-spacing: 0.06em;
  opacity: 0.75;
}

.toast-name {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 帯のまわりに弾ける星 */
.toast-stars {
  position: absolute;
  left: 32px;
  top: 50%;
}

.toast-stars i {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px;
  background: #f5c842;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
}

/* 自動で捨てた知らせは星を弾かせない */
#codex-toast.is-quiet .toast-stars {
  display: none;
}

#codex-toast.is-shown .toast-stars i {
  animation: toast-star 0.9s ease-out;
}

@keyframes toast-star {
  0% { opacity: 1; transform: rotate(var(--a)) translateX(8px) scale(0.6); }
  100% { opacity: 0; transform: rotate(var(--a)) translateX(46px) scale(1.2); }
}

/* 動きを減らす（設定。初期値は prefers-reduced-motion。settings.js が body に付ける） */
body.is-reduced-motion #codex-toast,
body.is-reduced-motion #codex-toast.is-shown,
body.is-reduced-motion #welcome-note,
body.is-reduced-motion #welcome-note.is-shown {
  transform: translate(-50%, 0);
}

body.is-reduced-motion #codex-toast.is-shown .toast-stars i,
body.is-reduced-motion #codex-toast.is-mythic.is-shown,
body.is-reduced-motion #codex-button.is-nudged,
body.is-reduced-motion #stage.is-resting #rest-note {
  animation: none;
}

body.is-reduced-motion #friends-button,
body.is-reduced-motion #friends-button:active,
body.is-reduced-motion #mute-button,
body.is-reduced-motion #mute-button:active {
  transition: none;
  transform: none;
}

/* 獲得した物が飛んでいく演出。画面全体に重ね、操作は下へ通す */
/* PC の両脇の背景（js/backdrop.js）。ゲーム画面の後ろに敷く。解像度を下げて描くので引き伸ばす */
#backdrop-canvas {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* チュートリアル（tutorial.js）。白い輪は見た目だけで操作を下へ通す。説明のカードは画面の上か下の端に固定し（的にかぶらない側。tutorial.js の top）、
   カードを押すと次の段へ進む。カードの外は何も覆わない。図鑑・設定の画面より前に置いているので、画面を開くとその下に隠れる */
#tutorial-ring {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

#tutorial-ring::before {
  content: "";
  position: absolute;
  left: -26px;
  top: -26px;
  width: 52px;
  height: 52px;
  /* 台の上は金色のコインで埋まっているので、白に濃い縁取りで目立たせる */
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(60, 40, 10, 0.6), inset 0 0 0 2px rgba(60, 40, 10, 0.6), 0 0 14px rgba(255, 255, 255, 0.7);
  animation: tutorial-pulse 1.6s ease-in-out infinite;
}

@keyframes tutorial-pulse {
  50% { transform: scale(1.18); opacity: 0.65; }
}

#tutorial-card {
  position: fixed;
  left: 8px; /* 横の位置と幅は tutorial.js がプッシャーと庭に合わせる */
  bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  width: calc(100vw - 16px);
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(253, 246, 227, 0.97);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  color: #4a3b2a;
  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;
  /* カードの上の指の動きをスクロールなどに取られないように（押した瞬間に進む。tutorial.js） */
  touch-action: none;
}

#tutorial-card.is-top {
  top: calc(8px + env(safe-area-inset-top));
  bottom: auto;
}

#tutorial-ring[hidden],
#tutorial-card[hidden],
.tutorial-skip[hidden] {
  display: none;
}

#tutorial-card.is-entering {
  animation: tutorial-enter 0.3s ease;
}

.tutorial-count {
  flex-basis: 100%;
  color: #8a7a62;
  font-size: 11px;
}

.tutorial-text {
  flex: 1 1 180px;
}

.tutorial-buttons {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  margin-left: auto;
}

.tutorial-skip,
.tutorial-next {
  min-height: 36px;
  padding: 4px 12px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.tutorial-skip {
  background: transparent;
  color: #8a7a62;
}

.tutorial-next {
  background: var(--accent);
  color: #4a3b2a;
  font-weight: bold;
}

@keyframes tutorial-enter {
  from { opacity: 0; }
}

/* 育っている作物の指標のカード（D32）。収穫したあとにも出す（D39）。区画の上に出して、どこかを押すか 8秒（収穫したあとは 4秒）で消える。操作は下へ通す */
#crop-card {
  position: fixed;
  left: 0;
  top: 0;
  width: 208px;
  padding: 8px 10px 7px;
  border-radius: 12px;
  background: rgba(253, 246, 227, 0.96);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  color: #4a3b2a;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  animation: tutorial-enter 0.2s ease;
}

#crop-card[hidden] {
  display: none;
}

.crop-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.crop-card-name {
  font-size: 14px;
  font-weight: 700;
}

.crop-card-grow {
  color: #7a6a55;
  font-variant-numeric: tabular-nums;
}

.crop-card-traits {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.crop-card-traits li {
  display: grid;
  grid-template-columns: 3.4em 1fr 2em 2.6em;
  align-items: center;
  gap: 6px;
}

.crop-card-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(74, 59, 42, 0.15);
  overflow: hidden;
}

.crop-card-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: #9cc76a;
}

.crop-card-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.crop-card-dots {
  color: #d08a1e;
  font-size: 9px;
  letter-spacing: 1px;
}

/* 90 以上の指標は金色にする（当たりの合図） */
.crop-card-traits li.is-great .crop-card-fill {
  background: #f0b92e;
}

.crop-card-traits li.is-great .crop-card-value {
  color: #b57a00;
  font-weight: 700;
}

.crop-card-gold {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 5px 0 2px;
  padding-top: 4px;
  border-top: 1px solid rgba(74, 59, 42, 0.15);
}

.crop-card-amount {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 収穫したあとのカード（D39）は、入ったお金を金色にする */
#crop-card.is-harvested .crop-card-amount {
  color: #b57a00;
}

/* 熟れ具合の一行（D41）。食べごろは金色、熟れすぎは茶色 */
.crop-card-ripe {
  display: block;
  margin-bottom: 2px;
  color: #7a6a55;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.crop-card-ripe.is-peak {
  color: #b57a00;
  font-weight: 700;
}

.crop-card-ripe.is-over {
  color: #8a5a32;
}

.crop-card-note {
  display: block;
  color: #7a6a55;
  font-size: 10px;
}

body.is-reduced-motion #crop-card {
  animation: none;
}

body.is-reduced-motion #tutorial-ring::before,
body.is-reduced-motion #tutorial-card.is-entering {
  animation: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(360px, 100%);
  padding: 20px;
  border-radius: 12px;
  background: var(--panel);
}

.overlay-panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.overlay-panel button {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: #3c6e71;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

/* 図鑑・設定の画面（見出しと×、中身はスクロール） */
.overlay-panel.codex-panel,
.overlay-panel.settings-panel,
.overlay-panel.bag-panel,
.overlay-panel.tree-panel {
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
}

.codex-head,
.overlay-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px 20px;
  border-bottom: 1px solid #eadfc2;
}

.codex-head h2,
.overlay-head h2 {
  margin: 0;
}

#codex-percent {
  font-size: 15px;
  font-weight: 600;
  color: #8a6a2a;
  font-variant-numeric: tabular-nums;
}

.overlay-panel #codex-close,
.overlay-panel .overlay-close {
  margin-left: auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: #efe3c4;
  color: #4a3b2a;
  font-size: 20px;
}

#codex-body,
.overlay-body {
  padding: 4px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  user-select: none;
}

.codex-section h3 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 14px 0 6px;
  font-size: 15px;
}

.codex-count {
  font-size: 13px;
  font-weight: 600;
  color: #8a6a2a;
  font-variant-numeric: tabular-nums;
}

.codex-rewards {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: #9a8a70;
}

.codex-rewards li::before {
  content: "☆ ";
}

.codex-rewards li.is-reached {
  color: #8a6a2a;
  font-weight: 600;
}

.codex-rewards li.is-reached::before {
  content: "★ ";
  color: #e0a912;
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.codex-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 10px;
  background: #f1e8d0;
  color: #a89878;
  font-size: 11px;
  text-align: center;
}

.codex-card.is-found {
  background: #fff;
  box-shadow: 0 1px 3px rgba(74, 59, 42, 0.18);
  color: #4a3b2a;
}

.codex-art {
  width: 52px;
  height: 52px;
}

.codex-name {
  line-height: 1.25;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.codex-times {
  font-size: 10px;
  color: #9a8a70;
  font-variant-numeric: tabular-nums;
}

.codex-worth {
  font-size: 10px;
  color: #8a6a2a;
  font-variant-numeric: tabular-nums;
}

/* 収穫した価値の合計（図鑑の上） */
.codex-score {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 8px 20px;
  border-bottom: 1px solid #eadfc2;
  font-size: 13px;
  color: #6a5a40;
}

#codex-score {
  font-size: 17px;
  font-weight: 700;
  color: #8a6a2a;
  font-variant-numeric: tabular-nums;
}

/* 設定の画面 */
.overlay-panel.settings-panel {
  width: min(400px, 100%);
}

.settings-section h3 {
  margin: 14px 0 6px;
  font-size: 15px;
}

.settings-note {
  margin: 4px 0 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #8a7a60;
}

.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  font-size: 14px;
  cursor: pointer;
}

.settings-toggle + .settings-toggle {
  border-top: 1px solid #eadfc2;
}

/* スイッチ */
.settings-toggle input {
  flex: none;
  appearance: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 13px;
  background: #d8ccb0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.settings-toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.settings-toggle input:checked {
  background: #3c6e71;
}

.settings-toggle input:checked::after {
  transform: translateX(18px);
}

.settings-toggle input:disabled {
  opacity: 0.45;
  cursor: default;
}

.settings-toggle input:focus-visible {
  outline: 2px solid #3c6e71;
  outline-offset: 2px;
}

body.is-reduced-motion .settings-toggle input,
body.is-reduced-motion .settings-toggle input::after {
  transition: none;
}

/* 音量 */
.settings-range {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
  font-size: 14px;
  border-top: 1px solid #eadfc2;
}

.settings-range input {
  flex: 1;
  min-width: 0;
  margin: 0;
  accent-color: #3c6e71;
}

.settings-range input:disabled {
  opacity: 0.45;
}

/* 同席の合言葉・なまえ */
.settings-field {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px;
  font-size: 14px;
}

.settings-field span {
  flex: none;
  width: 4.5em;
}

html[lang="en"] .settings-field span {
  width: 6em;
}

.settings-field input,
.settings-field select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #d8ccb0;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS で入力時に拡大されないように */
  user-select: text;
}

.settings-field input:disabled {
  background: #f3ecd8;
  color: #8a7a60;
}

.settings-field input:focus-visible,
.settings-field select:focus-visible {
  outline: 2px solid #3c6e71;
  outline-offset: 1px;
}

.settings-field + .settings-buttons {
  margin-top: 6px;
}

.settings-status {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: #8a6a2a;
}

.settings-status:empty {
  display: none;
}

.settings-buttons,
.settings-reset {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.settings-reset {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eadfc2;
}

.settings-reset p {
  flex-basis: 100%;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.overlay-panel button.is-quiet {
  background: #efe3c4;
  color: #4a3b2a;
}

.overlay-panel button.is-danger {
  background: #b5523b;
}

#debug-panel {
  position: fixed;
  right: 8px;
  bottom: 8px;
  max-width: calc(100vw - 16px);
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 12px;
  user-select: text;
}

#debug-panel[hidden] {
  display: none;
}

#debug-panel h2 {
  margin: 0 0 4px;
  font-size: 12px;
  opacity: 0.7;
}

.debug-info {
  margin: 0 0 6px;
}

.debug-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.debug-buttons button {
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  background: transparent;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

/* 図鑑のペット：庭に出すペットを選ぶ */
.pet-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f7efd9;
  font-size: 12px;
  color: #6a5a40;
}

.pet-summary strong {
  font-size: 14px;
  color: #4a3b2a;
  font-variant-numeric: tabular-nums;
}

.pet-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pet-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 4px;
  border-radius: 10px;
  background: #f1e8d0;
  color: #a89878;
  font-size: 12px;
}

.pet-row.is-found {
  background: #fff;
  box-shadow: 0 1px 3px rgba(74, 59, 42, 0.18);
  color: #4a3b2a;
}

.pet-row .codex-art {
  flex: none;
}

.pet-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pet-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  font-size: 14px;
  font-weight: 600;
}

.pet-role {
  padding: 0 6px;
  border-radius: 8px;
  background: #efe3c4;
  font-size: 11px;
  font-weight: 600;
  color: #8a6a2a;
}

.pet-rarity {
  margin-left: auto;
  font-size: 10px;
  font-weight: 400;
  color: #a08a60;
  white-space: nowrap;
}

/* まぼろしのペット（D35） */
.pet-rarity.is-mythic {
  font-weight: 700;
  color: #c8921a;
}

/* でんせつのペット（鳳凰。D55） */
.pet-rarity.is-legend {
  color: #d0502a;
}

.pet-effect {
  color: #6a5a40;
  line-height: 1.35;
}

.pet-count {
  font-size: 11px;
  color: #9a8a70;
  font-variant-numeric: tabular-nums;
}

.pet-controls {
  display: flex;
  flex: none;
  gap: 6px;
}

.overlay-panel button.pet-step {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.overlay-panel button.pet-step:disabled {
  background: #d9cfb6;
  color: #f4efe2;
  cursor: default;
}

/* 種袋・卵を選んで捨てる画面（D36） */
#bag-count {
  font-size: 15px;
  font-weight: 600;
  color: #8a6a2a;
  font-variant-numeric: tabular-nums;
}

.overlay-panel .overlay-close[hidden] {
  display: none;
}

#bag-note {
  margin: 10px 0;
}

#bag-note.is-alert {
  color: #b5523b;
  font-weight: 600;
}

#bag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.overlay-panel button.bag-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border: 2px solid #eadfc2;
  border-radius: 10px;
  background: #fffaf0;
  color: #4a3b2a;
  font-size: 12px;
}

.overlay-panel button.bag-tile.is-shiny {
  border-color: #e6d27a;
}

.overlay-panel button.bag-tile[aria-pressed="true"] {
  border-color: #b5523b;
  background: #f7e0d8;
}

.bag-art {
  width: 40px;
  height: 40px;
}

.bag-empty {
  grid-column: 1 / -1;
  margin: 8px 0;
  font-size: 13px;
  color: #8a6a2a;
}

.bag-buttons {
  justify-content: space-between;
}

#bag-auto {
  margin-bottom: 4px;
  border-top: 1px solid #eadfc2;
}

.overlay-panel button#bag-pick:disabled,
.overlay-panel button#bag-discard:disabled {
  opacity: 0.45;
  cursor: default;
}

/* コインの木の画面（D38） */
#tree-level {
  padding: 1px 8px;
  border-radius: 8px;
  background: #e9cf98;
  font-size: 14px;
  font-weight: 700;
  color: #5a3d20;
  font-variant-numeric: tabular-nums;
}

.tree-summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 10px 0 8px;
  padding: 10px;
  border-radius: 10px;
  background: #f7efd9;
  font-size: 12px;
  color: #6a5a40;
}

.tree-summary p {
  margin: 0;
}

.tree-next {
  font-size: 14px;
  font-weight: 700;
  color: #4a3b2a;
  font-variant-numeric: tabular-nums;
}

.tree-bar {
  height: 8px;
  border-radius: 4px;
  background: #e6d9b8;
  overflow: hidden;
}

.tree-bar span {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #d9a13a, #f5c842);
}

.tree-detail {
  font-variant-numeric: tabular-nums;
}

.tree-help {
  line-height: 1.45;
  color: #8a7a5a;
}

.tree-slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.overlay-panel button.tree-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 72px;
  padding: 6px 4px;
  border: 2px dashed #d9c9a0;
  border-radius: 10px;
  background: #fffaf0;
  color: #a89878;
  font-size: 11px;
  cursor: default;
}

.overlay-panel button.tree-slot.is-set {
  border: 2px solid #e0a912;
  background: #fff;
  color: #4a3b2a;
  cursor: pointer;
}

.overlay-panel button.tree-slot.is-locked {
  background: #efe6cf;
}

.tree-slot-name {
  line-height: 1.25;
  font-weight: 600;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.tree-slot-tier {
  font-size: 10px;
  font-weight: 700;
  color: #c8921a;
}

.tree-slots-note,
.tree-section-note {
  margin: 6px 0 0;
  font-size: 11px;
  color: #8a7a5a;
}

.tree-section h3 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 16px 0 6px;
  font-size: 15px;
}

.tree-section-note {
  margin: 0 0 6px;
}

.tree-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(74, 59, 42, 0.18);
  color: #4a3b2a;
  font-size: 12px;
}

.tree-row.is-set {
  border-color: #e0a912;
}

.tree-row.is-locked {
  background: #f1e8d0;
  box-shadow: none;
  color: #a89878;
}

.tree-badge {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--badge, #cdbf9e);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 0 0 2px rgba(255, 255, 255, 0.8);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

.tree-row.is-locked .tree-badge {
  box-shadow: none;
}

.tree-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tree-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  font-size: 14px;
  font-weight: 600;
}

.tree-pips {
  display: inline-flex;
  gap: 2px;
}

.tree-pips i {
  padding: 0 4px;
  border-radius: 6px;
  background: #efe3c4;
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
  color: #c9b890;
}

.tree-pips i.is-on {
  background: #e0a912;
  color: #fff;
}

.tree-effect {
  color: #6a5a40;
  line-height: 1.35;
}

.tree-next-tier {
  font-size: 11px;
  color: #a08a60;
  line-height: 1.35;
}

.tree-controls {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 4px;
  width: 92px;
}

.overlay-panel button.tree-buy,
.overlay-panel button.tree-set {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 4px;
  font-size: 12px;
  line-height: 1.25;
}

.overlay-panel button.tree-buy {
  background: #c8921a;
}

.tree-price {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.overlay-panel button.tree-set.is-on {
  background: #efe3c4;
  color: #4a3b2a;
}

.overlay-panel button.tree-buy:disabled,
.overlay-panel button.tree-set:disabled {
  background: #d9cfb6;
  color: #f4efe2;
  cursor: default;
}

/* 庭のランタンの画面（D49）。部品は木の画面と同じ。--flame はいまのレベルの灯りの色 */
#lantern-level {
  padding: 1px 8px;
  border-radius: 8px;
  background: #3a3350;
  box-shadow: 0 0 10px var(--flame, #ffd27a);
  font-size: 14px;
  font-weight: 700;
  color: var(--flame, #ffd27a);
  font-variant-numeric: tabular-nums;
}

.lantern-bar span {
  background: linear-gradient(90deg, #e0a0c8, #b99bff);
}

.lantern-detail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 4px;
}

.lantern-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--flame, #ffd27a);
  box-shadow: 0 0 6px var(--flame, #ffd27a);
}

/* 虹の ON/OFF（D53。最高レベルのご褒美） */
.lantern-rainbow {
  margin: 10px 0 4px;
  padding: 4px 12px 8px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(255, 107, 107, 0.12), rgba(255, 224, 102, 0.12), rgba(140, 233, 154, 0.12), rgba(116, 192, 252, 0.12), rgba(151, 117, 250, 0.12));
  border: 1px solid #eadfc2;
}

.lantern-rainbow.is-locked {
  padding-top: 8px;
  background: none;
  border-style: dashed;
}

.lantern-rainbow-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: #8a7a60;
}

.lantern-slot-family {
  font-size: 10px;
  font-weight: 700;
  color: #8a7a5a;
}

/* ---- すすみぐあいの欄（js/progress.js）。狭い画面では HUD の下に開き、広い画面では右に並べる ---- */
#progress {
  position: fixed;
  top: calc(env(safe-area-inset-top) + var(--hud-h));
  left: 50%;
  display: none;
  flex-direction: column;
  gap: 10px;
  width: min(300px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--hud-h) - env(safe-area-inset-top) - 16px);
  overflow-y: auto;
  scrollbar-width: none; /* はみ出したときもスクロールはできるが、バーは出さない */
  padding: 10px;
  border-radius: 14px;
  background: rgba(34, 46, 52, 0.94);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
}

#progress::-webkit-scrollbar {
  display: none;
}

#progress.is-open {
  display: flex;
}

@media (min-width: 820px) {
  #progress {
    position: static;
    display: flex;
    flex-shrink: 0;
    width: var(--progress-w);
    max-height: calc(100dvh - var(--hud-h) - env(safe-area-inset-top) - 12px);
    margin-top: var(--hud-h);
    padding: 0;
    background: none;
    box-shadow: none;
    transform: none;
  }
}

.progress-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

button.progress-card:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* 庭のカードは見るだけ（押しても何も開かない） */
section.progress-card {
  cursor: default;
}

.progress-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-head .progress-big {
  margin-left: auto;
}

/* 並べかえのつまみ（点が2列×3段）。ここをドラッグするとカードが動く */
.progress-grip {
  flex-shrink: 0;
  width: 14px;
  height: 20px;
  margin: -4px -2px -4px -6px;
  border-radius: 4px;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.45) 1.3px, transparent 1.6px);
  background-size: 6px 6px;
  background-position: 1px 1px;
  cursor: grab;
  touch-action: none;
}

.progress-grip:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.progress-card.is-dragging {
  position: relative;
  z-index: 1;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  background: rgba(70, 86, 94, 0.98);
  transition: none;
}

.progress-card.is-dragging .progress-grip {
  cursor: grabbing;
}

.progress-title {
  font-size: 15px;
  font-weight: 600;
}

.progress-big {
  color: #ffe9a3;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.progress-row-head {
  display: flex;
  justify-content: space-between;
}

.progress-row-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.progress-bar {
  display: block;
  height: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}

.progress-line {
  font-size: 12px;
  opacity: 0.7;
}

.progress-slots {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.progress-slot {
  display: flex;
  align-items: center;
  gap: 7px;
}

.progress-slot-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-size: 11px;
  font-weight: 600;
}

.progress-slot.is-empty .progress-slot-mark {
  background: none;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.3);
}

.progress-slot.is-empty .progress-slot-name {
  opacity: 0.5;
}

/* ランタンのカード：系統の名前をマークの前に小さく */
.progress-slot-family {
  flex-shrink: 0;
  width: 5.5em;
  font-size: 11px;
  opacity: 0.6;
}

.progress-fill.lantern-fill {
  background: linear-gradient(90deg, #e0a0c8, #b99bff);
}

/* 庭のカード：区画ごとの作物のタイル（2列）と、種袋・卵・水・コインの木 */
.progress-plots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.progress-plot {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 3px 6px 3px 3px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  line-height: 1.2;
}

.progress-plot.is-fresh,
.progress-plot.is-peak,
.progress-plot.is-over {
  background: rgba(245, 200, 66, 0.16);
}

.progress-plot-art {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.progress-plot-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.progress-plot-name,
.progress-plot-state,
.progress-plot-gold {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-plot-name {
  font-size: 12px;
}

.progress-plot.is-empty .progress-plot-name {
  opacity: 0.45;
}

.progress-plot-state,
.progress-plot-gold {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.progress-plot-gold {
  color: #ffe9a3;
  opacity: 1;
}

.progress-plot .progress-bar {
  height: 4px;
}

.progress-plot .progress-bar[hidden],
.progress-plot-gold[hidden] {
  display: none;
}

.progress-plot.is-peak .progress-plot-state {
  color: #ffe9a3;
  font-weight: 600;
  opacity: 1;
}

.progress-plot.is-over .progress-plot-state {
  color: #e6c9a0;
}

.progress-plot.is-rarity-1 {
  background: rgba(185, 120, 240, 0.16);
}

.progress-plot.is-rarity-2 {
  background: rgba(255, 210, 80, 0.16);
}

.progress-plot.is-waiting .progress-plot-state {
  opacity: 0.55;
}

.progress-empty {
  grid-column: 1 / -1;
}

.progress-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

.progress-item {
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
