/*
 * Cue surface styles (TASK-54.16 projection + TASK-54.6 HUD).
 *
 * Shared verbatim by the app and by the Reaper web-remote cue page, so the live
 * surface is identical in both places. PicoCSS variables are given fallbacks so
 * the Reaper page (which does not load Pico) renders the same true-black stage.
 */

/* Cue timeline projection (TASK-54.16) — base semantic list; the HUD (54.6)
   layers the true-black stage presentation over this. */
.cue-projection {
  margin-top: var(--pico-spacing, 1rem);

  ri-song {
    display: block;
  }

  ri-event {
    display: block;
    position: relative;
    padding: 0.35rem 0 0.35rem 5.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color, #444);
    font-weight: 600;

    /* The HUD stamps data-time (mm:ss) and data-duration (bars); these plain
       tags cannot format their own attributes, so the values arrive ready. */
    &::before {
      content: attr(data-time);
      position: absolute;
      left: 0;
      top: 0.4rem;
      color: var(--pico-muted-color, #888);
      font-size: 0.85rem;
      font-weight: 400;
      font-variant-numeric: tabular-nums;
    }

    &::after {
      content: attr(data-duration);
      position: absolute;
      left: 0;
      top: 1.45rem;
      color: var(--pico-muted-color, #888);
      font-size: 0.7rem;
      font-weight: 400;
      font-variant-numeric: tabular-nums;
    }
  }

  ri-detail {
    display: block;
    margin-top: 0.15rem;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--pico-muted-color, #888);

    &[role="chords"] {
      letter-spacing: 0.02em;
      font-variant-numeric: tabular-nums;
    }
  }

  ri-tempo {
    display: block;
    padding: 0.3rem 0;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--pico-muted-color, #888);

    &::before {
      content: "♩ = " attr(bpm) " · " attr(signature);
    }
  }
}

/* Dev-only cue projection preview (TASK-54.6 support, throwaway). */
.cue-preview {
  .cue-preview-note {
    color: var(--pico-muted-color, #888);
  }

  .cue-preview-stage {
    background: #000;
    color: #fff;
    padding: 1rem 1.25rem;
    margin-top: var(--pico-spacing, 1rem);
    border-radius: var(--pico-border-radius, 0.25rem);
    overflow: hidden;

    .cue-projection {
      margin: 0;
    }

    ri-event {
      display: block;
      position: relative;
      padding: 0.75rem 0.75rem 0.75rem 5.5rem;
      border-left: 4px solid transparent;
      border-bottom: 1px solid #1f1f1f;
      transition: background-color 120ms linear, border-color 120ms linear;

      &::before {
        content: attr(data-time);
        position: absolute;
        left: 0.75rem;
        top: 0.7rem;
        color: #777;
        font-size: 0.85rem;
        font-variant-numeric: tabular-nums;
      }

      &::after {
        content: attr(data-duration);
        position: absolute;
        left: 0.75rem;
        top: 1.6rem;
        color: #555;
        font-size: 0.7rem;
        font-variant-numeric: tabular-nums;
      }

      &[active] {
        background: #0e0e0e;
        border-left-color: var(--role-color, #00ff97);
      }

      &[next] {
        border-left-color: var(--role-color, #00fbff);
      }

      &[countdown] {
        border-left-color: #ffb300;
      }

      &[active] > * {
        font-size: 1.05rem;
      }
    }

    ri-event[role="instrumental"] { --role-color: #00ff97; }
    ri-event[role="section-a"] { --role-color: #00fbff; }
    ri-event[role="section-b"] { --role-color: #b18cff; }
    ri-event[role="section-c"] { --role-color: #ff7ac6; }
    ri-event[role="break"] { --role-color: #ffb300; }
    ri-event[role="ending"] { --role-color: #ff5c5c; }

    ri-detail {
      color: #b8b8b8;

      &[role="chords"] {
        color: #ffffff;
      }
    }

    ri-tempo {
      color: #777;
    }
  }

  .cue-preview-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: var(--pico-spacing, 1rem);

    input[type="range"] {
      flex: 1;
      margin: 0;
    }
  }

  .cue-preview-state {
    color: var(--pico-muted-color, #888);
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
  }

  .cue-preview-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
    padding: 0;
    margin-top: var(--pico-spacing, 1rem);

    li {
      margin: 0;
    }
  }

  .cue-preview-swatch {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-left: 4px solid var(--role-color, #00ff97);
    background: #000;
    color: #fff;
    font-size: 0.8rem;
  }
}

.cue-preview-role-instrumental { --role-color: #00ff97; }
.cue-preview-role-section-a { --role-color: #00fbff; }
.cue-preview-role-section-b { --role-color: #b18cff; }
.cue-preview-role-section-c { --role-color: #ff7ac6; }
.cue-preview-role-break { --role-color: #ffb300; }
.cue-preview-role-ending { --role-color: #ff5c5c; }

/* Cue heads-up display (TASK-54.6). Light-DOM <ri-cue-hud> wraps the
   server-rendered projection and adds a Stage button + wake-lock toggle. The
   projection keeps its base list styles above; active/next are emphasised here.
   The stage is a true-black (#000) full-screen-capable surface for phones on
   mic stands. */
ri-cue-hud {
  display: block;

  .ri-cue-hud-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: var(--pico-spacing, 1rem);

    button {
      width: auto;
      margin: 0;
      padding: 0.4rem 0.9rem;
      font-size: 0.85rem;
      background: transparent;
      border: 1px solid var(--pico-primary, #00fbff);
      color: var(--pico-primary, #00fbff);
      border-radius: var(--pico-border-radius, 0.25rem);
      cursor: pointer;
    }

    button[aria-pressed="true"] {
      background: var(--pico-primary, #00fbff);
      color: var(--pico-primary-inverse, #000);
    }

    button:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }

  .cue-projection {
    ri-event[active] {
      border-left: 4px solid var(--role-color, #00ff97);
      background: color-mix(in srgb, var(--role-color, #00ff97) 8%, transparent);
    }

    ri-event[next] {
      border-left: 4px solid var(--role-color, #00fbff);
    }

    ri-event[countdown] {
      border-left-color: #ffb300;
    }
  }

  .ri-cue-hud-stage {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    background: #000;
    color: #fff;
    padding: clamp(1rem, 4vw, 3rem);
    overflow: hidden;
    box-sizing: border-box;
  }

  .ri-cue-hud-stage[hidden] {
    display: none;
  }

  /* Role tints the stage through --role-color; it is a modifier, never the
     trigger for the armed state (see data-stage below). */
  .ri-cue-hud-stage[data-role="instrumental"] { --role-color: #00ff97; }
  .ri-cue-hud-stage[data-role="section-a"] { --role-color: #00fbff; }
  .ri-cue-hud-stage[data-role="section-b"] { --role-color: #b18cff; }
  .ri-cue-hud-stage[data-role="section-c"] { --role-color: #ff7ac6; }
  .ri-cue-hud-stage[data-role="break"] { --role-color: #ffb300; }
  .ri-cue-hud-stage[data-role="ending"] { --role-color: #ff5c5c; }

  /* Armed (precount): a role-coloured inset frame marks the count-forward
     stage, the hero is the upcoming cue and the next ribbon is redundant. */
  .ri-cue-hud-stage[data-stage="armed"] {
    box-shadow: inset 0 0 0 clamp(3px, 1vw, 10px) color-mix(in srgb, var(--role-color, #ffb300) 75%, transparent);
  }

  .ri-cue-hud-stage[data-stage="armed"] .ri-cue-hud-next {
    display: none;
  }

  .ri-cue-hud-close {
    position: absolute;
    top: clamp(0.75rem, 2vw, 1.5rem);
    right: clamp(0.75rem, 2vw, 1.5rem);
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    margin: 0;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #fff;
    border-radius: 999px;
    font-size: 1.1rem;
    cursor: pointer;
  }

  .ri-cue-hud-stage-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: clamp(0.5rem, 2vh, 1.5rem);
    min-height: 0;
    overflow: hidden;
  }

  .ri-cue-hud-context {
    font-size: clamp(0.9rem, 3vw, 1.8rem);
    line-height: 1.2;
    font-weight: 600;
    color: #8a8a8a;
    overflow-wrap: anywhere;
  }

  .ri-cue-hud-context[hidden] {
    display: none;
  }

  .ri-cue-hud-label {
    font-size: clamp(2.5rem, 11vw, 9rem);
    line-height: 1.02;
    font-weight: 800;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-wrap: balance;
  }

  .ri-cue-hud-chords {
    font-size: clamp(1.4rem, 5.5vw, 3.5rem);
    line-height: 1.15;
    font-weight: 600;
    color: #00fbff;
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
  }

  .ri-cue-hud-footer {
    display: flex;
    flex-direction: column;
    gap: clamp(0.5rem, 1.5vh, 1rem);
  }

  .ri-cue-hud-next {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  .ri-cue-hud-next-label {
    font-size: clamp(0.85rem, 2.4vw, 1.4rem);
    color: #b8b8b8;
    overflow-wrap: anywhere;
  }

  .ri-cue-hud-progress {
    height: 0.4rem;
    background: #222;
    border-radius: 999px;
    overflow: hidden;

    .ri-cue-hud-progress-fill {
      display: block;
      height: 100%;
      width: 0;
      background: #00fbff;
      transition: width 120ms linear;
    }
  }

  .ri-cue-hud-countin {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .ri-cue-hud-countin[hidden] {
    display: none;
  }

  .ri-cue-hud-countin-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
  }

  .ri-cue-hud-countin-label {
    font-size: clamp(0.75rem, 2vw, 1.1rem);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--role-color, #ffb300);
  }

  .ri-cue-hud-countin-beat {
    font-size: clamp(0.85rem, 2.2vw, 1.3rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #fff;
  }

  .ri-cue-hud-countin-bar {
    display: flex;
    width: 100%;
    gap: clamp(4px, 1vw, 12px);
    box-sizing: border-box;
  }

  .ri-cue-hud-countin-gap {
    flex: 1 1 0;
    height: clamp(0.6rem, 2.5vw, 1.2rem);
    border-radius: 999px;
    background: #222;
    transition: background-color 90ms linear, transform 90ms linear;
  }

  .ri-cue-hud-countin-gap.on {
    background: color-mix(in srgb, var(--role-color, #ffb300) 50%, #000);
  }

  .ri-cue-hud-countin-gap.current {
    background: var(--role-color, #ffb300);
    transform: scaleY(1.25);
  }
}
