:root {
  --ink: #17201f;
  --muted: #687371;
  --line: #c8cfcc;
  --surface: #ffffff;
  --surface-soft: #f3f6f5;
  --table: #dde4e1;
  --header: #263432;
  --accent: #176b63;
  --accent-strong: #10544e;
  --building: #c69a57;
  --animal: #72a968;
  --knowledge: #d8b83f;
  --castle: #467965;
  --mine: #80898d;
  --ship: #4e8db2;
  --goods-1: #d9b43b;
  --goods-2: #5689b4;
  --goods-3: #a7689c;
  --goods-4: #6d9c68;
  --goods-5: #c96c5f;
  --goods-6: #8a715c;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--table);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--table);
  color: var(--ink);
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: wait;
  opacity: 0.55;
}

.app-header {
  position: sticky;
  z-index: 60;
  top: 0;
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  padding: 8px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid #394846;
  background: var(--header);
  color: white;
}

.brand-block,
.header-actions,
.turn-strip,
.turn-strip > div,
.market-heading,
.modal-heading,
.estate-heading,
.estate-stats,
.dice-row,
.zone-heading {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid #dfc77a;
  background: #182321;
  color: #dfc77a;
  font-family: Georgia, "Songti SC", serif;
  font-size: 18px;
  font-weight: 700;
}

.brand-block h1 {
  overflow: hidden;
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: 17px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-block p {
  margin: 3px 0 0;
  color: #b9c5c2;
  font-size: 11px;
}

.header-actions {
  gap: 8px;
}

.command-button,
.icon-command,
.primary-button,
.quick-action,
.dialog-action,
.icon-button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-weight: 650;
}

.command-button {
  border-color: #697774;
  background: #f7faf9;
  color: #20302e;
  padding: 0 13px;
}

.icon-command,
.icon-button {
  display: grid;
  width: 36px;
  padding: 0;
  place-items: center;
}

.icon-command {
  border-color: #697774;
  background: transparent;
  color: white;
  font-size: 17px;
}

.game-shell {
  display: grid;
  width: min(100%, 1540px);
  min-height: calc(100vh - 58px);
  margin: 0 auto;
  grid-template-columns: minmax(560px, 1.22fr) minmax(520px, 1fr);
  align-items: start;
}

.table-section {
  min-width: 0;
  min-height: calc(100vh - 58px);
  padding: 14px 18px 88px;
  border-right: 1px solid #b8c2bf;
  background: #e7ecea;
}

.turn-strip {
  min-height: 42px;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.turn-strip > div:first-child {
  min-width: 0;
  gap: 10px;
}

.phase-badge {
  flex: 0 0 auto;
  border: 1px solid #80908c;
  border-radius: 3px;
  background: #f8faf9;
  color: #41504d;
  font-size: 11px;
  font-weight: 750;
  padding: 5px 7px;
}

#turnLabel {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.turn-order {
  display: flex;
  min-width: 0;
  gap: 3px;
  overflow-x: auto;
}

.turn-token {
  display: grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid #87938f;
  border-radius: 50%;
  background: #f9fbfa;
  color: #3c4a47;
  font-size: 10px;
  font-weight: 800;
}

.turn-token.current {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.supply-board {
  border: 1px solid #aeb9b5;
  background-color: #d5ddda;
  padding: 10px;
}

.depot-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.depot {
  min-width: 0;
  min-height: 142px;
  border: 1px solid #b6c0bd;
  background: rgba(255, 255, 255, 0.82);
  padding: 8px;
}

.depot-heading {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}

.depot-die,
.die {
  display: grid;
  place-items: center;
  border: 1px solid #596663;
  border-radius: 5px;
  background: white;
  color: #202928;
  font-family: Georgia, serif;
  font-weight: 800;
}

.depot-die {
  width: 31px;
  height: 31px;
  font-size: 15px;
}

.depot-heading strong {
  font-size: 12px;
}

.goods-line {
  display: flex;
  min-height: 18px;
  align-items: center;
  gap: 3px;
  overflow-x: auto;
}

.goods-tile {
  display: grid;
  width: 19px;
  height: 15px;
  flex: 0 0 19px;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.28);
  color: white;
  font-size: 8px;
  font-weight: 800;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
}

