/* 活動扭蛋「活動星環」（web/gacha.js 動態建立 dialog.gacha） */
dialog.gacha {
  --gc-brand: var(--brand, #c2410c);
  --gc-ink: var(--ink, #1f1c18);
  --gc-muted: var(--muted, #6d665c);
  --gc-line: var(--line, #e7e0d5);
  --gc-bg: var(--bg, #faf7f2);
  --gc-soft: var(--brand-soft, #fdeee4);
  --gc-energy: 0;
  width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 22px; overflow: auto; overscroll-behavior: contain;
  background: var(--surface, #fff); color: var(--gc-ink);
  box-shadow: 0 24px 70px rgba(60, 30, 10, .35);
}
dialog.gacha::backdrop { background: rgba(31, 20, 10, .55); backdrop-filter: blur(2px); }
dialog.gacha[open] { animation: gc-pop .32s cubic-bezier(.2, .8, .2, 1); }
@keyframes gc-pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }

.gc-wrap { padding: 16px 18px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.gc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.gc-head h2 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 900; letter-spacing: .02em; }
.gc-head h2::before { content: ""; display: inline-block; width: .62em; height: .62em; margin-right: 8px; vertical-align: .06em;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe7cf, #fb923c 45%, #c2410c 80%);
  box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px rgba(194, 65, 12, .35); }
.gc-sub { margin: 2px 0 0; font-size: 13.5px; color: var(--gc-muted); }
.gc-close {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--gc-bg); color: var(--gc-ink); font-size: 22px; line-height: 1;
}
.gc-close:hover { background: var(--gc-soft); color: var(--gc-brand); }
.gc-tools { flex: none; display: flex; gap: 6px; }
.gc-sound {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--gc-bg); font-size: 17px; line-height: 1; filter: grayscale(.6); opacity: .75;
}
.gc-sound[aria-pressed="true"] { filter: none; opacity: 1; background: var(--gc-soft); }
.gc-sound:hover { background: var(--gc-soft); opacity: 1; }

/* ---------- 舞台 ---------- */
.gc-stage {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; aspect-ratio: 360 / 320; border-radius: 18px; overflow: hidden; overflow: clip;   /* clip 不是捲動容器，aspect-ratio 才會隨結果卡長高 */
  background:
    radial-gradient(120% 70% at 50% 100%, #fde3cc 0%, rgba(253, 227, 204, 0) 60%),
    radial-gradient(90% 80% at 50% 30%, #fffaf3 0%, #fbeee1 70%, #f7e2cf 100%);
  box-shadow: inset 0 0 0 1px rgba(194, 65, 12, .10), inset 0 -30px 60px -40px rgba(194, 65, 12, .25);
  isolation: isolate;
}
/* 地圖模式：舞台高度約原本 55%（SVG 以 meet 等比縮小，星環跟著縮）；結果卡出現時舞台仍會隨內容長高 */
dialog.gacha.gc-compact .gc-stage { aspect-ratio: 360 / 176; }
.gc-svg, .gc-confetti { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.gc-confetti { z-index: 3; pointer-events: none; }
.gc-svg { z-index: 0; transition: opacity .5s ease, filter .5s ease; }
dialog.gacha.revealed .gc-svg .gc-world, dialog.gacha.revealed .gc-svg .gc-sky,
dialog.gacha.revealed .gc-svg .gc-beam, dialog.gacha.revealed .gc-svg .gc-padg { opacity: .32; transition: opacity .6s ease; }
.gc-svg .gc-world, .gc-svg .gc-sky, .gc-svg .gc-beam, .gc-svg .gc-padg { transition: opacity .4s ease; }

.gc-star { fill: #f59e0b; opacity: .35; animation: gc-twinkle 3s ease-in-out infinite; }
.gc-spark { fill: #fb923c; opacity: .55; }
@keyframes gc-twinkle { 50% { opacity: .9; } }
.gc-ring { fill: none; stroke: rgba(194, 65, 12, .38); stroke-width: 1.3; }
.gc-band { fill: none; stroke: rgba(251, 146, 60, calc(.14 + var(--gc-energy) * .2)); stroke-width: 16; }
.gc-streak { fill: none; stroke: #f97316; stroke-width: 2.6; stroke-linecap: round; stroke-dasharray: 9 16 3 22; opacity: 0;
  filter: drop-shadow(0 0 4px rgba(251, 146, 60, .95)); }
.gc-cap .gc-c-l, .gc-hero .gc-c-l { fill: #9a8f80; transition: fill .6s ease; }
.gc-c-r { fill: #fffaf3; }
.gc-c-edge { fill: none; stroke: rgba(31, 28, 24, .22); stroke-width: .8; }
.gc-c-shine { fill: #fff; opacity: .6; }
.gc-seam { fill: #fde68a; filter: drop-shadow(0 0 2px #f59e0b); }
.gc-hero .gc-c-edge { stroke-width: .5; }
.gc-ripple { transform-box: fill-box; transform-origin: center; }
.gc-planet { filter: drop-shadow(0 6px 10px rgba(124, 45, 18, calc(.18 + var(--gc-energy) * .25))); }

.gc-skip {
  position: absolute; top: 10px; right: 10px; z-index: 4; border: 0; cursor: pointer;
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: rgba(255, 255, 255, .82); color: var(--gc-brand); box-shadow: 0 1px 4px rgba(124, 45, 18, .18);
}
.gc-skip:hover { background: #fff; }
.gc-skip[hidden] { display: none; }

.gc-empty {
  position: relative; z-index: 2; margin: 0 24px; padding: 10px 16px; border-radius: 14px; text-align: center;
  background: rgba(255, 255, 255, .92); color: var(--gc-ink); font-size: 14.5px; font-weight: 500;
  box-shadow: 0 6px 20px rgba(124, 45, 18, .15); align-self: start; margin-top: 14px;
}
.gc-empty[hidden] { display: none; }

/* ---------- 結果卡 ---------- */
.gc-result { position: relative; z-index: 2; width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; padding: 14px; }
.gc-result[hidden] { display: none; }
.gc-card {
  width: min(300px, 100%); background: #fff; border-radius: 16px; overflow: hidden; text-align: left;
  box-shadow: 0 0 0 1px rgba(194, 65, 12, .08), 0 18px 40px -8px rgba(124, 45, 18, .35), 0 0 60px rgba(253, 186, 116, .55);
}
.gc-card-img { position: relative; aspect-ratio: 5 / 2; background: var(--c, #9a8f80); display: grid; place-items: center; overflow: hidden; }
.gc-card-img::before { content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 25% 20%, rgba(255, 255, 255, .35), transparent 55%), repeating-linear-gradient(135deg, rgba(255, 255, 255, .07) 0 10px, transparent 10px 20px); }
.gc-card-img span { position: relative; color: #fff; font-weight: 900; font-size: 22px; letter-spacing: .1em; text-shadow: 0 1px 6px rgba(0, 0, 0, .2); }
.gc-card-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.gc-card-body { padding: 10px 14px 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }
.gc-card-tag { justify-self: start; font-size: 12px; font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 12%, #fff);
  padding: 1px 9px; border-radius: 999px; }
.gc-card h3 { margin: 2px 0 2px; font-size: 16.5px; line-height: 1.4; font-weight: 800;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gc-meta { margin: 0; font-size: 13.5px; color: var(--gc-muted); line-height: 1.5; display: flex; align-items: baseline; gap: 4px; min-width: 0; }
.gc-meta .gc-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gc-dist { flex: none; margin-left: 2px; padding: 0 7px; border-radius: 999px; background: var(--gc-soft); color: var(--gc-brand); font-size: 12px; font-weight: 700; }
.gc-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.gc-btn {
  border: 1px solid var(--gc-line); background: #fff; color: var(--gc-ink); border-radius: 999px;
  padding: 8px 10px; font-weight: 700; font-size: 14px; cursor: pointer;
}
.gc-btn:hover { border-color: var(--gc-brand); color: var(--gc-brand); }
.gc-btn:focus-visible, .gc-close:focus-visible, .gc-sound:focus-visible, .gc-skip:focus-visible { outline: 3px solid #fdba74; outline-offset: 2px; }
.gc-btn.gc-primary { background: var(--gc-brand); border-color: var(--gc-brand); color: #fff; }
.gc-btn.gc-primary:hover { background: #a3360a; color: #fff; }

/* ---------- 控制區 ---------- */
.gc-controls { display: grid; gap: 10px; }
.gc-controls fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.gc-controls legend { padding: 0; margin-bottom: 6px; font-size: 13px; font-weight: 700; color: var(--gc-muted); }
.gc-modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.gc-modes legend { grid-column: 1 / -1; }
.gc-controls label { position: relative; display: block; cursor: pointer; }
.gc-controls input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.gc-modes label span {
  display: grid; justify-items: center; gap: 0; height: 100%; padding: 8px 4px 7px; border-radius: 14px; text-align: center;
  border: 1.5px solid var(--gc-line); background: #fff; transition: border-color .15s, background .15s, box-shadow .15s;
}
.gc-modes b { font-size: 14px; line-height: 1.35; white-space: nowrap; }
.gc-modes small { font-size: 11.5px; color: var(--gc-muted); line-height: 1.3; }
.gc-modes input:checked + span { border-color: var(--gc-brand); background: var(--gc-soft); color: var(--gc-brand); box-shadow: 0 2px 8px -2px rgba(194, 65, 12, .3); }
.gc-modes input:checked + span small { color: #9a3412; }
.gc-controls label:hover span { border-color: #e9b48f; }
.gc-controls input:focus-visible + span { outline: 3px solid #fdba74; outline-offset: 2px; }
.gc-controls input:disabled + span { opacity: .55; cursor: default; }
.gc-mode-pick.off { display: none; }

.gc-radius { display: flex; align-items: center; gap: 6px; }
.gc-radius label { flex: 1 1 0; min-width: 0; }
.gc-radius[hidden] { display: none; }
.gc-radius legend { float: left; margin: 0 4px 0 0; white-space: nowrap; }
.gc-radius label span {
  display: block; padding: 4px 6px; border-radius: 999px; font-size: 13.5px; font-weight: 500; text-align: center; white-space: nowrap;
  border: 1.5px solid var(--gc-line); background: #fff; transition: all .15s;
}
.gc-radius input:checked + span { background: var(--gc-brand); border-color: var(--gc-brand); color: #fff; }

.gc-map-wrap { border-radius: 14px; overflow: hidden; border: 1.5px solid var(--gc-line); transition: border-color .2s; }
.gc-map-wrap[hidden] { display: none; }
.gc-map-wrap.nudge { border-color: var(--gc-brand); animation: gc-nudge .5s ease; }
@keyframes gc-nudge { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.gc-map { height: 210px; background: #eef2ea; }
.gc-pin { background: none; border: 0; }
.gc-pin span {
  display: block; width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: radial-gradient(circle at 50% 50%, #fff 0 4px, var(--brand, #c2410c) 4.5px); box-shadow: 0 3px 6px rgba(0, 0, 0, .3);
}

.gc-status { margin: 0; min-height: 1.5em; font-size: 13.5px; color: var(--gc-muted); text-align: center; }
.gc-status.warn { color: #b45309; font-weight: 500; }

.gc-spin {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 13px 18px; border: 0; border-radius: 999px; cursor: pointer; color: #fff; font-size: 17px; font-weight: 800; letter-spacing: .12em;
  background: linear-gradient(180deg, #e0561a, var(--gc-brand) 60%, #a3360a);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .35) inset, 0 8px 18px -6px rgba(194, 65, 12, .6);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s;
}
.gc-spin:hover { filter: brightness(1.06); }
.gc-spin:active { transform: translateY(1px) scale(.99); }
.gc-spin:focus-visible { outline: 3px solid #fdba74; outline-offset: 3px; }
.gc-spin:disabled { cursor: progress; filter: saturate(.75) brightness(.97); }
.gc-spin-ico { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, .9); border-right-color: transparent; position: relative; }
.gc-spin-ico::after { content: ""; position: absolute; right: -4px; top: -1px; border: 4px solid transparent; border-left-color: rgba(255, 255, 255, .9); transform: rotate(-30deg); }
dialog.gacha.spinning .gc-spin-ico { animation: gc-rot .7s linear infinite; }
dialog.gacha.revealed .gc-spin { display: none; }
@keyframes gc-rot { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  dialog.gacha { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); border-radius: 20px; }
  .gc-wrap { padding: 14px 14px 16px; gap: 10px; }
  .gc-head h2 { font-size: 18px; }
  .gc-modes b { font-size: 13px; }
  .gc-map { height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.gacha[open] { animation: none; }
  .gc-star { animation: none; }
  dialog.gacha.spinning .gc-spin-ico { animation: none; }
  .gc-map-wrap.nudge { animation: none; }
}
