/* Custom CSS Variables for Crisp Light Textbook Theme */
:root {
  --bg-primary: #faf8f5;     /* Warm off-white textbook page */
  --bg-secondary: #f1ede4;   /* Slightly darker beige for inputs */
  --bg-card: #ffffff;        /* Pure white cards */
  --border-color: #cbd5e1;   /* Clean light gray borders */
  --border-active: #d97706;  /* Warm wood/orange active border */
  
  --text-primary: #0f172a;   /* Dark slate (almost black) for primary text */
  --text-secondary: #475569; /* Slate gray for secondary text */
  --text-muted: #94a3b8;

  --accent-emerald: #059669; /* Darker emerald for light theme */
  --accent-cyan: #0891b2;    /* Darker cyan for text labels */
  --accent-orange: #d97706;  /* Warm amber/orange */
  
  --glow-cyan: 0 0 10px rgba(8, 145, 178, 0.2);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.03);

  --font-main: 'Outfit', 'Noto Sans JP', sans-serif;
}

/* Global resets and typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  gap: 24px;
}

/* Header */
.app-header {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

h1 {
  display: flex;
  flex-direction: column;
}

.title-sub {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent-orange);
  font-weight: 700;
}

.title-main {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Settings Panel */
.settings-panel {
  display: flex;
  gap: 20px;
  align-items: center;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Switch (Sound toggle) */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-secondary);
  transition: .3s;
}

