/* -------------------------------------------------------------
   NOTION DESIGN SYSTEM - 黒猫リズム METRONOME
------------------------------------------------------------- */
:root {
  --color-canvas-soft: #f6f5f4;
  --color-surface: #ffffff;
  --color-primary: #0075de;
  --color-primary-active: #005bab;
  --color-hairline: #e6e6e6;
  --color-ink: #000000;
  --color-ink-secondary: #31302e;
  --color-ink-muted: #615d59;
  --color-ink-faint: #a39e98;

  /* Accent Sticker Tokens */
  --accent-green: #1aae39;
  --accent-orange: #dd5b00;
  --accent-purple: #d6b6f6;
  --accent-sky: #62aef0;
  --accent-pink: #ff64c8;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  --shadow-level1: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-level2: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background-color: var(--color-canvas-soft);
  color: var(--color-ink);
  font-family: var(--font-family);
  overflow-x: hidden;
  overflow-y: auto;
}

/* -------------------------------------------------------------
   APP LAYOUT (Header 100%, Main centered, Banner, Footer 100%)
------------------------------------------------------------- */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  background-color: var(--color-canvas-soft);
}

/* -------------------------------------------------------------
   HEADER: 幅100%、背景白、左右配置
------------------------------------------------------------- */
.app-header {
  width: 100%;
  background-color: #ffffff;
  border-bottom: 1px solid var(--color-hairline);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(3px, 0.7vh, 6px) 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 一番左: アプリアイコン */
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.header-logo-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline);
  padding: 1px;
  flex-shrink: 0;
}

.header-title-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  gap: 1px;
}

.header-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--color-ink);
  white-space: nowrap;
}

/* バージョン: 角の丸い背景 */
.header-version-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-primary);
  background: rgba(0, 117, 222, 0.1);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  letter-spacing: 0.2px;
  line-height: 1.2;
  white-space: nowrap;
}

.header-produce-row {
  font-size: 10px;
  font-weight: 500;
  color: var(--color-ink-muted);
  white-space: nowrap;
}

.header-produce-row a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s ease;
}

.header-produce-row a:hover {
  text-decoration: underline;
}

/* 右寄せ: ヘルプボタンと設定ボタン（アイコン） */
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--color-hairline);
  background: var(--color-canvas-soft);
  color: var(--color-ink-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.header-icon-btn:hover {
  background: var(--color-hairline);
  color: var(--color-ink);
  transform: translateY(-1px);
}

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

.header-svg-icon {
  width: 16px;
  height: 16px;
}

/* -------------------------------------------------------------
   MAIN CONTAINER (見栄え良い中央寄せ幅・画面内に収まる設計)
------------------------------------------------------------- */
.main-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: clamp(2px, 0.8vh, 6px) 12px clamp(2px, 0.5vh, 4px) 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: clamp(4px, 1vh, 8px);
  flex: 1;
}

