:root {
  color-scheme: dark;
  --bg: #141614;
  --bg-2: #1b1f1c;
  --surface: #232923;
  --surface-2: #2b332d;
  --line: #394238;
  --line-2: #4b574a;
  --text: #f2f5ef;
  --muted: #a9b2a5;
  --faint: #75806f;
  --accent: #73d5c7;
  --accent-2: #5db8ab;
  --good: #82d17d;
  --bad: #ff8c6a;
  --gold: #d8b35e;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--sans);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent-2);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#app,
.app-shell {
  height: 100vh;
  min-height: 100vh;
}

.app-shell {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 350px;
  gap: 18px;
  align-items: center;
  min-height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}

.brand,
.tick-indicator,
.res-chip,
.nav-item,
.chip,
.count,
.side-header span {
  font-family: var(--mono);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span:last-child {
  color: var(--faint);
  font-size: 0.78rem;
}

.brand-dot,
.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(115, 213, 199, 0.7);
}

.resbar {
  display: flex;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.res-chip {
  display: grid;
  grid-template-columns: 26px minmax(52px, auto) minmax(42px, auto);
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 5px 9px;
  border-radius: 6px;
  color: var(--muted);
  cursor: help;
}

.res-chip:hover {
  background: var(--surface);
}

.res-icon {
  display: grid;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--bg);
  object-fit: cover;
}

.res-value {
  color: var(--text);
  font-size: 0.9rem;
  text-align: right;
}

.res-rate {
  color: var(--faint);
  font-size: 0.72rem;
}

.pos {
  color: var(--good) !important;
}

.neg {
  color: var(--bad) !important;
}

.tick-indicator {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.game-time {
  color: var(--text);
  white-space: nowrap;
}

.logout-btn,
.surrender-btn {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 0.72rem;
}

.surrender-btn {
  border-color: rgba(255, 140, 106, 0.4);
  color: var(--bad);
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.35);
  }
}

.main-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 350px;
  height: calc(100vh - 58px);
  min-height: 0;
  overflow: hidden;
}

.leftnav,
.right-panel {
  background: var(--bg-2);
  overflow-y: auto;
}

.leftnav {
  padding: 14px 0;
  border-right: 1px solid var(--line);
}

.nav-section {
  margin: 0;
  padding: 10px 18px 7px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.nav-section.spaced {
  margin-top: 14px;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 8px 18px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  border-left-color: var(--accent);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--faint);
  font-size: 0.72rem;
}

.nav-item strong,
.count,
.side-header span {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--faint);
  font-size: 0.72rem;
}

.viewport {
  min-width: 0;
  background:
    linear-gradient(var(--bg) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--bg) 1px, transparent 1px) 0 0 / 32px 32px,
    #181b18;
  display: flex;
  flex-direction: column;
}

.viewport-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(27, 31, 28, 0.96);
}

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

.viewport-header h1 {
  margin-bottom: 3px;
  font-size: 1.15rem;
}

.viewport-header p,
.build-card p,
.formula-row p,
.empty,
.empty-state {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  min-height: 34px;
  padding: 6px 12px;
  color: var(--muted);
}

.tab.active {
  border-color: var(--accent-2);
  background: var(--surface);
  color: var(--text);
}

.viewport-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 22px;
}

.build-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 12px;
}

.build-card,
.formula-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.build-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 315px;
  padding: 13px;
}

.build-card:hover {
  border-color: var(--accent-2);
}

