:root {
  --bg-main: #08090c;
  --bg-card: rgba(16, 18, 26, 0.75);
  --bg-card-hover: rgba(24, 28, 40, 0.9);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(56, 189, 248, 0.3);
  --accent-cyan: #38bdf8;
  --accent-glow: #0284c7;
  --accent-downbeat: #f43f5e;
  --accent-downbeat-glow: rgba(244, 63, 94, 0.5);
  --accent-amber: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(circle at 50% 15%, rgba(56, 189, 248, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(244, 63, 94, 0.05) 0%, transparent 40%),
    linear-gradient(180deg, #090a0e 0%, #050608 100%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px 48px;
}

@media (min-width: 600px) {
  body {
    padding: 24px 16px 48px;
  }
}

/* Flash Overlay */
#flashOverlay {
  position: fixed;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.12);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.04s ease-out;
  z-index: 9999;
}
#flashOverlay.active {
  opacity: 1;
}

/* Container */
.app-container {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (min-width: 768px) {
  .app-container {
    gap: 20px;
  }
}

/* Header */
.app-header {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 12px 18px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
  filter: contrast(1.15) brightness(1.05);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.brand-logo:hover {
  transform: rotate(90deg) scale(1.08);
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff;
  text-transform: uppercase;
}
@media (min-width: 600px) {
  .brand-info h1 {
    font-size: 1.35rem;
    letter-spacing: 0.14em;
  }
}

.brand-info p {
  font-size: 0.68rem;
  color: var(--accent-cyan);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}

/* Card Base */
.card {
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}
@media (min-width: 600px) {
  .card {
    padding: 24px;
  }
}

/* Hero Section */
.hero-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  width: 100%;
}
@media (min-width: 768px) {
  .hero-section {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }
}

/* Secondary 2-Column Grid for Timbres & Subdivisões */
.secondary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  width: 100%;
}
@media (min-width: 768px) {
  .secondary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }
}

/* Radar & Tempo Center */
.radar-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 340px;
}

.beat-radar-container {
  position: relative;
  width: 240px;
  height: 240px;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.radar-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.12);
  transition: border-color 0.1s;
}

.radar-ticks {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.radar-tick {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: all 0.1s ease-out;
}

.radar-tick.active {
  background: var(--accent-cyan);
  border-color: #fff;
  box-shadow: 0 0 16px var(--accent-cyan), 0 0 32px var(--accent-glow);
  transform: translate(-50%, -50%) scale(1.4);
}

.radar-tick.active.downbeat {
  background: var(--accent-downbeat);
  border-color: #fff;
  box-shadow: 0 0 20px var(--accent-downbeat), 0 0 40px var(--accent-downbeat-glow);
  transform: translate(-50%, -50%) scale(1.6);
}

/* Center Tempo Display */
.tempo-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 2;
  cursor: pointer;
  user-select: none;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  position: relative;
}
.tempo-display:hover {
  background: rgba(255, 255, 255, 0.04);
}

.tempo-num {
  font-size: clamp(3.8rem, 15vw, 5rem);
  font-weight: 800;
  line-height: 1;
  font-family: var(--font-mono);
  letter-spacing: -0.04em;
  color: #fff;
  text-shadow: 0 0 25px rgba(56, 189, 248, 0.3);
  transition: all 0.15s ease;
  border-bottom: 2px dashed transparent;
}
.tempo-display:hover .tempo-num {
  color: var(--accent-cyan);
  border-bottom-color: rgba(56, 189, 248, 0.4);
}

.tempo-input {
  font-size: clamp(3.2rem, 13vw, 4.4rem);
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: -0.04em;
  text-align: center;
  color: var(--accent-cyan);
  background: rgba(8, 10, 16, 0.95);
  border: 2px solid var(--accent-cyan);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.45);
  border-radius: var(--radius-sm);
  width: 140px;
  max-width: 100%;
  padding: 2px 4px;
  line-height: 1;
  outline: none;
  margin: 0 0 4px 0;
  -moz-appearance: textfield;
}
.tempo-input::-webkit-outer-spin-button,
.tempo-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tempo-bpm-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--accent-cyan);
  text-transform: uppercase;
  margin-top: 2px;
}

.tempo-marking {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 4px;
}

.tempo-hint {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.28);
  margin-top: 5px;
  font-weight: 600;
  transition: color 0.2s;
}
.tempo-display:hover .tempo-hint {
  color: var(--accent-cyan);
}

