@layer layout {
  .main {
    display: block;
    padding: 0;
    place-items: stretch;
  }
  .board {
    inline-size: 100%;
    min-block-size: 100dvh;
    justify-self: stretch;
  }
}

@layer components {
  @keyframes card-turn {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(180deg); }
  }

  .board__banner {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    padding: 1.5rem 1rem 1.25rem;
    border-block-end: var(--hairline) solid var(--border);
    text-align: center;
  }
  .board__banner .wordmark,
  .board__banner .line {
    margin: 0;
  }
  .board__stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 1rem 1rem 2.5rem;
  }
  .board__figure {
    display: flex;
    justify-content: center;
    inline-size: 100%;
    overflow: auto;
  }
  .board__svg {
    flex: none;
    inline-size: 800px;
    block-size: 640px;
    background: none;
    touch-action: none;
  }
  .board__panel {
    inline-size: min(100%, 40rem);
    padding: 0;
    background: transparent;
  }
  .panel__modes {
    display: flex;
    align-items: end;
    gap: 0.5rem;
  }
  .panel__mode-col {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 0.4rem;
    min-inline-size: 0;
  }
  .panel__tally {
    margin: 0;
    text-align: center;
    text-wrap: balance;
    color: var(--muted);
    font-family: var(--font-display);
    font-size: 0.75em;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.12em;
  }
  .panel__mode,
  .panel__confirm {
    font-family: var(--font-display);
    font-size: 0.75em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }
  .panel__mode {
    inline-size: 100%;
  }
  .panel__mode.is-chosen {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 0.75rem var(--accent);
  }
  .panel__mode.is-chosen:disabled {
    color: var(--accent);
    cursor: default;
  }
  .panel__confirm {
    inline-size: 100%;
    margin-block: 0.75rem;
  }
  .cards {
    margin-block-start: 0.75rem;
  }
  .cards__plus {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.5rem;
  }
  .place--north { grid-column: 3; grid-row: 1; }
  .place--west { grid-column: 2; grid-row: 2; }
  .place--center { grid-column: 3; grid-row: 2; }
  .place--east { grid-column: 4; grid-row: 2; }
  .place--south { grid-column: 3; grid-row: 3; }
  .place {
    inline-size: 100%;
    min-inline-size: 0;
  }
  .place__name {
    display: grid;
    place-items: center;
    aspect-ratio: 800 / 1120;
    margin: 0;
    padding: 0.35rem;
    color: var(--muted);
    font-family: var(--font-display);
    font-size: 0.68rem;
    line-height: 1.15;
    text-align: center;
    text-wrap: balance;
  }
  /* Same five tracks as the plus, so the middle card sits under the center. */
  .cards__array {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-block-start: 0.75rem;
  }
  .cards__array > .card,
  .group > .card {
    inline-size: calc((100% - 2rem) / 5);
    flex: none;
  }
  .card {
    position: relative;
    display: block;
    inline-size: 100%;
    min-inline-size: 0;
    aspect-ratio: 800 / 1120;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0.45rem;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    user-select: none;
  }
  .card--down {
    perspective: 24rem;
  }
  .card--down .card__inner {
    position: absolute;
    inset: 0;
    display: block;
    transform-style: preserve-3d;
    transform-origin: center;
  }
  /* Plays when .is-flipped is added to a card already in the array. */
  .card--down.is-flipped .card__inner {
    transform: rotateY(180deg);
    animation: card-turn var(--motion) ease;
  }
  .card__face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 0.45rem;
    background: #08070b;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  .card--down .card__face--front {
    transform: rotateY(180deg);
  }
  .face {
    inline-size: 100%;
    block-size: 100%;
  }
  .face__index {
    font-feature-settings: 'liga' 0, 'calt' 0, 'kern' 1;
  }
  .card.is-selected {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .card[aria-disabled="true"] {
    cursor: default;
  }
  @media (prefers-reduced-motion: reduce) {
    .card--down.is-flipped .card__inner {
      animation: none;
    }
  }
  .groups {
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
  }
  .group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
    margin-block-end: 0.35rem;
  }
  .readout {
    margin-block-start: 0.75rem;
    text-align: center;
  }
  .readout__status,
  .readout__score {
    margin: 0;
    font-family: var(--font-display);
    text-align: center;
  }
  .readout__status {
    letter-spacing: 0.04em;
  }
  .lights {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-block-start: 0.75rem;
  }
  .light {
    display: block;
    flex: none;
    inline-size: 0.85rem;
    block-size: 0.85rem;
    border: var(--hairline) solid var(--border);
    border-radius: 50%;
    background: var(--surface);
  }
  /* Gold and teal are the two inks already on the card faces. */
  .light--summon {
    border-color: #c58d35;
    background: #c58d35;
    box-shadow: 0 0 0.55rem #c58d35;
  }
  .light--complement {
    border-color: #017d99;
    background: #017d99;
    box-shadow: 0 0 0.55rem #017d99;
  }
  .readout__score {
    margin-block-start: 0.75rem;
    font-size: 1.05rem;
    text-wrap: balance;
  }
  .edge {
    fill: none;
    stroke: var(--border);
    stroke-width: 1.5;
  }
  .edge__head {
    fill: var(--border);
    stroke: none;
  }
  .edge__label,
  .node-group__label {
    fill: var(--muted);
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 400;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
  }
  .node-group {
    cursor: grab;
  }
  .node-group__circle {
    fill: var(--surface);
    stroke: var(--border);
    stroke-width: 1.5;
  }
  .node-group__label {
    fill: var(--text);
    font-size: 15px;
  }
  .node-group.is-dragging {
    cursor: grabbing;
    filter: drop-shadow(0 0 6px var(--accent));
  }
  .node-group.is-dragging .node-group__circle {
    stroke: var(--accent);
    stroke-width: 2;
  }
}

@media (hover: hover) {
  .node-group:hover .node-group__circle {
    stroke: var(--accent);
  }
  .edge:hover {
    stroke: var(--accent);
  }
  .card:hover {
    outline: 2px solid var(--accent-dim);
    outline-offset: 2px;
  }
  .card.is-selected:hover {
    outline-color: var(--accent);
  }
}
