:root {
  font-family: "Bookman Old Style", "URW Bookman", Georgia, serif;
  color: #e8dcc2;
  background: #111914;
  color-scheme: dark;
  --emerald: #143f31;
  --emerald-object: #31785d;
  --bronze-chocolate: #4c3020;
  --bronze-object: #93603e;
  --ink: #111914;
  --panel: rgba(10, 15, 12, 0.58);
  --surface: rgba(31, 28, 22, 0.82);
  --text: #e6dcc5;
  --muted-text: #b8aa8e;
  --border: #806c4d;
  --focus: #b99a68;
  --disabled: #68675d;
  --resource-building: #a06c43;
  --resource-upgrade: #b5965e;
  --resource-third: #65a78c;
  --type-optical-shift: 0.09em;
  --radius-panel: 14px;
  --radius-control: 10px;
  --radius-small: 7px;
  --field-width: min(90vw, 189vh);
  --block-height: 9vh;
  --block-gap: 4.5vh;
}

* { box-sizing: border-box; }

.rotate-device { display: none; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(232, 220, 194, 0.06), transparent 52%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(8, 11, 9, 0.24)),
    linear-gradient(90deg, var(--emerald) 0 50%, var(--bronze-chocolate) 50% 100%);
}

.game {
  width: var(--field-width);
  display: flex;
  flex-direction: column;
  gap: var(--block-gap);
}

.information, .abilities {
  width: 100%;
  height: var(--block-height);
  flex: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
}

.information {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  column-gap: clamp(14px, 2vw, 30px);
  align-items: center;
  padding: 0 18px;
}

.information.empty > * { visibility: hidden; }

.resources {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  font-size: clamp(19px, 1.65vw, 24px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.resource-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42em;
  color: var(--text);
  white-space: nowrap;
}

.resource-value > span { transform: translateY(var(--type-optical-shift)); }

.resource-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  border: 1px solid rgba(230, 220, 197, 0.34);
  border-radius: 3px;
}

.resource-building { background: var(--resource-building); }
.resource-upgrade { background: var(--resource-upgrade); }
.resource-third { background: var(--resource-third); }

.timer {
  font-size: clamp(26px, 2.15vw, 32px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transform: translateY(var(--type-optical-shift));
}

.income-exchange {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 0.65vw, 10px);
  font-size: clamp(16px, 1.35vw, 20px);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1;
}

.exchange-arrow {
  position: relative;
  display: inline-block;
  width: clamp(18px, 1.7vw, 26px);
  height: 10px;
  flex: none;
}

.exchange-arrow::before {
  content: "";
  position: absolute;
  top: calc(50% - 0.5px);
  height: 1px;
  background: var(--muted-text);
}

.exchange-arrow::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: translateY(-50%);
}

.exchange-arrow-right::before { left: 0; right: 5px; }
.exchange-arrow-right::after { right: 0; border-left: 6px solid var(--muted-text); }
.exchange-arrow-left::before { left: 5px; right: 0; }
.exchange-arrow-left::after { left: 0; border-right: 6px solid var(--muted-text); }
.income-exchange > span:not(.exchange-arrow), #buy-income > span { transform: translateY(var(--type-optical-shift)); }

#buy-income {
  min-height: 36px;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

#battlefield {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 1;
  flex: none;
}

#battlefield.targeting { cursor: crosshair; }

[hidden] { display: none !important; }

.central {
  width: 100%;
  aspect-ratio: 3 / 1;
  position: relative;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  overflow: hidden;
  background: linear-gradient(90deg, var(--emerald) 0 50%, var(--bronze-chocolate) 50% 100%);
}

.lobby-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vw, 24px);
  background: rgba(10, 15, 12, 0.18);
}

.lobby-card,
.room-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: 0 14px 34px rgba(6, 9, 7, 0.25);
}

.identity-card {
  height: min(100%, 310px);
  width: auto;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  display: grid;
  align-content: center;
  gap: clamp(10px, 1.2vw, 16px);
  padding: clamp(18px, 3vw, 34px);
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted-text);
  font-size: clamp(12px, 1.1vw, 16px);
}

input {
  min-width: 0;
  height: clamp(34px, 3.2vw, 42px);
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  color: var(--text);
  background: rgba(12, 17, 14, 0.72);
  font: inherit;
}

input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }

.main-menu {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: clamp(8px, 1.2vw, 14px);
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.main-menu button {
  height: 100%;
  width: auto;
  min-height: 0;
  aspect-ratio: 1;
  flex: none;
  font-size: clamp(15px, 1.6vw, 22px);
}
.main-menu button.active { border-color: var(--resource-third); box-shadow: inset 0 0 0 1px var(--resource-third); }

.private-menu {
  width: 100%;
  height: 100%;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: stretch;
  justify-content: space-evenly;
  gap: 0;
}

.room-card {
  height: 100cqh;
  width: 100cqh;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  flex: none;
  display: grid;
  align-content: center;
  gap: clamp(8px, 1.1vw, 14px);
  padding: clamp(14px, 2.5vw, 30px);
}

.waiting-card {
  width: auto;
  height: 50%;
  aspect-ratio: 1;
  padding: clamp(18px, 3vw, 34px);
  display: grid;
  gap: 16px;
  text-align: center;
}

.waiting-card p {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(10px, 1.25vw, 17px);
}

.confirmation-card {
  height: 55%;
  width: auto;
  aspect-ratio: 1;
  display: grid;
  align-content: center;
  gap: clamp(12px, 2vw, 22px);
  padding: clamp(14px, 2.5vw, 28px);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
}

.confirmation-card p { margin: 0; font-size: clamp(14px, 1.7vw, 22px); }
.confirmation-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.menu-screen {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  background: var(--panel);
  border-radius: inherit;
}

.menu-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: clamp(8px, 1.8vw, 18px);
  background: transparent;
  border: 0;
  border-radius: inherit;
}

.construction-panel {
  width: 100%;
  height: 100%;
}

.building-cards {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.building-card {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: clamp(5px, 0.8vw, 10px);
  display: grid;
  grid-template-rows: minmax(1em, auto) minmax(0, 1fr) minmax(2.2em, auto);
  gap: clamp(3px, 0.55vw, 7px);
  place-items: center;
  border-radius: var(--radius-control);
}
.building-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: clamp(9px, 1.15vw, 16px); font-weight: 700; }
.building-preview { position: relative; display: grid; place-items: center; width: 100%; height: 100%; min-width: 0; min-height: 0; }
.building-preview svg { width: 100%; height: 100%; display: block; fill: var(--emerald-object); stroke: var(--ink); stroke-width: 2; }
.building-preview i { position: absolute; font-size: clamp(10px, 1.2vw, 17px); font-style: normal; font-weight: 700; transform: translateY(var(--type-optical-shift)); }
.building-description {
  width: 100%;
  min-height: 0;
  overflow: hidden;
  align-self: start;
  font-size: clamp(7px, 0.82vw, 12px);
  line-height: 1.05;
  text-align: center;
}

.upgrade-panel {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  gap: clamp(8px, 2vw, 28px);
}

.upgrade-information {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: clamp(24px, 18%, 46px) minmax(0, 1fr) var(--ability-button-height, clamp(24px, 18%, 46px));
  gap: clamp(2px, 0.55vw, 6px);
}

.upgrade-title {
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: clamp(12px, 1.7vw, 25px);
  line-height: 1.1;
  text-align: center;
}

.upgrade-middle {
  display: grid;
  grid-template-rows: minmax(0, 0.62fr) minmax(0, 1.8fr) minmax(0, 0.62fr);
  gap: clamp(2px, 0.4vw, 5px);
  min-height: 0;
}

.upgrade-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-flow: column;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  column-gap: clamp(7px, 1vw, 14px);
  align-items: center;
  font-size: clamp(7px, 0.86vw, 13px);
  line-height: 1;
}

.upgrade-stat {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, auto) auto minmax(0, 1fr);
  gap: 0.25em;
  align-items: baseline;
  text-align: left;
  white-space: nowrap;
}

.upgrade-stat b { font-weight: 400; color: var(--muted-text); }
.upgrade-stat span { overflow: hidden; text-overflow: ellipsis; }
.upgrade-stat .stat-separator { overflow: visible; color: var(--muted-text); }
.upgrade-stat i { color: var(--focus); font-style: normal; }

.upgrade-bonus {
  text-align: center;
  font-size: clamp(9px, 1.05vw, 16px);
  line-height: 1.15;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 2px;
  color: var(--muted-text);
  opacity: 0.24;
  overflow-wrap: anywhere;
  transition: opacity 160ms ease, color 160ms ease;
}

.upgrade-bonus.earned {
  color: var(--text);
  opacity: 1;
}