input:checked + .slider {
  background-color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

input:checked + .slider:before {
  transform: translateX(24px);
  background-color: #ffffff;
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Main Layout Grid */
.app-main {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 24px;
  flex: 1;
}

@media (max-width: 820px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

/* Crisp Cards */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.glass-card:hover {
  border-color: #94a3b8;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  border-left: 3px solid var(--accent-orange);
  padding-left: 8px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Keyboard Section (Horizontal Bar at Top) */
.keyboard-section {
  padding: 12px 20px;
}

.keyboard-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* All Buttons are strictly identical in size (62px width, 38px height) */
.key-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
  width: 62px;
  height: 38px;
}

.key-btn:hover {
  transform: translateY(-1.5px);
  border-color: var(--accent-orange);
  background: #fdfbf7;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.key-btn:active {
  transform: translateY(0.5px);
}

.key-btn.active {
  background: #fffbeb; /* Warm amber light bg */
  border-color: var(--accent-orange);
  box-shadow: 0 2px 6px rgba(217, 119, 6, 0.15);
}

.key-syllable {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  transition: color 0.2s ease;
}

.overline-text {
  text-decoration: overline;
  text-decoration-thickness: 2.5px;
}

.key-btn.active .key-syllable {
  color: #b45309; /* Warm brown active text */
}

/* Score Section (Sheet Music) */
.score-container {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 180px;
}

.staff-line {
  stroke: #1e293b; /* Dark sharp music staff lines */
  stroke-width: 1.5;
}

.ledger-line {
  stroke: #1e293b;
  stroke-width: 2.2;
  transition: opacity 0.3s ease;
}

.ledger-line.hide {
  opacity: 0;
}

/* Note Head & Stem (Printed textbook style) */
#note-head {
  fill: #1e293b; /* Solid music note */
  filter: none;
}

#note-stem {
  stroke: #1e293b;
  stroke-width: 2.5;
}

/* Note Info Container */
.note-info-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.note-names {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.note-syllable {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Recorder Visualizer (Center Column) */
.recorder-visualizer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  flex: 1;
}

.front-body-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#recorder-body-svg {
  width: 320px;
  height: 540px;
  display: block;
  overflow: visible;
}

.recorder-silhouette {
  fill: #14161c;
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
}

.recorder-windway {
  fill: #0c0e15;
}

.recorder-hole {
  fill: #ffffff; /* Default open state is empty white */
  stroke: #92400e;
  stroke-width: 2.5;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* State Classes for Holes - Closed/Covered holes are solid black */
.recorder-hole.state-closed {
  fill: #000000; /* Solid black when closed */
  stroke: #92400e;
  filter: none;
}

.recorder-hole.state-open {
  fill: #ffffff;
  stroke: #92400e;
}

.recorder-hole.state-half {
  fill: url(#thumb-half-filled); /* Half-black, half-white */
  stroke: #92400e;
}

/* Double Hole Inner Circles (Hole 7) */
.double-hole-inner {
  fill: #ffffff; /* White openings when open */
  stroke: #92400e;
  stroke-width: 0.8;
  pointer-events: none;
  transition: fill 0.3s ease, stroke 0.3s ease;
}

.recorder-hole.state-closed ~ .double-hole-inner {
  fill: #000000; /* Solid black when covered */
  stroke: #000000;
}

/* --- Flat 2D Finger Slide Animation styling --- */

.flat-finger {
  fill: url(#skin-gradient);
  stroke: #92400e;
  stroke-width: 1.5;
  transition: fill 0.28s ease, stroke 0.28s ease, filter 0.28s ease;
  pointer-events: none;
}

/* Active Finger skin gradient and shadow */
.state-active .flat-finger {
  fill: url(#skin-gradient-active);
  stroke: #b45309;
  filter: drop-shadow(0 2px 6px rgba(180, 83, 9, 0.2));
}

/* Special "half-shift" state for E6/F6 thumb register (Red/Rose) */
.left-thumb.state-half .flat-finger {
  fill: url(#skin-gradient-half);
  stroke: #b45309;
  filter: drop-shadow(0 2px 6px rgba(180, 83, 9, 0.25));
}

/* Right Ring G#5 half-closed state (normal pink skin) */
.right-finger.state-half .flat-finger {
  fill: url(#skin-gradient-active);
  stroke: #b45309;
  filter: drop-shadow(0 2px 6px rgba(180, 83, 9, 0.2));
}

/* Next Finger state - colored green */
.state-next .flat-finger {
  fill: url(#skin-gradient-next) !important;
  stroke: #047857 !important;
  filter: drop-shadow(0 2px 6px rgba(4, 120, 87, 0.25)) !important;
}

/* Hiragana "はんぶんずらす" text styling */
.half-shift-text {
  font-family: var(--font-main);
  font-size: 8.5px;
  font-weight: 800;
  fill: #4338ca;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.finger-nail {
  fill: #ffffff;
  stroke: #cbd5e1;
  stroke-width: 0.8;
  transition: stroke 0.28s ease;
  pointer-events: none;
}

.state-active .finger-nail {
  stroke: #fca5a5;
}

.left-thumb.state-half .finger-nail {
  stroke: #c7d2fe;
}

.right-finger.state-half .finger-nail {
  stroke: #fca5a5;
}

/* Left Hand Fingers slide right (0 to cover, -24px when open) */
.left-finger {
  transform: translateX(-24px);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.left-finger.state-active {
  transform: translateX(0);
}

/* Left Thumb slides right (0 to cover, -35px when open) */
.left-thumb {
  transform: translateX(-35px);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.left-thumb.state-active {
  transform: translateX(0);
}

.left-thumb.state-half {
  transform: translate(0px, -10px);
}

/* Right Hand Fingers slide left (0 to cover, 24px when open) */
.right-finger {
  transform: translateX(24px);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.right-finger.state-active {
  transform: translateX(0);
}

.right-finger.state-half {
  transform: translateX(12px); /* Halfway slide to cover only the right double-hole */
}

.hand-title-label {
  font-family: var(--font-main);
  font-size: 9.5px;
  font-weight: 800;
  fill: var(--text-secondary);
  letter-spacing: 0.1em;
}

.hide {
  display: none !important;
}

/* Mastered Check Button for Platform Sync */
.mastered-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  vertical-align: middle;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.mastered-btn:hover {
  border-color: var(--accent-emerald);
  color: var(--accent-emerald);
  background: #f0fdf4;
  transform: translateY(-1px);
}

.mastered-btn:active {
  transform: translateY(0.5px);
}

.mastered-btn.active {
  background: var(--accent-emerald);
  border-color: var(--accent-emerald);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.15);
}

.mastered-btn .check-icon {
  font-size: 0.95rem;
  opacity: 0.5;
  font-weight: 900;
}

.mastered-btn.active .check-icon {
  opacity: 1;
}

/* Keyboard Rows */
.keyboard-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 8px;
}
.keyboard-row {
  display: flex;
  justify-content: center;
  width: 100%;
  gap: 8px;
  flex-wrap: wrap;
}
.keyboard-row.lower-row {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* Mode Selection Panel & Tabs */
.mode-control-panel {
  margin-top: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.mode-tabs {
  display: flex;
  justify-content: center;
  gap: 12px;
  border-bottom: 2px solid var(--bg-secondary);
  padding-bottom: 8px;
}

.tab-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 8px;
}

.tab-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.tab-btn.active {
  background: #fffbeb;
  color: var(--accent-orange);
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.1);
  font-weight: 700;
}

.mode-content {
  min-height: 100px;
}

/* Hide helper class */
.hide {
  display: none !important;
}

/* 1. Practice Mode Styling */
.practice-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.song-select-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.song-select-dropdown {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.85rem;
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.control-btn:hover {
  border-color: var(--accent-orange);
  background: #fffbeb;
  color: var(--accent-orange);
}

.control-btn.play-btn {
  background: var(--accent-orange);
  color: #ffffff;
  border-color: var(--accent-orange);
}

.control-btn.play-btn:hover {
  background: #b45309;
  color: #ffffff;
}

.progress-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 45px;
  text-align: center;
}

/* Song Staff Container */
/* Fingering Tip container style */
.fingering-tip {
  background: #fef2f2;
  border-left: 4px solid var(--accent-orange);
  color: var(--text-dark);
  padding: 12px 16px;
  border-radius: 4px 12px 12px 4px;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: all 0.3s ease;
}

/* Practice Carousel Section (Large Fingering Cards) */
.practice-carousel-section {
  width: 100%;
  padding: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  position: relative;
  margin-bottom: 24px;
  transition: background-color 0.3s ease;
}

.practice-carousel-viewport {
  position: relative;
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none; /* Hide scrollbar Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  padding: 24px 0;
  min-height: 540px;
  display: flex;
  align-items: center;
}

.practice-carousel-viewport::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Playhead center vertical line indicator */
.practice-carousel-playhead {
  display: none !important;
}

.practice-carousel-track {
  display: flex;
  gap: 24px;
  align-items: center;
  padding-left: 36px;
  padding-right: 36px;
  min-width: max-content;
  transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Large Practice Card Styling */
.practice-carousel-section .practice-note-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px 8px;
  border-radius: 24px;
  border: 2px solid #e2e8f0;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  height: 480px;
  /* Support smooth collapsing and scaling transitions for right-to-left slide effect */
  transition: width 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              padding 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              margin 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              opacity 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              transform 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              border-color 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              box-shadow 0.5s cubic-bezier(0.25, 1, 0.5, 1),
              filter 0.5s cubic-bezier(0.25, 1, 0.5, 1);
  cursor: pointer;
  box-sizing: border-box;
  overflow: visible;
  flex-shrink: 0;
  opacity: 0.8;
  transform: translateX(15px) scale(0.96);
}

/* Hide older past cards smoothly by collapsing width and fading out */
.practice-carousel-section .practice-note-card.is-past {
  width: 0 !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  margin-left: -12px !important;
  margin-right: -12px !important;
  opacity: 0 !important;
  border-width: 0 !important;
  pointer-events: none !important;
}

/* Style the immediately preceding note card */
.practice-carousel-section .practice-note-card.previous {
  opacity: 0.35;
  transform: translateX(-15px) scale(0.85);
  filter: grayscale(40%);
  border-color: #cbd5e1;
}

.practice-carousel-section .practice-note-card:hover {
  border-color: #cbd5e1;
  transform: translateY(-2px) scale(0.98);
  opacity: 0.8;
}

/* Faint rest card */
.practice-carousel-section .practice-note-card.is-rest {
  background: rgba(248, 250, 252, 0.6);
  border-style: dashed;
  border-color: #cbd5e1;
  opacity: 0.65;
  transform: translateX(15px) scale(0.96);
}

.practice-carousel-section .practice-note-card.is-rest:hover {
  opacity: 0.75;
}

/* Active State - Raised and colorful */
.practice-carousel-section .practice-note-card.active {
  border-color: var(--accent-emerald);
  border-width: 2.5px;
  background: #ffffff;
  box-shadow: 0 20px 30px -8px rgba(16, 185, 129, 0.22), 0 10px 16px -8px rgba(16, 185, 129, 0.15);
  transform: translateY(-6px) translateX(0) scale(1.05);
  z-index: 5;
  opacity: 1;
  filter: none;
}

.practice-carousel-section .practice-note-card.is-rest.active {
  border-color: var(--accent-cyan);
  background: #ffffff;
  box-shadow: 0 20px 30px -8px rgba(6, 182, 212, 0.22), 0 10px 16px -8px rgba(6, 182, 212, 0.15);
  opacity: 1;
}

/* Next State - Prominently styled as upcoming card */
.practice-carousel-section .practice-note-card.next {
  border-color: var(--accent-emerald);
  border-style: dashed;
  opacity: 0.8;
  transform: translateX(15px) scale(0.96);
  filter: none;
}

.practice-carousel-section .practice-note-card.is-rest.next {
  border-color: var(--accent-cyan);
  border-style: dashed;
  opacity: 0.65;
  transform: translateX(15px) scale(0.96);
}

/* Card inner content */
.practice-carousel-section .practice-card-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
}

/* SVG container inside the card */
.practice-carousel-section .card-svg-container {
  flex: 1;
  width: 100%;
  max-height: 360px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
}

.practice-carousel-section .card-svg-container svg {
  height: 100%;
  width: 213px;
  min-width: 213px;
  max-width: none;
  overflow: visible;
}

/* Katakana Note Name at the bottom */
.practice-carousel-section .card-syllable-label {
  font-size: 2rem;
  font-weight: 900;
  color: var(--text-dark);
  margin-top: 16px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.05);
  letter-spacing: 0.05em;
}

/* Large rest glyph style inside rest card */
.practice-carousel-section .large-rest-visualizer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 360px;
}

.practice-carousel-section .large-rest-glyph-svg {
  width: 140px;
  height: 140px;
  color: #94a3b8;
  transition: color 0.3s ease, transform 0.3s ease;
  overflow: visible;
}

.practice-carousel-section .practice-note-card.is-rest.active .large-rest-glyph-svg {
  color: #0e7490;
  animation: restPulse 1.5s ease-in-out infinite;
}

@keyframes restPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.80; }
}

.practice-carousel-section .large-rest-label {
  font-size: 1.1rem;
  font-weight: 700;
  color: #94a3b8;
}

.practice-carousel-section .practice-note-card.is-rest.active .large-rest-label {
  color: #0e7490;
}

/* Progress Fill Element Overlay */
.practice-carousel-section .practice-card-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: rgba(16, 185, 129, 0.12); /* emerald tint */
  z-index: 1;
  pointer-events: none;
  transition: width 0.03s linear;
  border-top-left-radius: 22px;
  border-bottom-left-radius: 22px;
}

.practice-carousel-section .practice-note-card.is-rest .practice-card-progress {
  background: rgba(6, 182, 212, 0.08); /* cyan tint for rests */
}


/* 2. Editor Mode Styling */
.editor-workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.composer-staff-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.composer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.song-name-input {
  flex: 1;
  min-width: 150px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.9rem;
}

.composer-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn.danger {
  background: #fee2e2;
  color: #ef4444;
}

.action-btn.danger:hover {
  background: #fca5a5;
}

.action-btn.success {
  background: var(--accent-emerald);
  color: #ffffff;
}

.action-btn.success:hover {
  background: #047857;
}

.editor-tip {
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: #fffbeb;
  padding: 6px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--accent-orange);
}

/* Grid Staff Composer */
.composer-grid-outer {
  display: flex;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
}

.composer-grid-y-labels {
  display: grid;
  grid-template-rows: repeat(11, 12px);
  width: 32px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  text-align: center;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-secondary);
  user-select: none;
}

.pitch-y-label {
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}

.composer-grid-scroll {
  flex: 1;
  overflow-x: auto;
}

.composer-grid {
  display: grid;
  grid-template-rows: repeat(11, 12px);
  grid-template-columns: repeat(16, 36px);
  min-width: max-content;
}

.composer-cell {
  position: relative;
  height: 12px;
  border-right: 1.5px solid rgba(226, 232, 240, 0.45); /* Light grey vertical grid lines */
  border-bottom: 1px solid transparent; /* Completely transparent to display unbroken staff lines */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  box-sizing: border-box;
}

/* Clear vertical divider every 4 columns (1 beat intervals) */
.composer-cell.beat-boundary {
  border-right: 2px solid rgba(148, 163, 184, 0.65);
}

/* Subtle ledger line guide for empty C5 cells (Row 10) */
.composer-cell[data-row="10"]::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 5px;
  height: 1px;
  border-top: 1px dashed #cbd5e1;
  pointer-events: none;
  z-index: 1;
}

/* Staff lines (Rows 0, 2, 4, 6, 8 draw centered lines inside cells) */
.composer-cell[data-row="0"]::before,
.composer-cell[data-row="2"]::before,
.composer-cell[data-row="4"]::before,
.composer-cell[data-row="6"]::before,
.composer-cell[data-row="8"]::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 5px;
  height: 2px;
  background-color: #64748b;
  z-index: 2;
  pointer-events: none;
}