.build-card.disabled {
  opacity: 0.62;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-head h2,
.side-header h2,
.formula-row h2 {
  margin: 0;
  font-size: 0.96rem;
}

.thumb {
  width: 100%;
  height: 108px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    repeating-linear-gradient(-45deg, #30382f 0 7px, #252b25 7px 14px);
}

.chip-row,
.cost {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 23px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.72rem;
}

.resource-token {
  white-space: nowrap;
}

.resource-token img {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  object-fit: cover;
}

.token-value {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chip.have {
  border-color: rgba(130, 209, 125, 0.45);
  color: var(--good);
}

.chip.missing {
  border-color: rgba(255, 140, 106, 0.55);
  color: var(--bad);
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.card-footer button {
  min-width: 94px;
  min-height: 36px;
  background: var(--accent);
  color: #10201d;
  font-weight: 800;
}

.action-slot {
  display: inline-flex;
  min-width: 94px;
}

.action-slot button {
  width: 100%;
}

.action-slot button:disabled {
  pointer-events: none;
}

.right-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  border-left: 1px solid var(--line);
}

.right-panel section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.queue-list,
.log-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  list-style: none;
}

.queue-list li {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) minmax(80px, 1fr) 28px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

meter {
  width: 100%;
}

.log-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.log-list li span {
  color: var(--gold);
  font-family: var(--mono);
}

.formula-list {
  display: grid;
  gap: 10px;
}

.formula-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, auto);
  gap: 12px;
  align-items: start;
  padding: 13px;
}

.formula-row strong {
  color: var(--accent);
  font-family: var(--mono);
  text-align: right;
}

.formula-row small {
  grid-column: 1 / -1;
  color: var(--faint);
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.player-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.player-card.current {
  border-color: var(--accent-2);
}

.player-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-card header h2 {
  margin: 0;
}

.player-card header span {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 0.78rem;
}

.player-resources {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.player-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.player-columns strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
}

.player-columns ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.player-columns li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.muted-line {
  color: var(--faint);
}

.management-list {
  display: grid;
  gap: 10px;
}

.management-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 112px;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.management-row img {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.management-row h2 {
  margin: 0 0 5px;
}

.management-row h2 span {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.management-row p {
  margin-bottom: 8px;
}

.management-row button {
  min-height: 38px;
}

[data-tip] {
  position: relative;
}

.game-tooltip {
  position: fixed;
  z-index: 1000;
  width: min(360px, calc(100vw - 16px));
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: #0f120f;
  color: var(--text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.42);
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.4;
  pointer-events: none;
}

.game-tooltip[hidden] {
  display: none;
}

.game-tooltip div + div {
  margin-top: 3px;
}

.game-tooltip .tip-title {
  margin-bottom: 5px;
  color: var(--text);
  font-weight: 800;
}

.game-tooltip .tip-ok {
  color: var(--good);
}

.game-tooltip .tip-missing {
  color: var(--bad);
}

.empty,
.empty-state {
  padding: 14px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 15%, rgba(115, 213, 199, 0.16), transparent 34%),
    linear-gradient(var(--bg) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--bg) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--bg-2);
}

.defeat-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(var(--bg) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--bg) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--bg-2);
}

.defeat-panel {
  display: grid;
  gap: 18px;
  width: min(520px, 100%);
  padding: 26px;
  border: 1px solid rgba(255, 140, 106, 0.65);
  border-radius: 10px;
  background: rgba(35, 41, 35, 0.98);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.defeat-panel h1 {
  margin-bottom: 8px;
}

.defeat-panel p {
  color: var(--muted);
  line-height: 1.45;
}

.defeat-panel button {
  min-height: 42px;
  background: var(--bad);
  color: #1f0f0a;
  font-weight: 800;
}

.kicker {
  margin-bottom: 8px;
  color: var(--bad) !important;
  font-family: var(--mono);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.login-panel {
  width: min(430px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(35, 41, 35, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.login-brand h1 {
  margin: 0 0 3px;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.login-form input {
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
}

.login-form button {
  min-height: 42px;
  background: var(--accent);
  color: #10201d;
  font-weight: 800;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--bad);
}

.load-error {
  width: min(640px, calc(100% - 32px));
  margin: 18vh auto 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .resbar {
    justify-content: flex-start;
  }

  .main-shell {
    grid-template-columns: 210px minmax(0, 1fr);
    height: auto;
    min-height: calc(100vh - 58px);
    overflow: visible;
  }

  .right-panel {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .main-shell {
    grid-template-columns: 1fr;
  }

  .leftnav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-section {
    grid-column: 1 / -1;
  }

  .viewport-header,
  .card-footer,
  .right-panel {
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .tabs {
    width: 100%;
  }

  .tab,
  .card-footer button {
    flex: 1;
  }
}
