/* ---------- planet minigames: overlay shell (fishing, fight) ---------- */
.gm {
  position: fixed; inset: 0; z-index: 8; pointer-events: none;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  opacity: 0; transition-property: opacity; transition-duration: 220ms; transition-timing-function: var(--ease-out);
  font-family: var(--font-body); color: var(--ink);
}
.gm.is-in { opacity: 1; }
.gm.is-out { opacity: 0; transition-duration: 150ms; }
.gm > * { pointer-events: auto; }
:where(.gm) button { font: inherit; color: inherit; }
.gm :focus-visible { outline: 3px solid var(--berry-deep); outline-offset: 2px; }

/* top bar */
.gm-top { display: flex; align-items: center; gap: 8px; pointer-events: none; }
.gm-top > * { pointer-events: auto; }
.gm-chip {
  background: var(--sign); border-radius: var(--r-pill); padding: 6px 14px;
  box-shadow: 0 3px 0 rgba(59, 47, 51, .16), 0 6px 14px rgba(59, 47, 51, .16);
  outline: 2px dashed var(--stitch); outline-offset: -5px;
}
.gm-title { font-family: var(--font-display); font-size: 22px; line-height: 1.3; padding: 8px 18px; }
.gm-stats { display: flex; gap: 8px; flex: 1; min-width: 0; }
.gm-stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; padding: 4px 12px; }
.gm-stat-label { font-size: 12px; line-height: 1.2; color: var(--muted); font-weight: 600; }
.gm-stat-value { font-family: var(--font-display); font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.gm-stat.is-bump { animation: gm-bump 320ms var(--ease-out); }
@keyframes gm-bump { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }
.gm-close {
  position: relative; flex: none; margin-left: auto; width: 48px; height: 48px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; cursor: pointer; background: var(--cream);
  box-shadow: 0 3px 0 rgba(59, 47, 51, .18), 0 6px 14px rgba(59, 47, 51, .2);
  outline: 2px dashed var(--stitch); outline-offset: -6px;
  transition-property: transform; transition-duration: 120ms; transition-timing-function: ease-out;
}
.gm-close svg { width: 22px; height: 22px; }
.gm-close:active { transform: scale(.92); }

/* centre stage */
.gm-stage { position: relative; display: grid; place-items: center; min-height: 0; pointer-events: none; }
.gm-stage > * { pointer-events: auto; }
.gm-card {
  width: min(400px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--stitch) transparent;
  background: var(--cream); border-radius: var(--r-card); padding: 24px 22px 20px;
  box-shadow: var(--shadow); outline: 2px dashed var(--stitch); outline-offset: -10px;
  opacity: 0; transform: translateY(10px) scale(.98);
  transition-property: opacity, transform; transition-duration: 260ms; transition-timing-function: var(--ease-out);
}
.gm-card.is-in { opacity: 1; transform: none; }
.gm-card-kicker { margin: 0 0 4px; font-size: 15px; font-weight: 700; color: var(--berry-deep); text-align: center; }
.gm-card-title { margin: 0 0 10px; font-family: var(--font-display); font-weight: 400; font-size: 26px; line-height: 1.25; text-align: center; text-wrap: balance; }
.gm-card-text { margin: 0 0 12px; font-size: 16px; line-height: 1.55; text-wrap: pretty; text-align: center; }
.gm-card-note { color: var(--muted); font-size: 15px; }
.gm-card-score { margin: 2px 0 6px; font-family: var(--font-display); font-size: 56px; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.gm-card-unit { font-size: 22px; margin-left: 4px; color: var(--muted); }
.gm-card-lines { list-style: none; margin: 0 0 14px; padding: 0; text-align: center; font-size: 15px; line-height: 1.6; color: var(--ink); }
.gm-fishlist { list-style: none; margin: 0 0 16px; padding: 10px 14px; background: var(--sign); border-radius: 18px; display: grid; gap: 6px; }
.gm-fishlist li { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.gm-fishlist b { margin-left: auto; font-variant-numeric: tabular-nums; }
.gm-fishdot { width: 14px; height: 14px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; box-shadow: inset 0 0 0 2px rgba(59, 47, 51, .25); }

/* buttons + form */
.gm-btn {
  min-height: 48px; padding: 0 20px; border-radius: var(--r-pill); border: 0; cursor: pointer;
  background: var(--sign); font-weight: 700; font-size: 16px;
  box-shadow: 0 3px 0 rgba(59, 47, 51, .16); outline: 2px dashed var(--stitch); outline-offset: -5px;
  transition-property: transform, opacity; transition-duration: 120ms; transition-timing-function: ease-out;
}
.gm-btn:active { transform: scale(.96); }
.gm-btn:disabled { opacity: .45; cursor: default; }
.gm-btn-primary { background: var(--berry-deep); color: var(--sign); outline-color: rgba(251, 243, 228, .45); }
.gm-btn-quiet { background: transparent; box-shadow: none; }
.gm-btn-wide { width: 100%; font-size: 18px; min-height: 52px; }
.gm-form { margin: 0 0 14px; }
.gm-form-label { display: block; margin: 0 0 6px; font-size: 14px; font-weight: 700; color: var(--muted); }
.gm-form-row { display: flex; gap: 8px; }
.gm-input {
  flex: 1; min-width: 0; height: 48px; padding: 0 16px; border-radius: 24px;
  background: var(--input); border: 2px dashed var(--stitch); font: inherit; font-size: 16px; color: var(--ink);
}
.gm-input::placeholder { color: var(--muted); }
.gm-input:focus-visible { outline: 3px solid var(--berry-deep); outline-offset: 2px; }
.gm-form-msg { min-height: 22px; margin: 6px 0 0; font-size: 15px; color: var(--berry-deep); font-weight: 600; text-wrap: pretty; }
.gm-form.is-done .gm-form-row { display: none; }
.gm-form.is-done .gm-form-label { display: none; }
.gm-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.gm-actions .gm-btn { flex: 1; }

/* leaderboard */
.gm-lb-title { margin: 0 0 6px; font-family: var(--font-display); font-size: 20px; text-align: center; }
.gm-lb { list-style: none; margin: 0; padding: 6px; background: var(--sign); border-radius: 18px; }
.gm-lb-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; font-size: 16px; line-height: 1.4; }
.gm-lb-row:nth-child(-n+3) .gm-lb-rank { background: var(--butter); }
.gm-lb-row.is-mine { background: var(--blush); }
.gm-lb-rank { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--cream); font-variant-numeric: tabular-nums; }
.gm-lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-lb-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.gm-lb-empty { padding: 12px; text-align: center; color: var(--muted); font-size: 15px; text-wrap: pretty; }

/* toast */
.gm-toast {
  position: absolute; left: 50%; top: 16%; translate: -50% 0; white-space: nowrap; pointer-events: none;
  padding: 10px 20px; border-radius: var(--r-pill); background: var(--sign); box-shadow: var(--shadow);
  font-family: var(--font-display); font-size: 24px; line-height: 1.2;
  opacity: 0; transform: translateY(8px) scale(.9);
  transition-property: opacity, transform; transition-duration: 260ms; transition-timing-function: var(--ease-out);
}
.gm-toast.is-in { opacity: 1; transform: none; }
.gm-toast.is-out { opacity: 0; transform: translateY(-8px); transition-duration: 200ms; }
.gm-toast.is-hit { background: var(--meadow); }
.gm-toast.is-gold { background: var(--butter); outline: 2px dashed var(--berry-deep); outline-offset: -6px; }
.gm-toast.is-miss { background: var(--cream); color: var(--muted); }

/* bottom: big action button + fishing timing bar */
.gm-bottom { display: flex; flex-direction: column; align-items: center; gap: 14px; pointer-events: none; }
.gm-bottom > * { pointer-events: auto; }
.gm-big {
  width: min(360px, 100%); min-height: 84px; border: 0; border-radius: var(--r-pill); cursor: pointer;
  font-family: var(--font-display); font-size: 30px; line-height: 1; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: var(--sign); box-shadow: 0 6px 0 rgba(59, 47, 51, .22), 0 12px 24px rgba(59, 47, 51, .22);
  outline: 2px dashed var(--stitch); outline-offset: -9px;
  transition-property: transform, background-color, box-shadow; transition-duration: 90ms; transition-timing-function: ease-out;
}
.gm-big:active { transform: translateY(3px) scale(.97); box-shadow: 0 3px 0 rgba(59, 47, 51, .22), 0 6px 14px rgba(59, 47, 51, .2); }
.gm-big.is-wait { background: var(--cream); color: var(--muted); }
.gm-big.is-hot { background: var(--berry-deep); color: var(--sign); outline-color: rgba(251, 243, 228, .5); animation: gm-hot 600ms ease-in-out infinite alternate; }
@keyframes gm-hot { to { transform: scale(1.04); } }
.gm-big.is-hot:active { animation: none; transform: scale(.96); }
.gm-mash { min-height: 110px; font-size: 38px; background: var(--butter); }
.gm-big[hidden], .gm-bar[hidden], .gm-tug[hidden] { display: none; }

.gm-bar {
  position: relative; width: min(360px, 100%); height: 34px; border-radius: var(--r-pill);
  background: var(--sign); box-shadow: inset 0 0 0 2px rgba(59, 47, 51, .12), 0 4px 12px rgba(59, 47, 51, .2);
  outline: 2px dashed var(--stitch); outline-offset: -6px;
  opacity: 0; transform: translateY(8px);
  transition-property: opacity, transform; transition-duration: 180ms; transition-timing-function: var(--ease-out);
}
.gm-bar.is-on { opacity: 1; transform: none; }
.gm-bar-zone { position: absolute; top: 4px; bottom: 4px; border-radius: 10px; background: var(--butter); box-shadow: inset 0 0 0 2px var(--berry-deep); }
.gm-bar-mark { position: absolute; top: -6px; bottom: -6px; width: 8px; margin-left: -4px; border-radius: 4px; background: var(--ink); left: 0; }
.gm-bar-mark.is-hit { background: #3f8f4f; }
.gm-bar-mark.is-miss { background: var(--berry); }

/* fight: tug bar + countdown */
.gm-fight .gm-stage { align-content: start; }
.gm-tug { width: min(560px, 100%); margin-top: 8px; padding: 12px 16px 14px; background: rgba(251, 243, 228, .94); border-radius: 22px; box-shadow: var(--shadow); align-self: start; }
.gm-tug-names { display: flex; justify-content: space-between; margin-bottom: 8px; }
.gm-tug-side { display: flex; align-items: center; gap: 8px; }
.gm-tug-side.is-right { flex-direction: row-reverse; }
.gm-tug-name { font-family: var(--font-display); font-size: 22px; line-height: 1.2; }
.gm-tug-name em { font-style: normal; font-family: var(--font-body); font-size: 13px; font-weight: 700; color: var(--muted); margin-left: 6px; }
.gm-tug-side.is-right .gm-tug-name em { margin: 0 6px 0 0; }
.gm-tug-side.is-right .gm-tug-name { display: flex; flex-direction: row-reverse; align-items: baseline; }
.gm-pips { display: flex; gap: 4px; }
.gm-pips i { width: 14px; height: 14px; border-radius: 50%; background: var(--cream); box-shadow: inset 0 0 0 2px var(--stitch); }
.gm-pips i.is-on { background: var(--berry-deep); box-shadow: none; }
.gm-tug-track { position: relative; height: 26px; border-radius: var(--r-pill); background: var(--sky); overflow: visible; box-shadow: inset 0 0 0 2px rgba(59, 47, 51, .12); }
.gm-tug-fill { position: absolute; inset: 0; border-radius: var(--r-pill); background: var(--blush); transform-origin: left center; transform: scaleX(.5); }
.gm-tug-mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: rgba(59, 47, 51, .35); }
.gm-tug-knob { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: var(--sign); box-shadow: 0 3px 0 rgba(59, 47, 51, .2), 0 5px 10px rgba(59, 47, 51, .2); outline: 2px dashed var(--berry-deep); outline-offset: -6px; }
.gm-count {
  position: absolute; left: 50%; top: 46%; translate: -50% -50%; pointer-events: none; white-space: nowrap;
  font-family: var(--font-display); font-size: 72px; line-height: 1; color: var(--sign);
  text-shadow: 0 4px 0 rgba(59, 47, 51, .35), 0 10px 24px rgba(59, 47, 51, .35);
  opacity: 0; transform: scale(.6);
}
.gm-count.is-in { opacity: 1; transform: none; transition-property: opacity, transform; transition-duration: 280ms; transition-timing-function: cubic-bezier(.34, 1.56, .64, 1); }
.gm-count.is-go { color: var(--butter); }
.gm-count.is-win { color: var(--butter); font-size: 54px; }
.gm-count.is-lose { color: var(--cream); font-size: 54px; }

@media (max-width: 560px) {
  .gm-title { display: none; }
  .gm-stat { min-width: 0; flex: 1; padding: 4px 8px; }
  .gm-stat-value { font-size: 20px; }
  .gm-card { padding: 20px 16px 16px; }
  .gm-card-score { font-size: 48px; }
  /* results card fits a 390×844 phone without scrolling: tighter rows and gaps */
  .gm-card-results { padding: 16px 16px 14px; }
  .gm-card-results .gm-card-lines { margin-bottom: 8px; line-height: 1.45; }
  .gm-card-results .gm-form { margin-bottom: 8px; }
  .gm-card-results .gm-form-msg { min-height: 0; margin-top: 4px; }
  .gm-card-results .gm-lb { padding: 4px; }
  .gm-card-results .gm-lb-row { padding: 2px 10px; }
  .gm-card-results .gm-lb-rank { width: 24px; height: 24px; }
  .gm-card-results .gm-actions { margin-top: 10px; }
  .gm-tug-name { font-size: 20px; }
  .gm-count { font-size: 64px; }
  .gm-count.is-win, .gm-count.is-lose { font-size: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .gm, .gm-card, .gm-toast, .gm-bar, .gm-count.is-in { transition-duration: 1ms !important; }
  .gm-card, .gm-toast, .gm-bar, .gm-count { transform: none !important; }
  .gm-stat.is-bump, .gm-big.is-hot { animation: none; }
}