.goods-tile[data-color="1"] { background: var(--goods-1); }
.goods-tile[data-color="2"] { background: var(--goods-2); }
.goods-tile[data-color="3"] { background: var(--goods-3); }
.goods-tile[data-color="4"] { background: var(--goods-4); }
.goods-tile[data-color="5"] { background: var(--goods-5); }
.goods-tile[data-color="6"] { background: var(--goods-6); }

.tile-row {
  display: flex;
  min-height: 55px;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  padding: 2px 0;
}

.tile-chip,
.board-hex {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  clip-path: polygon(25% 4%, 75% 4%, 100% 50%, 75% 96%, 25% 96%, 0 50%);
  color: #17201f;
  font-weight: 800;
  text-align: center;
}

.tile-chip {
  width: 48px;
  height: 43px;
  flex: 0 0 48px;
  padding: 2px 5px;
  font-size: 10px;
  line-height: 1.05;
}

.tile-chip::after,
.board-hex::after {
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  clip-path: inherit;
  content: "";
  pointer-events: none;
}

.tile-building { background: var(--building); }
.tile-animal { background: var(--animal); }
.tile-knowledge { background: var(--knowledge); }
.tile-castle { background: var(--castle); color: white; }
.tile-mine { background: var(--mine); color: white; }
.tile-ship { background: var(--ship); color: white; }

.tile-chip.black-tile {
  box-shadow: inset 0 0 0 3px #222c2a;
}

.tile-chip.actionable {
  outline: 3px solid rgba(23, 107, 99, 0.4);
  outline-offset: 1px;
}

.tile-chip.selected {
  filter: brightness(0.9);
  outline: 3px solid #122b27;
  outline-offset: 2px;
}

.empty-label {
  color: var(--muted);
  font-size: 10px;
}

.black-market {
  margin-top: 9px;
  border-top: 4px solid #263432;
  background: #f8faf9;
  padding: 8px 10px 9px;
}

