:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --ink: #16130f;
  --muted: #6a655c;
  --hair: #e6e2da;
  --surface: #f7f5f0;
  --danger: #b3261e;
  --font: 'Schibsted Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11100e;
    --ink: #f6f3ee;
    --muted: #a8a297;
    --hair: #2e2c27;
    --surface: #1c1b18;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

[hidden] { display: none !important; }

.sr-only {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Layout: one column on phones, wheel beside everything else on wider screens */
.app {
  display: grid;
  gap: 14px;
  max-width: 560px;
  margin-inline: auto;
  padding: calc(14px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.head h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}

.head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
}

/* Wheel */
.stage {
  position: relative;
  width: min(100%, 60svh);
  aspect-ratio: 1;
  margin-inline: auto;
  container-type: inline-size;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* A rotated square is wider than its box, and would otherwise make the page scroll mid-spin. */
.wheel-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.wheel {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  will-change: transform;
}

.wedge {
  cursor: pointer;
  transition: opacity 0.22s ease;
}

.wedge.off { opacity: 0.13; }

.wedge path { stroke-width: 0.8; }

.wedge text {
  fill: #16130f;
  stroke: rgba(255, 255, 255, 0.72);
  stroke-width: 5px;
  stroke-linejoin: round;
  paint-order: stroke;
  font-family: var(--font);
  font-weight: 650;
  letter-spacing: -0.005em;
  pointer-events: none;
}

.wheel.no-labels text { visibility: hidden; }

.empty-wheel { fill: var(--surface); stroke: var(--hair); stroke-width: 2; }

.outline {
  fill: none;
  pointer-events: none;
  stroke-linejoin: round;
}

.outline.halo { stroke: #ffffff; stroke-width: 11; }
.outline.line { stroke: #16130f; stroke-width: 5; }
.outline.hover { stroke: #ffffff; stroke-width: 5; }

.outline.pop { animation: pop 0.7s ease-out; }

@keyframes pop {
  0% { stroke-width: 18; }
}

.pointer {
  position: absolute;
  top: -1.4%;
  left: 50%;
  width: 4.4%;
  height: 4.6%;
  margin-left: -2.2%;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0;
  pointer-events: none;
}

.pearl {
  position: absolute;
  top: 0;
  left: 0;
  width: max(12px, 3.3%);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffffff 0 22%, #f4efe4 48%, #bdb5a4 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  will-change: transform;
}

.spin {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30.4%;
  height: 30.4%;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  font-size: 7cqw;
  font-weight: 900;
  letter-spacing: -0.03em;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.spin:active:not(:disabled) { transform: translate(-50%, -50%) scale(0.96); }

.spin:disabled { color: var(--muted); cursor: default; }

@media (hover: hover) {
  .spin:hover:not(:disabled) { background: var(--ink); color: var(--bg); }
}

/* Result: a paint-chip swatch with the flavour's own wheel colour */
.card {
  overflow: hidden;
  border: 1px solid var(--hair);
  border-radius: 6px;
}

.band {
  --band: linear-gradient(90deg, #ffd200, #4a9a4d, #1f76ae, #6a3a7c, #a81e22, #f6871f);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--band);
  color: var(--band-ink, #16130f);
  font-size: 14px;
  font-weight: 700;
  transition: background-color 0.12s linear;
}

.organic {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.organic svg, .leaf {
  width: 14px;
  height: 14px;
  flex: none;
  fill: currentColor;
}

.card-body { padding: 12px 14px 14px; }

.card-body h2 {
  margin: 0;
  min-height: 1.12em;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.12;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.card-body a {
  display: inline-block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  text-underline-offset: 3px;
}

.card-body a.none { visibility: hidden; }

/* Filters */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.chip small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.chip .dot {
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 50%;
}

.chip[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.chip[aria-pressed="true"] small { color: inherit; opacity: 0.75; }

.chip:disabled { cursor: default; }

@media (hover: hover) {
  .chip:hover:not(:disabled):not([aria-pressed="true"]) { border-color: var(--ink); }
  .browse:hover:not(:disabled) { border-color: var(--ink); }
}

.filter-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.filter-foot p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.notice {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.browse {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--hair);
  border-radius: 6px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
}

.foot {
  color: var(--muted);
  font-size: 12.5px;
}

.foot a { color: inherit; text-underline-offset: 2px; }

/* Edit sheet */
.sheet {
  width: min(1040px, calc(100vw - 32px));
  max-width: none;
  max-height: min(88svh, 900px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--hair);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
}

.sheet::backdrop { background: rgba(10, 8, 5, 0.5); }

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

.sheet-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.sheet-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  padding: 14px 16px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: end;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface);
}

.field { display: grid; gap: 4px; }

.field-name { grid-column: 1 / -1; }

.field label {
  font-size: 13px;
  font-weight: 700;
}

.field input, .field select, .link-row input {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--hair);
  border-radius: 6px;
  background: var(--bg);
  /* 16px stops iOS zooming the page when a field is focused */
  font-size: 16px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--ink);
}

.actions {
  display: flex;
  grid-column: 1 / -1;
  gap: 8px;
}

.primary {
  flex: 1;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  font-weight: 800;
}

.primary:disabled { opacity: 0.6; cursor: default; }

.form-error {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
}

.sheet-cols {
  margin-top: 6px;
  columns: 3 280px;
  column-gap: 22px;
}

.group h3 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 14px 4px 2px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
  break-after: avoid;
}

.group h3 small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.row {
  display: flex;
  align-items: center;
  gap: 2px;
  break-inside: avoid;
}

.row-name {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 40px;
  padding: 4px;
  border: 0;
  border-radius: 5px;
  background: none;
  font-size: 15px;
  line-height: 1.2;
  text-align: left;
  overflow-wrap: anywhere;
}

.row-name .swatch {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 3px;
}

.row-name .leaf { color: #3c8b45; }

.icon-btn {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
}

.icon-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.row.editing .row-name { font-weight: 800; }

@media (hover: hover) {
  .row-name:hover, .icon-btn:hover { background: var(--surface); }
  .icon-btn:hover { color: var(--ink); }
}

.sheet-empty {
  margin: 0;
  padding: 24px 16px;
  color: var(--muted);
  text-align: center;
}

.list-tools {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--hair);
}

.list-tools h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.list-tools p {
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.link-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.link-row input {
  min-width: 0;
  flex: 1;
  background: var(--surface);
  font-size: 14px;
}

@media (max-width: 640px) {
  .link-row input { font-size: 16px; }
}

.text-btn {
  min-height: 40px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
}

.toast button {
  flex: none;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid currentColor;
  border-radius: 6px;
  background: none;
  color: inherit;
  font-size: 14px;
  font-weight: 800;
}

/* Laptop and up, and phones held sideways */
@media (min-width: 900px), (min-width: 600px) and (orientation: landscape) {
  .app {
    grid-template-columns: minmax(0, 1fr) clamp(300px, 31vw, 410px);
    grid-template-rows: 1fr auto auto auto auto 1fr;
    column-gap: clamp(28px, 5vw, 76px);
    row-gap: 18px;
    max-width: 1320px;
    min-height: 100svh;
    padding: 24px clamp(20px, 4vw, 56px);
  }

  .stage {
    grid-column: 1;
    grid-row: 1 / -1;
    align-self: center;
    width: min(100%, calc(100svh - 48px), 820px);
  }

  .head { grid-column: 2; grid-row: 2; }
  .card { grid-column: 2; grid-row: 3; }
  .filters { grid-column: 2; grid-row: 4; }
  .foot { grid-column: 2; grid-row: 5; }

  .head h1 { font-size: clamp(34px, 3.6vw, 48px); }

  .band { min-height: 84px; }

  .card-body h2 { font-size: clamp(24px, 2.2vw, 30px); }

  .editor {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto auto;
  }

  .field-name { grid-column: auto; }

  .actions { grid-column: auto; }

  .primary { flex: none; }

  .form-error { grid-column: 1 / -1; }
}

/* Short windows: the side column scrolls, so keep the wheel in view instead of centring it */
@media (min-width: 900px) and (max-height: 740px), (min-width: 600px) and (orientation: landscape) and (max-height: 740px) {
  .stage {
    position: sticky;
    top: 24px;
    align-self: start;
  }

  .band { min-height: 44px; }
}

/* Full-screen sheet on phones */
@media (max-width: 640px) {
  .sheet {
    width: 100vw;
    height: 100svh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .sheet-head { padding-top: calc(12px + env(safe-area-inset-top)); }

  .toast { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
