/* Index of Marks — direct two-color editor.
   The large pair preview is the color control itself: no duplicate mini swatches. */

.palette-popover {
  --palette-head-h: 52px;
  --palette-preview-h: 104px;
  width: min(360px, calc(100vw - 28px));
  border: 1px solid var(--fg) !important;
  background: var(--bg);
  box-shadow: 0 14px 32px color-mix(in srgb, var(--fg) 10%, transparent);
}

.palette-popover-head {
  box-sizing: border-box;
  height: var(--palette-head-h);
  min-height: var(--palette-head-h);
  padding: 9px 10px 9px 13px;
}
.palette-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -.015em;
}
.palette-subtitle { display: none; }
.palette-close {
  width: 32px;
  height: 32px;
}
.palette-close svg {
  width: 15px;
  height: 15px;
}

/* One large, legible pair. The invisible native color inputs are placed over
   these halves, so clicking the visible color itself opens the system picker. */
.palette-pair-preview {
  position: relative;
  height: var(--palette-preview-h);
  border-top: 1px solid var(--fg);
  border-bottom: 1px solid var(--fg);
}
.palette-preview-bg,
.palette-preview-fg {
  position: relative;
  transition: box-shadow 120ms ease;
}
/* The color boundary itself is enough separation; no extra divider is needed. */
.palette-preview-bg { border-right: 0; }

.palette-color-input {
  position: absolute;
  top: var(--palette-head-h);
  z-index: 5;
  width: 50%;
  height: var(--palette-preview-h);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.palette-color-input[data-palette-color="bg"] { left: 0; }
.palette-color-input[data-palette-color="fg"] { left: 50%; }

.palette-popover:has([data-palette-color="bg"]:focus-visible) .palette-preview-bg,
.palette-popover:has([data-palette-color="bg"]:hover) .palette-preview-bg,
.palette-popover:has([data-palette-color="fg"]:focus-visible) .palette-preview-fg,
.palette-popover:has([data-palette-color="fg"]:hover) .palette-preview-fg {
  box-shadow: inset 0 0 0 2px var(--fg);
}

/* Labels and values belong directly under their corresponding swatch. */
.palette-swatches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  border-bottom: 0;
}
.palette-field {
  display: block;
  min-width: 0;
  padding: 11px 13px 12px;
  cursor: default;
}
.palette-field + .palette-field {
  border-top: 0;
  border-left: 0;
}
.palette-field-label {
  display: block;
  margin: 0 0 5px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: .01em;
}
.palette-field:nth-child(2) .palette-field-label {
  font-size: 0;
}
.palette-field:nth-child(2) .palette-field-label::after {
  content: "Symbol";
  font-size: 10px;
}
.palette-field-value {
  display: block;
  min-width: 0;
}
.palette-hex-input {
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.25;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}
.palette-hex-input:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 3px;
}
.palette-hex-input.is-invalid {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Swap is one centered icon + label unit. The button keeps its existing
   accessible/native text; the pseudo-element is only the visual icon. */
.palette-swap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: fit-content;
  min-height: 32px;
  margin: 8px auto 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
}
.palette-swap::before {
  content: "⇄";
  box-sizing: border-box;
  display: block;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid var(--fg);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 400;
  line-height: 30px;
  text-align: center;
  transform: translateY(-.25px);
}
.palette-swap::after { content: none; }

/* Palette style is one quiet inset setting rather than another full-width row. */
.palette-family {
  position: relative;
  min-height: 42px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
  margin: 8px 12px 0;
  border: 1px solid var(--fg);
  font-size: 11px;
}
.palette-family span {
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.palette-family select {
  min-width: 0;
  width: 100%;
  min-height: 40px;
  padding: 0 34px 0 8px;
  border: 0;
  border-radius: 0;
  background: var(--bg);
  background-image: none !important;
  color: var(--fg);
  font: inherit;
  font-size: 11px;
  -webkit-appearance: none;
  appearance: none;
}
/* Safari/iOS paints its native select indicator independently from the page
   palette. Replace it with a CSS chevron that follows --fg/currentColor. */
.palette-family::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 13px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  color: var(--fg);
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
  transform-origin: 50% 50%;
}
.palette-family select:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: -3px;
  box-shadow: none;
}

/* Actions sit inside the panel with breathing room instead of becoming its edge. */
.palette-buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin: 8px 12px 12px;
}
.palette-buttons button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 11px;
}
.palette-buttons button:last-child { border-right: 1px solid var(--fg); }
.palette-buttons .palette-primary {
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

@media (hover: hover) {
  /* Override the legacy full-button palette hover: only the circular swap glyph
     inverts, while the centered label stays on the panel background. */
  .palette-swap:hover {
    background: transparent;
    color: var(--fg);
  }
  .palette-swap:hover::before {
    background: var(--fg);
    color: var(--bg);
  }
  .palette-buttons button:not(.palette-primary):hover {
    background: var(--fg);
    color: var(--bg);
  }
  .palette-buttons .palette-primary:hover { opacity: .82; }
}

/* Mobile remains a detached, four-sided popover. The controls simplify rather
   than stack into a second toolbar, and editable text stays at 16px for iOS. */
@media (max-width: 760px) {
  .palette-popover {
    --palette-head-h: 48px;
    --palette-preview-h: 88px;
    top: calc(100% + 8px);
    right: 0;
    bottom: auto;
    left: 0;
    width: auto;
    max-width: none;
    max-height: calc(100svh - var(--palette-header-height, 58px) - 20px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--fg) !important;
    padding-bottom: 0;
    box-shadow: 0 12px 26px color-mix(in srgb, var(--fg) 9%, transparent);
  }
  .palette-popover-head {
    padding: 7px 9px 7px 11px;
  }
  .palette-field {
    padding: 10px 11px 11px;
  }
  .palette-field-label {
    margin-bottom: 5px;
  }
  .palette-hex-input {
    font-size: 16px;
    line-height: 1.2;
  }
  .palette-swap {
    min-height: 34px;
    margin-top: 8px;
    font-size: 11px;
  }
  .palette-swap::before {
    width: 34px;
    height: 34px;
    line-height: 32px;
  }
  .palette-family {
    min-height: 44px;
  }
  .palette-family select {
    min-height: 42px;
    font-size: 16px;
  }
  .palette-buttons button {
    min-height: 44px;
    font-size: 12px;
  }
}

@media (max-width: 390px) {
  .palette-popover {
    --palette-preview-h: 78px;
  }
  .palette-field {
    padding-inline: 9px;
  }
  .palette-family,
  .palette-buttons {
    margin-left: 9px;
    margin-right: 9px;
  }
}