.composer-cell:hover {
  background: #fffbeb;
}

.composer-cell.glow {
  background: #fef3c7;
}

/* Pointer events pass-through during drag (exclude currently dragged block to prevent Safari cancellation) */
.composer-grid.is-dragging-active .composer-note-block:not(.dragging) {
  pointer-events: none !important;
}

.composer-note-glyph {
  font-family: 'Noto Music', serif;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 2;
}

.composer-rest-glyph {
  font-family: 'Noto Music', serif;
  font-size: 2.5rem; /* Enlarge rest size to match note volume */
  line-height: 1;
  color: var(--text-secondary);
  pointer-events: none;
  z-index: 2;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* perfectly centered inside grid row */
}

/* Enlarge rest symbols inside the palette list to match note symbols */
.palette-item[data-is-rest="true"] .note-symbol {
  font-size: 2.2rem !important;
}

.composer-glyph-container {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  cursor: grab;
}

.composer-glyph-container:active {
  cursor: grabbing;
}

.composer-glyph-container.dragging {
  opacity: 0.5;
}

.composer-palette-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-secondary);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.palette-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
  margin-bottom: 2px;
}

.palette-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.palette-item {
  display: flex;
  flex-direction: column; /* Align symbol and text label vertically */
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 58px; /* Fixed square tile size */
  height: 58px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  box-sizing: border-box;
}

