:root {
  color-scheme: light;
  --ink: #1f2623;
  --muted: #53635c;
  --paper: #f5f0df;
  --paper-deep: #e7dcc2;
  --line: #b8a988;
  --teal: #247f77;
  --teal-dark: #155f5a;
  --gold: #c9902f;
  --rust: #a84d37;
  --moss: #5e7c45;
  --deep: #24352f;
  --water: #2b6f8f;
  --wet: #6fa46c;
  --dry: #baa36d;
  --high: #8b7b62;
  --rival: #923440;
  --white: #fffaf0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(36, 127, 119, 0.16), transparent 32%),
    linear-gradient(300deg, rgba(168, 77, 55, 0.14), transparent 36%),
    var(--paper);
}

button {
  font: inherit;
}

.game-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.mast {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 10px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.15rem, 5vw, 4.1rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.objective {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  background: rgba(255, 250, 240, 0.72);
  box-shadow: 0 3px 0 rgba(31, 38, 35, 0.12);
  font-size: 1rem;
  line-height: 1.45;
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.meter-card,
.map-panel,
.command-panel {
  border: 2px solid var(--line);
  background: rgba(255, 250, 240, 0.78);
  box-shadow: 0 4px 0 rgba(31, 38, 35, 0.12);
}

.meter-card {
  min-height: 78px;
  padding: 10px;
}

.label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meter-card strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.1;
}

.bar {
  width: 100%;
  height: 9px;
  margin-top: 8px;
  border: 1px solid rgba(31, 38, 35, 0.22);
  background: #d2c4a7;
  overflow: hidden;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 180ms ease;
}

.danger .bar span {
  background: var(--rust);
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.map-panel,
.command-panel {
  padding: 14px;
}

.map-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.map-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(40px, 1fr));
  gap: 5px;
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 8px;
  border: 2px solid #735f43;
  background: #52472f;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 2px solid rgba(31, 38, 35, 0.24);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, outline-color 120ms ease;
}

.tile:hover,
.tile:focus-visible {
  z-index: 2;
  filter: brightness(1.08);
  outline: 3px solid var(--gold);
  outline-offset: 1px;
}

.tile.selected {
  outline: 4px solid #f1be4f;
  outline-offset: -3px;
}

.tile.water {
  background: linear-gradient(135deg, #2a6e90, #143f5f);
  color: #eef8ff;
}

.tile.low {
  background: linear-gradient(135deg, #baa36d, #d7c58a);
}

.tile.fertile {
  background: linear-gradient(135deg, #6fa46c, #a9c278);
}

.tile.high {
  background: linear-gradient(135deg, #756b5a, #a89572);
  color: #fff7dc;
}

.tile.rival {
  border-color: rgba(80, 15, 23, 0.64);
}

.tile.player {
  border-color: rgba(20, 85, 80, 0.78);
}

.tile.blight::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 3px dashed rgba(114, 20, 31, 0.9);
  background: rgba(146, 52, 64, 0.18);
  pointer-events: none;
}

.tile-label {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 74%;
  min-width: 26px;
  aspect-ratio: 1;
  border: 2px solid rgba(31, 38, 35, 0.24);
  background: rgba(255, 250, 240, 0.72);
  font-size: clamp(0.72rem, 1.5vw, 1.1rem);
  font-weight: 900;
  line-height: 1;
}

.tile.water .tile-label {
  border-color: rgba(255, 250, 240, 0.25);
  background: rgba(31, 38, 35, 0.22);
}

.tile.player .tile-label {
  color: #f6fffb;
  background: var(--teal-dark);
}

.tile.rival .tile-label {
  color: #fff6ee;
  background: #762330;
}

.tile.cairn .tile-label::before {
  content: "C";
  position: absolute;
  top: -11px;
  right: -9px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(31, 38, 35, 0.28);
  background: #d8a63b;
  color: var(--ink);
  font-size: 0.75rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(31, 38, 35, 0.25);
}

.legend-swatch.water {
  background: var(--water);
}

.legend-swatch.fertile {
  background: var(--wet);
}

.legend-swatch.high {
  background: var(--high);
}

.legend-swatch.player {
  background: var(--teal-dark);
}

.legend-swatch.rival {
  background: var(--rival);
}

.command-panel {
  display: grid;
  gap: 12px;
}

.panel-block {
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(184, 169, 136, 0.72);
}

.panel-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

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

.action-button,
.primary-button,
.ghost-button {
  border: 2px solid rgba(31, 38, 35, 0.25);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  line-height: 1.2;
  box-shadow: 0 3px 0 rgba(31, 38, 35, 0.18);
}

.action-button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 10px;
  background: #efe5c9;
  text-align: left;
}

.action-button small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.action-button.selected {
  border-color: var(--teal-dark);
  background: #d0eadc;
}

.action-button:disabled {
  color: #81786b;
  cursor: not-allowed;
  filter: grayscale(0.42);
  opacity: 0.68;
}

.cost {
  padding: 4px 7px;
  border: 1px solid rgba(31, 38, 35, 0.2);
  background: var(--white);
  color: var(--teal-dark);
  white-space: nowrap;
}

.primary-button,
.ghost-button {
  padding: 10px 14px;
  white-space: nowrap;
}

.primary-button {
  background: var(--teal);
  color: #f8fff8;
}

.ghost-button {
  background: var(--paper-deep);
}

.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.tile-details {
  min-height: 102px;
  padding: 10px;
  border: 2px solid rgba(31, 38, 35, 0.18);
  background: rgba(255, 250, 240, 0.58);
  line-height: 1.42;
}

.tile-details strong {
  display: block;
  margin-bottom: 4px;
}

.tile-details span {
  display: inline-block;
  margin: 3px 6px 3px 0;
  padding: 3px 6px;
  background: #e8dcc1;
  font-weight: 800;
}

.log-block {
  min-height: 160px;
}

.log-list {
  display: grid;
  gap: 7px;
  max-height: 220px;
  margin: 0;
  padding-left: 21px;
  overflow: auto;
  color: var(--muted);
  line-height: 1.35;
}

.game-over .board {
  filter: saturate(0.85);
}

@media (max-width: 920px) {
  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .command-panel {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 620px) {
  .game-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
  }

  .mast,
  .map-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .board {
    grid-template-columns: repeat(9, minmax(28px, 1fr));
    gap: 3px;
    padding: 5px;
  }

  .tile-label {
    width: 80%;
    min-width: 20px;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }
}
