/* The builder (dashboard/builders/show, docs/BUILDER.md): the draft's blocks and the block
   library, the settings of what is chosen, and the phone. The editor is a Turbo Frame laid out
   with `display: contents`, so its panes and the phone, which is outside it, share one grid.
   Three columns from 80rem; under that the phone stays beside the editor, and under 52rem
   everything is one column with the phone last. */
@layer tokens, base, layout, components, screens;

@layer screens {
  /* The builder needs the whole width the shell's main column can give. */
  .shell__main:has(.builder) {
    max-width: none;
  }

  .builder > * + * {
    margin-block-start: var(--space-4);
  }

  .builder__panes {
    display: grid;
    grid-template-columns: minmax(13rem, 16rem) minmax(18rem, 1fr) 21rem;
    grid-template-areas:
      "toolbar toolbar toolbar"
      "library settings phone";
    align-items: start;
    gap: var(--space-4);
  }

  .builder__frame {
    display: contents;
  }

  .builder__toolbar {
    grid-area: toolbar;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-5);
    padding: var(--space-3) var(--space-4);
  }

  .builder__toolbar p + p {
    margin-block-start: 0;
  }

  .builder__library {
    grid-area: library;
    padding: var(--space-4);
  }

  .builder__settings {
    grid-area: settings;
    min-width: 0;
  }

  .builder__phone {
    grid-area: phone;
    position: sticky;
    inset-block-start: var(--space-4);
    display: grid;
    gap: var(--space-3);
  }

  .builder__phone > * {
    margin: 0;
  }

  @media (max-width: 80rem) {
    .builder__panes {
      grid-template-columns: minmax(0, 1fr) 21rem;
      grid-template-areas:
        "toolbar toolbar"
        "library phone"
        "settings phone";
    }
  }

  @media (max-width: 52rem) {
    .builder__panes {
      grid-template-columns: minmax(0, 1fr);
      grid-template-areas: "toolbar" "library" "settings" "phone";
    }

    .builder__phone {
      position: static;
    }
  }

  /* While the editor is being fetched it is dimmed and says it is busy (Turbo's [busy]). */
  turbo-frame[busy] :is(.builder__library, .builder__settings, .builder__toolbar) {
    opacity: 0.6;
    cursor: progress;
  }

  /* An entry of the lists: a block, the theme, a type of the library. */
  .builder-entries,
  .builder-blocks,
  .builder-library {
    display: grid;
    gap: var(--space-1);
    margin-block-start: var(--space-2);
    padding: 0;
    list-style: none;
  }

  .builder-entry {
    display: grid;
    gap: 0.125rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
    overflow-wrap: anywhere;
  }

  a.builder-entry:hover {
    background: var(--sunken);
    color: var(--ink);
  }

  .builder-entry[aria-current="true"] {
    background: var(--accent-soft);
    color: var(--accent-strong);
    box-shadow: inset 0.1875rem 0 0 var(--accent);
  }

  .builder-library small {
    font-weight: 400;
  }

  /* A block of the draft: a handle to drag it by, its name and what it is, and its moves. */
  .builder-block {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-1);
    padding-inline-start: var(--space-1);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .builder-block[draggable="true"] {
    cursor: grab;
  }

  .builder-block--dragging {
    border-style: dashed;
    border-color: var(--accent);
    opacity: 0.7;
  }

  .builder-block--withdrawn .builder-entry {
    color: var(--ink-soft);
  }

  .builder-block__handle {
    width: 0.625rem;
    height: 1.25rem;
    background-image: radial-gradient(var(--line-strong) 1.5px, transparent 1.5px);
    background-size: 0.3125rem 0.3125rem;
  }

  .builder-block__body {
    display: grid;
    min-width: 0;
    padding-block: var(--space-1);
  }

  .builder-block__body > .builder-entry {
    padding: var(--space-1) var(--space-2);
  }

  .builder-block__body > :is(small, .badge) {
    margin-inline-start: var(--space-2);
    justify-self: start;
  }

  .builder-block__moves {
    display: flex;
    flex-direction: column;
  }

  .builder-block__moves button {
    min-height: 1.75rem;
    padding: 0 var(--space-2);
    font-size: var(--text-sm);
  }

  .builder-block__moves button:disabled {
    opacity: 0.4;
    cursor: default;
  }

  .builder__toolbar button:disabled {
    opacity: 0.5;
    cursor: default;
  }

  /* Who Home is drawn for. */
  .builder__phone-head {
    display: grid;
    gap: var(--space-2);
  }

  .builder__viewer legend {
    font-size: var(--text-sm);
  }

  .choice-inline {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 400;
  }

  .builder__phone-state p {
    color: var(--ink-soft);
    font-size: var(--text-sm);
  }

  /* The phone: a 390 by 844 screen, drawn at four fifths so that it fits beside the editor
     on a laptop. Taps land where they are drawn. */
  .phone {
    position: relative;
    width: 21rem;
    max-width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--line-strong);
    border-radius: 2.25rem;
    background: var(--ink);
  }

  .phone__screen {
    width: calc(390px * 0.8);
    height: calc(844px * 0.8);
    max-width: 100%;
    overflow: hidden;
    border-radius: 1.625rem;
    background: var(--surface);
  }

  .phone__screen iframe {
    display: block;
    width: 390px;
    height: 844px;
    border: 0;
    transform: scale(0.8);
    transform-origin: top left;
  }

  /* Over the screen while the app starts, or when it cannot be shown. */
  .phone__cover {
    position: absolute;
    inset: 0.75rem;
    display: grid;
    place-items: center;
    margin: 0;
    padding: var(--space-5);
    border-radius: 1.625rem;
    background: var(--sunken);
    color: var(--ink-soft);
    text-align: center;
  }

  .phone--empty {
    display: grid;
    place-items: center;
    min-height: 20rem;
    padding: var(--space-5);
    background: var(--sunken);
    border-color: var(--line);
    color: var(--ink-soft);
    text-align: center;
  }
}
