/* static/css/articles/playable-midi-block.css */

/* =========================================================
   Playable MIDI Block
   ========================================================= */

.playable-midi-block {
  width: 100%;
  max-width: 100%;
  margin: 32px 0;
  padding: 22px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.06);
}

.playable-midi-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.playable-midi-header > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.playable-midi-eyebrow {
  margin: 0 0 4px;
  color: #4f46e5;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.playable-midi-header h3 {
  margin: 0;
  color: #111827;
  font-size: 24px;
  font-weight: 850;
  line-height: 1.18;
  word-break: break-word;
}

.playable-midi-meta {
  max-width: 760px;
  margin: 8px 0 0;
  color: #64748b;
  font-size: 15px;
  line-height: 1.65;
}

.playable-midi-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.playable-midi-actions button {
  min-height: 38px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff;
  color: #111827;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.playable-midi-actions button:hover {
  border-color: #4f46e5;
  color: #4f46e5;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.11);
}

.playable-midi-actions button:active {
  transform: translateY(1px);
}

/* =========================================================
   Small meta chips
   ========================================================= */

.playable-midi-small-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.playable-midi-small-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 3px 9px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

/* =========================================================
   Status + timeline
   ========================================================= */

.playable-midi-status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f8fafc;
  color: #64748b;
  font-size: 13px;
  font-weight: 750;
}

.playable-midi-timeline {
  margin-top: 14px;
}

.playable-midi-time-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: #64748b;
  font-size: 12px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.playable-midi-progress-track {
  position: relative;
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
  cursor: pointer;
  touch-action: manipulation;
}

.playable-midi-progress-track:hover {
  background: #dbe3ef;
}

.playable-midi-progress-track:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.22);
  outline-offset: 3px;
}

.playable-midi-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4f46e5, #06b6d4);
  transition: width 0.08s linear;
}

/* =========================================================
   Progression chips
   ========================================================= */

.playable-midi-progression {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.progression-chip {
  position: relative;
  min-height: 66px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #ffffff;
  color: #111827;
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 850;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.progression-chip span {
  display: block;
  margin-top: 4px;
  color: #64748b;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 750;
}

.progression-chip:hover {
  border-color: #4f46e5;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.12);
}

.progression-chip.is-active {
  border-color: #4f46e5;
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.16);
}

.progression-chip.is-active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 8px;
  height: 3px;
  border-radius: 999px;
  background: #4f46e5;
}

/* =========================================================
   Piano keyboard
   ========================================================= */

.playable-piano {
  position: relative;
  width: 100%;
  height: 172px;
  margin-top: 22px;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 14px;
  background: #f8fafc;
  padding: 14px;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.playable-piano::-webkit-scrollbar {
  height: 8px;
}

.playable-piano::-webkit-scrollbar-track {
  background: transparent;
}

.playable-piano::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cbd5e1;
}

.playable-piano-inner {
  position: relative;
  height: 138px;
  min-width: 980px;
}

.playable-key {
  position: absolute;
  box-sizing: border-box;
  transition:
    background 0.08s ease,
    box-shadow 0.08s ease,
    transform 0.08s ease;
}

.playable-key.white {
  bottom: 0;
  top: auto;
  width: 38px;
  height: 136px;
  border: 1px solid #cbd5e1;
  border-radius: 0 0 7px 7px;
  background: #ffffff;
  z-index: 1;
}

.playable-key.black {
  top: 0;
  bottom: auto;
  width: 24px;
  height: 84px;
  border: 1px solid #1e293b;
  border-radius: 0 0 5px 5px;
  background: #334155;
  z-index: 3;
}

.playable-key-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 750;
  text-align: center;
  pointer-events: none;
}

.playable-key.black .playable-key-label {
  display: none;
}

/* Scale-degree strip */
.playable-key.white::before,
.playable-key.black::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: var(--degree-color, transparent);
}

.playable-key.white::before {
  border-radius: 0 0 7px 7px;
}

