/* Browser installation page: the quiet semantic startup language from #1122/#1123,
   adapted to the richer decision content needed before TURN is installed. */

html.turn-browser:not(.turn-browser-launched),
html.turn-browser:not(.turn-browser-launched) body {
  max-width: 100%;
  min-height: 100%;
  overflow-x: clip;
  background: var(--turn-surface-page);
  color: var(--turn-text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  display: grid !important;
  justify-items: center;
  align-items: stretch;
  overflow-x: clip;
  overflow-y: auto;
  padding:
    max(var(--turn-gutter), env(safe-area-inset-top))
    max(var(--turn-gutter), env(safe-area-inset-right))
    max(var(--turn-gutter), env(safe-area-inset-bottom))
    max(var(--turn-gutter), env(safe-area-inset-left));
  background: var(--turn-surface-page);
  color: var(--turn-text);
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-shell {
  box-sizing: border-box;
  width: min(100%, 760px);
  min-width: 0;
  min-height: calc(100vh - var(--turn-gutter) - var(--turn-gutter));
  min-height: calc(100dvh - var(--turn-gutter) - var(--turn-gutter));
  margin-inline: auto;
  align-self: start;
  padding: var(--turn-space-12) 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--turn-space-8);
  align-items: start;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) :is(.install-art, .install-card) {
  min-width: 0;
  max-width: 100%;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-art {
  display: grid;
  place-items: center;
  align-self: end;
}

/* Use the same TURN app-mark treatment as the startup/loading screen: the base icon
   shape plus the same tokenized border weight and action shadow. */
html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-icon {
  width: clamp(104px, 20vh, 156px);
  max-width: 100%;
  max-height: none;
  border-width: var(--turn-border-default);
  box-shadow: var(--turn-shadow-action);
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-card {
  box-sizing: border-box;
  width: 100%;
  min-height: 100%;
  max-width: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* Keep the document's real H1 for the region label and for the startup cover. */
html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-card h1 {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-copy {
  max-width: var(--turn-content-max);
  margin: 0;
  color: var(--turn-text);
  font-size: var(--turn-type-title);
  font-weight: 700;
  line-height: var(--turn-leading-body);
  text-align: center;
}

.install-accessibility {
  width: min(100%, var(--turn-content-max));
  margin-top: var(--turn-space-8);
  display: grid;
  justify-items: center;
}

.install-accessibility-symbol {
  display: none;
}

/* Preserve the Wikimedia mark's original blue in light mode. Dark mode uses TURN's
   lighter blue locally so the global theme remains limited to neutral roles. */
.install-accessibility::before {
  content: "";
  display: block;
  width: calc(var(--turn-space-12) + var(--turn-space-12));
  aspect-ratio: 1;
  background: var(--turn-accessibility-mark);
  -webkit-mask: url("./assets/icons/accessibility.svg") center / contain no-repeat;
  mask: url("./assets/icons/accessibility.svg") center / contain no-repeat;
}

:root[data-theme="dark"] .install-accessibility::before {
  background: var(--turn-blue-300);
}

.install-accessibility-title {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.install-accessibility-list {
  box-sizing: border-box;
  width: 100%;
  margin: var(--turn-space-4) 0 0;
  padding-inline-start: var(--turn-space-8);
  color: var(--turn-text);
  font-size: var(--turn-type-small);
  font-weight: 700;
  line-height: var(--turn-leading-body);
  text-align: left;
}

.install-accessibility-list li + li {
  margin-top: var(--turn-space-1);
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-actions {
  width: min(100%, var(--turn-content-max));
  margin-top: var(--turn-space-12);
  /* A simple stack avoids stale intrinsic grid-row heights after WebKit reflow. */
  display: flex;
  flex-direction: column;
  gap: var(--turn-space-4);
  align-items: stretch;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-actions button {
  box-sizing: border-box;
  min-width: 0;
  width: 100%;
  overflow-wrap: anywhere;
  min-height: calc(var(--turn-control-height) + var(--turn-space-8));
  padding: var(--turn-space-4) var(--turn-space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: var(--turn-border-control) solid var(--turn-outline);
  border-radius: var(--turn-radius-control);
  box-shadow: none;
  color: var(--turn-text);
  font: inherit;
  font-size: var(--turn-type-body);
  font-weight: var(--turn-weight-label);
  line-height: var(--turn-leading-title);
  letter-spacing: var(--turn-tracking-micro);
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-primary {
  background: var(--turn-action-primary);
  color: var(--turn-ink);
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-secondary {
  border-color: var(--turn-outline);
  background: var(--turn-surface-page);
  color: var(--turn-text);
  opacity: 1;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-secondary:active {
  transform: none;
  box-shadow: none;
}

.install-browser-label,
.install-browser-recommendation {
  display: block;
}

.install-browser-recommendation {
  margin-top: var(--turn-space-1);
  font-size: var(--turn-type-small);
  font-weight: var(--turn-weight-label);
  letter-spacing: var(--turn-tracking-micro);
}

/* Browser-specific install guidance still updates this live status node. It is useful
   to assistive technology but deliberately not part of the quiet visual composition. */
html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-note {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-kicker {
  max-width: 100%;
  margin: auto 0 0;
  padding: var(--turn-space-12) 0 0;
  display: inline-flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: var(--turn-space-3);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: var(--turn-type-small);
  font-weight: var(--turn-weight-label);
  line-height: var(--turn-leading-body);
  letter-spacing: var(--turn-tracking-micro);
  text-transform: uppercase;
}

html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-kicker-separator {
  display: none;
}

.install-about-trigger {
  appearance: none;
  min-height: var(--turn-target-min);
  padding: 0 var(--turn-space-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  box-shadow: none;
  font: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  text-decoration: underline;
  text-decoration-thickness: var(--turn-border-micro);
  text-underline-offset: var(--turn-space-1);
  text-transform: inherit;
}

/* ABOUT TURN and TURN WIKI share one row under the build line. */
.install-kicker-links {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  column-gap: var(--turn-space-4);
}

.install-wiki-link {
  gap: 0.25em;
}

.install-about-trigger:hover {
  transform: none;
}

.install-about-trigger:active {
  transform: none;
  box-shadow: none;
}

.install-about-trigger:focus-visible,
html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-actions button:focus-visible {
  outline: var(--turn-border-default) solid var(--turn-form-control-focus);
  outline-offset: var(--turn-space-1);
}

/* The browser-only context must disappear when PLAY IN BROWSER hands the same DOM to
   the startup cover. #1122/#1123 remain the sole loading/recovery composition. */
#installGate.turn-startup-loading .install-accessibility {
  display: none !important;
}

.install-guide {
  position: fixed;
  box-sizing: border-box;
  overflow-x: clip;
}

.install-guide-card {
  width: min(420px, 100%);
  max-width: 100%;
  padding: var(--turn-space-6);
  border: var(--turn-border-dialog) solid var(--turn-outline);
  border-radius: var(--turn-radius-dialog);
  box-shadow: var(--turn-shadow-dialog);
}

.install-guide-head {
  gap: var(--turn-space-4);
}

.install-guide h2 {
  font-size: var(--turn-type-heading);
  line-height: var(--turn-leading-title);
  overflow-wrap: anywhere;
}

.install-guide .install-close {
  width: var(--turn-target-min);
  height: var(--turn-target-min);
  flex-basis: var(--turn-target-min);
  border-radius: var(--turn-radius-circle);
  box-shadow: var(--turn-shadow-control);
}

.install-about-dialog {
  z-index: 2200;
}

@media (max-height: 700px) {
  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-shell {
    padding-block: var(--turn-space-6);
    gap: var(--turn-space-6);
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-icon {
    width: min(104px, 18vh);
  }

  .install-accessibility {
    margin-top: var(--turn-space-6);
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-actions {
    margin-top: var(--turn-space-8);
    gap: var(--turn-space-3);
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-kicker {
    padding-top: var(--turn-space-8);
  }
}

@media (max-height: 520px) and (min-width: 560px) {
  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-shell {
    width: min(100%, 980px);
    min-height: calc(100vh - var(--turn-gutter) - var(--turn-gutter));
    min-height: calc(100dvh - var(--turn-gutter) - var(--turn-gutter));
    padding-block: var(--turn-space-6);
    grid-template-columns: minmax(104px, 0.32fr) minmax(0, 1fr);
    grid-template-rows: minmax(min-content, 1fr) auto;
    grid-template-areas:
      "art card"
      "kicker kicker";
    gap: var(--turn-space-12);
    align-items: center;
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-art {
    grid-area: art;
    align-self: start;
    justify-items: start;
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-icon {
    width: 156px;
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-card {
    min-height: 0;
    grid-area: card;
    align-self: start;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "copy"
      "accessibility"
      "actions";
    column-gap: var(--turn-space-8);
    row-gap: var(--turn-space-3);
    grid-auto-rows: max-content;
    align-content: start;
    align-items: start;
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-copy {
    grid-area: copy;
    justify-self: stretch;
    font-size: var(--turn-type-title);
  }

  .install-accessibility {
    grid-area: accessibility;
    margin-top: 0;
  }

  .install-accessibility::before {
    width: calc(var(--turn-space-12) + var(--turn-space-6));
  }

  .install-accessibility-list {
    margin-top: var(--turn-space-2);
    font-size: var(--turn-type-small);
    line-height: var(--turn-leading-body);
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-actions {
    grid-area: actions;
    width: 100%;
    margin-top: 0;
    gap: var(--turn-space-2);
    align-self: start;
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-actions button {
    min-height: var(--turn-control-height);
    padding-block: var(--turn-space-2);
    font-size: var(--turn-type-body);
  }

  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-kicker {
    grid-area: kicker;
    width: 100%;
    align-self: end;
    margin-top: 0;
    padding-top: 0;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--turn-space-3) var(--turn-space-6);
    font-size: var(--turn-type-micro);
    text-align: left;
  }
}

/* Three columns need room for the two action labels as well as the feature list.
   A narrow landscape phone keeps the content in one column beside the app mark;
   the auto-sized row can grow and scroll without centering text above the viewport. */
@media (max-height: 520px) and (min-width: 760px) {
  html.turn-browser:not(.turn-browser-launched) #installGate:not(.turn-startup-loading) .install-card {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 0.95fr);
    /* The feature list spans two rows; its height must not stretch the actions. */
    grid-template-rows: max-content max-content;
    grid-template-areas:
      "copy accessibility"
      "actions accessibility";
  }
}