.upgrade-bonus.previewed { color: var(--text); opacity: 0.64; }

.upgrade-footer {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.level-button {
  position: relative;
  width: min(100%, var(--ability-button-width, 50%));
  height: 100%;
  min-height: 0;
  overflow: hidden;
  font-size: clamp(11px, 1.25vw, 19px);
  font-weight: 700;
}

.level-label,
.level-price {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  padding: 8px 12px;
  transition: opacity 140ms ease;
}

.level-price { opacity: 0; }
.level-price > span,
.level-label { transform: translateY(var(--type-optical-shift)); }
.level-button:hover .level-label,
.level-button:focus-visible .level-label { opacity: 0; }
.level-button:hover .level-price,
.level-button:focus-visible .level-price { opacity: 1; }
.level-button.maximum { border-color: var(--resource-third); }
.level-button.maximum:disabled { color: var(--text); }

.upgrade-preview {
  position: relative;
  display: grid;
  place-items: center;
  width: auto;
  height: 100%;
  flex: none;
  aspect-ratio: 1;
  justify-self: center;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
}

.upgrade-preview svg {
  position: absolute;
  inset: 12%;
  width: 76%;
  height: 76%;
  fill: var(--emerald-object);
  stroke: var(--ink);
  stroke-width: 2;
}

.upgrade-branches {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.branch-option {
  --branch-edge: rgba(128, 108, 77, 0.72);
  position: relative;
  width: 100%;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center end;
  padding: 0 clamp(8px, 1.3vw, 18px) 0 clamp(3px, 0.6vw, 8px);
  border: 0;
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  background: linear-gradient(90deg, transparent 0%, rgba(31, 28, 22, 0.22) 38%, rgba(31, 28, 22, 0.82) 100%);
  overflow: hidden;
}

.branch-option::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, var(--branch-edge)) top right / 100% 1px no-repeat,
    linear-gradient(90deg, transparent, var(--branch-edge)) bottom right / 100% 1px no-repeat,
    linear-gradient(var(--branch-edge), var(--branch-edge)) right / 1px 100% no-repeat;
}

.branch-option:disabled { color: inherit; }

.branch-description {
  min-width: 0;
  align-self: center;
  color: var(--muted-text);
  font-size: clamp(9px, 1.15vw, 16px);
  opacity: 0.24;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 140ms ease, color 140ms ease;
}

.branch-option:hover .branch-description,
.branch-option:focus-visible .branch-description {
  opacity: 0.58;
}

.branch-option:hover,
.branch-option:focus-visible { --branch-edge: var(--focus); }

.branch-option.active .branch-description {
  color: var(--text);
  opacity: 1;
}

.branch-option.active { --branch-edge: var(--resource-third); }

#result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--panel);
  border-radius: var(--radius-panel);
}

#result-label { font-size: 24px; margin: 0; }

button {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-control);
  line-height: 1;
}

button:hover:not(:disabled) { border-color: var(--focus); }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button:disabled { color: var(--disabled); cursor: default; }
button[aria-disabled="true"] { cursor: default; }

.abilities {
  display: flex;
  align-items: center;
  padding: 10px 18px;
  gap: 12px;
}

.ability-controls {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(8px, 1.2vw, 16px);
}

.session-status {
  flex: 1;
  margin: 0;
  text-align: center;
  color: var(--muted-text);
  font-size: clamp(13px, 1.35vw, 19px);
  transform: translateY(var(--type-optical-shift));
}

