:root {
  --be-red: #c8001a;
  --be-red-bright: #e40827;
  --be-red-deep: #8f0013;
  --be-charcoal: #22242c;
  --be-gold: #f5b700;
  --be-gold-light: #fde047;
  --be-pink: #ff3b8d;
  --deck-top: #ffffff;
  --deck-bottom: #e9edf4;
  --ink-dark: #1f232e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #1b1d24;
  color: #ffffff;
  font-family: "M PLUS Rounded 1c", -apple-system, BlinkMacSystemFont, "Hiragino Maru Gothic ProN", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.cabinet-shell {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  max-width: 1024px;
  margin: 0 auto;
  background: #f2f4f8;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.55);
}

/* ====== 3D ガラス窓ステージ ====== */
.viewport-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #eef1f7;
  cursor: grab;
}

.viewport-stage:active {
  cursor: grabbing;
}

#craneCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ====== 上部 HUD（BIG ECHO公式赤白ブランド） ====== */
.top-hud {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 12;
  pointer-events: none;
}

.top-hud > * {
  pointer-events: auto;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 7px;
  border-radius: 12px;
  background: #c81018;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 6px 18px rgba(158, 0, 20, 0.34);
}

.brand-logo-img {
  display: block;
  height: 30px;
  width: auto;
  border-radius: 6px;
}

.brand-ver {
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.78);
  align-self: flex-end;
  padding-bottom: 2px;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border: 2px solid var(--be-gold);
  border-radius: 999px;
  background: rgba(34, 36, 44, 0.88);
  color: #ffffff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.16s ease;
}

.score-pill i {
  color: var(--be-gold-light);
  font-size: 15px;
}

.score-pill:active {
  transform: scale(0.94);
}

.score-pill.bump {
  animation: pill-bump 0.42s cubic-bezier(0.22, 1.4, 0.36, 1);
}

@keyframes pill-bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.88);
  color: var(--be-charcoal);
  font-size: 15px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
  transition: transform 0.15s ease, background 0.18s ease, color 0.18s ease;
}

.icon-btn:active {
  transform: scale(0.9);
}

.icon-btn.is-active {
  background: linear-gradient(135deg, var(--be-red-bright), var(--be-red));
  border-color: #ffffff;
  color: #ffffff;
  box-shadow: 0 0 16px rgba(228, 8, 39, 0.55);
}

.icon-btn.is-muted {
  color: #94a3b8;
}

/* ====== 視点ステータスピル ====== */
.view-pill-wrap {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 10;
}

.view-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.65);
  background: rgba(34, 36, 44, 0.78);
  color: #ffffff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.view-pill:active {
  transform: scale(0.94);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.9);
}

.status-dot.is-live {
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.95);
}

.status-dot.is-searching {
  background: var(--be-gold);
  box-shadow: 0 0 8px rgba(245, 183, 0, 0.9);
}

/* ====== インカメラ小型プレビュー ====== */
.cam-preview {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 72px;
  height: 92px;
  border-radius: 14px;
  overflow: hidden;
  border: 2.5px solid #ffffff;
  background: #18181b;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
  z-index: 10;
}

.cam-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.cam-reticle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #22c55e;
  background: rgba(34, 197, 94, 0.25);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: left 0.08s linear, top 0.08s linear;
}

/* ====== トースト ====== */
.toast-banner {
  position: absolute;
  top: calc(68px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(34, 36, 44, 0.9);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 25;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast-banner.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== 3D 景品飛び出し「ゲット！」オーバーレイ（元動画リスペクト） ====== */
.win-overlay {
  position: absolute;
  inset: 0;
  z-index: 28;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(74px + var(--safe-top)) 20px 34px;
  background: radial-gradient(circle at 50% 48%, rgba(255, 236, 153, 0.34) 0%, rgba(200, 0, 26, 0.18) 55%, rgba(20, 22, 34, 0.42) 100%);
  animation: win-fade 0.28s ease-out;
}

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

@keyframes win-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.win-sunburst {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 140vmax;
  height: 140vmax;
  margin-left: -70vmax;
  margin-top: -70vmax;
  z-index: -1;
  pointer-events: none;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 243, 176, 0.32) 0deg 14deg,
    transparent 14deg 30deg
  );
  -webkit-mask-image: radial-gradient(circle at center, transparent 10%, black 24%);
  mask-image: radial-gradient(circle at center, transparent 10%, black 24%);
  animation: spin-burst 18s linear infinite;
}

@keyframes spin-burst {
  to { transform: rotate(360deg); }
}

.win-header-group {
  text-align: center;
  pointer-events: none;
}

.win-rarity-tag {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--be-red-bright), var(--be-red));
  border: 2px solid #ffffff;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  box-shadow: 0 6px 16px rgba(200, 0, 26, 0.4);
}