.palette-item:hover {
  border-color: var(--accent-orange);
  background: rgba(254, 243, 199, 0.2);
}

.palette-item.active {
  border-color: var(--accent-orange) !important;
  background: #fffbeb !important;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
}

.palette-item .note-symbol {
  font-family: 'Noto Music', serif;
  font-size: 1.5rem;
  line-height: 1.1;
  text-align: center;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.palette-item .note-label {
  display: block !important; /* Make sure labels are always visible */
  font-size: 0.58rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
  color: var(--text-secondary);
  white-space: normal; /* Allow text wrapping if needed */
}

.palette-item.active .note-label {
  color: var(--accent-orange);
}

/* Smartphone Responsive / One-screen No-Scroll Fit */
@media (max-width: 600px) {
  html, body {
    overflow-y: auto !important; /* Allow scroll on mobile for editor layout */
    height: auto !important;
    position: static !important;
  }

  .app-container {
    height: auto !important;
    padding: 8px;
    gap: 8px;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .keyboard-row.lower-row {
    gap: 4px;
  }
  .keyboard-row {
    gap: 4px;
  }

  .keyboard-section {
    padding: 4px;
  }

  .keyboard-container {
    gap: 6px;
  }

  .key-btn {
    width: 38px;
    height: 28px;
    padding: 2px 1px;
    border-radius: 6px;
  }

  .key-syllable {
    font-size: 0.72rem;
  }

  .app-main {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: 0;
  }

  .glass-card {
    padding: 8px;
  }

  .info-section {
    display: none !important;
  }

  .visualizer-section {
    min-height: 240px;
  }

  .recorder-visualizer {
    padding: 0;
  }

  #recorder-body-svg {
    max-height: 40vh;
  }

  .editor-workspace {
    grid-template-columns: 1fr;
  }
  .composer-palette-section {
    order: -1;
  }
  .palette-list {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }
  .palette-item {
    flex-direction: column;
    padding: 4px;
    min-width: 58px;
    align-items: center;
    gap: 2px;
  }
  .palette-item .note-symbol {
    font-size: 1.4rem;
    width: auto;
  }
  .palette-item .note-label {
    font-size: 0.55rem;
  }
}

/* Rest state styling - Dimming guide overlay */
.app-main.is-rest-active {
  background-color: rgba(15, 23, 42, 0.45);
  transition: background-color 0.3s ease;
  border-radius: 16px;
}
.app-main.is-rest-active .info-section,
.app-main.is-rest-active .visualizer-section {
  opacity: 0.65;
  transition: opacity 0.3s ease;
}
.song-staff-container.is-rest-active {
  background-color: #cbd5e1 !important;
  transition: background-color 0.3s ease;
}

/* Drag-hover glow effect on Grid composer cells */
.composer-cell.drag-hover {
  background-color: #fef3c7 !important;
  box-shadow: inset 0 0 0 2px var(--accent-orange);
}

/* Mode-specific Layout Overrides */
.app-container.mode-explore-active .app-main {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
}
.app-container.mode-explore-active #explore-sheet-card {
  display: block;
}
.app-container.mode-explore-active .visualizer-section {
  display: block;
}

