/* Beer Game: uses the shared colors and buttons from style.css; adds forms, cards and the chart. */

/* Chart line colors, one per business (checked for color-blind safety in both themes). */
:root {
  --s-retailer: #2a78d6;
  --s-wholesaler: #eb6834;
  --s-distributor: #1baf7a;
  --s-factory: #eda100;
}

:root[data-theme="dark"] {
  --s-retailer: #3987e5;
  --s-wholesaler: #d95926;
  --s-distributor: #199e70;
  --s-factory: #c98500;
}

.bg-stack {
  display: grid;
  gap: 16px;
}

.bg-stack h1,
.bg-stack h2,
.bg-stack p {
  margin: 0;
}

.bg-stack h2 {
  font-size: 1.25rem;
  margin-top: 8px;
}

.bg-stack .intro {
  margin-bottom: 0;
}

/* Fields (buttons are shared, in style.css) */
.bg-field {
  display: grid;
  gap: 4px;
  font-weight: 600;
}

.bg-stack input[type="text"],
.bg-stack input[type="password"],
.bg-stack input[type="number"],
.bg-stack select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

.bg-stack input:disabled {
  opacity: 0.55;
}

.bg-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.bg-row .bg-num {
  width: 140px;
  font-size: 1.25rem;
}

.bg-row .bg-link {
  flex: 1 1 240px;
  width: auto;
}

/* Cards and text */
.bg-choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 600px) {
  .bg-choices {
    grid-template-columns: repeat(2, 1fr);
  }
}

.bg-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 20px;
  border: 2px solid var(--edge);
  border-radius: 4px;
  background: var(--surface);
}

.bg-card h2,
.bg-card h3 {
  margin: 0;
  font-size: 1.125rem;
}

.bg-card p {
  margin: 0;
}

.bg-hint,
.bg-note {
  color: var(--text-muted);
}

.bg-strong {
  font-weight: 600;
}

.bg-status {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 4px;
  background: var(--surface);
  margin: 0 0 16px;
}

.bg-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
}

.bg-how summary {
  padding: 10px 0;
  font-weight: 600;
  cursor: pointer;
}

.bg-how ul {
  margin: 0;
  padding-left: 20px;
}

.bg-how li + li {
  margin-top: 6px;
}

/* Lobby */
.bg-roles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 600px) {
  .bg-roles {
    grid-template-columns: repeat(2, 1fr);
  }
}

.bg-role {
  grid-template-columns: 1fr auto;
  align-items: center;
}

/* Play */
.bg-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}

.bg-week {
  font-weight: 600;
  color: var(--text-muted);
}

.bg-numbers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 0;
}