.win-title-text {
  margin: 8px 0 0;
  font-size: 50px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-shadow:
    0 4px 0 #c8001a,
    0 10px 24px rgba(0, 0, 0, 0.42);
  animation: title-pop 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

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

.win-footer-group {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.win-name-text {
  margin: 0;
  padding: 6px 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--be-charcoal);
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

.win-count-text {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}

.win-take-btn {
  min-width: 190px;
  padding: 13px 34px;
  border-radius: 999px;
  border: 3px solid #ffffff;
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  font-family: inherit;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(29, 78, 216, 0.5);
  transition: transform 0.14s ease;
}

.win-take-btn:active {
  transform: scale(0.94);
}

/* ====== 初回スタートオーバーレイ ====== */
.start-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 22, 32, 0.45);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 30;
  transition: opacity 0.28s ease;
}

.start-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.start-card {
  width: min(336px, 84vw);
  padding: 26px 24px 24px;
  border-radius: 28px;
  text-align: center;
  background: #ffffff;
  color: var(--be-charcoal);
  border: 3px solid var(--be-red);
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.35);
}

.start-logo-box {
  display: inline-block;
  padding: 6px;
  border-radius: 14px;
  background: #c81018;
  margin-bottom: 14px;
  box-shadow: 0 8px 20px rgba(200, 0, 26, 0.28);
}

.start-logo-box img {
  display: block;
  width: 210px;
  height: auto;
  border-radius: 10px;
}

.start-title {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  color: var(--be-charcoal);
}

.start-sub {
  margin: 6px 0 20px;
  font-size: 14px;
  font-weight: 700;
  color: #64748b;
}

.start-buttons {
  display: grid;
  gap: 10px;
}

.primary-cta,
.secondary-cta {
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  border: none;
  transition: transform 0.14s ease;
}

.primary-cta {
  background: linear-gradient(135deg, var(--be-red-bright), var(--be-red));
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(200, 0, 26, 0.35);
}

.secondary-cta {
  background: #f1f5f9;
  color: var(--be-charcoal);
  border: 1.5px solid #cbd5e1;
}

.primary-cta:active,
.secondary-cta:active {
  transform: scale(0.96);
}

/* ====== 実機風コントロールパネル（店舗フロントの赤×白×黒ストライプ） ====== */
.control-deck {
  position: relative;
  background: linear-gradient(180deg, var(--deck-top) 0%, var(--deck-bottom) 100%);
  color: var(--ink-dark);
  padding: 16px 20px calc(18px + var(--safe-bottom));
  box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.22), inset 0 2px 0 #ffffff;
  z-index: 15;
}

.deck-stripe-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7px;
  background: linear-gradient(
    90deg,
    var(--be-red-deep) 0% 8%,
    #ffffff 8% 10%,
    var(--be-charcoal) 10% 15%,
    #ffffff 15% 17%,
    var(--be-red) 17% 83%,
    #ffffff 83% 85%,
    var(--be-charcoal) 85% 90%,
    #ffffff 90% 92%,
    var(--be-red-deep) 92% 100%
  );
}

.deck-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
}

.control-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 12px;
  font-weight: 800;
  color: #475569;
  letter-spacing: 0.08em;
}

/* ジョイスティック（クリムゾンレッド艶玉） */
.joystick-base {
  position: relative;
  width: clamp(112px, 24vw, 146px);
  height: clamp(112px, 24vw, 146px);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #f1f5f9 0%, #cbd5e1 65%, #94a3b8 100%);
  border: 4px solid #ffffff;
  box-shadow:
    0 10px 22px rgba(15, 23, 42, 0.2),
    inset 0 8px 16px rgba(15, 23, 42, 0.22);
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: pointer;
}

.joystick-base::after {
  content: "";
  position: absolute;
  width: 44%;
  height: 44%;
  border-radius: 50%;
  background: radial-gradient(circle, #2a2d37 0%, #14161c 100%);
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.7);
}

.joystick-arrows {
  position: absolute;
  inset: 9px;
  pointer-events: none;
  color: rgba(34, 36, 44, 0.4);
  font-size: 14px;
}

.joystick-arrows i { position: absolute; }
.joystick-arrows .arrow-u { top: 0; left: 50%; transform: translateX(-50%); }
.joystick-arrows .arrow-d { bottom: 0; left: 50%; transform: translateX(-50%); }
.joystick-arrows .arrow-l { left: 2px; top: 50%; transform: translateY(-50%); }
.joystick-arrows .arrow-r { right: 2px; top: 50%; transform: translateY(-50%); }

.joystick-shaft {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #94a3b8, #f8fafc, #64748b);
  z-index: 2;
  transform-origin: center center;
  pointer-events: none;
}

