/*
 * Adapted from the Chrome Music Lab spectrogram experiment:
 * https://github.com/googlecreativelab/chrome-music-lab/tree/master/spectrogram
 * Modified for a standalone Fiume /app-poly entrypoint.
 */

:root {
  color-scheme: dark;
  --poly-bg: #06080b;
  --poly-panel: rgba(10, 14, 19, 0.72);
  --poly-panel-strong: rgba(14, 20, 27, 0.94);
  --poly-border: rgba(182, 219, 255, 0.16);
  --poly-text: #eff6fb;
  --poly-muted: rgba(239, 246, 251, 0.72);
  --poly-accent: #f3b55c;
  --poly-accent-strong: #ffd18c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body.poly-page {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(66, 209, 127, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(76, 167, 255, 0.16), transparent 34%),
    linear-gradient(180deg, #0d1117 0%, var(--poly-bg) 100%);
  color: var(--poly-text);
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
}

.poly-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(14, 22, 30, 0.75) 0%, rgba(5, 8, 12, 0.94) 100%);
}

.poly-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.poly-scale {
  pointer-events: none;
}

.fiume-brand-link {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 4px 14px 4px 4px;
  border: 1px solid var(--poly-border);
  border-radius: 999px;
  background: rgba(9, 13, 19, 0.78);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
  color: var(--poly-text);
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.fiume-brand-link:hover,
.fiume-brand-link:focus-visible {
  border-color: rgba(243, 181, 92, 0.48);
  background: rgba(28, 44, 35, 0.92);
  color: var(--poly-accent-strong);
  outline: none;
  transform: translateY(-1px);
}

.fiume-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--poly-accent-strong);
  background: linear-gradient(180deg, rgba(243, 181, 92, 0.18), rgba(76, 167, 255, 0.08));
  border: 1px solid rgba(255, 222, 173, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.fiume-brand-mark svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.poly-detection {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 2;
  width: fit-content;
  max-width: calc(100vw - 24px);
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 9px 12px;
  border: 1px solid var(--poly-border);
  border-radius: 16px;
  background: rgba(9, 13, 19, 0.78);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
  transform: translateX(-50%);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.poly-detection.is-empty {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(-8px);
}

.poly-detection-mode {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
}

.poly-detection-mode:empty,
.poly-note-markers:empty {
  display: none;
}

.poly-note-markers {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
  z-index: 2;
}

.poly-note-chip {
  position: absolute;
  left: 0;
  transform: translate(-100%, -50%);
  --poly-note-dot: rgba(126, 240, 176, 0.92);
  --poly-note-line: rgba(239, 246, 251, 0.44);
  border: 1px solid var(--poly-border);
  border-radius: 999px;
  background: rgba(8, 13, 18, 0.74);
  backdrop-filter: blur(14px);
  padding: 5px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
}

.poly-note-chip::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -14px;
  width: 12px;
  height: 1px;
  background: var(--poly-note-line);
  transform: translateY(-50%);
}

.poly-note-chip::before {
  content: "";
  position: absolute;
  top: 50%;
  right: -18px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--poly-note-dot);
  transform: translateY(-50%);
}

.poly-mode-link {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--poly-border);
  border-radius: 999px;
  background: rgba(9, 13, 19, 0.78);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
  color: var(--poly-text);
  text-decoration: none;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.poly-mode-link:hover,
.poly-mode-link:focus-visible {
  border-color: rgba(126, 240, 176, 0.64);
  background: rgba(28, 44, 35, 0.92);
  color: rgba(236, 255, 243, 0.98);
  outline: none;
  transform: translateY(-1px);
}

.poly-ui {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
  pointer-events: none;
}

.poly-ui.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
}

.poly-button {
  appearance: none;
  min-height: 54px;
  width: fit-content;
  padding: 0 26px;
  border: 1px solid var(--poly-border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--poly-text);
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
  pointer-events: auto;
}

.poly-button-label {
  display: inline-block;
}

.poly-button-icon {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}

.poly-button-icon-mic {
  width: 13px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 7px;
}

.poly-button-icon-mic::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 6px;
  background: currentColor;
  transform: translateX(-50%);
}

.poly-button-icon-mic::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 6px);
  width: 12px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transform: translateX(-50%);
}

.poly-button-primary {
  background: linear-gradient(135deg, var(--poly-accent), #f58e56);
  color: #1b1308;
  box-shadow: 0 18px 36px rgba(243, 181, 92, 0.22);
}

.poly-button:hover,
.poly-button:focus-visible {
  border-color: rgba(243, 181, 92, 0.48);
  background: linear-gradient(135deg, var(--poly-accent), #f58e56);
  outline: none;
  transform: translateY(-1px);
}

.poly-button:disabled {
  cursor: progress;
  opacity: 0.9;
}

.poly-status {
  margin: 0;
  width: fit-content;
  max-width: 100%;
  min-height: 1.5rem;
  padding: 10px 14px;
  border: 1px solid var(--poly-border);
  border-radius: 16px;
  background: var(--poly-panel);
  color: var(--poly-muted);
  font-size: 0.95rem;
  line-height: 1.5;
  backdrop-filter: blur(18px);
  pointer-events: auto;
}

.poly-status.is-error {
  color: #ffb4b4;
}

.poly-status:empty {
  display: none;
}

.poly-scale {
  position: absolute;
  inset: 0 18px 0 auto;
  width: 92px;
}

.poly-scale-label {
  position: absolute;
  right: 0;
  color: rgba(239, 246, 251, 0.78);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.poly-scale-label-top {
  top: 28px;
}

.poly-scale-label-upper {
  top: 26%;
}

.poly-scale-label-lower {
  top: 57%;
}

.poly-scale-label-bottom {
  bottom: 26px;
}

@media (max-width: 900px) {
  .fiume-brand-link {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    gap: 10px;
    min-height: 40px;
    padding: 4px 12px 4px 4px;
    font-size: 0.7rem;
  }

  .fiume-brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .poly-mode-link {
    left: max(12px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
    min-height: 32px;
    padding: 0 11px;
    font-size: 0.72rem;
  }

  .poly-ui {
    padding: 0 12px;
  }

  .poly-button {
    min-height: 54px;
    padding: 0 26px;
  }

  .poly-scale {
    display: none;
  }
}