/* Editor Mode active: Hide visualizer and explore-sheet-card entirely */
.app-container.mode-editor-active .app-main {
  display: none !important;
}
.app-container.mode-editor-active .visualizer-section {
  display: none !important;
}

/* Practice Mode active: Hide explore staff and static visualizer, show horizontal sliding carousel */
.app-container.mode-practice-active #explore-sheet-card {
  display: none !important;
}
.app-container.mode-practice-active .visualizer-section {
  display: none !important;
}
.app-container.mode-practice-active #practice-carousel-section {
  display: block !important;
  width: 100%;
}
.app-container.mode-practice-active .app-main {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  width: 100%;
}

/* Breath Glow Animation - lights up the recorder container when blowing a note */
@keyframes breathGlow {
  0% {
    background: radial-gradient(circle, rgba(16, 185, 129, 0.22) 0%, rgba(16, 185, 129, 0.05) 70%, rgba(16, 185, 129, 0) 100%);
    box-shadow: inset 0 0 50px rgba(16, 185, 129, 0.4), 0 0 30px rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.6);
  }
  100% {
    background: radial-gradient(circle, rgba(16, 185, 129, 0) 0%, rgba(16, 185, 129, 0) 100%);
    box-shadow: inset 0 0 0px rgba(16, 185, 129, 0), 0 0 0px rgba(16, 185, 129, 0);
    border-color: var(--border-color);
  }
}

