/* SA Web launcher: the full-window home screen (library/sa-launcher.js).
   Palette: asphalt, concrete, bone, sunset orange, grove green. Type: Archivo (OFL), heavy and
   expanded for headings, regular for text. Loaded after sa.css, which defines the --sa-* tokens. */

dialog.lib-dialog {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: var(--sa-asphalt);
  color: var(--sa-ink);
  opacity: 1;
  transition: opacity 600ms var(--ease-out, ease-out);
}

dialog.lib-dialog::backdrop {
  background: #000;
}

dialog.lib-dialog.is-leaving {
  opacity: 0;
}

dialog.lib-dialog:not([open]) {
  display: none;
}

/* The old dialog's own head and credit give way to the launcher's. */
.lib-head {
  position: absolute;
  z-index: 3;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 0 0;
}

.lib-head h2 {
  display: none;
}

.lib-head .btn-quiet {
  border: 1px solid var(--sa-line);
  background: rgb(10 10 11 / 0.6);
  color: var(--sa-ash);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
}

.lib-head .btn-quiet:hover {
  color: var(--sa-ink);
  border-color: #4a4a4e;
}

.lib-credit {
  display: none;
}

.lib {
  position: absolute;
  inset: 0;
}

/* ------------------------------------------------------------ the scene */

.sal {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: auto;
  background: var(--sa-asphalt);
  isolation: isolate;
}

/* The sky: the horizon of a hot evening behind the disc. One soft glow, nothing else. */
.sal-sky {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(90% 55% at 28% 100%, rgb(255 122 26 / 0.34), rgb(255 122 26 / 0) 70%),
    radial-gradient(60% 40% at 12% 108%, rgb(61 187 74 / 0.2), rgb(61 187 74 / 0) 70%),
    linear-gradient(180deg, #060607 0%, #0b0a0a 55%, #130d08 100%);
}

.sal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(20px, env(safe-area-inset-top)) max(130px, env(safe-area-inset-right)) 0 max(32px, env(safe-area-inset-left));
}

.sal-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sal-mark {
  height: 40px;
  width: auto;
  display: block;
}

.sal-brandname {
  font: 900 20px/1 var(--sa-display);
  font-stretch: 125%;
  letter-spacing: 0.01em;
  transform: skewX(-6deg);
}

/* Fullscreen or small: a two-way switch. */
.sal-screen {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--sa-line);
  border-radius: 999px;
  background: rgb(10 10 11 / 0.6);
}

.sal-seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--sa-ash);
  font: 600 13px/1 var(--sa-text);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.sal-seg:hover {
  color: var(--sa-ink);
}

.sal-seg[aria-checked="true"] {
  background: var(--sa-ink);
  color: var(--sa-asphalt);
}

.sal-main {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(16px, 4vw, 72px);
  padding: clamp(12px, 3vh, 40px) max(clamp(24px, 6vw, 96px), env(safe-area-inset-right)) clamp(20px, 4vh, 48px) max(clamp(24px, 6vw, 96px), env(safe-area-inset-left));
  min-height: 0;
}

/* ------------------------------------------------------------ the disc */

.sal-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.sal-halo {
  position: absolute;
  width: min(62vh, 44vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(255 138 31 / 0.22), rgb(255 138 31 / 0) 72%);
  filter: blur(8px);
  opacity: 0.55;
  transition: opacity 700ms ease;
}

.sal-disc {
  position: relative;
  width: min(56vh, 40vw);
  aspect-ratio: 1;
  filter: drop-shadow(0 24px 40px rgb(0 0 0 / 0.55));
  opacity: 0.42;
  transform: rotate(-14deg) scale(0.96);
  transition: opacity 700ms ease, transform 900ms cubic-bezier(0.2, 0.7, 0.2, 1), filter 700ms ease;
}

.sal-disc svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sal-ring {
  opacity: 0.5;
  transition: opacity 700ms ease;
}

/* The disc wakes when the game is chosen, and spins up when it starts. */
.sal[data-game="ok"] .sal-disc,
.sal[data-mode="starting"] .sal-disc {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.sal[data-game="ok"] .sal-halo {
  opacity: 1;
}

.sal[data-game="ok"] .sal-ring {
  opacity: 1;
}

.sal[data-game="busy"] .sal-disc {
  opacity: 0.7;
}

.sal[data-game="ok"][data-mode="setup"] .sal-disc svg {
  animation: sal-spin 14s linear infinite;
}

.sal[data-mode="starting"] .sal-disc svg {
  animation: sal-spin 1.1s linear infinite;
}

.sal[data-mode="starting"] .sal-halo {
  opacity: 1;
  animation: sal-pulse 1.8s ease-in-out infinite;
}

@keyframes sal-spin {
  to { transform: rotate(360deg); }
}

@keyframes sal-pulse {
  50% { opacity: 0.55; }
}

/* ------------------------------------------------------------ the panel */

.sal-panel {
  max-width: 560px;
  min-width: 0;
}

.sal-title {
  margin: 0 0 12px;
  font: 900 clamp(30px, 4.4vw, 56px)/1.02 var(--sa-display);
  font-stretch: 125%;
  letter-spacing: -0.01em;
  transform-origin: left bottom;
  transform: skewX(-6deg);
  text-wrap: balance;
  outline: none;
}

.sal .sal-title:focus,
.sal .sal-title:focus-visible {
  outline: none;
}

.sal-lead {
  margin: 0 0 28px;
  max-width: 46ch;
  color: var(--sa-ash);
  font: 400 clamp(15px, 1.3vw, 18px)/1.5 var(--sa-text);
}

.sal[data-mode="starting"] .sal-lead,
.sal[data-mode="starting"] .sal-steps {
  display: none;
}

.sal-steps {
  display: grid;
  gap: 10px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}

.sal-step {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--sa-line);
  border-radius: 14px;
  background: rgb(21 21 22 / 0.82);
  backdrop-filter: blur(6px);
  transition: border-color 200ms ease, background-color 200ms ease;
}

