:root {
  --bg: #f3f5f7;
  --bg-soft: #e9edf1;
  --card: rgba(255, 255, 255, 0.9);
  --line: rgba(42, 52, 65, 0.14);
  --text: #1f2937;
  --muted: #5f6c7b;
  --accent: #3a6ea5;
  --accent-2: #4f8f7a;
  --danger: #c95c5c;
  --down: #d35400;
  --up: #007f7a;
  --rest: #7b8794;
  --shadow: 0 8px 18px rgba(18, 26, 37, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, #edf1f4 0%, transparent 40%),
    linear-gradient(160deg, #f6f8fa 0%, #edf1f5 55%, #e8edf2 100%);
  position: relative;
  overflow-x: hidden;
}

button,
input,
textarea {
  font-family: inherit;
}

.bg-glow {
  position: fixed;
  border-radius: 999px;
  filter: blur(30px);
  pointer-events: none;
  z-index: 0;
}

.bg-glow-a {
  width: 240px;
  height: 240px;
  background: rgba(58, 110, 165, 0.06);
  top: 16%;
  left: -50px;
  animation: none;
}

.bg-glow-b {
  width: 300px;
  height: 300px;
  background: rgba(79, 143, 122, 0.05);
  right: -60px;
  bottom: 8%;
  animation: none;
}

@keyframes driftA {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-18px);
  }
}

@keyframes driftB {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(14px);
  }
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1100px, 94vw);
  margin: 32px auto 40px;
  display: grid;
  gap: 16px;
  padding: 15px;
}

.hero {
  padding: 0 4px;
  animation: none;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--muted);
}

.hero h3 {
  margin: 0;
  font-family: inherit;
  font-size: clamp(1.9rem, 1vw, 3.1rem);
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: none;
  padding: 14px;
  animation: none;
}

@keyframes reveal {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.control-panel {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-wrap: nowrap;
  border: none;
  padding: 0;
  margin: 0;
}

.row legend {
  color: var(--muted);
  padding: 0;
  margin: 0;
  margin-right: 12px;
  font-weight: 400;
  flex-shrink: 0;
}

.row input[type="radio"] {
  display: none;
}

.row label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: auto;
  margin: 0;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #ffffff;
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform 0.2s ease, background 0.2s ease;
}

.row label:hover {
  transform: translateY(-1px);
}

.row input[type="radio"]:checked + label {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.row input[type="radio"]:disabled + label {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f0f0f0;
}

.row input[type="radio"]:checked:disabled + label {
  color: #333;
}

label {
  min-width: 56px;
  color: var(--muted);
}

input[type="number"] {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 0;
  font-size: 0.95rem;
  font-family: inherit;
  text-align: center;
  max-width: 60px;
  background: #fff;
}

input[type="number"]:disabled {
  opacity: 0.5;
  background: #f0f0f0;
  cursor: not-allowed;
}

.voice-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: auto;
  padding: 5px 10px;
  margin-left: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #ffffff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.voice-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.custom-select {
  position: relative;
  min-width: 120px;
}

.custom-select-trigger {
  width: 100%;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 28px 8px 10px;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  position: relative;
}

.custom-select-trigger::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
}

.custom-select-list {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 22px rgba(18, 26, 37, 0.12);
  max-height: 240px;
  overflow-y: auto;
}

.custom-select.open .custom-select-list {
  display: block;
}

.custom-select-option {
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.2;
}

.custom-select-option:hover {
  background: #f3f6f9;
}

.custom-select-option.selected {
  background: #e9f0f7;
  color: #244d76;
}

input[type="range"] {
  width: min(560px, 85vw);
  accent-color: var(--accent);
  padding: 0 8px;
  box-sizing: content-box;
}

.bpm-row {
  align-items: flex-start;
}

.bpm-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bpm-scale-labels {
  width: calc(min(560px, 85vw) + 16px);
  padding: 0 8px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(19, minmax(0, 1fr));
  gap: 0;
  font-size: 0.6rem;
  color: var(--muted);
}