/* -------------------------------------------------------------
   成績データをAIに聞く セクション & 展開パネル
------------------------------------------------------------- */
.ai-query-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-query-section:not(.hidden) {
  animation: aiSectionAppear 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes aiSectionAppear {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.btn-ask-ai {
  width: 100%;
  padding: 7px 16px;
  border: 1.5px solid rgba(139, 92, 246, 0.45);
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #f5f0ff 0%, #eff6ff 100%);
  color: #5b21b6;
  font-family: var(--font-family);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.15), 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-ask-ai:hover {
  background: linear-gradient(135deg, #ede5ff 0%, #e0edff 100%);
  border-color: #7c3aed;
  color: #4c1d95;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.24);
}

.btn-ask-ai:active {
  transform: scale(0.98);
  background: linear-gradient(135deg, #e9d5ff 0%, #dbeafe 100%);
}

.ai-btn-icon {
  font-size: 17px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(124, 58, 237, 0.2));
}

/* AI展開パネル */
.ai-result-panel {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-level1);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: panelSlideDown 0.25s ease-out;
}

@keyframes panelSlideDown {
  0% {
    opacity: 0;
    transform: translateY(-8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* クリップボード貼り付け完了表示 */
.ai-copied-banner {
  background: #f0f7ff;
  border: 1px solid #c8e1fd;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ai-copied-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.ai-copied-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-copied-title {
  font-size: 13px;
  font-weight: 700;
  color: #0056b3;
}

.ai-copied-desc {
  font-size: 11px;
  color: var(--color-ink-muted);
  line-height: 1.4;
}

/* AIリンクボタン (Gemini, ChatGPT, Claude) */
.ai-service-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ai-link-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--color-hairline);
  background: var(--color-canvas-soft);
  color: var(--color-ink);
  transition: all 0.15s ease;
}

.ai-link-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-level1);
}

.ai-link-btn.gemini {
  border-color: #d1e3ff;
  background: #f4f8ff;
  color: #1a73e8;
}

.ai-link-btn.chatgpt {
  border-color: #c5edd9;
  background: #f0fbf6;
  color: #10a37f;
}

.ai-link-btn.claude {
  border-color: #f7ded4;
  background: #fff8f5;
  color: #cc5500;
}

.ai-link-badge {
  font-size: 18px;
}

.ai-link-name {
  white-space: nowrap;
}

/* AIパネル内のAmazonバナー */
.ai-panel-banner {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.banner-sub-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-panel-rec-content {
  width: 100%;
  min-height: 90px;
}

/* 成績をクリアして閉じるボタン */
.btn-clear-close-ai {
  width: 100%;
  padding: 10px;
  border: 1px solid #ffd1d5;
  background: #fff5f5;
  color: #dc3545;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear-close-ai:hover {
  background: #ffe3e6;
  border-color: #f5b5bc;
}

.btn-clear-close-ai:active {
  transform: scale(0.98);
}

/* -------------------------------------------------------------
   3段目以降: ゲームコンテンツ
------------------------------------------------------------- */
.tap-action-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* -------------------------------------------------------------
   AMAZON BANNER (フッターの上・横長)
------------------------------------------------------------- */
.global-banner-wrapper {
  width: 100%;
  max-width: 600px;
  margin: 0 auto clamp(2px, 0.6vh, 6px) auto;
  padding: 0 12px;
  box-sizing: border-box;
}

.global-banner-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.global-rec-content {
  width: 100%;
  min-height: 75px;
}

/* -------------------------------------------------------------
   FOOTER: 幅100%、背景白、1行で表示
------------------------------------------------------------- */
.app-footer {
  width: 100%;
  background-color: #ffffff;
  border-top: 1px solid var(--color-hairline);
  padding: clamp(3px, 0.6vh, 6px) 12px;
  margin-top: auto;
}

.footer-single-line {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  color: var(--color-ink-muted);
  white-space: nowrap;
  flex-wrap: wrap;
}

.footer-item-title {
  font-weight: 700;
  color: var(--color-ink);
}

.footer-dot {
  color: var(--color-ink-faint);
}

.footer-item-version {
  font-weight: 600;
}

.footer-item-produce a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s ease;
}

.footer-item-produce a:hover {
  text-decoration: underline;
}

/* -------------------------------------------------------------
   HELP MODAL
------------------------------------------------------------- */
.help-modal-card {
  max-width: 480px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-body-scrollable {
  overflow-y: auto;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.help-section h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-ink);
  margin-bottom: 6px;
}

.help-section p {
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-ink-secondary);
}

.help-list {
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-ink-secondary);
  padding-left: 20px;
}

.help-list li {
  margin-bottom: 4px;
}



.tempo-control-card {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-full);
  padding: 1px 8px;
  box-shadow: var(--shadow-level1);
  margin-bottom: 0;
}

.btn-step {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--color-canvas-soft);
  color: var(--color-ink);
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-step:active {
  background: var(--color-hairline);
  transform: scale(0.94);
}

.tempo-input-group {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

#tempo-input {
  width: 38px;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 16px;
  font-weight: 700;
  color: var(--color-ink);
  text-align: right;
  outline: none;
  -moz-appearance: textfield;
}

#tempo-input::-webkit-outer-spin-button,
#tempo-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tempo-unit {
  font-size: 9px;
  font-weight: 600;
  color: var(--color-ink-muted);
}

/* -------------------------------------------------------------
   MAIN STAGE: CAT & RHYTHM CARDS
------------------------------------------------------------- */
.main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 0;
  /* allows scaling inside flex */
}

/* Cat Stage */
.cat-stage-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 100%;
  padding: clamp(2px, 0.5vh, 6px) 0;
  flex: 1 1 auto;
}

