:root {
  --bg: #0f1419;
  --surface: #1a222c;
  --border: #2a3544;
  --text: #e8eef5;
  --muted: #8b9cb0;
  --accent: #3d9eff;
  --accent-dim: rgba(61, 158, 255, 0.25);
  --pulse-on: #5cffb0;
  --pulse-dim: #2a3d34;
  --sub-pulse: #4a5c6e;
  --downbeat: #ffb84d;
  --radius: 14px;
  --tap: 48px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.app {
  max-width: 480px;
  margin: 0 auto;
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 1.25rem;
  gap: 0.35rem;
}

.back-to-study {
  align-self: flex-start;
  font-size: 0.82rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.back-to-study:hover {
  text-decoration: underline;
}

.header h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 0.85rem;
}

.card-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.hint {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field.full {
  margin-top: 0.75rem;
}

.label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

input[type="number"],
select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 0.85rem;
  font-size: 1.15rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.transport .bpm-row {
  display: block;
}

.transport .field-bpm {
  width: 100%;
}

.bpm-input-line {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.bpm-input-line input[type="number"] {
  flex: 1 1 auto;
  min-width: 0;
}

.transport-btns {
  display: flex;
  flex-shrink: 0;
  gap: 0.5rem;
}

.btn {
  min-height: var(--tap);
  min-width: 96px;
  padding: 0 1.1rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-primary {
  background: linear-gradient(180deg, #4aa8ff, var(--accent));
  color: #0a1624;
}

.btn-primary.playing {
  background: linear-gradient(180deg, #ff6b6b, #e04545);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.live-bpm {
  margin-top: 0.85rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  text-align: center;
}

.live-bpm-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.live-bpm-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  justify-content: center;
}

.live-bpm-value {
  font-size: 1.85rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--pulse-on);
  line-height: 1.1;
}

.live-bpm-unit {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.progress-row {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.progress-value {
  font-size: 0.95rem;
  color: var(--pulse-on);
  font-variant-numeric: tabular-nums;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.check-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: end;
}

@media (min-width: 400px) {
  .grid-3 {
    gap: 0.65rem;
  }
}

.grid-3 .field {
  min-width: 0;
}

.grid-3 .label {
  font-size: clamp(0.58rem, 2.8vw, 0.75rem);
  line-height: 1.2;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.grid-3 input[type="number"] {
  padding-left: 0.45rem;
  padding-right: 0.45rem;
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  min-height: 44px;
}

.time-sig {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
}

.time-sig .field {
  flex: 1 1 100px;
}

.time-slash {
  font-size: 2rem;
  font-weight: 300;
  color: var(--muted);
  padding-bottom: 0.5rem;
}

.six-eight-block {
  margin-top: 0.85rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.six-eight-block .label {
  display: block;
  margin-bottom: 0.5rem;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.radio {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.radio input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.visual-card .visual-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.measure-display {
  font-size: 0.9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.beat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: stretch;
  min-height: 72px;
}

.beat-cell {
  flex: 1 1 56px;
  max-width: 88px;
  min-height: 68px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--pulse-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.05s ease, border-color 0.05s ease, transform 0.08s ease;
}

.beat-cell.downbeat {
  border-color: rgba(255, 184, 77, 0.45);
}

.beat-cell.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  transform: scale(1.04);
}

.beat-cell.active.downbeat {
  background: rgba(255, 184, 77, 0.35);
  border-color: var(--downbeat);
  box-shadow: 0 0 20px rgba(255, 184, 77, 0.35);
}

.beat-cell.sub {
  opacity: 0.85;
  min-height: 56px;
  border-style: dashed;
  background: rgba(74, 92, 110, 0.25);
}

.beat-cell.sub.active {
  background: rgba(92, 255, 176, 0.2);
  border-color: var(--pulse-on);
  border-style: solid;
}

.beat-num {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.beat-cell.sub .beat-num {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.beat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 2px;
}

.footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

#autoFields.disabled {
  opacity: 0.45;
  pointer-events: none;
}