.bpm-scale-labels span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
}

.bpm-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.bpm-nudge {
  padding: 0px 0px;
  max-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

input[type="number"] {
  width: 88px;
}

/* 隱藏 number input 的上下箭頭 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

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

.transport-row {
  justify-content: flex-start;
}

.btn {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 8px 14px;
  font-weight: 700;
 

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
} cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--accent);
  color: #ffffff;
}

.btn.primary.is-playing {
  background: #8b2d2d;
}

.btn.ghost {
  background: #5c87b611;
  color: var(--text);
  border-color: var(--line);
}

.status {
  color: var(--accent-2);
  font-weight: 500;
}

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

.preset-header h2,
.pattern-head h2 {
  margin: 0;
  font-family: inherit;
  font-size: 1.05rem;
}

.preset-desc {
  margin: 10px 0 0;
  color: var(--muted);
  min-height: 1.2em;
}

.preset-desc-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.preset-desc-row .preset-desc {
  margin: 0;
  flex: 1 1 auto;
}

.demo-btn {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.demo-btn.is-playing {
  background: #e9f0f7;
  border-color: #c7d7e8;
  color: #244d76;
}

.pattern-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.pattern-head p {
  margin: 0;
  color: var(--muted);
}

.down {
  color: var(--down);
}

.up {
  color: var(--up);
}

.rest {
  color: var(--rest);
}

.count-strip,
.pattern-grid {
  display: grid;
  gap: 0;
  margin-top: 10px;
  width: max-content;
}

.count-cell,
.step-btn {
  min-width: 28px;
  max-width: 28px;
  width: 28px;
  text-align: center;
  border: none;
  position: relative;
  overflow: hidden;
}

.count-cell {
  padding: 4px 2px;
  font-size: 0.92rem;
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease;
}

.count-cell.active {
  background: #e8eef5;
  color: #20384e;
  font-weight: 700;
}

.count-cell.active.beat-active {
  background: #ffe7bf;
  color: #7a3e00;
}

.step-btn {
  background: #ffffff;
  color: var(--text);
  padding: 10px 0;
  font-size: 1.28rem;
  font-weight: 900;
  cursor: pointer;
  border: none;
  box-shadow: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

body.is-playing .step-btn,
body.is-playing .count-cell {
  transition: none;
}

.step-btn:hover {
  transform: translateY(-1px);
}

.step-btn[data-val="D"] {
  color: var(--down);
}

.step-btn[data-val="U"] {
  color: var(--up);
}

.step-btn[data-val="-"] {
  color: var(--rest);
}

.step-btn.active {
  background: #e8eef5;
  box-shadow:
    inset 0 0 0 2px rgba(58, 110, 165, 0.38),
    0 2px 6px rgba(31, 41, 55, 0.08);
}

.step-btn.active.beat-active {
  background: #fff2dd;
  box-shadow:
    inset 0 0 0 2px rgba(211, 84, 0, 0.45),
    0 2px 6px rgba(31, 41, 55, 0.08);
}

.beat-divider {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(42, 52, 65, 0.22);
  pointer-events: none;
}

.pattern-panel {
  overflow-x: auto;
}

@media (max-width: 700px) {
  .app-shell {
    width: 95vw;
    margin-top: 0;
  }

  .card {
    padding: 12px;
    border-radius: 14px;
  }

  .count-cell,
  .step-btn {
    min-width: 20px;
    max-width: 20px;
    width: 20px;
    justify-self: center;
  }

  .count-cell {
    padding: 3px 1px;
    font-size: 0.82rem;
  }

  .step-btn {
    padding: 8px 0;
    font-size: 1.02rem;
  }

  .step-glyph {
    line-height: 1;
  }

  input[type="range"] {
    width: 100%;
  }

  .bpm-scale-labels {
    width: 100%;
  }
}