.ability-button {
  min-height: 0;
  padding: 4px clamp(4px, 1vw, 12px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ability-button { position: relative; overflow: hidden; }

.ability-name,
.ability-price {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.42em;
}

.ability-name,
.ability-price > span {
  min-width: 2ch;
  color: var(--resource-third);
  font-size: clamp(14px, 1.5vw, 22px);
  font-variant-numeric: tabular-nums;
  transform: translateY(var(--type-optical-shift));
}
.ability-price { display: none; }
.ability-button:hover .ability-name,
.ability-button:focus-visible .ability-name,
.ability-button:active .ability-name { display: none; }
.ability-button:hover .ability-price,
.ability-button:focus-visible .ability-price,
.ability-button:active .ability-price { display: flex; }
.ability-button.unaffordable .ability-price { opacity: 0.34; }
.ability-button.active { border-color: var(--resource-third); box-shadow: inset 0 0 0 1px var(--resource-third); }
.ability-button.cooldown .ability-name, .ability-button.locked .ability-name { color: var(--disabled); }

@media (max-width: 760px) {
  :root {
    --field-width: min(96vw, 210vh);
    --block-gap: clamp(8px, 2vh, 14px);
    --radius-panel: 10px;
    --radius-control: 7px;
  }

  .information {
    height: auto;
    min-height: 88px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 7px 10px;
    padding: 8px 10px;
  }

  .resources {
    grid-column: 1 / -1;
    grid-row: 1;
    font-size: clamp(12px, 3vw, 18px);
  }

  .timer {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
    font-size: clamp(20px, 5vw, 27px);
  }

  .income-exchange {
    grid-column: 2;
    grid-row: 2;
    justify-self: center;
    font-size: clamp(11px, 2.8vw, 16px);
    gap: clamp(3px, 1vw, 7px);
  }

  .exchange-arrow { width: clamp(12px, 4vw, 20px); }
  #buy-income { min-height: 28px; padding: 4px 7px; gap: 4px; }

  .menu-panel { padding: clamp(6px, 2vw, 10px); }
  .lobby-screen { padding: 8px; }
  .identity-card { height: min(100%, 230px); padding: clamp(10px, 3vw, 18px); gap: 7px; }
  .identity-card input { height: clamp(25px, 7vw, 34px); padding: 3px 7px; }
  .identity-card button { min-height: 28px; padding: 5px 10px; }
  .main-menu { width: 100%; padding: 0; gap: 6px; }
  .main-menu button { min-height: 0; padding: 5px 10px; }
  .private-menu { gap: 0; }
  .room-card { min-height: 0; padding: clamp(7px, 2vw, 12px); gap: 5px; }
  .room-card input { height: clamp(24px, 6vw, 32px); padding: 3px 6px; }
  .room-card button { min-height: 27px; padding: 4px 7px; font-size: clamp(9px, 2.2vw, 12px); }
  .upgrade-panel { column-gap: clamp(5px, 1.8vw, 10px); }
  .upgrade-information,
  .upgrade-branches { gap: clamp(2px, 0.8vw, 4px); }
  .branch-option { gap: clamp(3px, 1vw, 7px); }
  .building-cards { gap: 4px; }
  .building-card { min-height: 0; padding: 4px; }
  .building-name { font-size: clamp(8px, 2.3vw, 12px); }
  .building-description { font-size: clamp(6px, 1.7vw, 9px); }
  .building-preview i { font-size: clamp(8px, 2.4vw, 12px); }

  .abilities {
    height: clamp(46px, 9vh, 62px);
    padding: 6px 8px;
  }

  .session-status { font-size: clamp(10px, 2.5vw, 14px); }

  .ability-controls { gap: clamp(3px, 1vw, 7px); }
}

@media (orientation: landscape) and (max-height: 420px) {
  :root {
    --field-width: min(98vw, 240vh);
    --block-height: 58px;
    --block-gap: 6px;
  }

  .information {
    height: var(--block-height);
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: 1fr;
    gap: 6px;
    padding: 5px 8px;
  }

  .resources {
    grid-column: 1;
    grid-row: 1;
    font-size: clamp(10px, 1.9vw, 13px);
  }

  .timer {
    grid-column: 2;
    grid-row: 1;
    font-size: clamp(19px, 4.8vh, 25px);
  }

  .income-exchange {
    grid-column: 3;
    grid-row: 1;
    font-size: clamp(10px, 1.8vw, 13px);
    gap: 3px;
  }

  .exchange-arrow { width: 13px; }
  #buy-income { min-height: 26px; padding: 3px 5px; }
  .lobby-screen { padding: 7px; }
  .identity-card { height: 100%; width: auto; min-width: 0; padding: 10px 16px; gap: 6px; }
  .identity-card input { height: 26px; }
  .identity-card button { min-height: 27px; }
  .main-menu { gap: 7px; }
  .private-menu { gap: 0; }
  .room-card { padding: 10px 15px; }
  .room-card input { height: 27px; }
  .room-card button { min-height: 28px; }
  .waiting-card { padding: 12px; gap: 8px; }
  .waiting-card button { min-height: 27px; padding: 4px 8px; }
  .abilities { height: 40px; padding: 4px 7px; }
  .ability-button { min-height: 0; }
}

@media (orientation: portrait) and (max-width: 760px) {
  .game { display: none; }
  .rotate-device {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--text);
    font-size: clamp(22px, 7vw, 34px);
    text-align: center;
  }
}
