/* Practice Beat — Styles
   harmonica-app の配色・レイアウトパターンを踏襲 */

:root {
  /* Light mode */
  --bg-a: #fff6f1;
  --bg-b: #f3f0ff;
  --bg-c: #eef8ff;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-solid: #fffdfc;
  --ink: #4c3a44;
  --ink-soft: #8b7681;
  --line: rgba(120, 90, 105, 0.16);
  --accent: #e2503c;
  --accent-soft: #ffe3dd;
  --shadow-s: 0 1px 2px rgba(90, 60, 75, 0.10);
  --shadow-m: 0 6px 18px -8px rgba(90, 60, 75, 0.34);
  --radius: 16px;
  --font: "Hiragino Maru Gothic ProN", "M PLUS Rounded 1c", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-a: #2a1f2b;
    --bg-b: #221f33;
    --bg-c: #1d2531;
    --panel-solid: #332836;
    --ink: #f6ecf1;
    --ink-soft: #b7a3b1;
    --line: rgba(230, 200, 220, 0.16);
    --accent: #ff7f6b;
    --accent-soft: #b83528;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-a);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

header, footer {
  flex-shrink: 0;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ===== Header ===== */
.topbar {
  background: var(--panel-solid);
  padding: 16px;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-s);
}

.topbar__row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
}

.coco {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  position: relative;
}

.coco__sprite {
  width: 100%;
  height: 100%;
  background-image: url('assets/coco.webp');
  background-size: 800% 900%;
  background-position: 0% 0%;
  background-repeat: no-repeat;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
}

.coco__bubble {
  margin-top: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  max-width: 200px;
}

.topbar__title {
  flex: 1;
}

.title {
  margin: 0 0 4px 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.title span {
  font-size: 0.9em;
  opacity: 0.7;
  margin-left: 4px;
}

.subtitle {
  font-size: 12px;
  color: var(--ink-soft);
}

/* ===== Transport Control ===== */
.transport {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--panel-solid);
  padding: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-s);
  margin-bottom: 16px;
}

.btn-play, .btn-stop {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}

.btn-play:active, .btn-stop:active {
  opacity: 0.9;
}

.bpm-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bpm-control input {
  width: 80px;
  height: 24px;
}

.bpm-control span {
  font-weight: 600;
  min-width: 40px;
}

#timeSignature {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-a);
  color: var(--ink);
  font-family: var(--font);
  cursor: pointer;
}

.loop-indicator {
  font-weight: 600;
  color: var(--accent);
}

/* ===== Label ===== */
.label {
  margin: 0 0 12px 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
}

/* ===== Presets ===== */
.analyze-section {
  margin-bottom: 24px;
}

.analysis-start {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.analysis-start input {
  width: 84px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--ink);
  font: inherit;
  text-align: right;
}

.analysis-preview {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 0 2px 10px;
}

.analysis-waveform {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-solid);
  cursor: crosshair;
}

.analysis-preview audio {
  width: 100%;
  min-width: 0;
  height: 34px;
}

.analysis-rerun {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.analysis-rerun:hover,
.analysis-rerun:focus-visible {
  border-color: var(--accent);
}

.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 76px;
  padding: 14px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.6;
  cursor: pointer;
}

.drop-zone small {
  font-size: 12px;
  opacity: 0.8;
}

.drop-zone.over,
.drop-zone:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.drop-zone.busy {
  cursor: progress;
  opacity: 0.7;
}

.analyze-result {
  margin: 10px 2px 0;
  font-size: 14px;
  color: var(--ink);
  min-height: 1.2em;
}

.analyze-result:empty {
  margin-top: 0;
  min-height: 0;
}

.analyze-result.warn {
  color: var(--accent);
}

.detected-key {
  margin: 6px 2px 0;
  min-height: 1.2em;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.presets {
  margin-bottom: 24px;
}

.preset-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
}

.preset-chip {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 200ms;
  scroll-snap-align: start;
}

.preset-chip:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-s);
}

.preset-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== Beat Map（再生中だけ出る 4×4 の位置表示） ===== */
.beat-map {
  margin-bottom: 24px;
}

.beat-map__grid {
  display: grid;
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
}

.beat-map__cell {
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--bg-c);
}

.beat-map__cell.on {
  background: var(--accent);
  box-shadow: var(--shadow-s);
}

/* ===== Grid ===== */
.grid-section {
  margin-bottom: 24px;
}

.grid-scroll {
  max-height: 350px;
  overflow-x: auto;
  overflow-y: auto;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  padding: 8px;
  box-shadow: var(--shadow-s);
}

.grid {
  display: grid;
  grid-template-columns: 50px repeat(64, 1fr);
  gap: 2px;
  min-width: fit-content;
}

.grid-row-label {
  font-size: 10px;
  color: var(--ink-soft);
  text-align: right;
  padding-right: 4px;
  white-space: nowrap;
  display: flex;
  align-items: center;
}

.grid-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--bg-c);
  border: none;
  cursor: pointer;
  transition: all 100ms;
}

.grid-cell:hover {
  box-shadow: var(--shadow-s);
}

.grid-cell.active {
  background: var(--accent);
}

.grid-cell.beat {
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

/* 再生位置。transition は切る（プレイヘッドは即座に動く） */
.grid-cell.playing {
  outline: 2px solid var(--ink);
  outline-offset: -1px;
  transition: none;
}

.grid-cell.active.playing {
  background: var(--ink);
}

.grid-row:nth-child(4n) .grid-cell.beat {
  background: rgba(120, 90, 105, 0.08);
}

/* ===== Melody Section ===== */
.melody-section {
  margin-bottom: 24px;
  background: var(--panel-solid);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-s);
}

.instrument-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.btn-toggle {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--bg-a);
  color: var(--ink);
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: all 200ms;
}

.btn-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#chordPreset {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-a);
  color: var(--ink);
  font-family: var(--font);
  margin-bottom: 8px;
}

.key-control {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

#keyTranspose {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-a);
  color: var(--ink);
  font-family: var(--font);
}

.octave-display {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: right;
}

/* ===== Keyboard ===== */
#keyboard {
  display: flex;
  gap: 3px;
  margin-top: 16px;
  padding: 12px;
  background: var(--panel-solid);
  border-radius: var(--radius);
  box-shadow: var(--shadow-s);
  flex-wrap: wrap;
}

.keyboard-key {
  flex: 1;
  min-width: 30px;
  padding: 8px 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 10px;
  text-align: center;
  cursor: pointer;
  transition: all 100ms;
}

.keyboard-key:hover {
  box-shadow: var(--shadow-s);
}

.keyboard-key:active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ===== Footer ===== */
.foot {
  flex-shrink: 0;
  text-align: center;
  padding: 16px;
  color: var(--ink-soft);
  font-size: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-solid);
}

.foot p {
  margin: 0;
}

/* ===== Audio Hint ===== */
.audio-hint {
  text-align: center;
  color: var(--ink-soft);
  font-size: 12px;
  margin: 16px 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  main {
    padding: 12px;
  }

  .topbar__row {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .topbar__title {
    width: 100%;
  }

  .transport {
    flex-direction: column;
    width: 100%;
  }

  .bpm-control {
    width: 100%;
    justify-content: space-between;
  }

  #timeSignature {
    width: 100%;
  }

  .grid-scroll {
    max-height: 300px;
  }
}

/* ===== Coco Hop Animation ===== */
.is-hop {
  animation: hop 0.4s ease-out;
}

@keyframes hop {
  0% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
  100% { transform: translateY(0); }
}