.joystick-knob {
  position: relative;
  width: 56%;
  height: 56%;
  border-radius: 50%;
  z-index: 3;
  background: radial-gradient(circle at 34% 28%, #ff6b7f 0%, var(--be-red-bright) 48%, var(--be-red-deep) 100%);
  box-shadow:
    0 10px 20px rgba(143, 0, 19, 0.42),
    inset 0 -4px 10px rgba(80, 0, 10, 0.45);
  pointer-events: none;
  will-change: transform;
  transition: transform 0.08s ease-out;
}

.joystick-base.is-dragging .joystick-knob {
  transition: none;
}

.knob-gloss {
  position: absolute;
  top: 14%;
  left: 20%;
  width: 34%;
  height: 22%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.58);
  transform: rotate(-22deg);
}

/* 中央ミニモニター */
.deck-center {
  display: flex;
  justify-content: center;
}

.mini-display {
  width: clamp(118px, 24vw, 152px);
  padding: 11px 12px 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, #2a2d38 0%, #181a22 100%);
  border: 2.5px solid #cbd5e1;
  box-shadow:
    inset 0 4px 12px rgba(0, 0, 0, 0.6),
    0 4px 12px rgba(15, 23, 42, 0.14);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #ffffff;
}

.mini-phase-icon {
  font-size: 16px;
  color: var(--be-gold-light);
}

.mini-phase-text {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #f8fafc;
}

.coord-grid {
  position: relative;
  width: 72px;
  height: 54px;
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    rgba(255, 255, 255, 0.05);
  background-size: 18px 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  overflow: hidden;
}

.coord-chute {
  position: absolute;
  left: 3px;
  bottom: 3px;
  width: 24px;
  height: 20px;
  border-radius: 4px;
  background: rgba(245, 183, 0, 0.28);
  border: 1px dashed var(--be-gold);
}

.coord-dot {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--be-red-bright);
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(228, 8, 39, 0.95);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* 降下キャッチボタン */
.grab-btn {
  position: relative;
  width: clamp(112px, 24vw, 146px);
  height: clamp(112px, 24vw, 146px);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  display: grid;
  place-items: center;
}

.grab-btn-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
  box-shadow:
    0 10px 22px rgba(15, 23, 42, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.95);
}

.grab-btn-cap {
  position: relative;
  width: 82%;
  height: 82%;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #ffffff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: radial-gradient(circle at 35% 25%, #fde047 0%, #f59e0b 55%, #d97706 100%);
  box-shadow:
    0 8px 0 #b45309,
    0 14px 22px rgba(217, 119, 6, 0.4),
    inset 0 3px 6px rgba(255, 255, 255, 0.55);
  transform: translateY(-4px);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.18s ease;
}

.grab-btn-cap i {
  font-size: 24px;
  filter: drop-shadow(0 2px 3px rgba(120, 53, 15, 0.4));
}

.grab-btn:active:not(:disabled) .grab-btn-cap,
.grab-btn.is-pressed .grab-btn-cap {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 #b45309,
    0 4px 10px rgba(217, 119, 6, 0.35),
    inset 0 3px 6px rgba(255, 255, 255, 0.4);
}

.grab-btn:disabled {
  cursor: default;
}

.grab-btn:disabled .grab-btn-cap {
  filter: grayscale(0.55) brightness(0.9);
  transform: translateY(2px);
  box-shadow: 0 2px 0 #92400e;
}

/* ====== コレクションモーダル ====== */
.game-dialog {
  border: none;
  padding: 0;
  border-radius: 26px;
  background: transparent;
  overflow: visible;
  max-width: min(410px, 88vw);
  width: 100%;
}

.game-dialog::backdrop {
  background: rgba(20, 22, 32, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.collection-dialog {
  background: #ffffff;
  color: var(--be-charcoal);
  border: 3px solid var(--be-red);
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--be-charcoal);
}

.dialog-header h2 i {
  color: var(--be-red);
}

.dialog-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: var(--be-charcoal);
  font-size: 16px;
  cursor: pointer;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 52dvh;
  overflow-y: auto;
  padding-right: 2px;
}

.collection-card {
  padding: 12px 10px;
  border-radius: 18px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.collection-card.is-locked {
  opacity: 0.45;
}

.collection-swatch {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: #ffffff;
}

.collection-name {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--be-charcoal);
}

.collection-qty {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(200, 0, 26, 0.12);
  color: var(--be-red);
}

.dialog-footer {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.reset-link-btn {
  border: none;
  background: transparent;
  color: #64748b;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dialog-ver {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
}

@media (max-height: 680px) {
  .control-deck {
    padding: 10px 16px calc(12px + var(--safe-bottom));
  }
  .joystick-base,
  .grab-btn {
    width: 96px;
    height: 96px;
  }
  .mini-display {
    padding: 8px 10px;
  }
  .coord-grid {
    width: 60px;
    height: 42px;
  }
}
