/*
 * The Music Analyzer in the site's full-screen frame, the same frame as the site's other tools: a slim bar
 * with its name, the stage (the song, then its key, tempo and moods), and a dock along the bottom with the
 * main button.
 *
 * Colours and typefaces come from the site's theme (its custom properties), with the dark values as
 * fall-backs so the analyzer also looks right on a page of its own.
 */
.ma {
  --ma-card: var(--card, #17191E);
  --ma-soft: var(--soft, #1F2228);
  --ma-line: var(--card-line, #2E323A);
  --ma-line-strong: var(--line, #3A3F48);
  --ma-ink: var(--ink, #F2F0EA);
  --ma-text: var(--text, #C7CAD1);
  --ma-muted: var(--muted, #B9BCC4);
  --ma-display: var(--font-display, 'Archivo', 'Arial Black', sans-serif);
  --ma-body: var(--font-body, 'Figtree', 'Segoe UI', system-ui, sans-serif);
  --ma-mono: var(--font-mono, 'IBM Plex Mono', ui-monospace, Consolas, monospace);
  /* the analyzer's colour: as a fill, and as lettering on the page */
  --ma-c: #4FD1C5; --ma-ct: #4FD1C5;
  --app-top: 0px;                                /* how far down the page the analyzer starts; the script measures it */
  --app-pad: max(16px, calc(50vw - 600px));      /* content stays within 1200px, backgrounds run to the edges */
  --app-expand: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5'/%3E%3C/svg%3E");
  --ma-play: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 4.5v15l13-7.5z'/%3E%3C/svg%3E");
  --ma-pause: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 4h4.5v16H6zM13.5 4H18v16h-4.5z'/%3E%3C/svg%3E");

  position: relative; box-sizing: border-box; display: grid; width: 100%; margin: 0;
  min-height: max(560px, calc(100vh - var(--app-top)));
  min-height: max(560px, calc(100dvh - var(--app-top)));
  padding: 6px var(--app-pad) 0;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "name  full"
    "stage stage"
    "dock  dock";
  column-gap: 12px;
  font-family: var(--ma-body); font-size: 16px; line-height: 1.4; color: var(--ma-text); text-align: left;
}
:root[data-theme="light"] .ma { --ma-c: #3CC7BA; --ma-ct: #0B6B63; }
.ma, .ma *, .ma *::before, .ma *::after { box-sizing: border-box; }
.ma button { font: inherit; }
.ma button:focus-visible, .ma [role="button"]:focus-visible, .ma a:focus-visible { outline: 3px solid var(--focus, #4FD1C5); outline-offset: 2px; }

/* full screen: nothing above the analyzer */
.ma:fullscreen, html.rn-full .ma { --app-top: 0px; }
.ma:fullscreen { overflow-y: auto; background: var(--bg, #0E0F12); }

/* ---------- the bar: the name, and full screen ---------- */
.ma .ma-name {
  grid-area: name; display: flex; align-items: center; gap: 10px; min-height: 40px;
  font-family: var(--ma-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; color: var(--ma-ct);
}
.ma .ma-name::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ma-c); }
.ma .ma-full {
  grid-area: full; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin: 0; padding: 0;
  border: 1px solid var(--ma-line-strong); border-radius: 999px; background: transparent; color: var(--ma-ink); cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.ma .ma-full:hover { background: var(--ma-c); border-color: var(--ma-c); color: #0E0F12; }
.ma .ma-full::before { content: ""; width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--app-expand) center / contain no-repeat; mask: var(--app-expand) center / contain no-repeat; }

/* ---------- the stage ---------- */
.ma .ma-stage {
  grid-area: stage; position: relative; display: grid; grid-template-columns: minmax(0, 1fr); align-content: center; gap: 22px;
  width: 100%; max-width: 920px; margin: 0 auto; padding: 12px 0 20px;
}
/* a wash of the colour behind it all */
.ma .ma-stage::before {
  content: ""; position: absolute; z-index: 0; top: 0; left: 50%; width: min(760px, 100vw); height: 320px; transform: translateX(-50%); pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--ma-c) 16%, transparent), transparent);
}
.ma .ma-stage > * { position: relative; z-index: 1; }

/* the song: a place to drop it, then its waveform and a play button */
.ma #file-select-area { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ma #file-drop-area {
  display: flex; align-items: center; justify-content: center; min-height: 132px; padding: 22px 16px; cursor: pointer; text-align: center;
  border: 2px dashed color-mix(in srgb, var(--ma-c) 60%, var(--ma-line)); border-radius: 20px; background: color-mix(in srgb, var(--ma-c) 7%, transparent);
  color: var(--ma-text); font-size: 17px; transition: background-color 0.2s ease, border-color 0.2s ease;
}
.ma #file-drop-area:hover, .ma #file-drop-area.ma-over { border-color: var(--ma-c); background: color-mix(in srgb, var(--ma-c) 14%, transparent); }
.ma #file-drop-area b { color: var(--ma-ink); }
.ma #file-drop-area small { display: block; margin-top: 6px; font-family: var(--ma-mono); font-size: 12px; color: var(--ma-muted); }
.ma #waveform { min-height: 96px; padding: 10px 12px; border: 1px solid var(--ma-line); border-radius: 18px; background: var(--ma-card); }
.ma .controls { display: flex; justify-content: center; }
.ma #playPauseButton {
  display: inline-flex; align-items: center; gap: 9px; min-height: 44px; padding: 0 20px 0 16px; border: 1px solid var(--ma-line-strong); border-radius: 999px;
  background: transparent; color: var(--ma-ink); font-weight: 700; cursor: pointer; transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.ma #playPauseButton:hover:not(:disabled) { background: var(--ma-c); border-color: var(--ma-c); color: #0E0F12; }
.ma #playPauseButton:disabled { opacity: 0.45; cursor: not-allowed; }
.ma #playPauseIcon { width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--ma-play) center / contain no-repeat; mask: var(--ma-play) center / contain no-repeat; }
.ma #playPauseButton[data-playing="true"] #playPauseIcon { -webkit-mask-image: var(--ma-pause); mask-image: var(--ma-pause); }

/* what it found */
.ma #results { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.ma #bpm-and-key { display: grid; grid-template-columns: auto auto; justify-content: start; gap: 14px 48px; }
.ma .row-container { display: flex; flex-direction: column; gap: 6px; }
.ma .tag { font-family: var(--ma-mono); font-size: 11px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ma-ct); }
.ma #key-value, .ma #bpm-value {
  min-height: 1em; font-family: var(--ma-display); font-stretch: 116%; font-weight: 800; font-size: clamp(34px, 9vw, 56px); line-height: 1; letter-spacing: -0.02em; color: var(--ma-ink); white-space: nowrap;
}
.ma #key-value:empty::before, .ma #bpm-value:empty::before { content: "\2014"; color: var(--ma-line-strong); }
.ma .ma-moods { display: grid; gap: 12px; }
.ma .classifier { display: grid; grid-template-columns: 26px minmax(0, 1fr); align-items: center; gap: 10px; }
.ma .classifier > span { font-size: 20px; line-height: 1; text-align: center; }
/* each mood: its name, a bar filled to how strongly the song has it, and the figure */
.ma .classifier-meter {
  --meter: calc(var(--meter-width, 0) * 1%);
  display: grid; grid-template-columns: 116px minmax(0, 1fr) 40px; align-items: center; gap: 10px; font-size: 14px; color: var(--ma-text);
}
.ma .classifier-meter::before { content: attr(data-classifier); grid-column: 1; grid-row: 1; }
.ma .classifier-meter::after {
  content: ""; grid-column: 2; height: 8px; border-radius: 999px;
  background: linear-gradient(90deg, var(--ma-c) var(--meter), var(--ma-line-strong) var(--meter));
  transition: background 0.6s ease;
}
.ma .classifier-meter::after { grid-row: 1; }
.ma .ma-meter-value { grid-column: 3; grid-row: 1; font-family: var(--ma-mono); font-size: 12px; text-align: right; color: var(--ma-muted); }

/* while it works: the results dim under a spinner */
.ma #loader { position: absolute; inset: -8px; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; border-radius: 18px; text-align: center; }
.ma #loader.disabled { display: none; }
.ma #loader.active { background: color-mix(in srgb, var(--bg, #0E0F12) 78%, transparent); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.ma .ma-spinner { width: 42px; height: 42px; border: 4px solid color-mix(in srgb, var(--ma-c) 25%, transparent); border-top-color: var(--ma-c); border-radius: 50%; animation: ma-spin 0.9s linear infinite; }
@keyframes ma-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ma .ma-spinner { animation-duration: 3s; } }
.ma .ma-loader-text { max-width: 30em; font-weight: 600; color: var(--ma-ink); }

/* the credit, with the logo on a light chip so it reads in both modes */
.ma #links { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; font-family: var(--ma-mono); font-size: 11px; letter-spacing: 0.06em; color: var(--ma-muted); }
.ma #links a { display: inline-flex; padding: 5px 9px; border-radius: 8px; background: #F4F2EC; }
.ma #links img { display: block; height: 18px; width: auto; }

/* ---------- the dock: the main button ---------- */
.ma .ma-dock {
  grid-area: dock; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  margin: 0 calc(-1 * var(--app-pad)); padding: 12px var(--app-pad) 14px;
  background: color-mix(in srgb, var(--ma-c) 9%, var(--ma-card)); border-top: 1px solid color-mix(in srgb, var(--ma-c) 42%, var(--ma-line));
}
.ma .ma-hint { flex: 1 1 100%; font-family: var(--ma-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ma-muted); }
.ma #ma-choose {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; height: 52px; min-width: 150px; margin: 0; padding: 0 28px; border: 0; border-radius: 999px;
  background: var(--ma-c); color: #0E0F12; cursor: pointer; transition: background-color 0.2s ease, transform 0.15s ease;
  font-family: var(--ma-display); font-stretch: 112%; font-weight: 800; font-size: 17px; letter-spacing: 0.06em; text-transform: uppercase;
}
.ma #ma-choose:hover { background: color-mix(in srgb, var(--ma-c) 82%, #fff); }
.ma #ma-choose:active { transform: scale(0.97); }
.ma #ma-choose:disabled { cursor: progress; background: transparent; color: var(--ma-ct); box-shadow: inset 0 0 0 2px var(--ma-c); }

@media (max-width: 899px) and (max-height: 700px) {
  .ma .ma-stage { gap: 14px; padding-bottom: 12px; }
  .ma #results { gap: 14px; }
  .ma .ma-moods { gap: 8px; }
  .ma #file-drop-area { min-height: 104px; }
  .ma #waveform { min-height: 0; padding: 6px 10px; }
}

@media (min-width: 900px) {
  .ma { --app-pad: max(24px, calc(50vw - 600px)); padding-top: 12px; }
  .ma .ma-stage { gap: 30px 48px; }
  .ma #results { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 48px; }
  .ma #file-drop-area { min-height: 150px; }
  .ma .ma-dock { flex-wrap: nowrap; padding: 14px var(--app-pad) 18px; }
  .ma .ma-hint { flex: 1 1 auto; }
  .ma #ma-choose { flex: none; height: 56px; }
}
