:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #1c2526;
  --muted: #607071;
  --line: #d8dfdb;
  --accent: #0f7f83;
  --accent-2: #d89c24;
  --danger: #b6454c;
  --empty: #fbfaf5;
  --shadow: 0 18px 40px rgba(20, 32, 31, 0.11);
  --blue: #1688ad;
  --gray: #7b858d;
  --brown: #9a623d;
  --green: #6d9e3d;
  --yellow: #e6b832;
  --red: #c64f55;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 127, 131, 0.08), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  min-height: 38px;
  padding: 0 12px;
}

button:hover {
  border-color: #a8b8b4;
}

button:focus-visible,
.hex-group:focus-visible {
  outline: 3px solid rgba(15, 127, 131, 0.35);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin: 0 auto 16px;
  max-width: 1280px;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.1;
  margin: 0;
}

.topbar p {
  color: var(--muted);
  margin: 4px 0 0;
}

.actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.icon-button {
  font-size: 22px;
  line-height: 1;
  min-width: 42px;
  padding: 0;
}

.workspace {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(230px, 280px) minmax(420px, 1fr) minmax(250px, 310px);
  margin: 0 auto;
  max-width: 1280px;
}

.sidebar,
.board-stage {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  align-self: start;
  padding: 16px;
}

.tool-section + .tool-section {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

.tool-section h2 {
  font-size: 13px;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.segmented {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  min-height: 34px;
  padding: 0 8px;
}

.segmented button.active {
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(20, 32, 31, 0.13);
  color: var(--accent);
  font-weight: 700;
}

.palette {
  display: grid;
  gap: 8px;
}

.animal-picker {
  position: relative;
}

.animal-select {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  font: inherit;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto 10px;
  min-height: 38px;
  padding: 6px 9px 6px 10px;
  text-align: left;
  width: 100%;
}

.animal-picker-button::after {
  border: solid var(--muted);
  border-width: 0 1.5px 1.5px 0;
  content: "";
  display: block;
  height: 7px;
  justify-self: end;
  transform: rotate(45deg) translateY(-2px);
  width: 7px;
}

.animal-select-label,
.animal-option-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.animal-menu {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 30px rgba(20, 32, 31, 0.16);
  left: 0;
  max-height: 410px;
  overflow-y: auto;
  padding: 5px;
  position: absolute;
  right: 0;
  top: calc(100% + 5px);
  z-index: 20;
}

.animal-option {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 40px;
  padding: 6px 8px;
  text-align: left;
  width: 100%;
}

.animal-option:hover,
.animal-option:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.animal-option.selected {
  background: #e8efec;
  font-weight: 700;
}

.animal-requirement-strip {
  align-items: center;
  display: inline-flex;
  flex-shrink: 0;
  gap: 5px;
}

.animal-strip-item {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  display: inline-flex;
  height: 28px;
  justify-content: center;
  position: relative;
  width: 28px;
}

.animal-strip-item.target {
  border-color: rgba(216, 156, 36, 0.8);
  box-shadow: 0 0 0 2px rgba(216, 156, 36, 0.13);
}

.animal-strip-item.target::after {
  background: var(--accent-2);
  border: 1px solid rgba(28, 37, 38, 0.18);
  content: "";
  height: 7px;
  position: absolute;
  right: -1px;
  top: -1px;
  transform: rotate(45deg);
  width: 7px;
}

.animal-summary {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin-top: 8px;
  min-height: 36px;
}

.animal-preview {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.animal-preview-empty {
  color: var(--muted);
  font-size: 13px;
}

.animal-points {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.animal-point {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px;
}

.animal-pattern {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.animal-pattern-map {
  display: block;
  height: auto;
  max-width: 176px;
  width: min(100%, 176px);
}

.animal-pattern-edge {
  stroke: rgba(96, 112, 113, 0.2);
  stroke-linecap: round;
  stroke-width: 3;
}

.animal-pattern-hex {
  fill: var(--empty);
  stroke: #b9c2bd;
  stroke-width: 2;
}

.animal-pattern-cell.target .animal-pattern-hex {
  stroke: var(--accent-2);
  stroke-width: 3;
}

.animal-pattern-token {
  stroke: rgba(28, 37, 38, 0.28);
  stroke-width: 1;
}

.animal-pattern-cube {
  fill: var(--accent-2);
  stroke: rgba(28, 37, 38, 0.25);
  stroke-width: 1;
}

.animal-requirement {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  grid-template-rows: 38px auto;
  justify-items: center;
  min-width: 52px;
  padding: 7px 6px 6px;
}

.animal-requirement.target {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(216, 156, 36, 0.16);
}

.animal-requirement-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  max-width: 48px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spec-icon {
  align-items: end;
  display: inline-grid;
  grid-auto-flow: column;
  grid-template-columns: 1fr;
  height: 36px;
  justify-items: center;
  position: relative;
  width: 30px;
}

.spec-icon.compact {
  height: 24px;
  width: 22px;
}

.spec-token {
  border: 1px solid rgba(28, 37, 38, 0.25);
  border-radius: 50%;
  box-shadow: 0 1px 1px rgba(28, 37, 38, 0.16);
  display: block;
  grid-area: 1 / 1;
  height: 24px;
  width: 24px;
}

.spec-icon.compact .spec-token {
  height: 16px;
  width: 16px;
}

.wildcard-token {
  align-items: center;
  background: var(--surface-2);
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  justify-content: center;
}

.piece-button {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 22px 1fr auto;
  justify-items: start;
  padding: 7px 10px;
  text-align: left;
}

.piece-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 127, 131, 0.15);
}

.swatch {
  border: 1px solid rgba(28, 37, 38, 0.2);
  border-radius: 50%;
  display: inline-block;
  height: 18px;
  width: 18px;
}

.swatch.blue {
  background: var(--blue);
}

.swatch.gray {
  background: var(--gray);
}

.swatch.brown {
  background: var(--brown);
}

.swatch.green {
  background: var(--green);
}

.swatch.yellow {
  background: var(--yellow);
}

.swatch.red {
  background: var(--red);
}

.fill-blue {
  background: var(--blue);
  fill: var(--blue);
}

.fill-gray {
  background: var(--gray);
  fill: var(--gray);
}

.fill-brown {
  background: var(--brown);
  fill: var(--brown);
}

.fill-green {
  background: var(--green);
  fill: var(--green);
}

.fill-yellow {
  background: var(--yellow);
  fill: var(--yellow);
}

.fill-red {
  background: var(--red);
  fill: var(--red);
}

.piece-limit {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.selected-cell {
  color: var(--muted);
  min-height: 104px;
}

.selected-title {
  color: var(--ink);
  display: flex;
  font-weight: 700;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stack-chips,
.legal-next {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  gap: 5px;
  min-height: 24px;
  padding: 2px 8px 2px 5px;
}

.chip-dot {
  border-radius: 50%;
  height: 12px;
  width: 12px;
}

.board-stage {
  min-height: 560px;
  padding: 18px;
}

.board-svg {
  display: block;
  height: min(68vh, 620px);
  margin: 0 auto;
  max-height: 620px;
  max-width: 100%;
  width: 100%;
}

.edge-line {
  stroke: rgba(96, 112, 113, 0.16);
  stroke-width: 2;
}

.hex {
  fill: var(--empty);
  stroke: #b9c2bd;
  stroke-width: 2;
  transition: fill 120ms ease, stroke 120ms ease, opacity 120ms ease;
}

.hex.fill-blue {
  fill: color-mix(in srgb, var(--blue) 26%, white);
}

.hex.fill-gray {
  fill: color-mix(in srgb, var(--gray) 28%, white);
}

.hex.fill-brown {
  fill: color-mix(in srgb, var(--brown) 26%, white);
}

.hex.fill-green {
  fill: color-mix(in srgb, var(--green) 28%, white);
}

.hex.fill-yellow {
  fill: color-mix(in srgb, var(--yellow) 34%, white);
}

.hex.fill-red {
  fill: color-mix(in srgb, var(--red) 28%, white);
}

.hex-group {
  cursor: pointer;
}

.hex-group:hover .hex {
  stroke: var(--accent);
  stroke-width: 3;
}

.hex-group.legal .hex {
  stroke: rgba(15, 127, 131, 0.9);
  stroke-dasharray: 7 5;
}

.hex-group.animal-target .hex {
  stroke: var(--accent-2);
  stroke-dasharray: 4 4;
  stroke-width: 4;
}

.hex-group.animal-target:hover .hex {
  stroke: #9b6b10;
}

.hex-group.selected .hex {
  stroke: var(--accent-2);
  stroke-width: 4;
}

.hex-group.has-cube .hex {
  stroke: #1c2526;
  stroke-width: 4;
}

.hex-group.has-cube.selected .hex {
  stroke: var(--accent-2);
}

.hex-group.blocked {
  opacity: 0.42;
}

.hex-label {
  fill: rgba(28, 37, 38, 0.72);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
  text-anchor: middle;
}

.stack-count {
  fill: #ffffff;
  font-size: 13px;
  font-weight: 800;
  pointer-events: none;
  text-anchor: middle;
}

.stack-count.dark {
  fill: #1c2526;
}

.mini-token {
  stroke: rgba(28, 37, 38, 0.28);
  stroke-width: 1;
}

.animal-cube {
  fill: #2a2520;
  stroke: #ffffff;
  stroke-width: 2;
}

.animal-cube-text {
  fill: #ffffff;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
  text-anchor: middle;
}

.status-line {
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin-top: 14px;
  min-height: 38px;
  padding-top: 12px;
}

.status-line.good {
  color: var(--accent);
}

.status-line.bad {
  color: var(--danger);
}

.score-total {
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
}

.score-total span {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

.score-total strong {
  color: var(--accent);
  font-size: 42px;
  line-height: 1;
}

.score-breakdown {
  display: grid;
  gap: 8px;
  margin: 0;
}

.score-row,
.counter-row,
.cube-count {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
}

.score-row dt,
.score-row dd {
  margin: 0;
}

.score-row dt,
.counter-label,
.cube-count span {
  color: var(--muted);
}

.score-row dd,
.cube-count strong {
  font-weight: 800;
}

.token-counters {
  display: grid;
  gap: 10px;
}

.counter-row {
  grid-template-columns: 18px 1fr auto;
}

.counter-bar {
  background: var(--surface-2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.counter-fill {
  height: 100%;
  width: 0;
}

.animal-scores {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
}

.animal-score-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.animal-score-name {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.animal-score-value {
  font-weight: 800;
}

.animal-score-empty {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .board-stage {
    min-height: auto;
  }

  .board-svg {
    height: 520px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .board-svg {
    height: 420px;
  }

  .actions button:not(.icon-button) {
    flex: 1 1 90px;
  }
}
