:root {
  color-scheme: dark;
  --ink: #12151b;
  --paper: #f4f0dc;
  --panel: rgba(19, 23, 31, 0.9);
  --panel-strong: rgba(16, 19, 26, 0.96);
  --line: rgba(255, 255, 255, 0.14);
  --muted: #aeb5c4;
  --blue: #58c6e8;
  --green: #78c06c;
  --yellow: #e8c14d;
  --orange: #d98245;
  --red: #df6258;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #1b2228;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #f8f5e8;
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.14);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background:
    radial-gradient(circle at 60% 42%, rgba(88, 198, 232, 0.13), transparent 34%),
    linear-gradient(135deg, #2f5447, #263d48 52%, #27303b);
  transition:
    filter 220ms ease,
    transform 220ms ease;
}

#app.menu-active #gameCanvas {
  filter: blur(5px) saturate(1.2) brightness(0.72);
  transform: scale(1.018);
}

#app.menu-active .topbar,
#app.menu-active .build-panel,
#app.menu-active .operations-panel,
#app.menu-active .inspector,
#app.menu-active .command-strip,
#app.menu-active .event-log {
  opacity: 0;
  pointer-events: none;
}

#app.build-hidden .build-panel,
#app.operations-hidden .operations-panel {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-12px);
}

#app.inspector-hidden .inspector {
  opacity: 0;
  pointer-events: none;
  transform: translateX(12px);
}

#app.log-hidden .event-log {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}

#app.log-hidden .inspector {
  bottom: 104px;
}

.main-menu {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(90deg, rgba(10, 13, 18, 0.88), rgba(10, 13, 18, 0.48) 46%, rgba(10, 13, 18, 0.78)),
    radial-gradient(circle at 62% 44%, rgba(88, 198, 232, 0.16), transparent 32%);
}

.main-menu.open {
  display: grid;
}

