:root {
  --bg: #eef6ef;
  --panel-bg: #ffffff;
  --text: #3a3a3a;
  --accent: #7cc576;
  --accent-dark: #4f9c4a;
  --health: #e2846b;
  --coin: #e8c547;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

.screen {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden {
  display: none !important;
}

/* Journey screen */

#hud {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px;
  background: var(--panel-bg);
  width: 100%;
  max-width: 900px;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.hud-row {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.hud-block {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-label {
  font-size: 0.8rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hud-sublabel {
  font-size: 0.8rem;
  color: #888;
  white-space: nowrap;
}

.bar {
  width: 140px;
  height: 14px;
  background: #eee;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid #ddd;
}

.bar-fill {
  height: 100%;
  transition: width 0.15s ease-out;
}

.health-fill {
  background: var(--health);
  width: 100%;
}

/* Low-health warning: a slow, soft pulse toward a deeper red (plus a faint
   glow around the bar) rather than a hard on/off blink. */
.bar.low-health {
  animation: low-health-glow 1.6s ease-in-out infinite alternate;
}

.bar.low-health .health-fill {
  animation: low-health-fill 1.6s ease-in-out infinite alternate;
}

@keyframes low-health-glow {
  from { box-shadow: 0 0 0 rgba(204, 59, 59, 0); }
  to { box-shadow: 0 0 6px rgba(204, 59, 59, 0.5); }
}

@keyframes low-health-fill {
  from { background: var(--health); }
  to { background: #cc3b3b; }
}

@media (prefers-reduced-motion: reduce) {
  .bar.low-health,
  .bar.low-health .health-fill {
    animation: none;
  }

  .bar.low-health .health-fill {
    background: #cc3b3b;
  }
}

/* Sprites (sprites.js) inline with text: small and crisp. */
.sprite-icon {
  width: 16px;
  height: 16px;
  margin-right: 4px;
  vertical-align: -3px;
  image-rendering: pixelated;
}

/* Amounts ("5 [coin]", see amountsWithIcons): the icon follows the number,
   the pair never wraps apart, and pairs are spaced from each other. */
.amount {
  white-space: nowrap;
}

.amount .sprite-icon {
  margin: 0 0 0 2px;
}

.amount + .amount {
  margin-left: 8px;
}

/* Generated from RESOURCES (resources.js); its items join the parent's layout. */
.resource-list {
  display: contents;
}

.resource-count {
  font-weight: 600;
  color: #b8901f;
}

.item-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.item-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.item-btn:not(:disabled):hover {
  background: var(--accent-dark);
}

.small-btn {
  padding: 4px 10px;
  font-size: 0.85rem;
}

.secondary-btn {
  background: #8a97a8;
}

.secondary-btn.active {
  background: var(--accent-dark);
}

#debug-coords {
  font-family: monospace;
  font-size: 0.85rem;
  color: #888;
}

.secondary-btn:hover {
  background: #6d7a8b;
}

.item-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f4f4f4;
  border-radius: 6px;
  padding: 4px 8px 4px 12px;
  font-size: 0.9rem;
  cursor: help;
}

.passive-tag {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
}

/* The main view, and (once unlocked) the parallel universes' panel on its
   right - the pair stays centred, so the main view shifts left. On narrow
   windows the panel wraps below it. */
.universe-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
  margin-top: 16px;
}

#world-canvas {
  flex: none;
  max-width: calc(100vw - 32px);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  background: #000;
}

.parallel-panel {
  flex: none;
  width: 420px;
  max-width: calc(100vw - 32px);
}

.parallel-totals {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: #666;
}

/* The more universes, the smaller each view, to fit the same square area:
   main.js sets --columns. */
.parallel-universes {
  --columns: 1;
  display: grid;
  grid-template-columns: repeat(var(--columns), 1fr);
  gap: 4px;
}

.parallel-view canvas {
  display: block;
  width: 100%;
  border-radius: 3px;
  background: #000;
}

.parallel-view .bar {
  width: 100%;
  height: 4px;
  margin-top: 2px;
  border-radius: 2px;
  border: none;
}

/* Each mini view is framed in the colour of what its universe is going for
   right now (strategies.js); grey while it wanders. main.js sets
   --strategy-color. */
.parallel-view canvas {
  outline: 2px solid var(--strategy-color, #8a8a8a);
  outline-offset: -2px;
}

.strategy-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
  flex: none;
}

.strategy-option-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.strategy-slider {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}

/* A universe that has collapsed (or isn't generated yet) is greyed out. */
.parallel-view.ended,
.parallel-view.pending {
  filter: grayscale(1);
  opacity: 0.45;
}

#journey-hint {
  margin-top: 10px;
  color: #777;
  font-size: 0.9rem;
}

/* On-screen movement controls, shown only on touch devices without a mouse */

#mobile-dpad {
  display: none;
}