.cat-image-wrapper {
  position: relative;
  width: 100%;
  max-width: clamp(140px, 26vh, 220px);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-level1);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cat-stage-container:active .cat-image-wrapper {
  transform: scale(0.97);
  box-shadow: var(--shadow-level2);
}

.cat-img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  transition: transform 0.1s ease;
}

.cat-stage-container.playing .cat-image-wrapper {
  border-color: var(--color-primary);
}



/* Judgement Badge Overlay */
.judgement-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  box-shadow: var(--shadow-level2);
  transform: scale(1);
  animation: badgePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.judgement-badge.verygood {
  background: var(--accent-green);
}

.judgement-badge.good {
  background: var(--accent-sky);
}

.judgement-badge.bad {
  background: var(--accent-orange);
}

.hidden {
  display: none !important;
}

@keyframes badgePop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* -------------------------------------------------------------
   PATTERN & PROGRESS CARD
------------------------------------------------------------- */
.pattern-card {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: 6px 10px;
  box-shadow: var(--shadow-level1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* Timing Meter Wrapper */
.timing-meter-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.timing-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
}

.label-fast {
  color: var(--color-ink-muted);
  font-weight: 600;
}

.label-slow {
  color: var(--color-ink-muted);
  font-weight: 600;
}

.timing-diff-text {
  font-family: var(--font-family);
  font-size: 10px;
  font-weight: 700;
  color: var(--color-ink-secondary);
  background: var(--color-canvas-soft);
  padding: 1px 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-hairline);
  min-width: 60px;
  text-align: center;
  transition: all 0.2s ease;
}

.timing-diff-text.diff-just {
  background: #eaf8ed;
  color: #158a2d;
  border-color: rgba(26, 174, 57, 0.3);
}

.timing-diff-text.diff-fast {
  background: #fff2ea;
  color: #d34e00;
  border-color: rgba(221, 91, 0, 0.3);
}

.timing-diff-text.diff-slow {
  background: #f3eafc;
  color: #7b1fa2;
  border-color: rgba(123, 31, 162, 0.3);
}

/* Timing Meter Track & Zones (Soft Elegant Notion Theme) */
.timing-meter-track {
  position: relative;
  width: 100%;
  height: 16px;
  background: #eae8e5; /* 優しいソフトグレー背景 */
  border-radius: var(--radius-full);
  border: 1px solid var(--color-hairline);
  overflow: hidden;
}

/* 薄く優しい判定ゾーン */
.zone-good {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(98, 174, 240, 0.25); /* 薄いスカイブルー */
  border-radius: var(--radius-full);
  transition: left 0.3s ease, width 0.3s ease;
}

.zone-verygood {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(26, 174, 57, 0.28); /* 薄いグリーン */
  border-radius: var(--radius-full);
  transition: left 0.3s ease, width 0.3s ease;
}

.center-line {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-ink-muted);
  opacity: 0.5;
  transform: translateX(-50%);
  z-index: 2;
}

/* ユーザーのタップタイミング部分だけを【濃い色】で際立たせるマーカー */
.tap-marker {
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 6px;
  border-radius: 99px;
  transform: translateX(-50%);
  z-index: 5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: left 0.08s ease-out, background 0.15s ease;
  animation: markerPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tap-marker.verygood {
  background: #14802a; /* 濃くはっきりしたグリーン */
  box-shadow: 0 0 6px rgba(20, 128, 42, 0.5);
}

.tap-marker.good {
  background: #0050a0; /* 濃くはっきりしたブルー */
  box-shadow: 0 0 6px rgba(0, 80, 160, 0.5);
}

.tap-marker.bad {
  background: #c0390b; /* 濃くはっきりしたダークオレンジレッド */
  box-shadow: 0 0 6px rgba(192, 57, 11, 0.5);
}

@keyframes markerPop {
  0% { transform: translateX(-50%) scaleY(1.3); }
  100% { transform: translateX(-50%) scaleY(1); }
}

.pattern-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.pattern-header.center {
  justify-content: center;
}

.bar-counter-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-ink-secondary);
  letter-spacing: 0.5px;
}

/* 8-Bar Dots */
.bar-dots {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  padding: 1px 0;
}

.dot {
  flex: 1;
  height: 5px;
  background: var(--color-canvas-soft);
  border-radius: var(--radius-full);
  transition: background 0.2s ease, transform 0.15s ease;
}

.dot.active {
  background: var(--color-primary);
  transform: scaleY(1.3);
}