.sal-step[data-state="done"] {
  border-color: rgb(61 187 74 / 0.5);
}

.sal-step[data-state="error"] {
  border-color: rgb(255 194 51 / 0.6);
}

/* The step's badge is its position in the sequence until it's done, then a tick. */
.sal-steps {
  counter-reset: step;
}

.sal-badge {
  counter-increment: step;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid #4a4a4e;
  color: var(--sa-ash);
  font: 800 14px/1 var(--sa-display);
}

.sal-badge::before {
  content: counter(step);
}

.sal-step[data-state="done"] .sal-badge {
  border-color: var(--sa-grove);
  background: var(--sa-grove);
  color: #06210c;
}

.sal-step[data-state="done"] .sal-badge::before {
  content: "";
  width: 12px;
  height: 7px;
  border-left: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: translateY(-1px) rotate(-45deg);
}

.sal-step[data-state="busy"] .sal-badge {
  border-color: var(--sa-orange);
  border-top-color: transparent;
  animation: sal-spin 800ms linear infinite;
  color: transparent;
}

.sal-step[data-state="error"] .sal-badge {
  border-color: var(--sa-warn);
  color: var(--sa-warn);
}

.sal-step-text {
  min-width: 0;
}

.sal-step h2 {
  margin: 0 0 3px;
  font: 700 16px/1.2 var(--sa-text);
}

.sal-step p {
  margin: 0;
  color: var(--sa-ash);
  font: 400 14px/1.4 var(--sa-text);
  overflow-wrap: anywhere;
}

.sal-step .sal-warn {
  margin-top: 6px;
  color: var(--sa-warn);
}

.sal-step-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.sal-btn {
  appearance: none;
  border: 1px solid #46464a;
  border-radius: 999px;
  background: transparent;
  color: var(--sa-ink);
  font: 700 14px/1 var(--sa-text);
  padding: 11px 18px;
  min-height: 44px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.sal-btn:hover:not(:disabled) {
  background: rgb(255 255 255 / 0.08);
  border-color: #6a6a70;
}

.sal-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.sal-step[data-state="done"] .sal-btn {
  border-color: transparent;
  color: var(--sa-ash);
  font-weight: 600;
}

.sal-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--sa-ash);
  font: 500 13px/1.2 var(--sa-text);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.sal-link:hover {
  color: var(--sa-ink);
}

.sal-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.sal-chip {
  appearance: none;
  border: 1px solid #46464a;
  border-radius: 999px;
  background: transparent;
  color: var(--sa-ash);
  font: 600 12px/1 var(--sa-text);
  padding: 7px 11px;
  cursor: pointer;
}

.sal-chip[aria-pressed="true"] {
  border-color: var(--sa-grove);
  color: var(--sa-ink);
}

/* ------------------------------------------------------------ Play */

.sal-actions {
  display: flex;
  align-items: center;
}

.sal-play {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 60px;
  padding: 0 34px;
  background: var(--sa-orange);
  color: #1b0d00;
  font: 900 20px/1 var(--sa-display);
  font-stretch: 125%;
  letter-spacing: 0.005em;
  cursor: pointer;
  box-shadow: 0 10px 28px rgb(255 122 26 / 0.34), inset 0 -3px 0 rgb(0 0 0 / 0.16);
  transition: transform 120ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.sal-play-label {
  display: inline-block;
  transform: skewX(-6deg);
}

.sal-play:hover:not(:disabled) {
  background: var(--sa-orange-hi);
  transform: translateY(-1px);
}

.sal-play:active:not(:disabled) {
  transform: translateY(1px);
}

.sal-play:disabled {
  background: #1d1d1f;
  color: #77777b;
  box-shadow: none;
  cursor: default;
  font-size: 16px;
}

.sal[data-mode="starting"] .sal-actions {
  display: none;
}

.sal-note {
  min-height: 1.5em;
  margin: 16px 0 0;
  color: var(--sa-ink);
  font: 500 15px/1.4 var(--sa-text);
}

.sal-fine {
  margin: 10px 0 0;
  color: #77777b;
  font: 400 13px/1.45 var(--sa-text);
}

.sal[data-mode="starting"] .sal-fine {
  display: none;
}

/* Drop target */
.sal-drop {
  position: absolute;
  inset: 12px;
  z-index: 4;
  display: none;
  place-items: center;
  border: 2px dashed var(--sa-orange);
  border-radius: 20px;
  background: rgb(10 10 11 / 0.86);
  font: 800 clamp(20px, 3vw, 34px)/1.1 var(--sa-display);
  font-stretch: 125%;
  pointer-events: none;
}

.sal[data-drag="on"] .sal-drop {
  display: grid;
}

.sal :focus-visible {
  outline: 3px solid var(--sa-orange-hi);
  outline-offset: 3px;
}

/* ------------------------------------------------------------ narrow and short windows */

@media (max-width: 880px) {
  .sal-main {
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 8px;
  }

  .sal-stage {
    order: -1;
    height: 30vh;
  }

  .sal-disc {
    width: min(30vh, 62vw);
  }

  .sal-halo {
    width: min(36vh, 70vw);
  }

  .sal-panel {
    max-width: none;
  }

  .sal-step {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .sal-step-actions {
    grid-column: 2;
    justify-items: start;
  }

  .sal-step > .sal-btn {
    grid-column: 2;
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sal-disc,
  .sal-halo,
  .sal-disc svg,
  .sal-badge {
    animation: none !important;
    transition: none !important;
  }

  dialog.lib-dialog {
    transition: none;
  }
}