/* Active note */
.playable-key.is-active {
  background: var(--active-note-color, var(--degree-color, #4f46e5)) !important;
  box-shadow:
    0 0 0 2px rgba(15, 23, 42, 0.12),
    0 8px 22px rgba(15, 23, 42, 0.16);
  transform: translateY(2px);
}

.playable-key.white.is-active .playable-key-label {
  opacity: 0;
}

.playable-key.is-active::after {
  content: attr(data-active-label);
  position: absolute;
  left: 50%;
  bottom: 9px;
  z-index: 4;
  transform: translateX(-50%);
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.playable-key.black.is-active::after {
  bottom: 10px;
  font-size: 10px;
}

/* =========================================================
   Insight
   ========================================================= */

.playable-midi-insight {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

.playable-midi-insight h4 {
  margin: 0 0 8px;
  color: #111827;
  font-size: 18px;
  font-weight: 850;
}

.playable-midi-insight p {
  margin: 0;
  color: #475569;
  font-size: 15px;
  line-height: 1.75;
}

/* =========================================================
   Tablet
   ========================================================= */

@media (max-width: 768px) {
  .playable-midi-block {
    margin: 26px 0;
    padding: 18px;
    border-radius: 16px;
  }

  .playable-midi-header {
    gap: 14px;
  }

  .playable-midi-header h3 {
    font-size: 22px;
  }

  .playable-midi-meta {
    font-size: 14px;
  }

  .playable-midi-actions button {
    padding: 8px 12px;
  }

  .playable-midi-progression {
    grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  }

  .progression-chip {
    min-height: 60px;
    font-size: 21px;
  }

  .progression-chip span {
    font-size: 13px;
  }
}

/* =========================================================
   Mobile
   ========================================================= */

@media (max-width: 640px) {
  .playable-midi-block {
    margin: 22px 0;
    padding: 15px;
    border-radius: 14px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.055);
  }

  .playable-midi-header {
    display: block;
  }

  .playable-midi-eyebrow {
    font-size: 11px;
  }

  .playable-midi-header h3 {
    font-size: 20px;
    line-height: 1.22;
  }

  .playable-midi-meta {
    margin-top: 7px;
    font-size: 13.5px;
    line-height: 1.58;
  }

  .playable-midi-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
  }

  .playable-midi-actions button {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    border-radius: 12px;
    font-size: 14px;
  }

  .playable-midi-small-meta {
    gap: 6px;
    margin-top: 9px;
  }

  .playable-midi-small-meta span {
    min-height: 23px;
    padding: 3px 8px;
    font-size: 11px;
  }

  .playable-midi-status {
    margin-top: 12px;
    padding: 9px 10px;
    font-size: 12.5px;
  }

  .playable-midi-timeline {
    margin-top: 12px;
  }

  .playable-midi-time-row {
    margin-bottom: 6px;
    font-size: 11px;
  }

  .playable-midi-progress-track {
    height: 9px;
  }

  /*
    Mobile: progression chips should scroll horizontally.
    This keeps Roman/chord labels readable instead of squeezing into tiny cards.
  */
  .playable-midi-progression {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    padding: 2px 2px 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .playable-midi-progression::-webkit-scrollbar {
    height: 6px;
  }

  .playable-midi-progression::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #cbd5e1;
  }

  .progression-chip {
    flex: 0 0 76px;
    min-height: 56px;
    border-radius: 13px;
    font-size: 20px;
    scroll-snap-align: start;
  }

  .progression-chip span {
    margin-top: 3px;
    font-size: 12px;
  }

  .progression-chip.is-active::after {
    left: 12px;
    right: 12px;
    bottom: 7px;
  }

  .playable-piano {
    height: 146px;
    margin-top: 16px;
    padding: 10px;
    border-radius: 13px;
  }

  .playable-piano-inner {
    height: 124px;
    min-width: 780px;
  }

  .playable-key.white {
    width: 34px;
    height: 122px;
    border-radius: 0 0 6px 6px;
  }

  .playable-key.black {
    width: 21px;
    height: 76px;
    border-radius: 0 0 5px 5px;
  }

  .playable-key-label {
    bottom: 7px;
    font-size: 10px;
  }

  .playable-key.white::before,
  .playable-key.black::before {
    height: 4px;
  }

  .playable-key.is-active::after {
    bottom: 8px;
    font-size: 10px;
  }

  .playable-key.black.is-active::after {
    bottom: 9px;
    font-size: 9px;
  }

  .playable-midi-insight {
    margin-top: 16px;
    padding-top: 14px;
  }

  .playable-midi-insight h4 {
    font-size: 16px;
  }

  .playable-midi-insight p {
    font-size: 14px;
    line-height: 1.65;
  }
}

/* =========================================================
   Very small phones
   ========================================================= */

@media (max-width: 390px) {
  .playable-midi-block {
    padding: 13px;
  }

  .playable-midi-header h3 {
    font-size: 19px;
  }

  .playable-midi-actions {
    grid-template-columns: 1fr;
  }

  .progression-chip {
    flex-basis: 72px;
    min-height: 54px;
    font-size: 19px;
  }

  .playable-piano {
    height: 138px;
    padding: 9px;
  }

  .playable-piano-inner {
    height: 116px;
    min-width: 720px;
  }

  .playable-key.white {
    width: 32px;
    height: 114px;
  }

  .playable-key.black {
    width: 20px;
    height: 72px;
  }
}

/* =========================================================
   Final mobile/player polish
   ========================================================= */

.playable-midi-actions .js-midi-play {
  background: #111827;
  border-color: #111827;
  color: #ffffff;
}

.playable-midi-actions .js-midi-play:hover {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #ffffff;
}

.playable-midi-actions .js-midi-stop {
  background: #ffffff;
}

.playable-midi-progress-track {
  min-height: 10px;
}

.playable-midi-progress-track::after {
  content: "";
  position: absolute;
  top: -10px;
  right: 0;
  bottom: -10px;
  left: 0;
}

.playable-midi-progression {
  max-width: 100%;
}

@media (max-width: 640px) {
  .playable-midi-block {
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
    margin-left: 50%;
    transform: translateX(-50%);
  }

  .playable-midi-header,
  .playable-midi-header > div:first-child {
    min-width: 0;
  }

  .playable-midi-small-meta {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .playable-midi-small-meta span {
    flex: 0 0 auto;
  }

  .playable-midi-status {
    white-space: normal;
    word-break: break-word;
  }

  .playable-midi-progress-track {
    height: 11px;
  }

  .playable-piano {
    margin-left: -4px;
    margin-right: -4px;
    width: calc(100% + 8px);
  }
}

@media (max-width: 390px) {
  .playable-midi-block {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
  }

  .playable-midi-meta {
    font-size: 13px;
  }
}


/* =========================================================
   MusicXML score preview
   ========================================================= */

.playable-score-preview {
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #ffffff;
}

.playable-score-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
}

.playable-score-toolbar > div {
  min-width: 0;
}

.playable-score-kicker {
  display: block;
  margin-bottom: 2px;
  color: #4f46e5;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.playable-score-toolbar strong {
  display: block;
  overflow: hidden;
  color: #111827;
  font-size: 14px;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playable-score-toolbar button {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #ffffff;
  color: #334155;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.playable-score-toolbar button:hover {
  border-color: #4f46e5;
  color: #4f46e5;
}

.playable-score-scroll {
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  background: #ffffff;
  -webkit-overflow-scrolling: touch;
}

.playable-score-canvas {
  min-width: 720px;
}

.playable-score-canvas svg {
  max-width: none;
}

.playable-score-status {
  padding: 9px 12px;
  border-top: 1px solid #e5e7eb;
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
  font-weight: 750;
}

.playable-score-preview.is-collapsed .playable-score-scroll,
.playable-score-preview.is-collapsed .playable-score-status {
  display: none;
}

.playable-score-preview.is-error {
  border-color: #fecaca;
}

.playable-score-preview.is-error .playable-score-status {
  background: #fef2f2;
  color: #991b1b;
}

@media (max-width: 640px) {
  .playable-score-preview {
    margin-top: 14px;
    border-radius: 14px;
  }

  .playable-score-toolbar {
    align-items: flex-start;
    padding: 11px 12px;
  }

  .playable-score-toolbar strong {
    max-width: 190px;
    font-size: 13px;
  }

  .playable-score-toolbar button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 11px;
  }

  .playable-score-scroll {
    max-height: 300px;
    padding: 8px;
  }

  .playable-score-canvas {
    min-width: 640px;
  }

  .playable-score-status {
    padding: 8px 10px;
    font-size: 11.5px;
  }
}

@media (max-width: 390px) {
  .playable-score-toolbar {
    display: block;
  }

  .playable-score-toolbar button {
    margin-top: 8px;
    width: 100%;
  }

  .playable-score-toolbar strong {
    max-width: 100%;
  }

  .playable-score-canvas {
    min-width: 580px;
  }
}