.market-heading {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.market-heading div {
  display: grid;
}

.market-heading span {
  color: #4e5a58;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.market-heading strong {
  margin-top: 1px;
  font-size: 11px;
}

.market-cost {
  border: 1px solid #929e9a;
  background: #e8edeb;
  padding: 4px 6px;
}

.action-tray {
  position: sticky;
  z-index: 30;
  bottom: 0;
  display: grid;
  min-height: 70px;
  margin: 12px -18px -88px;
  grid-template-columns: minmax(150px, 0.45fr) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border-top: 1px solid #aeb9b5;
  background: rgba(247, 250, 249, 0.97);
  padding: 10px 18px max(10px, env(safe-area-inset-bottom));
}

.action-prompt {
  display: grid;
  min-width: 0;
}

.action-prompt span {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.action-prompt strong {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.25;
}

.quick-actions {
  display: flex;
  min-width: 0;
  gap: 6px;
  overflow-x: auto;
  padding: 2px;
}

.quick-action,
.dialog-action {
  border-color: #aab5b1;
  background: white;
  color: #25312f;
  text-align: left;
}

.quick-action {
  min-width: max-content;
  padding: 0 11px;
  font-size: 11px;
}

.quick-action.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.estates-section {
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(2, minmax(250px, 1fr));
  align-content: start;
  background: var(--surface-soft);
}

.estate {
  min-width: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 10px 12px;
}

.estate.human {
  background: #fbfdfc;
  box-shadow: inset 0 3px 0 var(--accent);
}

.estate.current {
  box-shadow: inset 0 3px 0 #b48728;
}

.estate-heading {
  min-height: 31px;
  justify-content: space-between;
  gap: 8px;
}

.estate-name {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 6px;
}

.estate-name strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.estate-name span {
  color: var(--muted);
  font-size: 9px;
}

.estate-stats {
  flex: 0 0 auto;
  gap: 4px;
}

.stat {
  min-width: 34px;
  border: 1px solid #c5cdca;
  border-radius: 3px;
  background: #f3f6f5;
  color: #4c5855;
  font-size: 9px;
  padding: 3px 4px;
  text-align: center;
}

.stat strong {
  display: block;
  color: var(--ink);
  font-size: 11px;
}

.estate-board {
  --hex-w: 38px;
  --hex-h: 34px;
  --hex-x: 28.5px;
  --hex-y: 34px;
  position: relative;
  width: 250px;
  height: 245px;
  margin: 0 auto;
}

.board-hex {
  position: absolute;
  left: calc(50% + var(--q) * var(--hex-x) - var(--hex-w) / 2);
  top: calc(50% + (var(--r) + var(--q) * 0.5) * var(--hex-y) - var(--hex-h) / 2);
  width: var(--hex-w);
  height: var(--hex-h);
  font-size: 9px;
  line-height: 1;
}

.board-hex.empty {
  border: 0;
  color: rgba(20, 30, 28, 0.7);
}

.board-hex.empty.tile-building { background: rgba(198, 154, 87, 0.3); }
.board-hex.empty.tile-animal { background: rgba(114, 169, 104, 0.3); }
.board-hex.empty.tile-knowledge { background: rgba(216, 184, 63, 0.3); }
.board-hex.empty.tile-castle { background: rgba(70, 121, 101, 0.3); }
.board-hex.empty.tile-mine { background: rgba(128, 137, 141, 0.3); }
.board-hex.empty.tile-ship { background: rgba(78, 141, 178, 0.3); }

.board-hex.target {
  z-index: 4;
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  animation: target-pulse 1.2s ease-in-out infinite;
}

@keyframes target-pulse {
  50% { filter: brightness(1.16); }
}

.player-zones {
  display: grid;
  gap: 6px;
}

.zone {
  min-width: 0;
  border-top: 1px solid #e0e5e3;
  padding-top: 5px;
}

.zone-heading {
  justify-content: space-between;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
}

.compact-row {
  display: flex;
  min-height: 37px;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
}

.compact-row .tile-chip {
  width: 38px;
  height: 34px;
  flex-basis: 38px;
  font-size: 8px;
}

.goods-stack {
  display: flex;
  min-width: 40px;
  min-height: 30px;
  align-items: center;
  gap: 3px;
  border: 1px solid #c4cdca;
  background: #f8faf9;
  padding: 3px;
}

.goods-stack.actionable {
  border-color: var(--accent);
  outline: 2px solid rgba(23, 107, 99, 0.2);
}

.goods-count {
  font-size: 10px;
  font-weight: 800;
}

.dice-row {
  gap: 6px;
}

.die {
  width: 34px;
  height: 34px;
  font-size: 15px;
}

.die.used {
  opacity: 0.32;
  text-decoration: line-through;
}

.die-label {
  color: var(--muted);
  font-size: 9px;
}

.modal {
  width: min(92vw, 470px);
  max-height: min(86vh, 760px);
  overflow-y: auto;
  border: 1px solid #7e8986;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 18px;
  box-shadow: 0 18px 54px rgba(22, 30, 29, 0.3);
}

.modal::backdrop {
  background: rgba(22, 30, 29, 0.55);
}

.modal-heading {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.modal-heading span {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.modal-heading h2 {
  margin: 2px 0 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: 20px;
}

.icon-button {
  flex: 0 0 36px;
  border-color: var(--line);
  background: #f4f6f5;
  color: #36413f;
  font-size: 21px;
}

.segmented-control {
  display: grid;
  margin: 0 0 15px;
  grid-template-columns: repeat(3, 1fr);
  border: 0;
  padding: 0;
}

.segmented-control legend {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
}

.segmented-control span {
  display: grid;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-right: 0;
  background: white;
  color: #43504d;
  font-size: 12px;
}

.segmented-control label:first-of-type span {
  border-radius: 4px 0 0 4px;
}

.segmented-control label:last-of-type span {
  border-right: 1px solid var(--line);
  border-radius: 0 4px 4px 0;
}

.segmented-control input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.form-row {
  display: grid;
  margin-bottom: 12px;
  grid-template-columns: 92px 1fr;
  align-items: center;
  gap: 10px;
  color: #46524f;
  font-size: 12px;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
}

.primary-button {
  background: var(--accent);
  color: white;
  padding: 0 17px;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
}

.modal-submit {
  width: 100%;
  min-height: 43px;
  margin-top: 8px;
}

.dialog-description {
  margin: -7px 0 13px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.dialog-action-list {
  display: grid;
  gap: 7px;
}

.dialog-action {
  width: 100%;
  min-height: 43px;
  padding: 8px 11px;
  font-size: 12px;
}

.dialog-action:hover,
.dialog-action:focus-visible {
  border-color: var(--accent);
  background: #eef6f3;
}

.rules-content {
  display: grid;
  gap: 14px;
}

.rules-content section {
  border-left: 3px solid #8aa19b;
  padding-left: 11px;
}

.rules-content h3 {
  margin: 0 0 4px;
  font-size: 13px;
}

.rules-content p {
  margin: 0;
  color: #4f5b58;
  font-size: 12px;
  line-height: 1.65;
}

.busy-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(225, 232, 229, 0.72);
  backdrop-filter: blur(2px);
}

.busy-overlay[hidden],
.toast[hidden] {
  display: none;
}

.thinking-box {
  display: grid;
  min-width: 190px;
  place-items: center;
  border: 1px solid #aeb9b5;
  background: white;
  padding: 17px 21px;
  box-shadow: 0 8px 30px rgba(22, 30, 29, 0.18);
}

.thinking-box strong {
  margin-top: 9px;
  font-size: 12px;
}

.thinking-indicator {
  display: flex;
  gap: 5px;
}

.thinking-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinking 900ms ease-in-out infinite;
}

.thinking-indicator span:nth-child(2) { animation-delay: 130ms; }
.thinking-indicator span:nth-child(3) { animation-delay: 260ms; }

@keyframes thinking {
  50% { opacity: 0.25; transform: translateY(-3px); }
}

.toast {
  position: fixed;
  z-index: 110;
  right: 16px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid #53605d;
  border-radius: 4px;
  background: #263432;
  color: white;
  font-size: 12px;
  padding: 10px 13px;
  box-shadow: 0 8px 24px rgba(22, 30, 29, 0.24);
}

@media (max-width: 1120px) {
  .game-shell {
    grid-template-columns: minmax(520px, 1.1fr) minmax(300px, 0.76fr);
  }

  .estates-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .game-shell {
    display: block;
  }

  .table-section {
    min-height: auto;
    border-right: 0;
    padding: 10px 10px 78px;
  }

  .estates-section {
    grid-template-columns: 1fr;
  }

  .estate {
    padding: 9px 10px 10px;
  }

  .estate.human {
    order: -1;
  }

  .action-tray {
    margin: 10px -10px -78px;
    grid-template-columns: 122px minmax(0, 1fr);
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 560px) {
  .app-header {
    min-height: 54px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .brand-block h1 {
    font-size: 15px;
  }

  .brand-block p {
    display: none;
  }

  .command-button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .turn-strip {
    min-height: 36px;
    margin-bottom: 7px;
  }

  .phase-badge {
    padding: 4px 5px;
  }

  #turnLabel {
    font-size: 12px;
  }

  .turn-order {
    display: none;
  }

  .supply-board {
    padding: 7px;
  }

  .depot-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .depot {
    min-height: 116px;
    padding: 6px;
  }

  .depot-heading {
    grid-template-columns: 28px 1fr;
    margin-bottom: 4px;
  }

  .depot-die {
    width: 27px;
    height: 27px;
    font-size: 13px;
  }

  .tile-chip {
    width: 42px;
    height: 38px;
    flex-basis: 42px;
    font-size: 9px;
  }

  .black-market {
    margin-top: 7px;
    padding: 6px 7px 7px;
  }

  .market-heading strong {
    font-size: 10px;
  }

  .action-tray {
    min-height: 64px;
    grid-template-columns: 105px minmax(0, 1fr);
    gap: 7px;
  }

  .action-prompt strong {
    font-size: 10px;
  }

  .quick-action {
    min-height: 34px;
    padding: 0 9px;
    font-size: 10px;
  }

  .estate-board {
    --hex-w: 36px;
    --hex-h: 32px;
    --hex-x: 27px;
    --hex-y: 32px;
    width: 238px;
    height: 228px;
  }

  .player-zones {
    grid-template-columns: 1fr 1fr;
  }

  .zone:first-child {
    grid-column: 1 / -1;
  }

  .modal {
    width: calc(100vw - 20px);
    padding: 15px;
  }
}
