/* ==========================================================================
   WaveCraft Studio — the prompt-to-console view
   Builds on the tokens in style.css; only Studio-specific layout lives here.
   ========================================================================== */

@layer components {
  .studio-main { max-width: 1280px; }
  /* The two views swap rather than stack, so the second one must not inherit
     the between-sections gap from a sibling that is hidden. */
  .studio-main > section + section { margin-top: 0; }

  /* ======================================================================
     Prompt view
     ====================================================================== */
  .compose-view {
    margin: clamp(2rem, 7vh, 4.5rem) auto 0;
    max-width: 780px;
    text-align: center;
  }
  .compose-view .eyebrow::before { display: none; }
  .compose-view h2 {
    font-size: clamp(2rem, 5.5vw, 3.1rem);
    letter-spacing: -0.035em;
    margin-bottom: 0.75rem;
  }
  .compose-view .lede { margin-inline: auto; }

  /* The prompt box is the product here, so it gets panel treatment: a raised
     card that focuses as one object rather than a textarea with a button. */
  .compose-form {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    margin: 1.75rem 0 0.5rem;
    padding: 0.6rem 0.6rem 0.6rem 0.3rem;
    border-radius: var(--r-lg);
    background: var(--surface);
    border: 1px solid var(--line-2);
    box-shadow: var(--shadow-2), var(--bevel);
    transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
  }
  .compose-form:focus-within {
    border-color: var(--accent);
    box-shadow: var(--shadow-2), 0 0 0 4px var(--accent-wash);
  }
  .compose-form textarea {
    flex: 1;
    resize: none;
    /* Grows with what you type instead of sitting at a guessed height */
    field-sizing: content;
    min-height: 3.4rem;
    max-height: 40vh;
    padding: 0.7rem 0.85rem;
    border: 0;
    background: none;
    box-shadow: none;
    text-align: left;
    font-size: 0.98rem;
    line-height: 1.5;
  }
  .compose-form textarea:focus-visible { outline: none; box-shadow: none; }
  .compose-form textarea::placeholder { color: var(--text-3); }
  .compose-form .btn-primary { padding: 0.6rem 1.15rem; }

  .starter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
    justify-content: center;
    margin-top: 1.1rem;
  }
  .starter-label {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-right: 0.25rem;
  }
  #template-chips { display: contents; }
  .studio-status {
    min-height: 1.4em;
    margin: 0.5rem 0;
    color: var(--text-2);
    font-size: 0.88rem;
  }
  .studio-status.error { color: var(--danger); }
  .studio-status.spin::before {
    content: "";
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    margin-right: 0.5em;
    border-radius: 50%;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    animation: studio-spin 0.7s linear infinite;
    vertical-align: -0.08em;
  }
  @keyframes studio-spin { to { rotate: 360deg; } }

  /* ======================================================================
     Toolbar
     ====================================================================== */
  .studio-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.9rem;
  }
  .studio-toolbar .studio-status { flex: 1; margin: 0; text-align: left; }
  .quality-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-2);
    font-size: 0.83rem;
    white-space: nowrap;
    user-select: none;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    background: var(--surface);
  }
  .export-group { display: flex; gap: 0.4rem; }
  .export-group .btn-secondary { padding: 0.42rem 0.85rem; font-size: 0.83rem; }

  /* ======================================================================
     The console
     ====================================================================== */
  .mixer {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-2), var(--bevel);
    overflow: hidden;
  }

  .mixer-transport {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
  }
  .mx-play, .mx-stop {
    width: 2.3rem;
    height: 2.3rem;
    padding: 0;
    border-radius: 50%;
    font-size: 0.85rem;
  }
  .mx-time {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    color: var(--text);
    min-width: 4.5rem;
    padding: 0.15rem 0.55rem;
    border-radius: var(--r-xs);
    background: var(--bg-sunk);
    border: 1px solid var(--line);
  }
  .mx-title { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
  .mx-meta { color: var(--text-3); font-size: 0.82rem; }
  .mx-loop {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-2);
    font-size: 0.82rem;
    user-select: none;
  }
  /* Transport reading order is transport → clock → what's loaded → options,
     but the markup puts Loop third. Reorder here rather than in the mixer,
     which has no business knowing about layout. */
  .mx-play { order: 1; }
  .mx-stop { order: 2; }
  .mx-time { order: 3; }
  .mx-title { order: 4; }
  .mx-meta { order: 5; }
  .mx-loop { order: 6; margin-left: auto; }

  /* Ruler: left pad matches .track-head width so sections align with lanes */
  .mixer-ruler { display: flex; border-bottom: 1px solid var(--line); background: var(--bg-sunk); }
  .ruler-pad { flex: 0 0 260px; border-right: 1px solid var(--line); }
  .ruler-lane { flex: 1; display: flex; min-width: 0; }
  .ruler-section {
    font-family: var(--font-mono);
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-3);
    padding: 0.3rem 0.5rem;
    border-right: 1px solid var(--line);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .ruler-tail { border-right: none; opacity: 0.45; }

  .mixer-track {
    display: flex;
    border-bottom: 1px solid var(--line);
    min-height: 84px;
    transition: background-color var(--dur-2) var(--ease-out);
  }
  .mixer-track:hover { background: var(--surface-2); }
  .mixer-track.is-muted .track-lane { opacity: 0.3; }
  .mixer-track.is-rendering .track-lane::after {
    content: "rendering…";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: light-dark(oklch(100% 0 0 / 0.6), oklch(15.5% 0.011 265 / 0.6));
    backdrop-filter: blur(2px);
    animation: studio-pulse 1.4s var(--ease-in-out) infinite;
  }
  @keyframes studio-pulse { 50% { opacity: 0.45; } }

  .track-head {
    flex: 0 0 260px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name btns" "preset btns" "fader fader" "pan pan";
    gap: 0.25rem 0.5rem;
    padding: 0.6rem 0.8rem;
    border-right: 1px solid var(--line);
    align-content: center;
  }
  .track-name {
    grid-area: name;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.92rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .track-preset { grid-area: preset; font-size: 0.75rem; max-width: 100%; }
  select.track-preset { padding: 0.18rem 0.35rem; border-radius: var(--r-xs); }
  .track-kit { color: var(--text-3); }
  .track-btns { grid-area: btns; display: flex; gap: 0.22rem; }
  .track-mute, .track-solo, .track-chat {
    width: 1.65rem;
    height: 1.65rem;
    display: grid;
    place-items: center;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-3);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 700;
    transition:
      background-color var(--dur-1) var(--ease-out),
      color var(--dur-1) var(--ease-out),
      border-color var(--dur-1) var(--ease-out),
      scale var(--dur-2) var(--ease-spring);
  }
  .track-mute:hover, .track-solo:hover, .track-chat:hover { color: var(--text); border-color: var(--line-2); }
  .track-mute:active, .track-solo:active, .track-chat:active { scale: 0.9; }
  .track-mute.on { background: var(--danger); color: var(--accent-ink); border-color: var(--danger); }
  .track-solo.on { background: var(--warn); color: light-dark(oklch(100% 0 0), oklch(20% 0.03 70)); border-color: var(--warn); }

  .track-fader-wrap { grid-area: fader; display: flex; align-items: center; gap: 0.5rem; }
  .track-fader { flex: 1; }
  .track-level-val {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.7rem;
    color: var(--text-3);
    min-width: 2.6rem;
    text-align: right;
  }
  .track-pan-wrap {
    grid-area: pan;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-3);
  }
  .track-pan { flex: 1; }
  /* Pan is bipolar, so its fill reads from the centre out rather than from
     the left — the track shows displacement, not amount. */
  .track-pan::-webkit-slider-runnable-track {
    background: linear-gradient(90deg, transparent 49.6%, var(--line-2) 49.6% 50.4%, transparent 50.4%), var(--bg-sunk);
  }
  .track-pan::-moz-range-track {
    background: linear-gradient(90deg, transparent 49.6%, var(--line-2) 49.6% 50.4%, transparent 50.4%), var(--bg-sunk);
  }

  .track-lane {
    flex: 1;
    position: relative;
    min-width: 0;
    cursor: text;
    background: var(--bg-sunk);
    background-image: repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent calc(12.5% - 1px),
      var(--line) calc(12.5% - 1px),
      var(--line) 12.5%);
  }
  .track-wave { position: absolute; inset: 0; width: 100%; height: 100%; }
  .track-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 1px;
    background: var(--accent-2);
    box-shadow: 0 0 8px oklch(from var(--accent-2) l c h / 0.8);
    pointer-events: none;
  }

  .mixer-master {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.9rem;
    background: var(--surface-2);
  }
  .mm-label {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.12em;
  }
  .mm-fader { flex: 0 1 320px; }

  /* ======================================================================
     Chats — the session chat and per-track pop-outs
     ====================================================================== */
  .song-chat { margin-top: 1rem; }

  .chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1), var(--bevel);
    overflow: hidden;
  }
  .chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.85rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
  }
  .chat-title {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-3);
  }
  .chat-close {
    display: grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--r-full);
    color: var(--text-3);
    cursor: pointer;
    font-size: 0.85rem;
    transition: color var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out);
  }
  .chat-close:hover { color: var(--danger); background: oklch(from var(--danger) l c h / 0.12); }

  .chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.8rem;
    overflow-y: auto;
    max-height: 13rem;
    min-height: 3.2rem;
    font-size: 0.87rem;
    overflow-anchor: none;
  }
  .chat-msg {
    padding: 0.45rem 0.7rem;
    border-radius: 14px;
    width: fit-content;
    max-width: 88%;
    white-space: pre-wrap;
    line-height: 1.45;
  }
  .chat-user {
    background: var(--accent);
    color: var(--accent-ink);
    align-self: flex-end;
    border-bottom-right-radius: 5px;
  }
  .chat-assistant {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-bottom-left-radius: 5px;
  }
  .chat-system { color: var(--text-3); font-size: 0.78rem; padding: 0.1rem 0.2rem; }
  .chat-error { color: var(--danger); font-size: 0.82rem; padding: 0.1rem 0.2rem; }
  .chat-pending::after { content: "…"; animation: studio-pulse 1s var(--ease-in-out) infinite; }
  @media (prefers-reduced-motion: no-preference) {
    .chat-msg { animation: chat-in 0.28s var(--ease-spring) both; }
  }
  @keyframes chat-in {
    from { opacity: 0; translate: 0 6px; scale: 0.97; }
    to   { opacity: 1; translate: 0 0; scale: 1; }
  }

  .chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 0.7rem;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
  }
  .chat-input {
    flex: 1;
    padding: 0.5rem 0.85rem;
    border-radius: var(--r-full);
    border: 1px solid var(--line-2);
    background: var(--bg-sunk);
    min-width: 0;
  }
  .chat-send { padding: 0.42rem 0.95rem; font-size: 0.85rem; }

  /* Pop-out dressing: floating cards above the page, draggable by the header */
  .chat-floating {
    position: fixed;
    right: 1rem;
    bottom: 5.5rem;
    width: min(24rem, calc(100vw - 2rem));
    z-index: 40;
    background: light-dark(oklch(100% 0 0 / 0.86), oklch(19.4% 0.013 265 / 0.86));
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: var(--shadow-3), var(--bevel);
  }
  @media (prefers-reduced-motion: no-preference) {
    .chat-floating { animation: popout-in 0.3s var(--ease-spring) both; }
  }
  @keyframes popout-in {
    from { opacity: 0; translate: 0 14px; scale: 0.96; }
    to   { opacity: 1; translate: 0 0; scale: 1; }
  }
  .chat-floating .chat-head { cursor: grab; user-select: none; touch-action: none; }
  .chat-floating .chat-head:active { cursor: grabbing; }
  .chat-floating .chat-messages { max-height: 11rem; }
  .chat-floating .chat-title { color: var(--accent); }

  .studio-hint { color: var(--text-3); font-size: 0.84rem; margin-top: 1rem; max-width: var(--measure); }

  /* ======================================================================
     Demo sessions — the product before the signup
     ====================================================================== */
  .demo-section { margin-top: clamp(2.5rem, 8vh, 4.5rem); }
  .demo-head { text-align: center; max-width: 640px; margin-inline: auto; }
  .demo-head h3 { font-size: clamp(1.3rem, 3vw, 1.75rem); letter-spacing: -0.02em; margin-bottom: 0.5rem; }
  .demo-head .lede { font-size: 0.92rem; }

  .demo-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 0.85rem;
    margin-top: 1.6rem;
  }
  .demo-card {
    display: grid;
    gap: 0.4rem;
    align-content: start;
    text-align: left;
    padding: 1.05rem 1.1rem 0.95rem;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-1), var(--bevel);
    cursor: pointer;
    --lift: 0;
    translate: 0 var(--lift);
    transition:
      translate var(--dur-2) var(--ease-spring),
      border-color var(--dur-2) var(--ease-out),
      box-shadow var(--dur-2) var(--ease-out);
  }
  .demo-card:hover:not(:disabled) { --lift: -3px; border-color: var(--accent); box-shadow: var(--shadow-2), var(--bevel); }
  .demo-card:active:not(:disabled) { --lift: 0; }
  .demo-card:disabled { opacity: 0.55; cursor: default; }
  .demo-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; letter-spacing: -0.015em; }
  .demo-blurb { color: var(--text-2); font-size: 0.86rem; line-height: 1.45; }
  .demo-prompt {
    color: var(--text-3);
    font-size: 0.79rem;
    line-height: 1.5;
    /* The prompt is provenance, not the pitch: three lines, then it stops. */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
  }
  .demo-meta {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-top: 0.15rem;
  }
  .demo-cta { color: var(--accent); font-size: 0.83rem; font-weight: 550; }
  .demo-card:hover .demo-cta .arrow { translate: 3px 0; }
  .demo-cta .arrow { display: inline-block; transition: translate var(--dur-2) var(--ease-spring); }

  .session-tag {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-wash);
    border-radius: var(--r-full);
    padding: 0.28rem 0.7rem;
    white-space: nowrap;
  }


  @media (max-width: 760px) {
    .compose-form { flex-direction: column; align-items: stretch; padding: 0.6rem; }
    .compose-form .btn-primary { width: 100%; }
    .track-head { flex-basis: 190px; }
    .ruler-pad { flex-basis: 190px; }
    .mx-meta { display: none; }
  }
}
