/* OFFSET — self-contained palette tool (chrome follows active palette) */

.offset {
  --ink: #0e0e0c;
  --paper: #efede6;
  --palette-bg: #252523;
  --palette-accent: #8a8a86;
  --palette-accent-fg: #efede6;
  --palette-highlight: var(--palette-accent);
  --palette-highlight-fg: var(--palette-accent-fg);
  --palette-accent-soft: color-mix(in srgb, var(--palette-accent) 10%, transparent);
  --palette-accent-border: color-mix(in srgb, var(--palette-accent) 42%, transparent);
  --background: #151514;
  --foreground: #efede6;
  --card: #1c1c1a;
  --card-foreground: #efede6;
  --muted: #252523;
  --muted-foreground: rgba(239, 237, 230, 0.55);
  --border: rgba(239, 237, 230, 0.12);
  --input: rgba(239, 237, 230, 0.12);
  --ring: rgba(239, 237, 230, 0.28);
  --radius: 0.5rem;
  --radius-lg: 0.625rem;
  --font-display: "Archivo", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --font-accent: "Instrument Serif", Georgia, serif;
  min-width: 0;
  min-height: 100vh;
  font-family: var(--font-display);
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
}

.offset ::selection {
  background: rgba(239, 237, 230, 0.18);
  color: inherit;
}

.offset .preview-frame ::selection {
  background: var(--palette-highlight);
  color: var(--palette-highlight-fg);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: clip;
  background: #151514;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 0.4375rem 0.75rem;
}

.btn-xs {
  font-size: 0.625rem;
  padding: 0.3125rem 0.5rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.btn-outline {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--foreground);
}

.btn-outline:hover {
  background: var(--muted);
}

.btn-primary {
  border: 1px solid var(--palette-accent);
  background: var(--palette-accent);
  color: var(--palette-accent-fg);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--palette-accent) 88%, white);
  border-color: color-mix(in srgb, var(--palette-accent) 88%, white);
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  color: var(--card-foreground);
  min-width: 0;
  max-width: 100%;
}

.card-header {
  display: grid;
  gap: 0.25rem;
  padding: 0.875rem 1rem 0;
}

.card-header--compact {
  padding-bottom: 0;
}

.card-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-content {
  padding: 0.75rem 1rem 1rem;
  display: grid;
  gap: 0.625rem;
  min-width: 0;
}

.card-content > * {
  min-width: 0;
}

.card-content--compact {
  padding-top: 0.625rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.1rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  white-space: nowrap;
}

.offset__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.offset__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.offset__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cbff1f;
  flex-shrink: 0;
}

.offset__wordmark {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.offset__labs-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease;
}

.offset__labs-link:hover,
.offset__labs-link:focus-visible {
  color: #cbff1f;
}

.offset__sep {
  color: rgba(239, 237, 230, 0.4);
}

.offset__tool {
  color: rgba(239, 237, 230, 0.7);
}

.offset__main {
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 40px;
  min-width: 0;
}

.offset__title {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 1.875rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}

.offset__lede {
  margin: 8px 0 16px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted-foreground);
  max-width: 38ch;
}

.page-intro {
  margin-bottom: 1rem;
}

.card-description {
  margin: 0;
  font-size: 0.6875rem;
  line-height: 1.35;
  color: var(--muted-foreground);
}

.studio-card {
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.result-card {
  overflow: hidden;
  min-width: 0;
}

.card-header--toolbar {
  padding-bottom: 0.25rem;
  overflow: visible;
  position: relative;
  z-index: 2;
}

.field {
  display: grid;
  gap: 0.3125rem;
  min-width: 0;
}

.field--inline {
  flex-shrink: 0;
  align-self: flex-start;
}

.label {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  padding: 0.5rem 0.625rem;
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  line-height: 1.3;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgba(239, 237, 230, 0.08);
}

.input--hex {
  min-height: 2.25rem;
  text-transform: uppercase;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.tool-tab.is-active {
  border-color: var(--palette-accent-border);
  background: var(--palette-accent-soft);
  color: var(--foreground);
}

.tool-tab__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  margin-left: 0.25rem;
  border-radius: 9999px;
  background: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  font-weight: 600;
  line-height: 1;
  color: var(--muted-foreground);
}

.tool-tab.is-active .tool-tab__count {
  background: var(--palette-accent-soft);
  color: var(--foreground);
}

.view-history[hidden],
.view-palette[hidden] {
  display: none;
}

.history-panel {
  display: grid;
  gap: 0.625rem;
  min-width: 0;
}

.history-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.625rem;
}

