:root {
  --bg: #f4f7f1;
  --card: #fff;
  --text: #223;
  --accent: #2f7a5f;
  --selected: #ffd166;
  --hex-size: 54;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 6.5rem;
}

.app { max-width: 1200px; margin: 0 auto; padding: 1rem 1rem 1.5rem; }
h1, h2 { margin: 0.4rem 0; }

.hidden { display: none !important; }

.setup-screen {
  margin-top: 1rem;
  background: var(--card);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  box-shadow: 0 1px 6px rgb(0 0 0 / 8%);
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 0.6rem 1rem;
  margin-bottom: 0.8rem;
}

.setup-grid label {
  display: grid;
  gap: 0.2rem;
  font-weight: 600;
}

.setup-grid select {
  padding: 0.4rem;
}

.setup-mode-row {
  margin-bottom: 0.8rem;
}

.setup-mode-row label {
  display: grid;
  gap: 0.2rem;
  font-weight: 600;
  max-width: 280px;
}

.setup-mode-row select {
  padding: 0.4rem;
}

.replay-setup {
  border: 1px solid #dce3ec;
  border-radius: 10px;
  background: #f8fafc;
  padding: 0.7rem;
  margin-bottom: 0.9rem;
}

.replay-setup h3 {
  margin: 0 0 0.2rem;
}

.replay-setup p {
  margin: 0 0 0.4rem;
  font-size: 0.92rem;
}

#log-input {
  width: 100%;
  min-height: 130px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 0.5rem;
}

.replay-setup-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
  align-items: start;
}

.main-column {
  min-width: 0;
}

.top-panel,
.market,
.board-section {
  margin-top: 1rem;
  background: var(--card);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  box-shadow: 0 1px 6px rgb(0 0 0 / 8%);
}

.top-panel { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: 1rem; align-items: flex-start; }
.status-summary p { margin: 0.2rem 0; }
.status-score-line { font-weight: 600; }
.replay-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.market-sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
}

.market-controls {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

button {
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
}

button:disabled {
  background: #9aa3ad;
  color: #e8edf2;
  cursor: not-allowed;
}

.score-breakdown {
  margin-top: 0.1rem;
  font-size: 0.9rem;
}

.score-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 0.8rem;
}