@media (pointer: coarse) {
  #mobile-dpad {
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(3, 56px);
    gap: 4px;
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 500;
  }
}

.dpad-btn {
  background: rgba(124, 197, 118, 0.85);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.3rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.dpad-btn:active {
  background: var(--accent-dark);
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

/* Expedition report modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--panel-bg);
  padding: 28px 32px;
  border-radius: 12px;
  width: 380px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.modal h2 {
  margin-top: 0;
  color: var(--accent-dark);
}

.modal p {
  margin: 10px 0;
  color: #555;
}

/* Base screen */

/* The header (resources, progress, loadout, start button) stays put; only
   the buildings below it scroll. */
.base-panel {
  background: var(--panel-bg);
  margin: 30px 0 30px;
  padding: 32px 40px 0;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  width: 460px;
  max-width: 92vw;
  text-align: center;
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.base-header {
  flex-shrink: 0;
  padding-bottom: 16px;
  border-bottom: 1px solid #e2e2e2;
}

.base-progress {
  margin: 0 0 12px;
  color: #666;
  font-size: 0.9rem;
}

/* Narrow screens: one column. The column wrappers are flattened away and
   each card's inline `order` (set by main.js) restores config order. */
.base-buildings {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 24px 0 8px;
}

.building-column {
  display: contents;
}

/* Wide screens: 3 independent columns, filled row by row. */
@media (min-width: 900px) {
  .base-panel {
    width: 1200px;
    max-width: 94vw;
  }

  .base-buildings {
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
  }

  .building-column {
    display: block;
    flex: 1;
    min-width: 0;
  }
}

.base-panel h1 {
  margin-top: 0;
  color: var(--accent-dark);
}

.night-report {
  min-height: 1.2em;
  color: #666;
  font-style: italic;
}

.base-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  align-items: baseline;
  font-size: 1.1rem;
  margin: 12px 0;
}

/* Narrow windows wrap the header between entries, never inside one (an icon
   above its count, or a button label on two lines). */
.base-stats > *,
.base-stats .resource-list > * {
  white-space: nowrap;
}

.base-stats b {
  font-weight: 700;
  color: #b8901f;
}

.building {
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
  text-align: left;
}

/* A building's own controls only show once it's built (see baseScreen.js). */
.building:not(.built) .when-built {
  display: none !important;
}

.building h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

/* "1 / 2" next to the title of buildings that can be built several times. */
.building-count {
  margin-left: 8px;
  font-size: 0.85rem;
  font-weight: normal;
  color: #888;
}

.building p {
  margin: 4px 0;
  color: #666;
  font-size: 0.9rem;
}

.build-btn, .start-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.build-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.build-btn:not(:disabled):hover, .start-btn:hover {
  background: var(--accent-dark);
}

.start-btn {
  font-size: 1.1rem;
  padding: 14px;
}

.shop-offers {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.shop-offer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f4f4f4;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.building-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.building-controls .item-btn.active {
  background: var(--accent-dark);
}

.controls-break {
  flex-basis: 100%;
  height: 0;
}

.loadout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  color: #666;
}

.loadout-drop-btn {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0 0 0 6px;
  font-size: 0.75rem;
  opacity: 0.6;
}

.loadout-drop-btn:hover {
  opacity: 1;
}

.bet-buttons {
  display: flex;
  gap: 4px;
}

.over-limit {
  color: #cc3b3b !important;
}

.loadout-tag {
  display: inline-block;
  background: #ede4fb;
  color: #6a3fb5;
  border-radius: 4px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  font-size: 0.8rem;
  font-weight: 600;
}