.history-panel__lede {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.separator {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.separator--inset {
  margin: 0.125rem 0 0.25rem;
}

.select-wrap {
  position: relative;
  display: inline-flex;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 0.625rem;
  top: 50%;
  width: 0.375rem;
  height: 0.375rem;
  border-right: 1.5px solid var(--muted-foreground);
  border-bottom: 1.5px solid var(--muted-foreground);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.select {
  appearance: none;
  min-width: 7.5rem;
  padding: 0.4375rem 1.75rem 0.4375rem 0.625rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.select:hover {
  background: var(--muted);
}

.select:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgba(239, 237, 230, 0.08);
}

.palette-panel {
  display: grid;
  gap: 0.5rem;
}

.palette-panel__label {
  margin: 0;
}

.palette-panel__grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: 0.5rem;
}

.swatch-card__role {
  display: block;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: capitalize;
  line-height: 1.2;
}

/* Pick bar */
.pick-bar {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.pick-bar__fields {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 8px;
}

.pick-bar__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.offset__wheel {
  position: relative;
  width: 112px;
  height: 112px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: crosshair;
  background: conic-gradient(
    from 0deg,
    oklch(0.65 0.22 0),
    oklch(0.65 0.22 60),
    oklch(0.65 0.22 120),
    oklch(0.65 0.22 180),
    oklch(0.65 0.22 240),
    oklch(0.65 0.22 300),
    oklch(0.65 0.22 360)
  );
  mask: radial-gradient(circle, transparent 38%, black 39%);
  -webkit-mask: radial-gradient(circle, transparent 38%, black 39%);
}

.offset__wheel-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.offset__hex-label {
  display: grid;
  gap: 4px;
}

.offset__hex-label-text {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.offset__hex {
  width: 100%;
  min-height: 40px;
  resize: none;
  background: var(--card);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.3;
  outline: none;
}

.offset__hex:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgba(239, 237, 230, 0.08);
}

/* Theme chips */
.theme-picker {
  min-width: 0;
}

.theme-picker__label {
  display: block;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.theme-picker__hint {
  margin: 0 0 6px;
  font-size: 0.6875rem;
  line-height: 1.35;
  color: var(--muted-foreground);
}

.theme-picker__hint a {
  color: rgba(239, 237, 230, 0.65);
}

.theme-picker__hint a:hover {
  color: var(--foreground);
}

.theme-picker__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}

.theme-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 5px 10px 5px 6px;
  background: var(--card);
  color: var(--foreground);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.theme-chip:hover {
  background: var(--muted);
}

.theme-chip.is-active {
  border-color: var(--palette-accent-border);
  background: var(--palette-accent-soft);
}

.theme-chip__dot {
  width: 14px;
  height: 14px;
  border-radius: 9999px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

/* Preview */
.preview-card {
  margin-bottom: 12px;
}

.ratio-bar {
  display: flex;
  height: 6px;
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.ratio-bar__segment {
  display: block;
  min-width: 0;
}

.ratio-bar__segment.is-selected {
  box-shadow: inset 0 0 0 1px var(--palette-accent);
}

.preview-frame {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 160px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  transition: background 0.2s ease;
}

.preview-frame__aside {
  grid-row: 1 / 3;
  width: 2.25rem;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-frame__aside[hidden] {
  display: none;
}

.preview-frame__body {
  padding: 1rem 1.125rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.375rem;
}

.preview-frame__headline {
  margin: 0;
  font-size: clamp(1.125rem, 3vw, 1.5rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.preview-frame__sub {
  margin: 0;
  font-family: var(--font-accent);
  font-style: italic;
  font-size: 0.875rem;
  line-height: 1.25;
}

.preview-frame__copy {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  opacity: 0.9;
}

.preview-frame__hl {
  padding: 0 0.15em;
  border-radius: 2px;
  font-weight: 600;
}

.preview-frame__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.125rem;
}

.preview-frame__btn {
  border: 1px solid transparent;
}

.preview-frame__chip[hidden] {
  display: none;
}

.preview-frame__footer {
  grid-column: 1 / -1;
  padding: 0.4375rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-frame__footer[hidden] {
  display: none;
}

.role-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.15rem 0.5rem 0.15rem 0.3rem;
  background: var(--muted);
  font-size: 0.625rem;
}

.role-badge.is-selected {
  border-color: var(--palette-accent-border);
  background: var(--palette-accent-soft);
}

.role-badge__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.role-badge__label {
  font-weight: 600;
}

.role-badge__hex {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--muted-foreground);
}

/* Swatches */
.swatch-card {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 0.3125rem;
  min-width: 0;
  cursor: pointer;
}

.swatch-card__chip {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: calc(var(--radius) - 2px);
  padding: 0;
  cursor: pointer;
  transition: box-shadow 0.15s ease, outline 0.15s ease;
}

.swatch-card.is-selected .swatch-card__chip {
  outline: 2px solid var(--palette-accent);
  outline-offset: 1px;
}

.swatch-card.is-locked .swatch-card__chip {
  box-shadow: inset 0 0 0 2px var(--palette-accent);
}

.swatch-card__meta {
  min-width: 0;
}

.swatch-card__hex {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  letter-spacing: 0.03em;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.swatch-card__lock {
  width: 100%;
}

.swatch-card__lock[aria-pressed="true"] {
  border-color: var(--palette-accent-border);
  color: var(--palette-accent);
}

.result-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 0.625rem;
  min-width: 0;
  position: relative;
}

/* Share menu — click-to-open dropdown */
.share-menu {
  position: relative;
  flex-shrink: 0;
}

.share-menu__trigger {
  gap: 0.375rem;
}

.share-menu__icon {
  flex-shrink: 0;
}

.share-menu__panel {
  position: fixed;
  z-index: 100;
  min-width: 10.5rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  display: grid;
  gap: 0.125rem;
}

.share-menu__panel[hidden] {
  display: none;
}

.share-menu__option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4375rem 0.625rem;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--foreground);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.share-menu__option:hover {
  background: var(--muted);
}

.share-menu__option.is-active {
  background: var(--palette-accent-soft);
}

/* History */
.history-card__clear {
  flex-shrink: 0;
}

.history-empty {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted-foreground);
}

.history-empty[hidden] {
  display: none;
}

.history-list {
  display: grid;
  gap: 0.375rem;
}

.history-empty[hidden] {
  display: none;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-display);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.history-item:hover {
  background: var(--muted);
  border-color: rgba(239, 237, 230, 0.18);
}

.history-item.is-active {
  border-color: var(--palette-accent-border);
}

.history-item__swatches {
  display: inline-flex;
  overflow: hidden;
  border-radius: 9999px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.history-item__swatch {
  display: block;
  width: 0.875rem;
  height: 0.875rem;
}

.history-item__meta {
  min-width: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item__time {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .result-toolbar {
    width: 100%;
    justify-content: space-between;
  }

  .share-menu {
    margin-left: auto;
  }

  .pick-bar {
    flex-direction: column;
    align-items: center;
  }

  .pick-bar__fields {
    width: 100%;
  }

  .offset__wheel {
    width: 100px;
    height: 100px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .preview-frame,
  .swatch-card__chip,
  .btn,
  .theme-chip,
  .share-menu__option {
    transition: none;
  }
}
