/* -------------------------------------------------------------
   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%;
  height: 100%;
  height: 100dvh;
  background-color: var(--color-canvas-soft);
  color: var(--color-ink);
  font-family: var(--font-family);
  overflow: hidden;
}

/* -------------------------------------------------------------
   APP CONTAINER (Fits 100dvh without scrolling)
------------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  padding: 12px 16px;
  background-color: var(--color-canvas-soft);
}

/* -------------------------------------------------------------
   HEADER
------------------------------------------------------------- */
.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 0 2px 0;
}

.app-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-ink);
  white-space: nowrap;
}

.app-credit {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-ink-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.app-credit:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* Mode Selection Segmented Controller (Above Cat Stage) */
.mode-toggle-container {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 3px;
  background: var(--color-surface);
  padding: 3px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-hairline);
  box-shadow: var(--shadow-level1);
  margin-bottom: 2px;
}

/* Mode Selection Button */
.btn-mode-select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--color-ink-muted);
  font-family: var(--font-family);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-mode-select:hover {
  color: var(--color-ink);
}

.btn-mode-select:active {
  transform: scale(0.96);
}

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

/* Easy Mode Active */
.btn-mode-select#mode-easy-btn.active {
  background: #eaf8ed;
  color: #1aae39;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(26, 174, 57, 0.2);
}

/* Severe Mode Active */
.btn-mode-select#mode-severe-btn.active {
  background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(255, 65, 108, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-mode-select#mode-severe-btn.active .mode-icon {
  display: inline-block;
  animation: flamePulse 1.2s infinite ease-in-out alternate;
}

/* Offbeat Mode Active */
.btn-mode-select#mode-offbeat-btn.active {
  background: linear-gradient(135deg, #7F00FF 0%, #E100FF 100%);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(225, 0, 255, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-mode-select#mode-offbeat-btn.active .mode-icon {
  display: inline-block;
  animation: zapPulse 1s infinite ease-in-out alternate;
}

@keyframes flamePulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.25); filter: drop-shadow(0 0 4px rgba(255, 200, 0, 0.8)); }
}

@keyframes zapPulse {
  0% { transform: scale(1) rotate(0deg); }
  100% { transform: scale(1.3) rotate(-10deg); filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.9)); }
}

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

.btn-step {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--color-canvas-soft);
  color: var(--color-ink);
  font-size: 18px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  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: 52px;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 22px;
  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: 11px;
  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: 12px;
  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: 8px 0;
}

.cat-image-wrapper {
  position: relative;
  width: 100%;
  max-width: 240px;
  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: 85%;
  height: 85%;
  object-fit: contain;
  transition: transform 0.1s ease;
}

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

/* Hint Text */
.cat-hint-text {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink-muted);
  background: var(--color-surface);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-hairline);
}

/* Judgement Badge Overlay */
.judgement-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 14px;
  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: 10px 14px;
  box-shadow: var(--shadow-level1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

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

.timing-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  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: 11px;
  font-weight: 700;
  color: var(--color-ink-secondary);
  background: var(--color-canvas-soft);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-hairline);
  min-width: 68px;
  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: 20px;
  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: 13px;
  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: 2px 0;
}

.dot {
  flex: 1;
  height: 6px;
  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: 8px;
}

.beat-pip {
  flex: 1;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-canvas-soft);
  border-radius: var(--radius-sm);
  font-size: 12px;
  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);
}

/* -------------------------------------------------------------
   FOOTER & TAP BUTTON
------------------------------------------------------------- */
.app-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 2px;
  padding-bottom: env(safe-area-inset-bottom, 8px);
}

.tap-guide-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-ink-muted);
  letter-spacing: 0.2px;
}

.btn-tap {
  width: 100%;
  height: 64px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #ffffff;
  font-family: var(--font-family);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  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: 24px;
}

/* -------------------------------------------------------------
   TOAST / CLEAR ANNOUNCEMENT
------------------------------------------------------------- */
.clear-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  background: var(--color-ink);
  color: #ffffff;
  padding: 16px 28px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-level2);
  animation: toastFade 0.4s ease-out;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
}

@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);
}

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

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