.hive-builder {
  --hive-cell-size: clamp(2.9rem, 13vw, 3.7rem);
  --hive-edge: #7a5f2a;
  position: relative;
  margin-bottom: 1rem;
  background: radial-gradient(ellipse at 24% 28%, #a16f2524, transparent 55%), var(--surface);
}
.hive-builder-heading { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: .85rem; }
.hive-builder-heading h2 { margin: .25rem 0 .45rem; }
.hive-builder-heading select { min-width: 8rem; }
.hive-workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .95fr); align-items: start; gap: clamp(.8rem, 4vw, 2.25rem); margin-top: 1rem; }
.hive-board, .hive-build-controls { min-width: 0; border: 1px solid var(--line); border-radius: .8rem; padding: clamp(.65rem, 2vw, 1rem); background: #080d1899; }
.hive-board { text-align: center; }
/* In-game hive: 5 columns of flat-topped hexagons, columns 2 and 4 raised half a slot. */
#hive-slots {
  --hive-h: calc(var(--hive-cell-size) * .866);
  --hive-gap: .2rem;
  display: grid;
  grid-template-columns: repeat(4, calc(var(--hive-cell-size) * .75 + var(--hive-gap))) var(--hive-cell-size);
  grid-auto-rows: calc(var(--hive-h) + var(--hive-gap));
  justify-content: center;
  width: max-content;
  max-width: 100%;
  margin: .75rem auto .5rem;
  padding: calc(var(--hive-h) / 2 + .7rem) .8rem .8rem;
  border: 1px solid #f6bd3826;
  border-radius: 1.1rem;
  background: radial-gradient(ellipse at 50% 30%, #f6bd3817, transparent 70%), #05080fb3;
  box-shadow: inset 0 0 30px #00000080;
}
#hive-slots[data-color="Red"] { --hive-edge: #a8545a; }
#hive-slots[data-color="Blue"] { --hive-edge: #4f78a8; }
#hive-slots[data-color="White"] { --hive-edge: #8d9cad; }
.hive-row { display: contents; }
.hive-row > .hive-cell:nth-child(2), .hive-row > .hive-cell:nth-child(4) { transform: translateY(-50%); }
.hive-cell {
  --hex: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: var(--hive-cell-size);
  height: var(--hive-h);
  border: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition: filter var(--ease);
}
.hive-cell::before, .hive-cell::after { position: absolute; z-index: -1; content: ""; inset: 0; clip-path: var(--hex); background: var(--hive-edge); }
.hive-cell::after { inset: 2px 2.5px; background: radial-gradient(circle at 50% 40%, #2c2110, #15100a 75%); }
.hive-cell:has(img)::after { background: radial-gradient(circle at 50% 40%, #3d2d12, #1d160b 75%); }
.hive-cell[data-gifted="true"]::before { background: #e9ac2c; }
.hive-cell[aria-pressed="true"]::before { background: #fff3ce; }
.hive-cell:hover, .hive-cell:focus-visible { z-index: 1; outline: none; filter: brightness(1.18) drop-shadow(0 0 6px #f6bd3866); }
.hive-cell img { width: 74%; height: 74%; object-fit: contain; filter: drop-shadow(0 1px 1px #0009); }
.hive-cell .hive-slot-gear { position: absolute; z-index: 2; right: 11%; bottom: 5%; width: 34%; height: auto; filter: drop-shadow(0 0 1px #000) drop-shadow(0 1px 1px #000a); pointer-events: none; }
.hive-empty-slot { color: #f6bd3859; font-size: 1.1rem; }
.hive-level-badge { position: absolute; z-index: 2; bottom: 7%; left: 13%; padding: 0 .18rem; border-radius: .25rem; background: #080d18d9; color: var(--gold-light); font: 700 .6rem/1.35 var(--mono); }
.hive-cell[data-mutation="true"] .hive-level-badge::before { content: ""; display: inline-block; width: .32rem; height: .32rem; margin-right: .17rem; border-radius: 50%; background: #e7a9ff; vertical-align: .08rem; }
.hive-bee-fallback { color: var(--gold-light); font: 700 .78rem var(--mono); }
.hive-slot-preview { min-height: 2.6rem; margin: .5rem 0 0; font-size: .88rem; color: var(--gold-light); }
.hive-keys { margin: .25rem 0 0; font-size: .76rem; }
.hive-toolbar { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.hive-toolbar .button { min-height: 2.25rem; padding: .3rem .8rem; font-size: .82rem; }
.hive-build-controls { display: grid; gap: .8rem; align-content: start; }
.hive-group { display: grid; gap: .6rem; padding: .85rem; border: 1px solid var(--line); border-radius: .7rem; background: #0c1322b3; }
.hive-group h3 { margin: 0; color: var(--gold-light); font: 700 .72rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: .1em; }
.hive-build-controls label, .hive-transfer { width: 100%; }
.hive-load-row { display: flex; align-items: end; gap: .45rem; }
.hive-load-row label { flex: 1; min-width: 0; }
details.hive-group { border-top: 1px solid var(--line); padding-top: .85rem; }
details.hive-group summary { margin-bottom: 0; cursor: pointer; }
details.hive-group[open] summary { margin-bottom: .55rem; }
.hive-stats { color: var(--gold-light); font: 650 .9rem/1.45 var(--mono); }
.hive-action-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.hive-transfer { border-top: 1px solid var(--line); padding-top: .5rem; }
.hive-transfer summary { color: var(--gold-light); margin-bottom: .45rem; }
.hive-transfer textarea { width: 100%; resize: vertical; background: var(--background); color: var(--text); border: 1px solid var(--control-line); border-radius: .5rem; padding: .55rem; font: .82rem var(--mono); }
.hive-references { margin-top: .8rem; }
.hive-references a { color: var(--gold-light); text-decoration: underline; }
.hive-builder .hive-dialog { width: min(58rem, calc(100% - 1.5rem)); }
.hive-editor-layout { display: grid; grid-template-columns: minmax(0, .72fr) minmax(0, 1.28fr); gap: .85rem; }
.hive-slot-controls, .hive-roster { min-width: 0; }
#hive-config { min-width: 0; padding: .65rem; border: 1px solid var(--line); border-radius: .55rem; margin: .5rem 0; display: grid; gap: .5rem; }
#hive-config:disabled { opacity: .55; }
.hive-gifted { display: flex; gap: .5rem; align-items: center; min-height: 2.75rem; }
.hive-gifted input[type="checkbox"] { appearance: auto; min-height: 0; width: 1rem; height: 1rem; margin: 0; padding: 0; accent-color: var(--gold); }
.hive-roster-filters { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.hive-roster-filters label:first-child { grid-column: 1 / -1; }
#hive-roster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .36rem; margin-top: .4rem; max-height: 16rem; overflow: auto; padding: .2rem; }
.hive-bee-option { min-width: 0; display: flex; align-items: center; gap: .4rem; text-align: left; padding: .4rem; min-height: 2.75rem; background: var(--raised); color: var(--text); border: 1px solid var(--line); border-radius: .5rem; font-size: .84rem; }
.hive-bee-option:hover, .hive-bee-option[aria-pressed="true"] { border-color: var(--gold); }
.hive-bee-option img, .hive-bee-option .hive-bee-fallback { flex: none; width: 1.8rem; height: 1.8rem; object-fit: contain; display: grid; place-items: center; }
.hive-bee-option small { display: block; color: var(--muted); font-size: .72rem; }
#hive-editor-status { margin-top: .5rem; }
#hive-confirm form { margin-top: .85rem; }
@media (max-width: 700px) {
  .hive-workspace, .hive-editor-layout { grid-template-columns: minmax(0, 1fr); }
  .hive-roster { grid-row: 1; }
  #hive-roster { max-height: 9.5rem; }
}
@media (max-width: 355px) {
  .hive-builder { --hive-cell-size: 2.45rem; }
  .hive-bee-option { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .hive-cell:hover, .hive-cell:focus-visible { filter: brightness(1.18); }
}

#hive-breakdown { margin: .4rem 0 0; }
#hive-breakdown dt { color: var(--gold-light); font-weight: 650; }
#hive-breakdown dd { margin: 0 0 .4rem; color: var(--muted); overflow-wrap: anywhere; }

.hive-cell[data-gifted="true"]::after { background: radial-gradient(circle at 50% 42%, #6b4b12, #33230a 72%); }
.hive-cell[data-gifted="true"][aria-pressed="true"]::before { background: #fff3ce; }
.hive-gifted-badge { position: absolute; z-index: 2; top: 3%; left: 50%; transform: translateX(-50%); color: #ffe08a; font-size: .55rem; line-height: 1; text-shadow: 0 0 3px #000; }
.hive-gifted-key { display: flex; justify-content: center; align-items: center; gap: .4rem; margin: 0; color: var(--muted); font-size: .8rem; }
.hive-gifted-key span { display: inline-block; width: 1.15rem; height: 1rem; background: #e9ac2c; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.hive-gifted-label { display: inline-block; margin-top: .35rem; padding: .15rem .4rem; border: 1px solid #dfaa4a; border-radius: .3rem; background: #4b351c; color: #ffe7a3; font-size: .85rem; }

.hive-board { position: relative; }
.hive-insight {
  position: absolute;
  z-index: 4;
  top: 3rem;
  left: calc(100% - .6rem);
  width: min(21rem, 38vw);
  max-height: min(29rem, calc(100vh - 20px));
  max-height: min(29rem, calc(100dvh - 20px));
  overflow: auto;
  padding: .8rem;
  border: 1px solid var(--control-line);
  border-radius: .8rem;
  background: var(--surface);
  box-shadow: 0 16px 40px #02050cc9;
  text-align: left;
}
.hive-insight-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .5rem; }
.hive-insight-head h3 { font-size: 1.12rem; }
.hive-insight-config { margin-bottom: .7rem; }
.hive-insight-config p + p { margin-top: .3rem; }
.hive-advice-card { margin-top: .5rem; padding: .55rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--background); }
.hive-advice-card p { margin: .25rem 0 .45rem; }
.hive-editor-advice { margin-top: .7rem; }
@media (max-width: 700px) {
  .hive-insight { position: static; width: 100%; max-height: none; margin-top: .55rem; }
}
[data-motion-paused] .hive-insight { animation: none; }

/* Short transitions keep feedback in step with slot selection. */
@keyframes hive-insight-in {
  from { opacity: .55; transform: translateY(2px) scale(.99); }
  to { opacity: 1; transform: none; }
}
@keyframes hive-art-in {
  from { opacity: .4; scale: .82; }
  to { opacity: 1; scale: 1; }
}
@keyframes hive-option-in {
  from { opacity: .68; translate: 0 3px; }
  to { opacity: 1; translate: 0; }
}
.hive-insight { animation: hive-insight-in 130ms ease-out both; }
.hive-insight-config, .hive-insight-advice { animation: hive-option-in 115ms ease-out both; }
.hive-builder dialog[open] { animation: hive-insight-in 185ms cubic-bezier(.2,.7,.3,1) both; }
.hive-slot-art { animation: hive-art-in 155ms ease-out both; }
.hive-cell::before, .hive-cell::after { transition: background-color var(--ease), inset var(--ease); }
.hive-gifted-badge, .hive-gifted-label { animation: hive-art-in 145ms ease-out both; }
.hive-bee-option {
  animation: hive-option-in 135ms ease-out both;
  transition: border-color var(--ease), background-color var(--ease), transform var(--ease);
}
.hive-bee-option:hover { background-color: #223149; transform: translateY(-1px); }
.hive-bee-option[aria-pressed="true"] { background-color: #46351e; }
.hive-bee-option:active { transform: translateY(1px); }
.hive-advice-card { animation: hive-option-in 145ms ease-out both; }
.hive-advice-card:focus-within { border-color: var(--gold); }
[data-motion-paused] .hive-builder *, [data-motion-paused] .hive-builder *::before, [data-motion-paused] .hive-builder *::after {
  animation: none !important;
  transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  .hive-bee-option:hover, .hive-bee-option:active { transform: none; }
}


@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion-paused]) .hive-cell:active { scale: .96; }
  :root:not([data-motion-paused]) .hive-cell {
    transition: scale var(--motion-press) var(--motion-out), filter var(--motion-control);
  }
  :root:not([data-motion-paused]) .hive-slot-art {
    animation-duration: var(--motion-control);
    animation-timing-function: var(--motion-out);
  }
  :root:not([data-motion-paused]) .hive-empty-slot { animation: hive-art-in var(--motion-control) var(--motion-out) both; }
  :root:not([data-motion-paused]) .hive-cell[data-mutation="true"] .hive-level-badge::before {
    animation: hive-art-in var(--motion-control) var(--motion-out) both;
  }
}

/* Keep the position and state indicator when polygon clipping is unavailable. */
@supports not (clip-path: polygon(0 0, 100% 0, 50% 100%)) {
  .hive-cell::before, .hive-cell::after { border-radius: 28%; }
}
.hive-builder .hive-cell:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: -3px;
}