/* KAROL frame: layout only, components come from hexart.css */

@layer k {
  .k-body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--hx-bg);
    color: var(--hx-fg);
  }

  .k-top {
    display: flex;
    align-items: center;
    gap: var(--hx-space-3);
    padding: var(--hx-space-2) var(--hx-space-4);
    border-bottom: 1px solid var(--hx-line);
    min-height: 3.25rem;
  }
  .k-top__brand {
    display: flex;
    align-items: center;
    gap: var(--hx-space-2);
    margin-right: auto;
    min-width: 0;
  }
  .k-top__icon {
    width: 2rem;
    height: 2rem;
    flex: none;
  }
  .k-top__name {
    font-family: var(--hx-font-condensed);
    font-weight: 700;
    letter-spacing: 0.12em;
    font-size: 1.25rem;
  }
  .k-top__tagline {
    color: var(--hx-fg-muted);
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .k-app {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 22rem);
    gap: var(--hx-space-4);
    padding: var(--hx-space-4);
    min-height: 0;
  }

  .k-player {
    display: flex;
    flex-direction: column;
    gap: var(--hx-space-2);
    min-width: 0;
  }

  .k-screen {
    position: relative;
    width: min(100%, calc((100dvh - 12rem) * 4 / 3));
    margin-inline: auto;
    container-type: inline-size;
  }
  .k-screen:fullscreen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100vw;
    background: var(--hx-carbon);
  }
  .k-screen:fullscreen .k-stage-wrap {
    width: min(100vw, calc(100vh * 4 / 3));
    margin: auto;
  }
  .k-stage-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--hx-carbon);
    overflow: hidden;
  }
  .k-stage,
  .k-stage__svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
  }

  .k-sub {
    position: absolute;
    left: 50%;
    bottom: 4%;
    translate: -50% 0;
    max-width: 88%;
    margin: 0;
    padding: 0.2em 0.6em;
    background: var(--hx-scrim);
    color: var(--hx-white);
    font-size: clamp(0.8rem, 2.6cqi, 1.35rem);
    line-height: 1.3;
    text-align: center;
  }
  .k-sub[data-kind="monolog"] {
    font-style: italic;
    color: var(--hx-mist);
  }
  .k-sub[data-kind="trzecia"] {
    font-weight: 600;
    color: var(--hx-gold-light);
  }

  .k-loading {
    position: absolute;
    inset: auto 0 45% 0;
    margin: 0;
    text-align: center;
    font-family: var(--hx-font-condensed);
    letter-spacing: 0.1em;
    color: var(--hx-white);
  }

  .k-controls {
    display: flex;
    align-items: center;
    gap: var(--hx-space-2);
    width: min(100%, calc((100dvh - 12rem) * 4 / 3));
    margin-inline: auto;
  }
  .k-ctl {
    flex: none;
  }
  .k-ico {
    width: 1.25rem;
    height: 1.25rem;
  }
  .k-ctl[data-state="playing"] .k-ico--play,
  .k-ctl[data-state="paused"] .k-ico--pause,
  .k-ctl[data-state="on"] .k-ico--muted,
  .k-ctl[data-state="muted"] .k-ico--on {
    display: none;
  }
  .k-ctl--text[aria-pressed="false"] {
    color: var(--hx-fg-subtle);
    text-decoration: line-through;
  }
  .k-time {
    font-family: var(--hx-font-mono);
    font-size: 0.8125rem;
    color: var(--hx-fg-muted);
    white-space: nowrap;
  }

  .k-scrub {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 2.75rem;
    display: flex;
    align-items: center;
  }
  .k-scrub__range {
    width: 100%;
    accent-color: var(--hx-accent);
    margin: 0;
  }
  .k-scrub__marks {
    position: absolute;
    inset: 50% 0.5rem auto 0.5rem;
    height: 0;
    pointer-events: none;
  }
  .k-scrub__mark {
    position: absolute;
    left: calc(var(--at) * 100%);
    top: -0.55rem;
    width: 2px;
    height: 0.4rem;
    background: var(--hx-fg-subtle);
  }
  .k-scrub__mark--wall {
    background: var(--hx-signal);
    height: 0.55rem;
    top: -0.7rem;
  }
  /* Start of an episode on the broadcast timeline: taller, in gold. */
  .k-scrub__mark--odcinek {
    background: var(--hx-accent);
    height: 0.7rem;
    top: -0.85rem;
  }

  .k-chapter {
    width: min(100%, calc((100dvh - 12rem) * 4 / 3));
    margin: 0 auto;
    color: var(--hx-fg-muted);
  }

  /* NA ZYWO: a sharp diamond, Signal Red only while the picture is at the live edge. */
  .k-live {
    gap: 0.45em;
    white-space: nowrap;
  }

  .k-live__dot {
    width: 0.55em;
    height: 0.55em;
    background: var(--hx-fg-muted);
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  }

  .k-live[data-live="on"] .k-live__dot {
    background: var(--hx-signal-red);
  }

  /* Here and now: one line, never wraps the layout; the full text is in the tooltip. */
  .k-here {
    display: flex;
    gap: var(--hx-space-3, 0.75rem);
    align-items: baseline;
    width: min(100%, calc((100dvh - 12rem) * 4 / 3));
    margin: 0 auto;
    color: var(--hx-fg-muted);
    font-size: var(--hx-text-sm, 0.875rem);
    min-width: 0;
  }

  .k-here__text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .k-here__credit {
    flex: 0 0 auto;
    font-size: 0.75em;
    opacity: 0.7;
  }

  /* A hero drawn from a real persona says so at the foot of the page and on the way in. */
  .k-parody,
  .k-gate__parody {
    margin: 0;
    font-size: 0.75rem;
    color: var(--hx-fg-muted);
  }
  .k-parody {
    max-width: 80ch;
    margin: 0 auto;
    padding: var(--hx-space-3, 0.75rem) var(--hx-space-4, 1rem) var(--hx-space-5, 1.5rem);
    text-align: center;
  }
  .k-gate__parody {
    max-width: 60ch;
    margin-bottom: var(--hx-space-5);
  }

  .k-chat {
    display: flex;
    flex-direction: column;
    gap: var(--hx-space-2);
    background: var(--hx-surface);
    border: 1px solid var(--hx-line);
    padding: var(--hx-space-4);
    min-height: 0;
    max-height: calc(100dvh - 5rem);
  }
  .k-chat__title {
    margin: 0;
    font-family: var(--hx-font-condensed);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 1rem;
  }
  .k-chat__you {
    margin: 0;
    color: var(--hx-fg-muted);
    font-size: 0.875rem;
    overflow-wrap: anywhere;
  }
  .k-chat__log {
    flex: 1;
    overflow-y: auto;
    min-height: 3rem;
  }
  .k-chat__msg {
    margin: 0 0 var(--hx-space-1);
    font-size: 0.9375rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  .k-chat__msg b {
    color: var(--hx-gold);
    font-weight: 600;
  }
  .k-chat__err {
    margin: 0;
    color: var(--hx-signal-red);
    font-size: 0.8125rem;
  }
  .k-chat__form {
    display: flex;
    gap: var(--hx-space-2);
  }
  .k-chat__form .hx-input {
    flex: 1;
    min-width: 0;
  }

  /* Gate: fits any screen, scrolls inside, actions always reachable */
  .k-gate {
    margin: auto;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--hx-fg);
    width: min(40rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    overflow: visible;
  }
  .k-gate::backdrop {
    background: var(--hx-scrim);
  }
  .k-gate__box {
    background: var(--hx-surface);
    border: 1px solid var(--hx-line-strong);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding: var(--hx-space-6);
  }
  .k-gate__art {
    display: block;
    width: 100%;
    height: auto;
    margin-bottom: var(--hx-space-4);
  }
  .k-gate__title {
    margin: 0 0 var(--hx-space-3);
    font-size: var(--hx-text-h3, 1.5rem);
  }
  #k-gate-warn .k-gate__title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .k-gate__lead {
    margin: 0 0 var(--hx-space-3);
    font-size: 1.0625rem;
  }
  .k-gate__rules {
    margin: 0 0 var(--hx-space-5);
    padding-left: 1.1rem;
    color: var(--hx-fg-muted);
    display: grid;
    gap: var(--hx-space-2);
  }
  .k-gate__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--hx-space-3);
    position: sticky;
    bottom: calc(-1 * var(--hx-space-6));
    padding-block: var(--hx-space-3);
    background: var(--hx-surface);
  }
  .k-gate__form .hx-field {
    margin-bottom: var(--hx-space-2);
  }

  /* Phone, portrait: the 4:3 frame stays on top, untouched; chat fills the rest.
     interactive-widget=resizes-content shrinks the layout viewport when the keyboard opens,
     so the frame keeps its place and only the chat log gets shorter. */
  @media (max-width: 52rem) {
    .k-top__tagline {
      display: none;
    }
    .k-app {
      grid-template-columns: 1fr;
      grid-template-rows: auto minmax(0, 1fr);
      padding: 0;
      gap: 0;
      height: calc(100dvh - 3.25rem);
    }
    .k-player {
      position: sticky;
      top: 0;
      z-index: 2;
      background: var(--hx-bg);
      gap: 0;
    }
    .k-screen,
    .k-controls,
    .k-chapter,
    .k-here {
      width: 100%;
    }
    .k-here {
      flex-wrap: wrap;
    }
    .k-here__credit {
      flex-basis: 100%;
    }
    /* The frame stays clean on a phone: subtitles move under it, in a fixed two-line slot. */
    .k-sub {
      position: static;
      translate: none;
      max-width: none;
      min-height: 2.7em;
      padding: var(--hx-space-1) var(--hx-space-3);
      background: transparent;
      font-size: 0.875rem;
    }
    .k-sub[hidden] {
      display: block;
      visibility: hidden;
    }
    .k-controls {
      padding-inline: var(--hx-space-2);
      flex-wrap: wrap;
      row-gap: 0;
    }
    .k-scrub {
      order: -1;
      flex-basis: 100%;
      height: 1.75rem;
    }
    .k-time {
      margin-right: auto;
    }
    .k-chapter {
      padding: 0 var(--hx-space-3) var(--hx-space-2);
      font-size: 0.75rem;
    }
    .k-chat {
      border: 0;
      border-top: 1px solid var(--hx-line);
      max-height: none;
      padding: var(--hx-space-3);
    }
    .k-gate__box {
      padding: var(--hx-space-4);
    }
    .k-gate__actions {
      bottom: calc(-1 * var(--hx-space-4));
    }
    .k-gate__actions .hx-btn {
      width: 100%;
    }
  }

  /* Phone, landscape: frame takes the full height, chat goes to the side */
  @media (max-height: 30rem) and (orientation: landscape) {
    .k-top {
      display: none;
    }
    .k-app {
      grid-template-columns: auto minmax(14rem, 1fr);
      height: 100dvh;
      padding: 0;
    }
    .k-screen,
    .k-controls,
    .k-chapter {
      width: calc((100dvh - 3rem) * 4 / 3);
    }
    .k-chapter {
      display: none;
    }
  }
}
