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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f0f2f5;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
  color: white;
  padding: 1.25rem 1rem;
  text-align: center;
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.back-link {
  display: inline-block;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.back-link:hover {
  color: white;
}

header h1 {
  font-size: 1.25rem;
  line-height: 1.35;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 0.25rem;
}

/* ===== Main layout ===== */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

/* ===== Ad unit ===== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ===== Tool section ===== */
.tool-section {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ===== Beat display (visual feedback) ===== */
.beat-display {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  min-height: 40px;
  align-items: center;
}

.beat-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #dde2ea;
  transition: background 0.05s, transform 0.05s;
  flex-shrink: 0;
}

.beat-dot.hidden {
  display: none;
}

.beat-dot.accent {
  background: #e74c3c;
  transform: scale(1.2);
  box-shadow: 0 0 14px rgba(231,76,60,0.6);
}

.beat-dot.active {
  background: #3498db;
  transform: scale(1.15);
  box-shadow: 0 0 12px rgba(52,152,219,0.5);
}

/* ===== BPM display ===== */
.bpm-display {
  text-align: center;
  margin-bottom: 1.25rem;
}

.bpm-number {
  font-size: 4rem;
  font-weight: 800;
  color: #1a1a2e;
  line-height: 1;
  letter-spacing: -2px;
}

.tempo-name {
  font-size: 1.1rem;
  color: #7f8c8d;
  margin-top: 0.2rem;
  font-style: italic;
}

/* ===== Controls ===== */
.control-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #555;
  min-width: 60px;
  flex-shrink: 0;
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.slider-min,
.slider-max {
  font-size: 0.75rem;
  color: #999;
  white-space: nowrap;
}

input[type="range"] {
  flex: 1;
  height: 6px;
  accent-color: #3498db;
  cursor: pointer;
  min-width: 0;
}

.bpm-input-num {
  width: 64px;
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid #dde2ea;
  border-radius: 8px;
  text-align: center;
  flex-shrink: 0;
  -moz-appearance: textfield;
}

.bpm-input-num::-webkit-outer-spin-button,
.bpm-input-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.bpm-input-num:focus {
  outline: none;
  border-color: #3498db;
}

.swing-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: #3498db;
  min-width: 36px;
  text-align: right;
}

/* ===== Time signature buttons ===== */
.time-sig-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.time-sig-btn {
  padding: 0.4rem 0.65rem;
  font-size: 0.9rem;
  font-weight: 700;
  background: #f0f2f5;
  color: #555;
  border: 2px solid #dde2ea;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  min-height: 44px;
  min-width: 52px;
}

.time-sig-btn:hover {
  border-color: #3498db;
  color: #3498db;
}

.time-sig-btn.active {
  background: #3498db;
  border-color: #3498db;
  color: white;
}

/* ===== Start/Stop button ===== */
.main-controls {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0 1rem;
}

.btn-start-stop {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 2.5rem;
  font-size: 1.2rem;
  font-weight: 800;
  background: #1a1a2e;
  color: white;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  min-height: 56px;
  letter-spacing: 0.03em;
}

.btn-start-stop:hover {
  background: #2c3e5a;
}

.btn-start-stop:active {
  transform: scale(0.97);
}

.btn-start-stop.running {
  background: #e74c3c;
}

.btn-start-stop.running:hover {
  background: #c0392b;
}

.btn-icon {
  font-size: 1.1rem;
}

/* ===== Tap tempo section ===== */
.tap-section {
  border-top: 1px solid #eee;
  padding-top: 1.25rem;
  margin-top: 0.5rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 0.5rem;
}

.tap-desc {
  font-size: 0.82rem;
  color: #888;
  margin-bottom: 0.9rem;
}

.btn-tap {
  display: block;
  width: 100%;
  min-height: 80px;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, #3498db, #2980b9);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  box-shadow: 0 4px 12px rgba(52,152,219,0.35);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn-tap:active {
  transform: scale(0.97);
  box-shadow: 0 2px 6px rgba(52,152,219,0.2);
}

.tap-result {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #2980b9;
  min-height: 1.8rem;
  margin-top: 0.6rem;
}

.btn-reset-tap {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.55rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  color: #999;
  border: 1px solid #dde2ea;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  transition: color 0.15s, border-color 0.15s;
}

.btn-reset-tap:hover {
  color: #555;
  border-color: #bbb;
}

/* ===== Memo section ===== */
.memo-section {
  border-top: 1px solid #eee;
  padding-top: 1.25rem;
  margin-top: 1.25rem;
}

.memo-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.memo-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #555;
  min-width: 64px;
  flex-shrink: 0;
}

.memo-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  border: 2px solid #dde2ea;
  border-radius: 8px;
  min-height: 44px;
}

.memo-input:focus {
  outline: none;
  border-color: #3498db;
}

.memo-bpm {
  max-width: 100px;
  -moz-appearance: textfield;
}

.memo-bpm::-webkit-outer-spin-button,
.memo-bpm::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.btn-save-memo {
  display: block;
  width: 100%;
  padding: 0.65rem;
  font-size: 0.95rem;
  font-weight: 700;
  background: #1a1a2e;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s;
}

.btn-save-memo:hover {
  background: #2c3e5a;
}

.memo-saved-list {
  margin-top: 0.75rem;
}

.memo-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  gap: 0.5rem;
}

.memo-item-name {
  font-weight: 600;
  color: #333;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memo-item-bpm {
  font-size: 0.85rem;
  color: #3498db;
  font-weight: 700;
  flex-shrink: 0;
}

.memo-item-apply {
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  min-height: 32px;
  flex-shrink: 0;
  transition: background 0.15s;
}

.memo-item-apply:hover {
  background: #2980b9;
}

.memo-item-delete {
  padding: 0.25rem 0.45rem;
  font-size: 0.78rem;
  background: transparent;
  color: #bbb;
  border: 1px solid #dde2ea;
  border-radius: 5px;
  cursor: pointer;
  min-height: 32px;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.memo-item-delete:hover {
  color: #e74c3c;
  border-color: #e74c3c;
}

/* ===== How-to section ===== */
.howto-section {
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.howto-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 0.75rem;
  margin-top: 1.25rem;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-steps {
  padding-left: 1.25rem;
  color: #555;
  font-size: 0.92rem;
}

.howto-steps li {
  margin-bottom: 0.5rem;
}

/* ===== Tempo table ===== */
.tempo-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
}

.tempo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  color: #444;
}

.tempo-table th {
  background: #f0f2f5;
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-weight: 700;
  color: #1a1a2e;
  border-bottom: 2px solid #dde2ea;
}

.tempo-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #f0f2f5;
}

.tempo-table tr:last-child td {
  border-bottom: none;
}

.howto-section p {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.7;
}

/* ===== FAQ ===== */
.faq-list {
  margin-top: 0.5rem;
}

.faq-list dt {
  font-weight: 700;
  font-size: 0.9rem;
  color: #333;
  margin-top: 0.75rem;
}

.faq-list dt:first-child {
  margin-top: 0;
}

.faq-list dd {
  font-size: 0.88rem;
  color: #666;
  margin-left: 0;
  margin-top: 0.2rem;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

footer a {
  color: #666;
  text-decoration: underline;
}

/* ===== Desktop ===== */
@media (min-width: 640px) {
  header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .bpm-number {
    font-size: 5.5rem;
  }

  .beat-dot {
    width: 44px;
    height: 44px;
  }

  .btn-tap {
    min-height: 100px;
    font-size: 2rem;
  }

  .memo-row {
    flex-wrap: nowrap;
  }
}