.app-main.is-blowing {
  border-radius: 16px;
  animation: breathGlow 1.1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Timeline Beat Blocks (DAW-style but made transparent to look like real sheet music) */
/* Timeline Beat Blocks - Visibly styled as neat rectangular blocks with borders */
.composer-note-block {
  position: relative;
  height: 12px;
  background: rgba(6, 182, 212, 0.16) !important; /* semi-transparent cyan block */
  border: 1.5px solid rgba(6, 182, 212, 0.75) !important; /* solid border */
  border-radius: 4px;
  display: flex;
  align-items: center;
  z-index: 10;
  cursor: grab;
  user-select: none;
  box-sizing: border-box;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.composer-note-block:hover {
  background: rgba(6, 182, 212, 0.26) !important;
  border-color: rgba(6, 182, 212, 1) !important;
  transform: scaleY(1.15); /* Slightly pop vertically to show interactive state */
}

.composer-note-block.is-rest {
  background: rgba(148, 163, 184, 0.22) !important; /* semi-transparent slate grey block */
  border: 1.5px solid rgba(148, 163, 184, 0.7) !important;
}

.composer-note-block.is-rest:hover {
  background: rgba(148, 163, 184, 0.32) !important;
  border-color: rgba(148, 163, 184, 1) !important;
  transform: scaleY(1.15);
}

.composer-note-block:active {
  cursor: grabbing;
}

.composer-note-block.dragging {
  opacity: 0.35;
}

.composer-note-block.selected {
  background: rgba(6, 182, 212, 0.18) !important;
  border: 1px solid rgba(6, 182, 212, 0.8) !important;
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
}

.composer-note-block svg {
  position: absolute;
  left: 4px;
  top: -42px; /* centered relative to cell */
  pointer-events: none;
}

.block-note-label {
  position: absolute;
  left: 32px;
  font-size: 0.65rem;
  font-weight: bold;
  color: var(--accent-cyan);
  pointer-events: none;
  white-space: nowrap;
}

/* App Header styling */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  margin-bottom: 12px;
  border-radius: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-sizing: border-box;
}
.app-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
}
.header-scan-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
  color: var(--accent-cyan);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}
