/* Page chrome around the stage: masthead, names switch, veils, disclaimer.
   House system throughout: see the note at the top of base.css. */

/* ---- Arrival: every block rises into the light, once -------------------- */

[data-rise] {
  opacity: 0;
  transform: translate3d(0, 14px, 0);
}

/* The masthead and the disclaimer arrive with the page; the rest waits for the model. */
.masthead[data-rise],
.disclaimer[data-rise],
[data-state="ready"] [data-rise] {
  opacity: 1;
  transform: none;
  transition:
    opacity var(--dur-5) var(--ease-rise) var(--rise-delay, 0ms),
    transform var(--dur-5) var(--ease-rise) var(--rise-delay, 0ms);
}

.masthead[data-rise],
.disclaimer[data-rise] {
  animation: rise var(--dur-5) var(--ease-rise) both;
  transition: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0);
  }
}

/* ---- Masthead ---------------------------------------------------------- */

.masthead {
  position: absolute;
  z-index: 4;
  top: calc(var(--edge) + env(safe-area-inset-top, 0px));
  left: calc(var(--edge) + env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.masthead__title {
  margin: 0;
  line-height: 0;
}

/* The in-market wordmark (sunstone/assets/brand/logos/wordmark.svg), in its
   approved charcoal. Nothing is added to it: no shadow, no holding shape, no
   text locked up with it. Clear space is half its own height on every side,
   which the tags below respect. */
.wordmark {
  display: block;
  width: clamp(140px, 12.4vw, 178px);
  height: auto;
}

.masthead__tags {
  display: flex;
  gap: 6px;
  margin: 15px 0 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--accent-text);
  background: rgb(107 117 89 / 0.1);
  box-shadow: inset 0 0 0 1px rgb(107 117 89 / 0.4);
  white-space: nowrap;
}

.tag--draft {
  display: none;
  color: var(--terracotta-700);
  background: rgb(166 84 64 / 0.08);
  box-shadow: inset 0 0 0 1px rgb(166 84 64 / 0.38);
}

[data-status="draft"] .tag--draft {
  display: inline-flex;
}

/* ---- Veils -------------------------------------------------------------
   The page's own paper, fading in over the model where the chrome sits. At the
   fitted view nothing is under them; zoomed in, the model dissolves into the
   page instead of running under the wordmark, the switch or the controls. */

.veil {
  position: absolute;
  z-index: 2;
  right: 0;
  left: 0;
  pointer-events: none;
}

.veil--top {
  top: 0;
  height: calc(var(--edge) + 132px + env(safe-area-inset-top, 0px));
  background: linear-gradient(to bottom,
    var(--linen) 0%, rgb(246 241 231 / 0.9) 34%, rgb(246 241 231 / 0.52) 66%, rgb(246 241 231 / 0) 100%);
}

.veil--bottom {
  bottom: 0;
  height: calc(var(--foot-row) + 108px);
  background: linear-gradient(to top,
    var(--linen) 0%, rgb(246 241 231 / 0.9) 38%, rgb(246 241 231 / 0.52) 68%, rgb(246 241 231 / 0) 100%);
}

/* ---- Names switch ------------------------------------------------------ */

.names {
  position: absolute;
  z-index: 4;
  top: calc(var(--edge) + env(safe-area-inset-top, 0px));
  right: calc(var(--edge) + env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

/* The switch, with the vineyard blocks' toggle (blocks.css) at its left when it is offered. */
.names__row {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* A block, not a flex row: WebKit drops the float of a flex fieldset's legend,
   which then stays the fieldset's caption, drawn above the options. */
.switch {
  display: flow-root;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

/* A floated legend drops out of the fieldset's border and lays out like any box:
   beside the track, 12px off it, and 10px down to centre on it (35.9px to 16px). */
.switch__legend {
  float: left;
  margin: 10px 12px 0 0;
  padding: 0;
  color: var(--ink-60);
}

.switch__track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
  border-radius: 999px;
  background: rgb(253 251 246 / 0.86);
  box-shadow: inset 0 0 0 1px var(--ink-45), 0 14px 30px -22px rgb(20 18 14 / 0.4);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

/* The thumb: one ink pill that slides to the chosen option. */
.switch__track::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 3);
  border-radius: 999px;
  background: var(--ink);
  transition: transform var(--dur-4) var(--ease-estate);
}

.switch__track:has(input[value="public"]:checked)::before {
  transform: translateX(100%);
}

.switch__track:has(input[value="all"]:checked)::before {
  transform: translateX(200%);
}

.switch__option {
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* A 44px-tall touch target without a taller pill. */
.switch__option::after {
  content: "";
  position: absolute;
  inset: -7px 0;
}

.switch__option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch__option span {
  position: relative;
  display: block;
  min-width: 34px;
  padding: 6px 14px 7px;
  border-radius: 999px;
  color: var(--ink-70);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.01em;
  text-align: center;
  white-space: nowrap;
  transition: color var(--dur-2) var(--ease-estate);
}

@media (hover: hover) {
  .switch__option:hover input:not(:checked, :disabled) + span {
    color: var(--ink);
    box-shadow: inset 0 0 0 1px var(--ink-45);
  }
}

.switch__option input:checked + span {
  color: var(--bone);
}

.switch__option input:focus-visible + span {
  box-shadow: var(--focus-ring);
}

.switch:disabled .switch__track {
  opacity: 0.5;
}

.switch:disabled .switch__option,
.switch:disabled .switch__option input {
  cursor: not-allowed;
}

/* The public copy of the map has no internal names: Off / On. */
.switch--two .switch__track {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.switch--two .switch__track::before {
  width: calc((100% - 6px) / 2);
}

/* Browsers without :has() get no sliding thumb: the chosen option is filled instead. */
@supports not selector(:has(*)) {
  .switch__track::before {
    display: none;
  }

  .switch__option input:checked + span {
    background: var(--ink);
  }
}

.names__note {
  box-sizing: border-box;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--terracotta-700);
  background: rgb(253 251 246 / 0.86);
  box-shadow: inset 0 0 0 1px rgb(166 84 64 / 0.45);
  animation: rise var(--dur-4) var(--ease-rise) both;
}

.names__note[hidden],
[data-mode="edit"] .names__note {
  display: none;
}

[data-state="error"] .names {
  display: none;
}

.notice {
  position: absolute;
  z-index: 4;
  top: calc(var(--edge) + 58px + env(safe-area-inset-top, 0px));
  right: calc(var(--edge) + env(safe-area-inset-right, 0px));
  max-width: min(300px, 70vw);
  margin: 0;
  color: var(--terracotta-700);
  font-size: 13px;
  line-height: 1.4;
  text-align: right;
}

/* ---- Disclaimer -------------------------------------------------------- */

.disclaimer {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: var(--foot);
  left: 0;
  padding: 0 var(--edge);
  text-align: center;
  pointer-events: none;
}

.disclaimer p {
  max-width: 86ch;
  margin: 0 auto;
  color: var(--ink-60);
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

/* ---- Small screens ----------------------------------------------------- */

@media (max-width: 640px) {
  .wordmark {
    width: 132px;
  }

  /* Row two of a phone's header: the tags on the left, the view controls on the
     right (controls.css), both below the names switch. */
  .masthead__tags {
    margin-top: 26px;
  }

  .switch__legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .switch__option span {
    padding: 6px 11px 7px;
  }

  /* The note takes the row under the tags and the view controls. */
  .names__note {
    position: fixed;
    top: calc(var(--edge) + 104px + env(safe-area-inset-top, 0px));
    right: auto;
    left: calc(var(--edge) + env(safe-area-inset-left, 0px));
    max-width: calc(100vw - 2 * var(--edge));
  }

  /* The note is fixed to the window, and a transform on .names would make .names
     its containing block while it rises: the note would be laid out inside the
     switch, half as wide, and ui.js would measure it there. So here the switch
     rises, not .names. */
  .names[data-rise] {
    transform: none;
  }

  .names[data-rise] .switch {
    transform: translate3d(0, 14px, 0);
  }

  [data-state="ready"] .names[data-rise] .switch {
    transform: none;
    transition: transform var(--dur-5) var(--ease-rise) var(--rise-delay, 0ms);
  }

  .veil--top {
    height: calc(var(--edge) + 136px + env(safe-area-inset-top, 0px));
  }

  .veil--bottom {
    height: calc(var(--foot-row) + 64px);
  }

  .notice {
    right: var(--edge);
    left: var(--edge);
    max-width: none;
  }
}

/* The narrowest phones: the wordmark and the switch still share one row, and
   the page title alone says what the map is. */
@media (max-width: 359px) {
  .wordmark {
    width: 112px;
  }

  .masthead__tags .tag:not(.tag--draft) {
    display: none;
  }

  .switch__option span {
    min-width: 0;
    padding: 6px 8px 7px;
    font-size: 12px;
  }
}

/* A phone on its side: little height, so the chrome keeps to thin bands. */
@media (max-height: 500px) and (orientation: landscape) {
  .wordmark {
    width: 120px;
  }

  .masthead__tags {
    display: none;
  }

  .names__note {
    display: none;
  }

  .veil--top {
    height: calc(var(--edge) + 58px + env(safe-area-inset-top, 0px));
  }

  .veil--bottom {
    height: calc(var(--foot-row) + 56px);
  }
}

/* Narrower than 480px on its side (only a desktop zoomed right in) the
   disclaimer takes two lines, set close enough to stay inside the foot row
   (base.css): 30px of text under rows that start 34px up. */
@media (max-width: 479px) and (max-height: 500px) and (orientation: landscape) {
  .disclaimer p {
    line-height: 1.25;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .switch__track,
  .names__note {
    background: var(--bone);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-rise],
  .masthead[data-rise],
  .disclaimer[data-rise],
  .names[data-rise] .switch {
    opacity: 1;
    transform: none;
  }
}