.dot.passed {
  background: rgba(0, 117, 222, 0.35);
}

/* Beat Visualizer (1, 2, 3, 4 Pips) */
.beat-visualizer {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.beat-pip {
  flex: 1;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-canvas-soft);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  color: var(--color-ink-muted);
  transition: background 0.1s ease, color 0.1s ease, transform 0.1s ease;
}

.beat-pip.active {
  background: var(--color-ink);
  color: var(--color-surface);
  transform: scale(1.04);
}

.beat-pip.sub-active {
  background: var(--color-primary);
  color: var(--color-surface);
}

/* -------------------------------------------------------------
   TAP ACTION AREA & TAP BUTTON
------------------------------------------------------------- */
.tap-guide-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-ink-muted);
  letter-spacing: 0.2px;
}

.btn-tap {
  width: 100%;
  height: clamp(44px, 5.8vh, 50px);
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #ffffff;
  font-family: var(--font-family);
  font-size: clamp(16px, 2.2vh, 19px);
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 117, 222, 0.35);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn-tap:not(:disabled):active {
  background: var(--color-primary-active);
  transform: scale(0.96);
  box-shadow: 0 2px 6px rgba(0, 117, 222, 0.2);
}

.btn-tap:disabled {
  background: #c5d7e8;
  color: #ffffff;
  cursor: not-allowed;
  box-shadow: none;
}

.tap-icon {
  font-size: 20px;
}

/* -------------------------------------------------------------
   TOAST / CLEAR ANNOUNCEMENT (少し透明な背景)
------------------------------------------------------------- */
.clear-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3000;
  background: rgba(0, 0, 0, 0.72); /* 少し透明なダーク背景 */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #ffffff;
  padding: 12px 22px;
  border-radius: var(--radius-full);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
  animation: toastFade 0.35s ease-out;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

.toast-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

@keyframes toastFade {
  0% {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.8);
  }

  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* -------------------------------------------------------------
   BLUETOOTH WARNING MODAL
------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
  animation: modalFadeIn 0.25s ease-out;
}

.modal-card {
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-xl);
  padding: 24px 20px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-level2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-icon {
  font-size: 40px;
  line-height: 1;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-ink);
}

.modal-message {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--color-ink-secondary);
  text-align: left;
  background: var(--color-canvas-soft);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-hairline);
}

.btn-modal-close {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #ffffff;
  font-family: var(--font-family);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 117, 222, 0.3);
  transition: all 0.15s ease;
  margin-top: 4px;
}

.btn-modal-close:hover {
  background: var(--color-primary-active);
}

.btn-modal-close:active {
  transform: scale(0.97);
}

/* -------------------------------------------------------------
   ADVANCED SETTINGS BUTTON & MODAL
------------------------------------------------------------- */
.btn-adv-settings {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-hairline);
  background: var(--color-surface);
  color: var(--color-ink-secondary);
  font-family: var(--font-family);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-level1);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  margin-bottom: 2px;
}

.btn-adv-settings:hover {
  background: #f0eeee;
  color: var(--color-ink);
}

.btn-adv-settings:active {
  transform: scale(0.96);
}

.btn-adv-settings:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.adv-modal-card {
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  text-align: left;
  align-items: stretch;
}

.modal-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-hairline);
}

.btn-modal-x {
  background: transparent;
  border: none;
  font-size: 18px;
  font-weight: 700;
  color: var(--color-ink-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.btn-modal-x:hover {
  color: var(--color-ink);
  background: var(--color-canvas-soft);
}

.adv-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 2px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-ink);
}

.settings-group-desc {
  font-size: 11px;
  color: var(--color-ink-muted);
  line-height: 1.3;
}

.pattern-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-ink-secondary);
  cursor: pointer;
  padding: 8px 12px;
  background: var(--color-canvas-soft);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-hairline);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.checkbox-item:hover {
  background: #eae8e5;
}

.checkbox-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.settings-select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-hairline);
  background: var(--color-canvas-soft);
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.settings-select:focus {
  border-color: var(--color-primary);
}

/* モーダル内テンポコントロール */
.adv-tempo-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-full);
  padding: 4px 10px;
  margin-top: 2px;
  width: fit-content;
}

.adv-tempo-input {
  width: 44px;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 16px;
  font-weight: 700;
  color: var(--color-ink);
  text-align: right;
  outline: none;
}

