/* The jig's Controls: a panel that floats over the grid (or the single
   view) on wide screens, and a sheet up from the bottom on phones */
.side {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.main > .side,
dialog.view .side {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  max-width: calc(100% - 32px);
  border: 1px solid var(--line);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  z-index: 4;
}
dialog.view .side {
  top: calc(72px + env(safe-area-inset-top, 0px));
}
.side[hidden],
.side [hidden] {
  display: none !important;
}
.side.in-view .g-only,
.side:not(.in-view) .v-only {
  display: none !important;
}

/* the head stays put while the panel scrolls */
.sidehead {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.sidehead h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.iconbtn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}
.iconbtn:hover {
  color: var(--text);
  background: var(--hover);
}
.iconbtn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
}

/* a section per kind of setting */
.sec {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 20px;
  border-bottom: 1px solid var(--line);
}
.sec:last-child {
  border-bottom: 0;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.sec h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}
.editing {
  margin: 16px 20px 0;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--focus);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.editing p {
  margin: 0;
}
.editing #editName {
  color: var(--focus);
}
.edithead {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}
.edithead .reset {
  margin-left: auto;
}
/* an info icon, its card on hover, focus or tap */
.info {
  display: inline-flex;
}
.infobtn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--dim);
  cursor: help;
}
.infobtn:hover,
.infobtn:focus-visible {
  color: var(--text);
}
.infobtn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
/* under the whole line, so a long name never pushes it out of the panel */
.infotip {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 3;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  visibility: hidden;
  opacity: 0;
  transition:
    opacity 0.12s,
    visibility 0.12s;
}
.info:hover .infotip,
.info:focus-within .infotip {
  visibility: visible;
  opacity: 1;
}
.side .hint,
.note p {
  margin: 0;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.5;
}
.note {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--hover);
}
.fmtnote {
  margin-top: -6px !important;
}

/* fields: a small label over its control */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > span {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--dim);
}
.field > span output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
/* with one of the two hidden, the other takes the row */
.two:has(> [hidden]) > :not([hidden]) {
  grid-column: 1 / -1;
}
select,
.num {
  height: 44px;
  width: 100%;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa3c7' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 12px center / 16px;
  appearance: none;
  cursor: pointer;
}
select:hover {
  border-color: var(--dim);
}
select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* colors: the name and its hex on one line, then the swatches, the last
   of them any color at all */
.colorhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.colorhead > span {
  font-size: 12px;
  color: var(--dim);
}
.hex {
  width: 92px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-size: 12px;
  text-align: right;
  text-transform: lowercase;
  font-variant-numeric: tabular-nums;
}
.hex:hover,
.hex:focus {
  border-color: var(--dim);
}
.swrow,
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.sw {
  width: 28px;
  height: 28px;
  flex: none;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 0;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s;
}
.sw:hover {
  transform: scale(1.08);
}
.sw[aria-pressed="true"],
.sw.pick.on {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.sw.clear {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 10px 10px;
  background-position:
    0 0,
    0 5px,
    5px -5px,
    -5px 0;
}
/* any color: a rainbow swatch with the system picker under it */
.sw.pick {
  position: relative;
  overflow: hidden;
  background: conic-gradient(
    #f7768e,
    #e0af68,
    #9ece6a,
    #7dcfff,
    #7aa2f7,
    #bb9af7,
    #f7768e
  );
}
.sw.pick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.sw.pick:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* switches: a label and a sliding toggle */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
}
.switch input {
  appearance: none;
  flex: none;
  position: relative;
  width: 40px;
  height: 22px;
  margin: 0;
  border: 1px solid var(--line);
  background: var(--hover);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--dim);
  transition:
    transform 0.15s,
    background 0.15s;
}
.switch input:checked {
  background: var(--focus);
  border-color: var(--focus);
}
.switch input:checked::after {
  transform: translateX(18px);
  background: var(--panel);
}
.switch input:disabled {
  opacity: 0.45;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--focus);
  cursor: pointer;
}

.side .btn {
  width: 100%;
  justify-content: center;
}
.side .stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tile .art.own {
  border-radius: 0;
  padding: 8px;
}

/* phones: a sheet up from the bottom, as wide as the screen */
@media (max-width: 720px) {
  .main > .side,
  dialog.view .side {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: min(82dvh, 720px);
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.4);
    z-index: 6;
    animation: sheet-up 0.2s ease-out;
  }
  /* over the single view, the design stays in sight above the sheet:
     the sheet takes just over half the screen, the design the rest */
  dialog.view .side {
    max-height: 55dvh;
  }
  dialog.view:has(.side:not([hidden])) .vwrap {
    padding-bottom: 55dvh;
  }
  dialog.view:has(.side:not([hidden])) .vart > svg {
    max-height: 100%;
  }
}
@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .main > .side,
  dialog.view .side {
    animation: none;
  }
}
