/* =========================================
   字幕アトリエ — OBS tab

   js/ui-obs.js: route picker, each route's settings and its help popover.
   The OBS window (obs-settings.html) loads this file too, for the connection
   status and the help popover; its own layout is css/obs-settings.css.

   Split out of styles.css. Everything stays inside @layer components:
   styles.css declares the layer order and must load first, and a rule
   left outside a layer would outrank every layered rule in the app.
   ========================================= */

@layer components {
  /* --- OBS tab: one column. Head (picker, ?, action), one sentence, then
         the selected route's settings. --- */
  .obs-section {
    display: grid;
    gap: var(--space-2);
    align-content: start;

    .form-row-label {
      color: var(--color-text-dim);
      font-size: var(--text-md);
      white-space: nowrap;
    }
  }

  .obs-body {
    display: grid;
    gap: var(--space-2);
  }

  /* Window / capture: label, the one value, and the caveat that matters most,
     on a single line. */
  .obs-setting-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: var(--space-3);
    row-gap: var(--space-1);
  }

  .obs-inline-hint {
    margin: 0;
    color: var(--color-text-dim);
    font-size: var(--text-sm);
    line-height: 1.4;
  }

  /* --- live connection status (js/ui-obs-status.js) --- */
  /* Status line + hint share one box, ~3 lines tall at least, so the usual
     one-line status and one-line hint appear and go without moving the rest
     of the tab. Longer text grows it instead of scrolling inside: Japanese
     wraps both to two lines on a failed connection, and a fixed box then cut
     them off behind a scrollbar of its own. The tab has the room, and the
     tab panel still scrolls as a whole if a window ever runs short. */
  .obs-conn {
    margin-top: var(--space-1);
    min-height: calc(var(--text-sm) * 1.3 * 3);
  }

  .obs-conn-status {
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 1.2em;
    color: var(--color-text-dim);
    font-size: var(--text-sm);
    line-height: 1.3;
  }

  .obs-conn-dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-faint);
  }

  .obs-conn-status[data-phase="connecting"] .obs-conn-dot {
    background: var(--color-warning);
    animation: dot-pulse 1.2s ease-in-out infinite;
  }
  .obs-conn-status[data-phase="connected"]  .obs-conn-dot {
    background: var(--color-success);
    box-shadow: 0 0 6px color-mix(in oklab, var(--color-success) 60%, transparent);
  }
  .obs-conn-status[data-phase="retrying"]   .obs-conn-dot { background: var(--color-danger); }

  .obs-conn-status[data-phase="connected"] { color: var(--color-text); }
  .obs-conn-status[data-phase="retrying"]  { color: var(--color-danger-text); }

  .obs-conn-hint {
    margin: var(--space-1) 0 0;
    color: var(--color-text-dim);
    font-size: var(--text-xs);
    line-height: 1.4;
  }

  /* Sequential instructions get sequential numbers: small numbered chips
     instead of bullets, so the order reads at a glance. */
  .help-steps {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    color: var(--color-text-dim);
    font-size: var(--text-sm);
    line-height: 1.45;
    counter-reset: help-step;

    li {
      counter-increment: help-step;
      display: grid;
      grid-template-columns: 16px 1fr;
      gap: var(--space-2);

      &::before {
        content: counter(help-step);
        display: inline-grid;
        place-items: center;
        width: 16px;
        height: 16px;
        margin-top: 1px;
        border-radius: var(--radius-full);
        background: var(--fill-1);
        color: var(--color-text-dim);
        font-size: 10px;
        font-weight: 600;
        line-height: 1;
      }
    }
  }

  /* The OBS tab stacks its two mutually exclusive bodies as siblings and hides
     one, but the adjacent selector above matches on the DOM rather than on what
     is rendered — so the visible body would draw a divider with nothing above
     it. Same trap as .panel-col[hidden] + .panel-col. */
  .panel-cols[hidden] + .panel-cols {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  /* The subtitle window's fixed key colour (OBS tab, obs.mode.window): shown,
     not picked, so it is a swatch and the hex to type into OBS. */
  .key-color {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;

    .key-color-swatch {
      width: 18px;
      height: 18px;
      border-radius: var(--radius-sm);
      background: #00FF00;
      box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
    }
    code {
      font-family: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
      font-size: var(--text-md);
      user-select: all;
    }
  }

  /* Caveats rather than a sequence: same typography as .help-steps so the two
     read as one voice, but a dot instead of a number — these are things to know,
     not things to do in order. */
  .help-notes {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    color: var(--color-text-dim);
    font-size: var(--text-sm);
    line-height: 1.45;
    list-style: none;

    li {
      display: grid;
      grid-template-columns: 16px 1fr;
      gap: var(--space-2);

      &::before {
        content: "";
        justify-self: center;
        width: 4px;
        height: 4px;
        margin-top: 0.55em;
        border-radius: var(--radius-full);
        background: var(--color-text-dim);
      }
    }
  }

  /* Route picker for the OBS tab: the switch, the help button beside it, and
     the route's one action pinned to the far end so it never moves when the
     route changes. Kept slim — the tab body below is height-constrained. */
  .obs-mode-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);

    > .seg-switch { flex-shrink: 0; }
  }

  .obs-help-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: 600;
    anchor-name: --obs-help-anchor;
  }

  .obs-action {
    margin-left: auto;
    flex-shrink: 0;
  }

  .obs-help-popover {
    position-anchor: --obs-help-anchor;
    position-area: bottom span-right;
    position-try-fallbacks: flip-block;
    margin: var(--space-2) 0;
    max-width: min(420px, 80vw);

    .help-notes {
      margin-top: var(--space-3);
      padding-top: var(--space-3);
      border-top: 1px solid var(--color-border);
    }
  }

  .obs-mode-desc {
    margin: 0 0 var(--space-1);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid color-mix(in oklab, var(--color-border) 60%, transparent);
    color: var(--color-text-dim);
    font-size: var(--text-sm);
    line-height: 1.4;
  }
}