.adv-tempo-input::-webkit-outer-spin-button,
.adv-tempo-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.adv-tempo-input[type="number"] {
  -moz-appearance: textfield;
}

/* 詳細設定モーダルフッター */
.adv-modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  align-items: center;
}

.btn-modal-share {
  flex: 1;
  height: 46px;
  border: 1.5px solid rgba(0, 117, 222, 0.4);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-primary);
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--shadow-level1);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-modal-share:hover {
  background: #f0f7ff;
  border-color: var(--color-primary);
  color: var(--color-primary-active);
  transform: translateY(-1px);
  box-shadow: var(--shadow-level2);
}

.btn-modal-share:active {
  transform: scale(0.97);
}

.btn-modal-share .share-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.adv-modal-footer .btn-modal-close {
  flex: 1.1;
  height: 46px;
  margin-top: 0;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* -------------------------------------------------------------
   RESULT & AMAZON BANNER MODAL
------------------------------------------------------------- */
.result-modal-card {
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  text-align: left;
}

.result-modal-body {
  overflow-y: auto;
  padding-right: 4px;
  margin: 12px 0 16px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

.result-summary-box {
  background: var(--color-canvas-soft);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-stat-badges {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--color-ink-muted);
}

.stat-badge strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-ink);
}

.stat-badge.stat-vg strong {
  color: #dd5b00; /* VERY GOOD */
}

.stat-badge.stat-good strong {
  color: #1aae39; /* GOOD */
}

.stat-badge.stat-bad strong {
  color: #615d59; /* BAD */
}

.result-modal-desc {
  font-size: 12px;
  line-height: 1.5;
  color: var(--color-ink-secondary);
  background: rgba(0, 117, 222, 0.08);
  border-left: 3px solid var(--color-primary);
  padding: 8px 10px;
  border-radius: var(--radius-xs);
}

.result-rec-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-rec-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-badge-tag {
  font-size: 11px;
  font-weight: 700;
  background: #ff9900;
  color: #111;
  padding: 2px 8px;
  border-radius: 4px;
}

.rec-badge-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-ink-muted);
}

.result-rec-content {
  min-height: 90px;
  width: 100%;
}

/* PC常時表示バナー（スマホ時は非表示） */
.pc-rec-wrapper {
  display: none;
  width: 100%;
}

.pc-rec-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.pc-rec-content {
  width: 100%;
  min-height: 90px;
}

/* バナー本体を親要素の100%にピタッと揃える */
.pc-rec-wrapper .amz-banner,
.pc-rec-wrapper .amz-layout-horizontal,
.result-rec-card .amz-banner,
.result-rec-card .amz-layout-horizontal,
.global-banner-wrapper .amz-banner,
.global-banner-wrapper .amz-layout-horizontal,
.ai-panel-banner .amz-banner,
.ai-panel-banner .amz-layout-horizontal {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.pc-rec-wrapper .amz-layout-horizontal a,
.result-rec-card .amz-layout-horizontal a,
.global-banner-wrapper .amz-layout-horizontal a,
.ai-panel-banner .amz-layout-horizontal a {
  box-sizing: border-box !important;
  width: 100% !important;
}

/* -------------------------------------------------------------
   RESPONSIVE ENHANCEMENTS FOR LARGER SCREENS / TABLET / PC
------------------------------------------------------------- */
@media (min-height: 720px) {
  .cat-image-wrapper {
    max-width: clamp(160px, 28vh, 240px);
  }

  .main-container {
    gap: clamp(6px, 1.2vh, 10px);
    padding: clamp(4px, 1vh, 10px) 16px;
  }

  .btn-tap {
    height: clamp(48px, 6.2vh, 54px);
    font-size: 20px;
  }

  .pattern-card {
    padding: 7px 12px;
    gap: 5px;
  }

  .beat-pip {
    height: 24px;
  }
}

@media (min-height: 820px) {
  .cat-image-wrapper {
    max-width: clamp(200px, 30vh, 270px);
  }

  .main-container {
    gap: clamp(8px, 1.5vh, 12px);
    padding: clamp(6px, 1.2vh, 12px) 16px;
  }

  .btn-tap {
    height: clamp(52px, 6.8vh, 58px);
    font-size: 21px;
  }

  .pattern-card {
    padding: 8px 14px;
    gap: 6px;
  }

  .beat-pip {
    height: 26px;
  }
}