.menu-shell {
  width: min(560px, calc(100vw - 40px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 18px;
  background: rgba(15, 19, 27, 0.88);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(18px);
}

.menu-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.menu-mark {
  width: 46px;
  height: 46px;
}

.menu-head p {
  margin: 0 0 3px;
  color: #9ee9ff;
  font-size: 13px;
  font-weight: 850;
}

.menu-head h1 {
  margin: 0;
  color: #fff9dd;
  font-size: 34px;
  line-height: 1;
}

.menu-section {
  margin-top: 16px;
}

.menu-credits {
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.menu-section-title {
  margin-bottom: 8px;
  color: #ffe58a;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.menu-copy {
  margin: 0;
  color: #d8dfec;
  font-size: 14px;
  line-height: 1.55;
}

.menu-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.menu-actions button {
  min-height: 50px;
  padding: 0 14px;
  font-weight: 900;
}

.menu-primary {
  border-color: rgba(232, 193, 77, 0.6);
  background: rgba(232, 193, 77, 0.22);
}

.menu-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.menu-stats span,
.menu-stats strong {
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #fff9dd;
  background: rgba(255, 255, 255, 0.07);
  font-size: 12px;
  font-weight: 850;
}

.menu-stats strong {
  color: #12151b;
  background: #e8c14d;
}

.credits-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.credit-card {
  min-width: 0;
  display: grid;
  grid-template-rows: 70px auto auto;
  gap: 6px;
  padding: 10px;
  border-left: 3px solid var(--blue);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
}

.credit-logo {
  display: grid;
  place-items: center;
  min-height: 70px;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.34);
}

.credit-logo-light {
  background: #f4f0dc;
}

.credit-logo img {
  display: block;
  max-width: 100%;
  max-height: 58px;
  object-fit: contain;
}

.credit-card strong {
  display: block;
  color: #fff9dd;
  font-size: 14px;
  line-height: 1.15;
}

.credit-card > span:not(.credit-logo) {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.topbar,
.build-panel,
.operations-panel,
.inspector,
.command-strip,
.event-log {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(16px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.topbar {
  top: 16px;
  left: 16px;
  right: 16px;
  min-height: 86px;
  display: grid;
  grid-template-columns: minmax(190px, 1.35fr) repeat(6, minmax(92px, 0.65fr));
  gap: 8px;
  align-items: stretch;
  padding: 10px;
  border-radius: 8px;
}

.brand,
.stat,
.market {
  min-width: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  padding: 10px 12px;
}

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

.brand strong,
.stat strong,
.market strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff9dd;
}

.brand small,
.stat span,
.market span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
}

.stat em,
.market em {
  display: block;
  margin-bottom: 3px;
  overflow: hidden;
  color: rgba(216, 223, 236, 0.72);
  font-size: 10px;
  font-style: normal;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small {
  margin: 1px 0 0;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: 0 0 auto;
  background:
    radial-gradient(circle at center, #9ee9ff 0 22%, transparent 23%),
    conic-gradient(from 18deg, var(--yellow), var(--blue), var(--orange), var(--yellow));
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 22px rgba(88, 198, 232, 0.5);
}

.market {
  border-color: rgba(232, 193, 77, 0.38);
}

.build-panel {
  left: 16px;
  top: 116px;
  bottom: 104px;
  width: 292px;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.operations-panel {
  left: 322px;
  top: 116px;
  bottom: 104px;
  width: 332px;
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
}

.ops-block + .ops-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.ops-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #fff5cf;
  font-size: 13px;
  font-weight: 850;
}

.ops-title strong {
  color: #9ee9ff;
  font-size: 12px;
}

.objective-list,
.diagnostic-list {
  display: grid;
  gap: 8px;
}

.objective-item {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 7px 10px;
  align-items: center;
  min-height: 54px;
  padding: 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
}

.objective-item strong,
.diagnostic-row strong,
.contract-name {
  display: block;
  color: #fff9de;
  font-size: 12px;
  line-height: 1.2;
}

.objective-item small,
.diagnostic-row small,
.contract-panel p,
.muted {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.objective-check {
  display: grid;
  place-items: center;
  min-width: 30px;
  min-height: 24px;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.07);
  font-size: 10px;
  font-weight: 900;
}

.objective-item.complete {
  border: 1px solid rgba(120, 192, 108, 0.4);
  background: rgba(120, 192, 108, 0.13);
}

.objective-item.complete .objective-check {
  color: #102118;
  background: #78c06c;
}

.mini-bar {
  grid-column: 1 / -1;
  position: relative;
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.mini-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--yellow));
}

.contract-panel p {
  margin: 4px 0 8px;
}

.contract-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #dbe2ef;
  font-size: 11px;
}

.contract-meta .ok {
  color: #9bea91;
}

.contract-meta .warn {
  color: #ffb86c;
}

.contract-progress span {
  background: linear-gradient(90deg, var(--yellow), var(--green));
}

.contract-reward {
  margin-top: 7px;
  color: #ffe58a;
  font-size: 11px;
  font-weight: 850;
}

.diagnostic-row {
  padding: 8px;
  border-left: 3px solid var(--blue);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
}

.diagnostic-row.ok {
  border-left-color: var(--green);
}

.diagnostic-row.warn {
  border-left-color: var(--yellow);
}

.diagnostic-row.danger {
  border-left-color: var(--red);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
}

.panel-head p {
  margin: 0;
  color: #fff5cf;
  font-weight: 800;
  letter-spacing: 0;
}

.panel-head button {
  padding: 8px 10px;
  font-size: 13px;
}

.build-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.build-section-title {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  color: #ffe58a;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.build-card {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: start;
  width: 100%;
  min-height: 96px;
  padding: 9px;
  text-align: left;
}

.build-card.selected {
  border-color: rgba(88, 198, 232, 0.75);
  background: rgba(88, 198, 232, 0.18);
}

.build-icon,
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 2px solid rgba(255, 255, 255, 0.62);
  overflow: hidden;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.swatch {
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.12);
}

.sprite-icon {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent),
    rgba(255, 255, 255, 0.07);
}

.sprite-icon img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  transform: translateY(2px);
}

.swatch-icon {
  color: #12151b;
  font-size: 10px;
  font-weight: 900;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.12);
}

.terrain-icon {
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.12);
}

.terrain-road {
  background:
    linear-gradient(90deg, transparent 0 42%, rgba(232, 193, 77, 0.9) 42% 58%, transparent 58% 100%),
    #4f5356;
}

.terrain-crosswalk {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 245, 0.96) 0 5px, #4f5356 5px 10px);
}

.terrain-concrete {
  background:
    radial-gradient(circle at 70% 28%, rgba(70, 76, 74, 0.28) 0 2px, transparent 3px),
    #a4aaa7;
}

.terrain-grass {
  background:
    radial-gradient(circle at 28% 68%, rgba(222, 226, 111, 0.36) 0 3px, transparent 4px),
    #66a96a;
}

.terrain-river {
  background:
    linear-gradient(135deg, rgba(207, 249, 255, 0.48) 0 16%, transparent 18% 42%, rgba(207, 249, 255, 0.34) 44% 58%, transparent 60%),
    #2f86a2;
}

.build-card strong {
  display: block;
  color: #fff9de;
  font-size: 13px;
  line-height: 1.18;
}

.build-card small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  margin-top: 2px;
}

.cost {
  align-self: center;
  color: #ffe58a;
  font-weight: 800;
  font-size: 12px;
}

.inspector {
  right: 16px;
  top: 116px;
  bottom: 276px;
  width: 330px;
  overflow: auto;
  border-radius: 8px;
  padding: 14px;
}

