/* ============================================================
   v6 Composition Visualizer
   ============================================================
   Compact, captivating modal shown during AI song generation.
   Replaces the dim inline indicators that had unreadable text.
   See src/ui/CompositionVisualizer.js for behavior.
*/

@layer v6-components {

  .v6-comp-viz {
    position: fixed;
    inset: 0;
    z-index: 10010; /* above modals + tooltips */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--ease-out-quart, ease-out);
  }
  .v6-comp-viz--visible {
    opacity: 1;
    pointer-events: auto;
  }

  .v6-comp-viz__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  /* ============================================================
     Card with animated rainbow border
     ============================================================ */
  .v6-comp-viz__card {
    position: relative;
    width: 400px;
    max-width: calc(100vw - 32px);
    padding: 22px 24px 20px;
    background: linear-gradient(180deg,
      rgba(20, 20, 22, 0.96) 0%,
      rgba(12, 12, 14, 0.96) 100%);
    border-radius: 16px;
    box-shadow:
      0 32px 80px rgba(0, 0, 0, 0.7),
      0 0 60px rgba(139, 92, 246, 0.25);
    transform: scale(0.96);
    transition: transform 220ms var(--ease-out-quart, ease-out);
  }
  .v6-comp-viz--visible .v6-comp-viz__card {
    transform: scale(1);
  }

  /* Slow-rotating conic gradient acts as a glowing border ring */
  .v6-comp-viz__border {
    position: absolute;
    inset: -2px;
    border-radius: 18px;
    background: conic-gradient(
      from 0deg,
      #8b5cf6 0%,
      #ec4899 20%,
      #f59e0b 40%,
      #34d399 60%,
      #06b6d4 80%,
      #8b5cf6 100%
    );
    z-index: -1;
    animation: v6-comp-border-spin 5s linear infinite;
    filter: blur(6px);
    opacity: 0.45;
  }
  @keyframes v6-comp-border-spin {
    to { transform: rotate(360deg); }
  }

  /* ============================================================
     Header
     ============================================================ */
  .v6-comp-viz__head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
  }

  .v6-comp-viz__spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: conic-gradient(
      from 0deg,
      rgba(139, 92, 246, 0.0) 0deg,
      rgba(167, 139, 250, 1.0) 280deg,
      rgba(139, 92, 246, 0.0) 360deg
    );
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    animation: v6-comp-spin 0.9s linear infinite;
    flex-shrink: 0;
    filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.6));
  }
  @keyframes v6-comp-spin { to { transform: rotate(360deg); } }

  .v6-comp-viz__title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  .v6-comp-viz__title {
    font-family: var(--font-sans, system-ui);
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
    letter-spacing: -0.005em;
  }
  .v6-comp-viz__subtitle {
    font-family: var(--font-sans, system-ui);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.65);
    font-weight: 500;
    line-height: 1.3;
  }

  /* ============================================================
     Live mini step-sequencer (5 rows × 16 cols)
     ============================================================ */
  .v6-comp-viz__grid {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    margin-bottom: 14px;
  }

  .v6-comp-viz__row {
    display: grid;
    grid-template-columns: 14px 1fr;
    align-items: center;
    gap: 8px;
    min-height: 12px;
  }
  .v6-comp-viz__row-label {
    font-family: var(--font-mono, monospace);
    font-size: 9px;
    font-weight: 700;
    text-align: center;
    line-height: 1;
    opacity: 0.8;
  }
  .v6-comp-viz__row-cells {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 2px;
    height: 12px;
  }
  .v6-comp-viz__cell {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 1.5px;
    /* Bar-group hint (subtle every 4) */
  }
  .v6-comp-viz__row-cells > .v6-comp-viz__cell:nth-child(4n) {
    background: rgba(255, 255, 255, 0.06);
  }

  /* A cell that has been "composed" */
  .v6-comp-viz__cell--active {
    background: var(--cell-color, #8b5cf6);
    box-shadow: 0 0 6px var(--cell-color, #8b5cf6);
    animation: v6-comp-cell-pop 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  @keyframes v6-comp-cell-pop {
    0%   { transform: scale(0); opacity: 0; }
    55%  { transform: scale(1.7); opacity: 1; box-shadow: 0 0 16px var(--cell-color, #8b5cf6); }
    100% { transform: scale(1); opacity: 1; }
  }

  /* Brief re-pulse for "polishing" */
  .v6-comp-viz__cell--pulse {
    animation: v6-comp-cell-repulse 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  @keyframes v6-comp-cell-repulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 6px var(--cell-color, #8b5cf6); }
    50%      { transform: scale(1.45); box-shadow: 0 0 18px var(--cell-color, #8b5cf6); }
  }

  /* ============================================================
     Phase text
     ============================================================ */
  .v6-comp-viz__phase {
    font-family: var(--font-sans, system-ui);
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.90);
    text-align: center;
    min-height: 18px;
    line-height: 1.4;
    letter-spacing: 0.005em;
    transition: opacity 140ms;
    text-shadow: 0 0 12px rgba(139, 92, 246, 0.35);
  }

  /* ============================================================
     Section badges (multi-pattern mode)
     ============================================================ */
  .v6-comp-viz__sections {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 12px;
    flex-wrap: wrap;
  }
  .v6-comp-viz__section-badge {
    display: inline-block;
    padding: 3px 9px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    font-family: var(--font-mono, monospace);
    font-size: 9px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.45);
    text-transform: uppercase;
    letter-spacing: 0.10em;
    line-height: 1.2;
    transition:
      background 320ms var(--ease-out-quart, ease-out),
      color 320ms var(--ease-out-quart, ease-out),
      border-color 320ms var(--ease-out-quart, ease-out),
      transform 320ms var(--ease-out-quart, ease-out),
      box-shadow 320ms var(--ease-out-quart, ease-out);
  }
  .v6-comp-viz__section-badge--active {
    background: rgba(139, 92, 246, 0.30);
    border-color: var(--accent-primary, #8b5cf6);
    color: #ffffff;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.50);
    transform: translateY(-1px);
  }
  .v6-comp-viz__section-badge--complete {
    background: rgba(34, 197, 94, 0.25);
    border-color: var(--accent-success, #22c55e);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.50);
  }

  /* ============================================================
     Complete state
     ============================================================ */
  .v6-comp-viz--complete .v6-comp-viz__spinner {
    background: var(--accent-success, #22c55e);
    animation: none;
    filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.7));
  }
  .v6-comp-viz--complete .v6-comp-viz__spinner::before {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #000;
    font-weight: 900;
    font-size: 16px;
    line-height: 1;
  }
  .v6-comp-viz--complete .v6-comp-viz__border {
    background: var(--accent-success, #22c55e);
    animation: none;
    opacity: 0.55;
    filter: blur(4px);
  }
  .v6-comp-viz--complete .v6-comp-viz__phase {
    color: var(--accent-success, #22c55e);
    text-shadow: 0 0 14px rgba(34, 197, 94, 0.55);
    font-weight: 700;
  }

  /* ============================================================
     Error state
     ============================================================ */
  .v6-comp-viz--error .v6-comp-viz__spinner {
    background: var(--accent-danger, #ef4444);
    animation: none;
    filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.7));
  }
  .v6-comp-viz--error .v6-comp-viz__spinner::before {
    content: '!';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #000;
    font-weight: 900;
    font-size: 18px;
    line-height: 1;
  }
  .v6-comp-viz--error .v6-comp-viz__border {
    background: var(--accent-danger, #ef4444);
    animation: none;
    opacity: 0.55;
  }
  .v6-comp-viz--error .v6-comp-viz__phase {
    color: var(--accent-danger, #ef4444);
    text-shadow: 0 0 14px rgba(239, 68, 68, 0.55);
    font-weight: 600;
  }

  /* ============================================================
     Reduced motion — keep the card but skip all animations
     ============================================================ */
  @media (prefers-reduced-motion: reduce) {
    .v6-comp-viz__border,
    .v6-comp-viz__spinner,
    .v6-comp-viz__cell--active,
    .v6-comp-viz__cell--pulse,
    .v6-comp-viz__section-badge {
      animation: none !important;
      transition: none !important;
    }
  }
  body.v6-reduced-motion .v6-comp-viz__border,
  body.v6-reduced-motion .v6-comp-viz__spinner,
  body.v6-reduced-motion .v6-comp-viz__cell--active,
  body.v6-reduced-motion .v6-comp-viz__cell--pulse,
  body.v6-reduced-motion .v6-comp-viz__section-badge {
    animation: none !important;
    transition: none !important;
  }
}

  /* ============================================================
     Persistent error card (replaces the in-flight viz on failure)
     White-on-dark monospace for the message so technical errors
     (JSON parse, etc.) are actually readable. No auto-dismiss —
     the user reads, then clicks Dismiss.
     ============================================================ */
  .v6-comp-viz--error .v6-comp-viz__error-body {
    padding: 14px 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 11px;
  }
  .v6-comp-viz--error .v6-comp-viz__error-title {
    align-self: flex-start;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #fff;
    background: rgba(239, 68, 68, 0.85);
    padding: 4px 10px;
    border-radius: 4px;
    text-transform: uppercase;
  }
  .v6-comp-viz--error .v6-comp-viz__error-message {
    font-size: 13.5px;
    line-height: 1.55;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    padding: 11px 13px;
    border-left: 3px solid #ef4444;
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    word-break: break-word;
    max-height: 220px;
    overflow-y: auto;
    user-select: text;
    -webkit-user-select: text;
  }
  .v6-comp-viz--error .v6-comp-viz__error-help {
    font-size: 12px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.72);
  }
  .v6-comp-viz--error .v6-comp-viz__error-dismiss {
    align-self: flex-start;
    padding: 7px 16px;
    background: rgba(239, 68, 68, 0.22);
    color: #fff;
    border: 1px solid rgba(239, 68, 68, 0.65);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.12s, transform 0.12s;
  }
  .v6-comp-viz--error .v6-comp-viz__error-dismiss:hover {
    background: rgba(239, 68, 68, 0.38);
  }
  .v6-comp-viz--error .v6-comp-viz__error-dismiss:active {
    transform: translateY(1px);
  }