@media (min-width: 600px) {
  .bg-numbers {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .bg-numbers {
    grid-template-columns: repeat(4, 1fr);
  }
}

.bg-numbers div {
  position: relative;
  padding: 12px 14px;
  border: 2px solid var(--edge);
  border-radius: 4px;
  background: var(--surface);
}

.bg-numbers dt {
  font-size: 0.875rem;
  font-weight: 600;
}

/* Pictures for the weekly numbers: crates, a truck, coins and a purchase order. */
.bg-pic-box {
  margin: 6px 0 2px;
}

.bg-pic {
  display: block;
  width: 100%;
  max-width: 120px;
  height: 77px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.bg-pic .bg-fill {
  fill: var(--accent);
}

.bg-pic .bg-paper {
  fill: var(--surface);
}

.bg-pic .bg-wheel {
  fill: var(--surface);
}

.bg-pic .bg-floor {
  stroke: var(--text-muted);
  stroke-width: 2;
}

.bg-pic text {
  fill: currentColor;
  stroke: none;
  text-anchor: middle;
  font-family: inherit;
}

.bg-pic .bg-po-head {
  fill: var(--on-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.bg-pic .bg-po-qty {
  font-size: 22px;
  font-weight: 800;
}

.bg-pic .bg-po-unit {
  font-size: 9px;
}

.bg-pic-key {
  font-size: 0.8125rem;
}

/* Hidden on screen but still read out by screen readers. */
.bg-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Supply chain picture: factory → distributor → wholesaler → retailer → shoppers. */
.bg-chain-box {
  margin: 0;
  padding: 16px 12px 12px;
  border: 2px solid var(--edge);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--shadow);
}

.bg-chain {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin: 0;
  padding: 0;
  list-style: none;
}

.bg-node {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
  font-size: 0.6875rem;
  letter-spacing: -0.01em;
}

/* The dashed track between businesses, drawn behind the icons. */
.bg-node:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 22px;
  left: calc(50% + 26px);
  right: calc(-50% + 26px);
  border-top: 3px dashed var(--text-muted);
}

.bg-node-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 4px;
  background: var(--header-bg);
  color: var(--header-text);
}

.bg-node-icon svg {
  width: 26px;
  height: 26px;
}

.bg-node b {
  font-weight: 600;
}

/* "(you)" goes on its own line so names never break mid-word on phones. */
.bg-node b small {
  display: block;
  font-size: inherit;
  font-weight: 600;
}

/* Your business: yellow badge with a thick outline, and "(you)" in its name. */
.bg-you .bg-node-icon {
  background: var(--accent);
  color: var(--on-accent);
  outline: 3px solid var(--edge);
  outline-offset: 2px;
}

.bg-you b {
  font-weight: 800;
}

.bg-end .bg-node-icon {
  background: transparent;
  color: var(--text);
  border: 2px dashed var(--border);
}

.bg-chain-flow {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 10px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

@media (min-width: 600px) {
  .bg-node {
    font-size: 0.9375rem;
  }

  .bg-node-icon {
    width: 56px;
    height: 56px;
  }

  .bg-node-icon svg {
    width: 32px;
    height: 32px;
  }

  .bg-node:not(:last-child)::after {
    top: 28px;
    left: calc(50% + 34px);
    right: calc(-50% + 34px);
  }
}

.bg-numbers dd {
  margin: 0;
}

.bg-numbers dd.bg-big-num {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bg-numbers dd.bg-hint {
  font-size: 0.8125rem;
  font-weight: 400;
}

/* Tables */
.bg-scroll {
  overflow-x: auto;
}

.bg-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.bg-table th,
.bg-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.bg-table th:first-child,
.bg-table td:first-child {
  text-align: left;
}

.bg-table thead th {
  font-size: 0.875rem;
}

.bg-me td {
  font-weight: 700;
  background: var(--surface);
}

.bg-board td:nth-child(2),
.bg-board th:nth-child(2) {
  text-align: left;
  white-space: normal;
}

/* Score card */
.bg-scorecard {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 28px 20px;
  border: 2px solid var(--edge);
  border-radius: 4px;
  box-shadow: 4px 4px 0 var(--shadow);
  background: var(--surface);
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .bg-scorecard {
    animation: bg-card-in 0.5s ease-out both;
  }
}

@keyframes bg-card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.bg-eyebrow {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.bg-team {
  font-weight: 600;
}

.bg-total {
  font-size: 1.125rem;
  font-weight: 600;
}

.bg-total span {
  display: block;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.bg-score-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  margin: 8px 0 0;
}

@media (min-width: 900px) {
  .bg-role-costs {
    grid-template-columns: repeat(4, 1fr);
  }
}

.bg-score-grid div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

/* Your own business on the score card: thicker border plus "(you)" in its label. */
.bg-score-grid .bg-mine {
  border: 2px solid var(--text);
}

.bg-score-grid dt {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.bg-score-grid dd {
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bg-score-grid dd.bg-cost {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.bg-score-grid dd.bg-hint {
  font-size: 0.8125rem;
  font-weight: 400;
}

/* Lecturer's board */
.bg-code-big {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.1;
}

.bg-games {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 600px) {
  .bg-games {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 900px) {
  .bg-games {
    grid-template-columns: repeat(3, 1fr);
  }
}

.bg-game {
  gap: 8px;
  padding: 16px;
}

.bg-game[data-status="playing"] {
  border-left: 4px solid var(--text);
}

.bg-game-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.bg-tag {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.bg-seats {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bg-seats li {
  display: grid;
  grid-template-columns: 6.5rem 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border-bottom: 1px solid var(--border);
}

.bg-seats li:last-child {
  border-bottom: 0;
}

.bg-seat-role {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.bg-seat-name {
  overflow-wrap: anywhere;
}

/* Stock, orders owed and cost so far for one business, on the lecturer's board */
.bg-seat-stats {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* "Signed in as …" with a Sign out button, above every signed-in screen */
.bg-who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.bg-x {
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 1.25rem;
  cursor: pointer;
}

.bg-x:hover {
  border-color: var(--border);
  color: var(--text);
}

/* Chart */
.bg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 0.875rem;
}

.bg-key::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 0;
  margin-right: 6px;
  vertical-align: middle;
  border-top: 3px solid var(--c);
}

.bg-key-demand::before {
  border-top: 2px dashed var(--text-muted);
}

.bg-chart {
  position: relative;
  min-width: 0;
}

.bg-chart svg {
  display: block;
  max-width: 100%;
}

.bg-grid {
  stroke: var(--border);
  stroke-opacity: 0.35;
}

.bg-axis {
  fill: var(--text-muted);
  font-size: 12px;
}

.bg-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.bg-demand {
  stroke: var(--text-muted);
  stroke-dasharray: 5 4;
}

.bg-cross {
  stroke: var(--text-muted);
  stroke-width: 1;
}

.bg-tip {
  position: absolute;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font-size: 0.875rem;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.bg-tip[hidden] {
  display: none;
}