.header-scan-btn:hover {
  background: var(--accent-cyan);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.35);
  transform: translateY(-1px);
}

/* Modals overlays & components */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.modal-overlay.hide {
  display: none !important;
}
.modal-content {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 24px;
  border-radius: 20px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  animation: modalSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes modalSlideUp {
  0% { transform: translateY(20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.4;
}
#qr-code-container img {
  margin: 0 auto;
  border: 8px solid #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.modal-close-btn {
  margin-top: 16px;
  padding: 10px 24px;
  border-radius: 10px;
  border: none;
  background: var(--accent-blue);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.modal-close-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.modal-close-btn.danger {
  background: #ef4444;
}
.modal-close-btn.danger:hover {
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
#scanner-preview {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--accent-cyan);
  background: #000000;
}

/* ==========================================================================
   Practice Mode Safe Screen-Fit Responsive Settings
   ========================================================================== */

/* 縦の高さが短い Chromebook (高低 720px 以下) や、スマートフォン (幅 768px 以下) の場合 */
@media (max-height: 720px), (max-width: 768px) {
  /* 練習モードがアクティブな時だけ、楽譜（横スクロールの音符リスト）を非表示にして縦幅を劇的に節約する */
  .app-container.mode-practice-active .song-staff-container {
    display: none !important;
  }

  /* 練習モード時の操作コントロール周辺の余白を小さくし、1画面に収まりやすくする */
  .app-container.mode-practice-active .mode-control-panel {
    margin-top: 8px !important;
    padding: 10px !important;
    gap: 10px !important;
  }

  .app-container.mode-practice-active .practice-controls {
    margin-bottom: 0 !important;
    gap: 8px !important;
  }

  /* アプリ全体のパディングも少し縮小 */
  .app-container.mode-practice-active {
    padding: 12px !important;
    gap: 12px !important;
  }
}

/* ==========================================================================
   Tie Feature & Blowing Visualizations
   ========================================================================== */

/* 1. Blowing Pulse Background Effect (Fade from Dark Water Blue to White) */
body.is-blowing-active.is-blowing-note {
  animation: blowing-water-fade 1.5s forwards ease-out;
}

@keyframes blowing-water-fade {
  0% {
    background-color: #00bcd4 !important; /* Most intense water blue */
  }
  100% {
    background-color: #ffffff !important; /* Pure white at the end */
  }
}

/* Force background to white when not active, not playing, or on rests */
body:not(.is-blowing-active),
body:not(.is-blowing-note) {
  background-color: #ffffff !important;
  transition: background-color 0.25s ease-out;
}

/* Blow visual border on visualizer card */
body.is-blowing-active .visualizer-section {
  border-color: var(--accent-cyan) !important;
  box-shadow: 0 0 20px rgba(34, 211, 238, 0.25) !important;
}

/* 2. Tie Feature Visuals on Editor composer blocks */
.composer-note-block.is-tied-active {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.composer-tie-arch {
  pointer-events: none;
}

/* 3. Tie arc curves on Practice mode staff note cards */
.practice-note-card.is-tied {
  position: relative;
}

.practice-note-card.is-tied::after {
  content: "⌒";
  position: absolute;
  right: -9px;
  top: 15%;
  font-size: 1.6rem;
  color: var(--accent-cyan);
  pointer-events: none;
  font-weight: bold;
  transform: rotate(0deg);
  z-index: 5;
}
