* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e0f13;
  --bg-soft: #1a1c22;
  --bg-card: #23262e;
  --border: #2e3138;
  --text: #e8e8ea;
  --text-soft: #a0a3ab;
  --text-dim: #6c7079;
  --accent: #4c9eff;
  --strong: #ff7b54;
  --medium: #ffb84c;
  --weak: #4c9eff;
  --play-active: #38d39f;
  --record: #ff5252;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.topbar {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 44px;
}
.topbar h1 { font-size: 17px; font-weight: 600; }
.status { font-size: 12px; color: var(--text-soft); min-height: 18px; }
.status.recording { color: var(--record); }
.status.recording::before { content: "\25CF "; }

.settings {
  padding: 12px 14px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.row { display: flex; align-items: center; gap: 10px; }
.row .label { font-size: 13px; color: var(--text-soft); width: 44px; flex-shrink: 0; }
.row .label.tight { width: auto; padding: 0 6px; }

.bpm-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.bpm-btn {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 22px; font-weight: 300;
  cursor: pointer;
  touch-action: manipulation;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.bpm-btn:active { background: var(--bg); transform: scale(0.95); }
.bpm-display {
  flex: 1;
  text-align: center;
  font-size: 36px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
}

.select {
  flex: 1; min-width: 0; height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
}

.accent-row { display: flex; gap: 6px; flex: 1; }
.accent-btn {
  flex: 1; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.accent-btn:active { transform: scale(0.95); }
.accent-btn.strong { background: var(--strong); border-color: var(--strong); color: white; }
.accent-btn.medium { background: var(--medium); border-color: var(--medium); color: #1a1c22; }

.compare {
  flex: 1;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px;
  overflow-y: auto; min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.panel {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.panel-label {
  font-size: 14px; font-weight: 600; color: var(--text-soft);
  display: flex; align-items: center; gap: 10px;
}
.panel-label::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
}
.panel[data-panel="A"] .panel-label::before { background: var(--accent); }
.panel[data-panel="B"] .panel-label::before { background: var(--play-active); }

.panel-play {
  flex-shrink: 0; height: 36px; min-width: 64px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.panel-play:active { transform: scale(0.96); }
.panel-play.active {
  background: var(--accent); border-color: var(--accent); color: white;
}
.panel[data-panel="B"] .panel-play.active {
  background: var(--play-active); border-color: var(--play-active);
}

.rhythm-display {
  display: flex; gap: 4px;
  position: relative;
  height: 38px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.beat {
  flex: 1; position: relative;
  border-radius: 4px;
  background: var(--bg-card);
  min-width: 0;
}
.beat:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -2.5px; top: 15%; bottom: 15%;
  width: 1px;
  background: var(--border);
}
.hit {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.06s, box-shadow 0.06s;
}
.hit.strong { width: 14px; height: 14px; background: var(--strong); }
.hit.medium { width: 11px; height: 11px; background: var(--medium); }
.hit.weak { width: 7px; height: 7px; background: var(--weak); opacity: 0.7; }
.hit.active {
  transform: translate(-50%, -50%) scale(1.7);
  box-shadow: 0 0 14px currentColor;
  opacity: 1;
}

.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.preset-btn {
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.preset-btn:active { transform: scale(0.96); }
.preset-btn.active {
  background: var(--accent); border-color: var(--accent); color: white; font-weight: 500;
}
.panel[data-panel="B"] .preset-btn.active {
  background: var(--play-active); border-color: var(--play-active);
}

.controls {
  padding: 12px;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
}
.ctrl-btn {
  height: 52px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.ctrl-btn:active { transform: scale(0.97); }
.ctrl-btn.primary {
  background: var(--accent); border-color: var(--accent); color: white; font-size: 15px; font-weight: 600;
}
.ctrl-btn.primary.active {
  background: var(--play-active); border-color: var(--play-active);
}
.ctrl-btn.record { color: var(--record); }
.ctrl-btn.record.recording {
  background: var(--record); border-color: var(--record); color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }

.controls-extra {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 12px 12px;
  background: var(--bg-soft);
  flex-shrink: 0;
}
.tempo-btn {
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.tempo-btn:active { transform: scale(0.97); }
.tempo-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

@media (orientation: landscape) and (max-height: 500px) {
  .compare { flex-direction: row; }
  .panel { flex: 1; }
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.modal p { font-size: 13px; color: var(--text-soft); margin-bottom: 16px; line-height: 1.5; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions button {
  flex: 1; height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.modal-actions button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.modal .row-input { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.modal .row-input label { font-size: 13px; color: var(--text-soft); width: 44px; flex-shrink: 0; }
.modal input[type="number"] {
  width: 100%; height: 44px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.hidden { display: none !important; }