.inspector h2 {
  margin: 0 0 4px;
  color: #fff5cf;
  font-size: 18px;
  line-height: 1.2;
}

.inspector p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.management-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}

.management-tabs button {
  min-height: 34px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 850;
}

.management-tabs button.active {
  border-color: rgba(88, 198, 232, 0.72);
  background: rgba(88, 198, 232, 0.18);
}

.management-section-title,
.tier-title {
  margin: 14px 0 8px;
  color: #ffe58a;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.employee-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.employee-summary div,
.research-points {
  min-width: 0;
  border-radius: 7px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.employee-summary span,
.research-points span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.employee-summary strong,
.research-points strong {
  display: block;
  margin-top: 2px;
  color: #fff9dd;
  font-size: 13px;
}

.employee-list,
.hire-list,
.research-tier {
  display: grid;
  gap: 8px;
}

.employee-card,
.hire-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.employee-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.employee-card strong,
.hire-card strong,
.research-node strong {
  display: block;
  color: #fff9dd;
  font-size: 13px;
  line-height: 1.2;
}

.employee-card small,
.hire-card small,
.research-node small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.employee-head span {
  flex: 0 0 auto;
  color: #ffe58a;
  font-size: 11px;
  font-weight: 850;
}

.employee-card p,
.hire-card p {
  margin: 0;
  font-size: 12px;
}

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

.role-grid button,
.employee-card > button,
.hire-card button {
  min-height: 32px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 800;
}

.role-grid button.active {
  border-color: rgba(120, 192, 108, 0.62);
  background: rgba(120, 192, 108, 0.18);
}

.research-points {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.research-tree {
  display: grid;
  gap: 8px;
}

.research-node {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 94px;
  padding: 10px;
  text-align: left;
  border-left: 3px solid var(--blue);
}

.research-node:disabled {
  opacity: 0.68;
}

.research-node span {
  color: #9ee9ff;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.research-node em {
  color: #ffe58a;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.research-node.unlocked {
  border-left-color: var(--green);
  background: rgba(120, 192, 108, 0.14);
  opacity: 1;
}

.research-node.locked {
  border-left-color: rgba(255, 255, 255, 0.18);
  opacity: 0.48;
}

.meter {
  margin-top: 12px;
}

.meter-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #dbe2ef;
  font-size: 12px;
  margin-bottom: 5px;
}

.bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
}

.bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--yellow), var(--green));
}

.inspector-actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.inspector-actions button {
  width: 100%;
  padding: 10px;
}

.inspector-actions button.danger {
  border-color: rgba(223, 98, 88, 0.5);
  background: rgba(223, 98, 88, 0.14);
}

.inspector-actions button.danger:hover {
  border-color: rgba(223, 98, 88, 0.78);
  background: rgba(223, 98, 88, 0.22);
}

.command-strip {
  left: 16px;
  right: 16px;
  bottom: 16px;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border-radius: 8px;
  overflow: auto;
}

.command-strip button {
  min-height: 48px;
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
}

.command-strip .primary {
  border-color: rgba(232, 193, 77, 0.55);
  background: rgba(232, 193, 77, 0.2);
}

.panel-toggle.active {
  border-color: rgba(88, 198, 232, 0.72);
  background: rgba(88, 198, 232, 0.18);
}

.event-log {
  right: 16px;
  bottom: 104px;
  width: 330px;
  height: 154px;
  border-radius: 8px;
  padding: 12px;
  overflow: hidden;
}

.ticker-title {
  margin-bottom: 8px;
  color: #fff5cf;
  font-weight: 800;
  font-size: 13px;
}

#eventLog {
  display: grid;
  gap: 6px;
}

.log-line {
  color: #cfd6e4;
  font-size: 12px;
  line-height: 1.35;
}

.log-line strong {
  color: #ffe58a;
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: repeat(3, 1fr);
  }

  .brand {
    grid-column: 1 / -1;
  }

  .build-panel {
    width: 248px;
  }

  .operations-panel {
    left: 278px;
    width: 300px;
  }

  .inspector,
  .event-log {
    width: 292px;
  }

  .command-strip {
    left: 16px;
    right: 16px;
  }
}

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

  .topbar {
    left: 8px;
    right: 8px;
    top: 8px;
    grid-template-columns: repeat(2, 1fr);
    max-height: 172px;
    overflow: auto;
  }

  .build-panel,
  .operations-panel,
  .inspector,
  .event-log {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 104px;
    width: auto;
  }

  .build-panel {
    height: 220px;
  }

  .operations-panel,
  .inspector {
    height: min(46vh, 320px);
  }

  .event-log {
    height: 160px;
    overflow: hidden;
  }

  .build-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .command-strip {
    left: 8px;
    right: 8px;
    bottom: 8px;
    overflow: auto;
  }
}