/* Quick Tempo Steppers */
.tempo-steppers {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  width: 100%;
  max-width: 320px;
  justify-content: center;
}

.step-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: #cbd5e1;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.step-btn:hover {
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--accent-cyan);
  color: #fff;
}
.step-btn:active {
  transform: scale(0.95);
}

/* Controls Card */
.controls-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}

/* Tempo Slider */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.slider-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.custom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-cyan);
  box-shadow: 0 0 12px var(--accent-cyan);
  cursor: pointer;
  transition: transform 0.1s;
}
.custom-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* Bar Settings Row (Responsive Wrap) */
.bar-settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(0, 0, 0, 0.25);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  width: 100%;
}

.meter-select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.meter-select-wrap label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}
.meter-chips {
  display: flex;
  gap: 4px;
}
.meter-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: #cbd5e1;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.meter-chip.active {
  background: var(--accent-cyan);
  color: #000;
  border-color: #fff;
}

.toggles-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  transition: background 0.2s;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle-input:checked + .toggle-switch {
  background: var(--accent-cyan);
}
.toggle-input:checked + .toggle-switch::after {
  transform: translateX(16px);
}
.toggle-input {
  display: none;
}

/* Big Practice Timer Card (Above Tap Tempo) */
.practice-timer-card {
  width: 100%;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.8) 0%, rgba(8, 10, 16, 0.95) 100%);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), inset 0 0 20px rgba(56, 189, 248, 0.05);
}

.practice-timer-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.practice-timer-tag {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-cyan);
}

.practice-timer-display {
  font-family: var(--font-mono);
  font-size: clamp(1.8rem, 7vw, 2.3rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  line-height: 1.1;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.45);
}

.practice-timer-reset {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 4px;
}
.practice-timer-reset:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

/* Tap Tempo & Transport Controls */
.action-buttons-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.tap-btn {
  width: 100%;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.6) 0%, rgba(15, 23, 42, 0.8) 100%);
  border: 1px solid var(--border-glow);
  color: var(--accent-cyan);
  padding: 13px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  user-select: none;
}
.tap-btn:active {
  transform: scale(0.97);
  background: var(--accent-cyan);
  color: #000;
  box-shadow: 0 0 20px var(--accent-cyan);
}

.primary-transport {
  display: flex;
  gap: 10px;
  width: 100%;
}

.play-btn {
  flex: 3;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 10px 25px rgba(2, 132, 199, 0.35);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.play-btn:hover {
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.45);
  transform: translateY(-2px);
}
.play-btn.playing {
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  box-shadow: 0 10px 25px rgba(244, 63, 94, 0.4);
}

.stop-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: #cbd5e1;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.stop-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* Sound & Subdivision Selection Tabs */
.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* 2-Column Responsive Grid for Chips (100% width on mobile) */
.grid-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}
@media (min-width: 480px) and (max-width: 767px) {
  .grid-selector {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}
@media (min-width: 900px) {
  .grid-selector {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
  }
}

.grid-chip {
  width: 100%;
  min-width: 0; /* Prevents overflow */
  min-height: 48px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s ease-out;
  text-align: left;
}
.grid-chip-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}
.grid-chip-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  color: var(--text-muted);
  transition: all 0.15s;
  flex-shrink: 0;
}
.grid-chip strong {
  font-size: 0.85rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-chip span {
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}
.grid-chip:hover .grid-chip-icon {
  color: #fff;
}
.grid-chip.active {
  background: rgba(56, 189, 248, 0.14);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.22);
}
.grid-chip.active strong {
  color: var(--accent-cyan);
}
.grid-chip.active .grid-chip-icon {
  color: var(--accent-cyan);
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.6));
}

/* Tabs for Advanced Features */
.tabs-header {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 10px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}
.tab-btn.active {
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

/* Trainer Controls Layout */
.trainer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.trainer-param {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.trainer-param label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}
.param-stepper-wrap {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.param-val {
  flex: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}
.param-step-btn {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.param-step-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Presets Bar */
.presets-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.preset-btn {
  flex: 1;
  min-width: 60px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.preset-btn:hover {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.1);
}
.preset-btn.saved {
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--accent-cyan);
}

/* Footer */
.app-footer {
  text-align: center;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  line-height: 1.5;
}