.score-column {
  background: #f8fafc;
  border: 1px solid #dce3ec;
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

.score-breakdown ul {
  margin: 0.2rem 0;
  padding-left: 1.1rem;
}

.score-subtotal {
  margin: 0.18rem 0;
}

.market-tiles {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow-y: auto;
  min-height: 0;
}

.pair {
  border: 2px solid #d6d9de;
  border-radius: 10px;
  padding: 0.6rem;
  background: #fafafa;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.pair.selected { border-color: var(--selected); box-shadow: 0 0 0 2px rgb(255 209 102 / 50%); }
.pair.selected-tile { border-color: #6f9fd8; box-shadow: 0 0 0 2px rgb(111 159 216 / 40%); }
.pair.selected-token { outline: 2px dashed #2f7a5f; }

.market-tile-row,
.market-token-row {
  width: 100%;
  display: flex;
  justify-content: center;
}

.token-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.market-token {
  font-size: 1.45rem;
  background: #fff;
  border: 1px solid #ccd2da;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.market-token.pick { outline: 2px solid #f2a93f; }

.hex-board {
  position: relative;
  min-height: 420px;
  overflow: auto;
  border: 1px dashed #b8bec8;
  border-radius: 10px;
  background: #fbfcfd;
}

.hex {
  --size: calc(var(--hex-size) * 1px);
  position: absolute;
  width: calc(var(--size) * 1.73);
  height: calc(var(--size) * 2);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border: none;
  box-shadow: inset 0 0 0 1px #7f8a99;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0.3rem;
  font-size: 0.85rem;
}

.market-hex {
  position: relative;
  width: calc(var(--hex-size) * 1.73px);
  height: calc(var(--hex-size) * 2px);
}

.hex.open {
  background: #eef2f5;
  box-shadow: inset 0 0 0 2px #8a96a5;
}

.hex.filled { color: #142; font-weight: 600; }
.hex.starter { outline: 2px solid #5d8fbf; }
.hex.bonus-tile .hex-star {
  text-shadow: 0 0 10px rgb(224 176 0 / 55%);
}
.hex.token-eligible {
  box-shadow: 0 0 0 3px rgb(47 122 95 / 35%);
}
.hex.token-ineligible {
  filter: grayscale(1) saturate(0.2);
  opacity: 0.5;
}

.hex-center {
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  height: 100%;
}

.hex-star {
  grid-area: 1 / 1;
  font-size: 4.65rem;
  line-height: 1;
  opacity: 0.9;
  z-index: 1;
  transform: translateY(-6.25%);
}

.hex-token {
  grid-area: 1 / 1;
  font-size: 3rem;
  line-height: 1;
  display: inline-block;
  position: relative;
  z-index: 3;
  text-shadow: 0 1px 0 #fff;
}

.hex-animals {
  grid-area: 1 / 1;
  font-size: 1.35rem;
  opacity: 0.96;
  display: inline-block;
  line-height: 1.2;
  position: relative;
  z-index: 2;
  text-shadow: 0 1px 0 rgb(255 255 255 / 70%);
}

.hex.preview {
  opacity: 0.75;
  box-shadow: inset 0 0 0 2px #3c4d66, 0 0 0 2px rgb(60 77 102 / 28%);
}

.hex.token-preview .hex-token {
  opacity: 0.65;
}
.hex-animals.token-count-3 {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.04rem;
  line-height: 1;
}

.hex-animals.token-count-3 .token-top {
  display: block;
}

.hex-animals.token-count-3 .token-bottom {
  display: block;
  letter-spacing: 0.1em;
}


.event-log-section {
  margin-top: 1rem;
  background: var(--card);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  box-shadow: 0 1px 6px rgb(0 0 0 / 8%);
}

.event-log {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #d5dce6;
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: #fbfcfd;
}

.event-entry {
  margin: 0.2rem 0;
  font-size: 0.88rem;
  line-height: 1.25;
}

.floating-status-bar {
  position: fixed;
  left: 50%;
  bottom: 0.8rem;
  transform: translateX(-50%);
  width: min(980px, calc(100% - 1.5rem));
  background: rgb(21 34 52 / 92%);
  color: #f3f7fb;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgb(0 0 0 / 24%);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  backdrop-filter: blur(2px);
}

.floating-status-text {
  flex: 1;
  text-align: center;
}

.floating-status-center {
  display: grid;
  gap: 0.35rem;
  justify-items: center;
  min-width: 0;
  flex: 1;
}

.floating-status-center .replay-controls {
  justify-content: center;
}

.status-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.status-actions button.hidden {
  display: none;
}


.info-popover {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border: 1px solid #8a96a5;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 0.28rem;
  color: #445;
  cursor: help;
  background: #fff;
}

.info-popover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.4rem);
  transform: translateX(-50%);
  min-width: 220px;
  max-width: 340px;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  background: #172235;
  color: #f5f8fc;
  font-size: 0.77rem;
  line-height: 1.25;
  font-weight: 500;
  box-shadow: 0 6px 18px rgb(0 0 0 / 28%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 200;
  white-space: normal;
}

.info-popover:hover::after,
.info-popover:focus-visible::after {
  opacity: 1;
}

.terrain-chip {
  width: 0.7rem;
  height: 0.7rem;
  display: inline-block;
  margin-right: 0.35rem;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 20%);
}

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

  .market-sidebar {
    position: static;
    max-height: none;
  }

  .top-panel {
    grid-template-columns: 1fr;
  }

  .score-columns {
    grid-template-columns: 1fr;
  }

  .app-header {
    flex-direction: column;
  }

  .floating-status-bar {
    width: calc(100% - 1rem);
    bottom: 0.4rem;
    font-size: 0.93rem;
    padding: 0.6rem 0.8rem;
    flex-direction: column;
  }

  .floating-status-center { order: -1; }
}
